[chronojump] guiTests with encoder gravitational support



commit 869c8042e48af230da276b741055376b270f41b6
Author: Xavier de Blas <xaviblas gmail com>
Date:   Fri Apr 14 08:39:55 2017 +0200

    guiTests with encoder gravitational support

 glade/app1.glade      |   19 ++++++++++++-
 src/encoderCapture.cs |   50 +++++++++++++++++++++++++++++++--
 src/gui/chronojump.cs |   42 +++++++++++++++++++++++-----
 src/gui/guiTests.cs   |   73 +++++++++++++++++++++++++++++++++++++++---------
 4 files changed, 159 insertions(+), 25 deletions(-)
---
diff --git a/glade/app1.glade b/glade/app1.glade
index c60585e..ac95bc1 100644
--- a/glade/app1.glade
+++ b/glade/app1.glade
@@ -1602,6 +1602,20 @@
                                       </packing>
                                     </child>
                                     <child>
+                                      <widget class="GtkComboBox" id="combo_gui_tests">
+                                        <property name="visible">True</property>
+                                        <property name="can_focus">False</property>
+                                        <property name="active">1</property>
+                                        <property name="items">EncoderGravitatoryCapture
+EncoderInertialCapture</property>
+                                      </widget>
+                                      <packing>
+                                        <property name="expand">True</property>
+                                        <property name="fill">True</property>
+                                        <property name="position">1</property>
+                                      </packing>
+                                    </child>
+                                    <child>
                                       <widget class="GtkButton" id="button_gui_tests">
                                         <property name="label">GUI TESTS</property>
                                         <property name="visible">True</property>
@@ -1612,7 +1626,7 @@
                                       <packing>
                                         <property name="expand">True</property>
                                         <property name="fill">True</property>
-                                        <property name="position">1</property>
+                                        <property name="position">2</property>
                                       </packing>
                                     </child>
                                   </widget>
@@ -20133,6 +20147,9 @@ then click this button.</property>
                                                             <child>
                                                             <placeholder/>
                                                             </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
                                                             </widget>
                                                             <packing>
                                                             <property name="expand">False</property>
diff --git a/src/encoderCapture.cs b/src/encoderCapture.cs
index 17c0818..6110fe2 100644
--- a/src/encoderCapture.cs
+++ b/src/encoderCapture.cs
@@ -90,6 +90,7 @@ public abstract class EncoderCapture
        protected bool capturingFirstPhase;
 
        protected static SerialPort sp;
+       private Random rand;
        protected bool finish;
        protected bool capturingInertialBG;
        protected bool showOnlyBars;
@@ -121,7 +122,12 @@ public abstract class EncoderCapture
                this.simulated = simulated;
 
                //---- a) open port -----
-               if(! simulated && ! capturingInertialBG) {
+               if(simulated)
+               {
+                       rand = new Random(40);
+                       SimulatedReset();
+               }
+               else if(! simulated && ! capturingInertialBG) {
                        LogB.Debug("runEncoderCaptureCsharp start port:", port);
                        sp = new SerialPort(port);
                        sp.BaudRate = 115200;
@@ -545,6 +551,40 @@ public abstract class EncoderCapture
        }
        */
 
+       private bool simulatedGoingUp = false;
+       private int simulatedMaxValue = 400;
+       private int simulatedLength;
+       private int simulatedMaxLength = 4000; //when signal stops
+
+       public void SimulatedReset()
+       {
+               simulatedLength = 0;
+       }
+
+       private int simulateByte()
+       {
+               System.Threading.Thread.Sleep(1);
+
+               //return 0's to end if signal needs to end
+               simulatedLength ++;
+               if(simulatedLength > simulatedMaxLength)
+                       return 0;
+
+               //get new value
+               int simValue;
+               if(simulatedGoingUp)
+                       simValue = rand.Next(0, 4);
+               else
+                       simValue = rand.Next(-4, 0);
+
+               //change direction if needed
+               if(simulatedGoingUp && sum > simulatedMaxValue)
+                       simulatedGoingUp = false;
+               else if(! simulatedGoingUp && sum < -1 * simulatedMaxValue)
+                       simulatedGoingUp = true;
+
+               return simValue;
+       }
 
        protected int readByte()
        {
@@ -556,8 +596,12 @@ public abstract class EncoderCapture
                */
                        if(capturingInertialBG)
                                return EncoderCaptureInertialBackgroundStatic.GetNext();
-                       else
-                               return sp.ReadByte();
+                       else {
+                               if(simulated)
+                                       return simulateByte();
+                               else
+                                       return sp.ReadByte();
+                       }
                //}
        }
        protected int convertByte(int b)
diff --git a/src/gui/chronojump.cs b/src/gui/chronojump.cs
index 56d7af4..9048355 100644
--- a/src/gui/chronojump.cs
+++ b/src/gui/chronojump.cs
@@ -43,6 +43,7 @@ public partial class ChronoJumpWindow
        
        [Widget] Gtk.HBox hbox_gui_tests;
        [Widget] Gtk.SpinButton spin_gui_tests;
+       [Widget] Gtk.ComboBox combo_gui_tests;
        [Widget] Gtk.Button button_carles;
        
        [Widget] Gtk.Viewport viewport_chronojump_logo;
@@ -2337,7 +2338,7 @@ public partial class ChronoJumpWindow
 
                if(reportWin != null)
                        reportWin.FillTreeView();
-               
+
                chronojumpWindowTestsNext();
        }
        
@@ -6252,12 +6253,39 @@ LogB.Debug("X");
                preferencesWin.DebugActivated();
        }
 
-       private void on_button_gui_tests_clicked (object o, EventArgs args) {
-               chronojumpWindowTestsStart(Convert.ToInt32(spin_gui_tests.Value),
-                               //CJTests.SequenceChangeMultitest
-                               //CJTests.SequenceRJsSimulatedFinishCancel
-                               CJTests.SequenceEncoderInertialCapture
-                               );
+       private void on_button_gui_tests_clicked (object o, EventArgs args)
+       {
+               string selected = UtilGtk.ComboGetActive(combo_gui_tests);
+               if(selected == "")
+               {
+                       new DialogMessage(Constants.MessageTypes.WARNING, "Need to select one test");
+                       return;
+               }
+
+               if (selected == "EncoderGravitatoryCapture" || selected == "EncoderInertialCapture")
+               {
+                       if (currentSession == null)
+                       {
+                               new DialogMessage(Constants.MessageTypes.WARNING, "Need to load SIMULATED 
session");
+                               return;
+                       }
+
+                       if (selected == "EncoderGravitatoryCapture")
+                               chronojumpWindowTestsStart(
+                                               Convert.ToInt32(spin_gui_tests.Value),
+                                               CJTests.SequenceEncoderGravitatoryCapture);
+                       else // (selected == "EncoderInertialCapture")
+                               chronojumpWindowTestsStart(
+                                               Convert.ToInt32(spin_gui_tests.Value),
+                                               CJTests.SequenceEncoderInertialCapture);
+               }
+               else
+                       new DialogMessage(Constants.MessageTypes.WARNING, "Selected test: " + selected);
+
+               /* other tests:
+               //CJTests.SequenceChangeMultitest
+               //CJTests.SequenceRJsSimulatedFinishCancel
+               */
        }
        
        private void on_button_carles_clicked (object o, EventArgs args)
diff --git a/src/gui/guiTests.cs b/src/gui/guiTests.cs
index a06ec48..5406ca0 100644
--- a/src/gui/guiTests.cs
+++ b/src/gui/guiTests.cs
@@ -59,9 +59,11 @@ public class CJTests
                ENCODER_SIGNAL_LOAD,
                ENCODER_ECC_CON_INVERT,
                ENCODER_CAPTURE,
+               ENCODER_CAPTURE_CALIBRATE,
                ENCODER_RECALCULATE,
                ENCODER_SET_SAVE_REPS,
                ENCODER_SET_SAVE_REPS_BUCLE,
+               WAIT_5_SECONDS,
                BUCLE_1_ON,
                BUCLE_1_OFF,
                BUCLE_2_ON,
@@ -169,26 +171,28 @@ public class CJTests
        public static List<Types> SequenceEncoderInertialCapture = new List<Types>
        {
                CJTests.Types.MODE_POWERINERTIAL,
-//             CJTests.Types.SESSION_LOAD,
-//             CJTests.Types.BUCLE_1_ON,
-//                     CJTests.Types.PERSON_SELECT, //bucle1startPos //repeat from here //when all persons 
have done a jumps/runs test, will end
-                       CJTests.Types.ENCODER_CAPTURE,
-                       CJTests.Types.ENCODER_CAPTURE,
-                       CJTests.Types.ENCODER_CAPTURE,
-                       CJTests.Types.ENCODER_CAPTURE,
-                       CJTests.Types.ENCODER_CAPTURE,
-                       CJTests.Types.ENCODER_CAPTURE,
-                       CJTests.Types.ENCODER_CAPTURE,
-                       CJTests.Types.ENCODER_CAPTURE,
-                       CJTests.Types.ENCODER_CAPTURE,
-                       CJTests.Types.ENCODER_CAPTURE,
+//             CJTests.Types.SESSION_LOAD, //better load it manually because it's a long process
+//             CJTests.Types.ENCODER_CAPTURE_CALIBRATE,
+               CJTests.Types.BUCLE_1_ON,
+                       CJTests.Types.PERSON_SELECT, //bucle1startPos //repeat from here //when all persons 
have done a jumps/runs test, will end
                        CJTests.Types.ENCODER_CAPTURE,
                        CJTests.Types.ENCODER_CAPTURE,
                        CJTests.Types.ENCODER_CAPTURE,
+                       CJTests.Types.ENCODER_CAPTURE, //4 captures for each person on simulated session
+               CJTests.Types.BUCLE_1_OFF,
+               CJTests.Types.END
+       };
+       public static List<Types> SequenceEncoderGravitatoryCapture = new List<Types>
+       {
+               CJTests.Types.MODE_POWERGRAVITATORY,
+//             CJTests.Types.SESSION_LOAD, //better load it manually because it's a long process
+               CJTests.Types.BUCLE_1_ON,
+                       CJTests.Types.PERSON_SELECT, //bucle1startPos //repeat from here //when all persons 
have done a jumps/runs test, will end
                        CJTests.Types.ENCODER_CAPTURE,
                        CJTests.Types.ENCODER_CAPTURE,
                        CJTests.Types.ENCODER_CAPTURE,
-//             CJTests.Types.BUCLE_1_OFF,
+                       CJTests.Types.ENCODER_CAPTURE, //4 captures for each person on simulated session
+               CJTests.Types.BUCLE_1_OFF,
                CJTests.Types.END
        };
 
@@ -389,6 +393,10 @@ public partial class ChronoJumpWindow
                        case CJTests.Types.ENCODER_CAPTURE:
                                chronojumpWindowTestsEncoderCapture();
                                break;
+                       case CJTests.Types.ENCODER_CAPTURE_CALIBRATE:
+                               chronojumpWindowTestsEncoderCaptureCalibrate();
+                               callNext = true;
+                               break;
                        case CJTests.Types.ENCODER_RECALCULATE:
                                chronojumpWindowTestsEncoderRecalculate();
                                break;
@@ -399,6 +407,10 @@ public partial class ChronoJumpWindow
                        case CJTests.Types.ENCODER_SET_SAVE_REPS_BUCLE:
                                chronojumpWindowTestsEncoderSetSaveRepsBucle();
                                break;
+                       case CJTests.Types.WAIT_5_SECONDS:
+                               chronojumpWindowTestsWait5seconds();
+                               callNext = true;
+                               break;
                }
 
                if(! bucleContinues)
@@ -442,6 +454,20 @@ public partial class ChronoJumpWindow
                        else
                                radio_menuitem_mode_runs_simple.Active = true;
                }
+               else if(m == Constants.Menuitem_modes.POWERGRAVITATORY)
+               {
+                       if(radio_menuitem_mode_power_gravitatory.Active)
+                               select_menuitem_mode_toggled(Constants.Menuitem_modes.POWERGRAVITATORY);
+                       else
+                               radio_menuitem_mode_power_gravitatory.Active = true;
+               }
+               else if(m == Constants.Menuitem_modes.POWERINERTIAL)
+               {
+                       if(radio_menuitem_mode_power_inertial.Active)
+                               select_menuitem_mode_toggled(Constants.Menuitem_modes.POWERINERTIAL);
+                       else
+                               radio_menuitem_mode_power_inertial.Active = true;
+               }
                
                LogB.TestEnd("chronojumpWindowTestsMode");
        }
@@ -590,6 +616,15 @@ public partial class ChronoJumpWindow
                LogB.TestEnd("chronojumpWindowTestsEncoderCapture");
        }
 
+       private void chronojumpWindowTestsEncoderCaptureCalibrate()
+       {
+               LogB.TestStart("chronojumpWindowTestsEncoderCaptureCalibrate");
+
+               on_button_encoder_inertial_calibrate_clicked (new Object (), new EventArgs ());
+
+               LogB.TestEnd("chronojumpWindowTestsEncoderCaptureCalibrate");
+       }
+
        private void chronojumpWindowTestsEncoderRecalculate()
        {
                LogB.TestStart("chronojumpWindowTestsEncoderRecalculate");
@@ -678,6 +713,16 @@ public partial class ChronoJumpWindow
                }
        }
        
+       private void chronojumpWindowTestsWait5seconds()
+       {
+               LogB.TestStart("chronojumpWindowTestsWait5seconds");
+
+               System.Threading.Thread.Sleep(5000);
+
+               LogB.TestEnd("chronojumpWindowTestsWait5seconds");
+       }
+
+
        void testsReport()
        {
                if(testsSuccededCount > 0 || testsFailedCount > 0)


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]