[chronojump] Reaction time discriminative done!



commit 4fc6e0be3cb6f0708c5b5c0b0782dbb94fc1e6cd
Author: Xavier de Blas <xaviblas gmail com>
Date:   Tue Apr 26 16:23:12 2016 +0200

    Reaction time discriminative done!

 .../chronopic-firmware-multitest.c                 |  141 ++++++++++------
 glade/chronojump.glade                             |  174 ++++++++++++++++----
 src/chronopic.cs                                   |    7 +-
 src/chronopicDetect.cs                             |   18 +-
 src/execute/event.cs                               |    9 +-
 src/execute/reactionTime.cs                        |   66 +++++++-
 src/gui/chronojump.cs                              |   23 ++-
 src/gui/reactionTime.cs                            |   82 ++++++++--
 8 files changed, 396 insertions(+), 124 deletions(-)
---
diff --git a/chronopic-firmware/chronopic-firmware-c/chronopic-firmware-multitest.c 
b/chronopic-firmware/chronopic-firmware-c/chronopic-firmware-multitest.c
index 02e04c9..453dbc5 100644
--- a/chronopic-firmware/chronopic-firmware-c/chronopic-firmware-multitest.c
+++ b/chronopic-firmware/chronopic-firmware-c/chronopic-firmware-multitest.c
@@ -9,7 +9,7 @@
        implementation of new outputs
        anticipation in an animated "led-wheel", using pauses on Timer2
        fast blinking led (flickr)
-  2016 Ferran Suarez & Xavier de Blas: Validation of led-wheel
+  2016 Ferran Suarez & Xavier de Blas: reaction time: Validation of led-wheel, discriminative fully 
implemented
 
 
  *
@@ -34,7 +34,7 @@ History:
              modify ISR and MAIN LOOP's if --> else if
              limit COUNTDEBOUNCE overflow in INTERRUPT(isr)
             assembler is more efficient than C
-  2012-04-19 if PC send command 'J' for port scanning, Chronopic will return 'J'  2014-08-30 if PC send 
command 'V' for getting version, ex: 2.1\n
+  2012-04-19 if PC send command 'J' for port scanning, Chronopic will return 'J'  2014-08-30 if PC send 
command 'n' for getting version, ex: 2.1\n
             if PC send command 'a' get debounce time , ex:0x01
             if PC send command 'bx' for setting debounce time, x is from byte value 0~255(\x0 ~ \xFF) 
   2015-02-19 
@@ -123,21 +123,31 @@ unsigned char my_char;
 unsigned char i = 0, j = 0;
 unsigned char option = 0;     // option: 0 button enable, 1 encoder enable
 unsigned char command_port_scanning = 'J';     // for port scanning, it will return 'J'
-unsigned char command_get_version = 'V';       // for getting version, it will return '2.1'
+unsigned char command_get_version = 'n';       // for getting version, it will return '2.1'
 unsigned char command_get_debounce_time = 'a'; // for getting debounce time, it will return x:0~255(HEX)
 unsigned char command_set_debounce_time = 'b'; // for setting debounce time, pc send two unsigned char, 'Sx' 
-- x:0~255
-unsigned char command_reaction_time_rb3_on = 'R';
-unsigned char command_reaction_time_rb6_on = 'S';
-unsigned char command_reaction_time_rb7_on = 'T';
-unsigned char command_reaction_time_rb3_off = 'r';
-unsigned char command_reaction_time_rb6_off = 's';
-unsigned char command_reaction_time_rb7_off = 't';
 unsigned char command_reaction_time_animation_light = 'l';
 unsigned char command_reaction_time_animation_flicker = 'f';
-unsigned char command_reaction_time_animation_discriminative1 = 'd'; //d for 'd'iscriminative
-unsigned char command_reaction_time_animation_discriminative2 = 'D';
-unsigned char command_reaction_time_animation_discriminative3 = 'i'; //i for d'i'scriminative
-unsigned char command_reaction_time_animation_discriminative4 = 'I';
+
+unsigned char command_reaction_time_disc_red           = 'r';
+unsigned char command_reaction_time_disc_yellow        = 's';
+unsigned char command_reaction_time_disc_green                 = 't';
+unsigned char command_reaction_time_disc_red_yellow    = 'u';
+unsigned char command_reaction_time_disc_red_green     = 'v';
+unsigned char command_reaction_time_disc_yellow_green  = 'w';
+unsigned char command_reaction_time_disc_all           = 'x';
+
+unsigned char command_reaction_time_disc_red_bz        = 'R';
+unsigned char command_reaction_time_disc_yellow_bz     = 'S';
+unsigned char command_reaction_time_disc_green_bz      = 'T';
+unsigned char command_reaction_time_disc_red_yellow_bz = 'U';
+unsigned char command_reaction_time_disc_red_green_bz  = 'V';
+unsigned char command_reaction_time_disc_yellow_green_bz= 'W';
+unsigned char command_reaction_time_disc_all_bz                = 'X';
+
+unsigned char command_reaction_time_disc_only_bz       = 'Z';
+
+
 unsigned char position = 0;
 unsigned int timer2Times;
 
@@ -150,11 +160,14 @@ unsigned int timer2Times;
 //TODO: maybe n_times have to be done 4 times to have reasonable values (between 0.0125 and 3.2 seconds)
 //2016 - With 1000 fps camera validation, found animation_tick=63 the best value
 unsigned int animation_tick = 63;
-unsigned int animation_tick_n_times = 160;
+unsigned int animation_tick_n_times = 160; //default value
 
 unsigned char animation_light_should_run = 0; //0 until and 'l' is sent from Chronojump
 unsigned char flicker_light_should_run = 0; //0 until and 'f' is sent from Chronojump
+
+unsigned char discriminative_light_should_run = 0; 
 unsigned char discriminative_running = 0;
+unsigned char discriminative_light_signal;
 
 char version_major = '1';
 char version_minor = '1';
@@ -165,6 +178,13 @@ char version_minor = '1';
 //-- encoder's valus
 //char encoder_count = 0; //wade
 
+void zero_value_timer_1()
+{
+       TMR1HH = 0;
+       TMR1H = 0;
+       TMR1L = 0;
+}
+
 
 // Interruptions routine
 // Find the interruption cause
@@ -211,9 +231,7 @@ void isr(void) __interrupt 0
                        {
                                //-- It's the first event after reset
                                //-- Put counter on zero and go to status reset=0
-                               TMR1HH = 0;
-                               TMR1H = 0;
-                               TMR1L = 0;
+                               zero_value_timer_1();
                                reset = 0;
                        }
                        //-- Store the value of chronometer on TIMESTAMP
@@ -222,9 +240,7 @@ void isr(void) __interrupt 0
                        TIMESTAMP_H = TMR1H;
                        TIMESTAMP_L = TMR1L;
                        //-- Initialize timer 1
-                       TMR1HH = 0;
-                       TMR1H = 0;
-                       TMR1L = 0;
+                       zero_value_timer_1();
                        //-- Initialize debouncing counter
                        COUNTDEBOUNCE =  DEBOUNCE_TIME;
 
@@ -525,22 +541,29 @@ void reaction_time_flicker_do()
        }
 }
 
-void reaction_time_discriminative_do(char mode)
+void reaction_time_discriminative_do() 
 {
-       switch(mode) {
-               case 'd':
+       //1st put timer to 0
+       zero_value_timer_1();
+       
+       //2nd fire signal
+       switch(discriminative_light_signal) {
+               case 'r':
                        RB7 = 0; RB3 = 1; RB0 = 0; RB2 = 0; //light red
                        break;
-               case 'D':
+               case 's':
                        RB7 = 0; RB3 = 0; RB0 = 1; RB2 = 1; //light yellow
                        break;
-               case 'i':
+               case 't':
                        RB7 = 0; RB3 = 0; RB0 = 1; RB2 = 0; //light green
                        break;
-               case 'I':
+               case 'Z':
                        RB7 = 0; RB3 = 0; RB0 = 0; RB2 = 1; //buzzer
                        break;
        }
+       
+       //3rd don't call this again
+       discriminative_light_should_run = 2;
 }
 void reaction_time_discriminative_stop()
 {
@@ -705,9 +728,7 @@ void main(void)
        T1CON = 0X31;
     // wade : end
     //-- Zero value
-    TMR1HH = 0;
-    TMR1H = 0;
-    TMR1L = 0;
+    zero_value_timer_1();
     //-- Enable interruption
     // wade : sart
     if (option == 0)
@@ -787,7 +808,7 @@ void main(void)
     //initialize lights stuff for animation wheel
     position = 0;
     timer2Times = animation_tick_n_times;
-    timer2_start();
+    timer2_start(); //TODO: delete this?
 
     
     //****************************
@@ -815,24 +836,24 @@ void main(void)
                        status_serv();
                else if (my_char == command_port_scanning)      // 'J'
                        sci_sendchar(command_port_scanning);
-               else if (my_char == command_get_version)        // 'V'
+               else if (my_char == command_get_version)        // 'n'
                        send_version();
                else if (my_char == command_get_debounce_time)  // 'a'
                        sci_sendline(DEBOUNCE_TIME + '0');      //if DEBOUNCE is 50ms (0x05), returns a 5 (5 
* 10ms = 50ms)
                else if (my_char == command_set_debounce_time)  // 'b'
                        DEBOUNCE_TIME = sci_readchar();
-               else if (my_char == command_reaction_time_rb3_on) // 'R'
-                       RB0 = 1; //RB3 = 1
-               else if (my_char == command_reaction_time_rb6_on) // 'S'
-                       RB2 = 1; //RB6 = 1
-               else if (my_char == command_reaction_time_rb7_on) // 'T'
-                       RB7 = 1;
-               else if (my_char == command_reaction_time_rb3_off) // 'r'
-                       RB0 = 0; //RB3 = 0
-               else if (my_char == command_reaction_time_rb6_off) // 's'
-                       RB2 = 0; //RB6 = 0
-               else if (my_char == command_reaction_time_rb7_off) // 't'
-                       RB7 = 0;
+               //else if (my_char == command_reaction_time_rb3_on) // 'R'
+               //      RB0 = 1; //RB3 = 1
+               //else if (my_char == command_reaction_time_rb6_on) // 'S'
+               //      RB2 = 1; //RB6 = 1
+               //else if (my_char == command_reaction_time_rb7_on) // 'T'
+               //      RB7 = 1;
+               //else if (my_char == command_reaction_time_rb3_off) // 'r'
+               //      RB0 = 0; //RB3 = 0
+               //else if (my_char == command_reaction_time_rb6_off) // 's'
+               //      RB2 = 0; //RB6 = 0
+               //else if (my_char == command_reaction_time_rb7_off) // 't'
+               //      RB7 = 0;
                else if (my_char == command_reaction_time_animation_light) { // 'l'
                        animation_light_convert(sci_readchar());
                        animation_light_should_run = 1;
@@ -842,13 +863,29 @@ void main(void)
                        flicker_light_should_run = 1;
                }
                else if (
-                               my_char == command_reaction_time_animation_discriminative1 ||
-                               my_char == command_reaction_time_animation_discriminative2 ||
-                               my_char == command_reaction_time_animation_discriminative3 ||
-                               my_char == command_reaction_time_animation_discriminative4 ) 
-               { // 'd', 'D', 'i', 'I'
-                       reaction_time_discriminative_do(my_char);
-                       discriminative_running = 1;
+                               my_char == command_reaction_time_disc_red ||
+                               my_char == command_reaction_time_disc_yellow ||
+                               my_char == command_reaction_time_disc_green ||
+                               my_char == command_reaction_time_disc_red_yellow ||
+                               my_char == command_reaction_time_disc_red_green ||
+                               my_char == command_reaction_time_disc_yellow_green ||
+                               my_char == command_reaction_time_disc_all ||
+                               my_char == command_reaction_time_disc_red_bz ||
+                               my_char == command_reaction_time_disc_yellow_bz ||
+                               my_char == command_reaction_time_disc_green_bz ||
+                               my_char == command_reaction_time_disc_red_yellow_bz ||
+                               my_char == command_reaction_time_disc_red_green_bz ||
+                               my_char == command_reaction_time_disc_yellow_green_bz ||
+                               my_char == command_reaction_time_disc_all_bz ||
+                               my_char == command_reaction_time_disc_only_bz
+                       ) {
+                       //use 10ms debounce
+                       DEBOUNCE_TIME = 0x01;
+
+                       //reaction_time_discriminative_do(my_char);
+                       discriminative_light_signal = my_char;
+               
+                       discriminative_light_should_run = 1;
                }
                else
                        send_error();
@@ -864,6 +901,10 @@ void main(void)
                        reaction_time_animation_lights_do();
                else if(flicker_light_should_run == 1)
                        reaction_time_flicker_do();
+               else if(discriminative_light_should_run == 1) {
+                       discriminative_running = 1;
+                       reaction_time_discriminative_do();
+               }
            }
            else if (status == STAT_DEBOUNCE)   // status = DEBOUNCE?
            {
diff --git a/glade/chronojump.glade b/glade/chronojump.glade
index b91a53d..8b0b3c3 100644
--- a/glade/chronojump.glade
+++ b/glade/chronojump.glade
@@ -5255,98 +5255,94 @@ after time</property>
                                                             </packing>
                                                             </child>
                                                             <child>
-                                                            <widget class="GtkHBox" id="hbox152">
+                                                            <widget class="GtkHBox" id="hbox21">
                                                             <property name="visible">True</property>
                                                             <property name="can_focus">False</property>
                                                             <property name="spacing">4</property>
                                                             <child>
-                                                            <widget class="GtkLabel" id="label178">
+                                                            <widget class="GtkLabel" id="label12">
                                                             <property name="visible">True</property>
                                                             <property name="can_focus">False</property>
                                                             <property name="label">[</property>
                                                             </widget>
                                                             <packing>
-                                                            <property name="expand">False</property>
-                                                            <property name="fill">False</property>
+                                                            <property name="expand">True</property>
+                                                            <property name="fill">True</property>
                                                             <property name="position">0</property>
                                                             </packing>
                                                             </child>
                                                             <child>
-                                                            <widget class="GtkRadioButton" 
id="radiobutton_reaction_time_disc_lr">
-                                                            <property name="label">red</property>
+                                                            <widget class="GtkCheckButton" 
id="check_reaction_time_disc_red">
+                                                            <property name="label" 
translatable="yes">red</property>
                                                             <property name="visible">True</property>
                                                             <property name="can_focus">True</property>
                                                             <property 
name="receives_default">False</property>
-                                                            <property name="active">True</property>
                                                             <property name="draw_indicator">True</property>
                                                             </widget>
                                                             <packing>
-                                                            <property name="expand">False</property>
-                                                            <property name="fill">False</property>
+                                                            <property name="expand">True</property>
+                                                            <property name="fill">True</property>
                                                             <property name="position">1</property>
                                                             </packing>
                                                             </child>
                                                             <child>
-                                                            <widget class="GtkRadioButton" 
id="radiobutton_reaction_time_disc_ly">
-                                                            <property name="label">yellow</property>
+                                                            <widget class="GtkCheckButton" 
id="check_reaction_time_disc_yellow">
+                                                            <property name="label" 
translatable="yes">yellow</property>
                                                             <property name="visible">True</property>
                                                             <property name="can_focus">True</property>
                                                             <property 
name="receives_default">False</property>
                                                             <property name="draw_indicator">True</property>
-                                                            <property 
name="group">radiobutton_reaction_time_disc_lr</property>
                                                             </widget>
                                                             <packing>
-                                                            <property name="expand">False</property>
-                                                            <property name="fill">False</property>
+                                                            <property name="expand">True</property>
+                                                            <property name="fill">True</property>
                                                             <property name="position">2</property>
                                                             </packing>
                                                             </child>
                                                             <child>
-                                                            <widget class="GtkRadioButton" 
id="radiobutton_reaction_time_disc_lg">
-                                                            <property name="label">green</property>
+                                                            <widget class="GtkCheckButton" 
id="check_reaction_time_disc_green">
+                                                            <property name="label" 
translatable="yes">green</property>
                                                             <property name="visible">True</property>
                                                             <property name="can_focus">True</property>
                                                             <property 
name="receives_default">False</property>
                                                             <property name="draw_indicator">True</property>
-                                                            <property 
name="group">radiobutton_reaction_time_disc_lr</property>
                                                             </widget>
                                                             <packing>
-                                                            <property name="expand">False</property>
-                                                            <property name="fill">False</property>
+                                                            <property name="expand">True</property>
+                                                            <property name="fill">True</property>
                                                             <property name="position">3</property>
                                                             </packing>
                                                             </child>
                                                             <child>
-                                                            <widget class="GtkLabel" id="label186">
+                                                            <widget class="GtkLabel" id="label15">
                                                             <property name="visible">True</property>
                                                             <property name="can_focus">False</property>
                                                             <property name="label">]</property>
                                                             </widget>
                                                             <packing>
-                                                            <property name="expand">False</property>
-                                                            <property name="fill">False</property>
+                                                            <property name="expand">True</property>
+                                                            <property name="fill">True</property>
                                                             <property name="position">4</property>
                                                             </packing>
                                                             </child>
                                                             </widget>
                                                             <packing>
-                                                            <property name="expand">False</property>
-                                                            <property name="fill">False</property>
+                                                            <property name="expand">True</property>
+                                                            <property name="fill">True</property>
                                                             <property name="position">1</property>
                                                             </packing>
                                                             </child>
                                                             <child>
-                                                            <widget class="GtkRadioButton" 
id="radiobutton_reaction_time_disc_bz">
-                                                            <property name="label">Buzzer</property>
+                                                            <widget class="GtkCheckButton" 
id="check_reaction_time_disc_buzzer">
+                                                            <property name="label" 
translatable="yes">buzzer</property>
                                                             <property name="visible">True</property>
                                                             <property name="can_focus">True</property>
                                                             <property 
name="receives_default">False</property>
                                                             <property name="draw_indicator">True</property>
-                                                            <property 
name="group">radiobutton_reaction_time_disc_lr</property>
                                                             </widget>
                                                             <packing>
-                                                            <property name="expand">False</property>
-                                                            <property name="fill">False</property>
+                                                            <property name="expand">True</property>
+                                                            <property name="fill">True</property>
                                                             <property name="position">2</property>
                                                             </packing>
                                                             </child>
@@ -16265,6 +16261,12 @@ on current Chronojump version.</property>
                                                             <child>
                                                             <placeholder/>
                                                             </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
+                                                            <child>
+                                                            <placeholder/>
+                                                            </child>
                                                             </widget>
                                                             <packing>
                                                             <property name="expand">False</property>
@@ -20888,6 +20890,12 @@ by you</property>
                         <child>
                           <placeholder/>
                         </child>
+                        <child>
+                          <placeholder/>
+                        </child>
+                        <child>
+                          <placeholder/>
+                        </child>
                       </widget>
                     </child>
                   </widget>
@@ -21992,6 +22000,12 @@ by you</property>
                         <child>
                           <placeholder/>
                         </child>
+                        <child>
+                          <placeholder/>
+                        </child>
+                        <child>
+                          <placeholder/>
+                        </child>
                       </widget>
                     </child>
                   </widget>
@@ -23588,6 +23602,12 @@ by you</property>
               <placeholder/>
             </child>
             <child>
+              <placeholder/>
+            </child>
+            <child>
+              <placeholder/>
+            </child>
+            <child>
               <widget class="GtkButton" id="button_video_url">
                 <property name="visible">True</property>
                 <property name="can_focus">True</property>
@@ -24241,6 +24261,12 @@ by you</property>
             <child>
               <placeholder/>
             </child>
+            <child>
+              <placeholder/>
+            </child>
+            <child>
+              <placeholder/>
+            </child>
           </widget>
           <packing>
             <property name="expand">True</property>
@@ -36833,6 +36859,42 @@ options</property>
                             <child>
                               <placeholder/>
                             </child>
+                            <child>
+                              <placeholder/>
+                            </child>
+                            <child>
+                              <placeholder/>
+                            </child>
+                            <child>
+                              <placeholder/>
+                            </child>
+                            <child>
+                              <placeholder/>
+                            </child>
+                            <child>
+                              <placeholder/>
+                            </child>
+                            <child>
+                              <placeholder/>
+                            </child>
+                            <child>
+                              <placeholder/>
+                            </child>
+                            <child>
+                              <placeholder/>
+                            </child>
+                            <child>
+                              <placeholder/>
+                            </child>
+                            <child>
+                              <placeholder/>
+                            </child>
+                            <child>
+                              <placeholder/>
+                            </child>
+                            <child>
+                              <placeholder/>
+                            </child>
                           </widget>
                         </child>
                       </widget>
@@ -39212,6 +39274,30 @@ To differentiate between male and female, use the values 1/0, or m/f, or M/F on
                     <child>
                       <placeholder/>
                     </child>
+                    <child>
+                      <placeholder/>
+                    </child>
+                    <child>
+                      <placeholder/>
+                    </child>
+                    <child>
+                      <placeholder/>
+                    </child>
+                    <child>
+                      <placeholder/>
+                    </child>
+                    <child>
+                      <placeholder/>
+                    </child>
+                    <child>
+                      <placeholder/>
+                    </child>
+                    <child>
+                      <placeholder/>
+                    </child>
+                    <child>
+                      <placeholder/>
+                    </child>
                   </widget>
                 </child>
               </widget>
@@ -40530,12 +40616,6 @@ To differentiate between male and female, use the values 1/0, or m/f, or M/F on
                                       <placeholder/>
                                     </child>
                                     <child>
-                                      <placeholder/>
-                                    </child>
-                                    <child>
-                                      <placeholder/>
-                                    </child>
-                                    <child>
                                       <widget class="GtkLabel" id="label218">
                                         <property name="visible">True</property>
                                         <property name="can_focus">False</property>
@@ -41639,6 +41719,12 @@ To differentiate between male and female, use the values 1/0, or m/f, or M/F on
                                     <child>
                                       <placeholder/>
                                     </child>
+                                    <child>
+                                      <placeholder/>
+                                    </child>
+                                    <child>
+                                      <placeholder/>
+                                    </child>
                                   </widget>
                                 </child>
                               </widget>
@@ -45629,6 +45715,12 @@ It starts before and arrives there with some speed.</property>
                         <child>
                           <placeholder/>
                         </child>
+                        <child>
+                          <placeholder/>
+                        </child>
+                        <child>
+                          <placeholder/>
+                        </child>
                       </widget>
                       <packing>
                         <property name="left_attach">2</property>
@@ -46397,6 +46489,12 @@ It starts before and arrives there with some speed.</property>
                     <child>
                       <placeholder/>
                     </child>
+                    <child>
+                      <placeholder/>
+                    </child>
+                    <child>
+                      <placeholder/>
+                    </child>
                   </widget>
                 </child>
               </widget>
@@ -47180,6 +47278,12 @@ It starts before and arrives there with some speed.</property>
                     <child>
                       <placeholder/>
                     </child>
+                    <child>
+                      <placeholder/>
+                    </child>
+                    <child>
+                      <placeholder/>
+                    </child>
                   </widget>
                 </child>
               </widget>
diff --git a/src/chronopic.cs b/src/chronopic.cs
index 7a2147c..e63b53d 100644
--- a/src/chronopic.cs
+++ b/src/chronopic.cs
@@ -115,6 +115,9 @@ public class Chronopic {
                //-- produzca un timeout
                ok = Read_cambio(trama);
 
+               LogB.Warning("after Read_cambio =");
+               LogB.Warning(ok.ToString());
+
                //-- Si hay timeout o errores
                if (ok==false) {
                        plataforma = Plataforma.UNKNOW;
@@ -167,7 +170,7 @@ public class Chronopic {
                }
 
                
-               sp.Write("V");
+               sp.Write("n");
                LogB.Information("Version: " + 
                                (char) sp.ReadByte() +
                                (char) sp.ReadByte() +
@@ -310,6 +313,8 @@ public class Chronopic {
                        do {
                                try {
                                        n = sp.Read(respuesta,count,5-count);
+                                       LogB.Warning("respuesta = ");
+                                       LogB.Warning(respuesta.ToString());
                                        count+=n;
                                        success = true;
                                } catch {}
diff --git a/src/chronopicDetect.cs b/src/chronopicDetect.cs
index 6d6b1b3..65a40a3 100644
--- a/src/chronopicDetect.cs
+++ b/src/chronopicDetect.cs
@@ -442,7 +442,7 @@ public class ChronopicAutoCheck : ChronopicAuto
                IsChronopicAuto = ( (char) sp.ReadByte() == 'J');
                if (IsChronopicAuto) 
                {
-                       sp.Write("V");
+                       sp.Write("n");
                        int major = (char) sp.ReadByte() - '0'; 
                        sp.ReadByte();          //.
                        int minor = (char) sp.ReadByte() - '0'; 
@@ -540,14 +540,14 @@ public class ChronopicStartReactionTimeAnimation : ChronopicAuto
                                b = 0x6c;
                        else if(CharToSend == "f")
                                b = 0x66;
-                       else if(CharToSend == "d")
-                               b = 0x64;
-                       else if(CharToSend == "D")
-                               b = 0x44;
-                       else if(CharToSend == "i")
-                               b = 0x69;
-                       else if(CharToSend == "I")
-                               b = 0x49;
+                       else if(CharToSend == "r")
+                               b = 0x72;
+                       else if(CharToSend == "s")
+                               b = 0x73;
+                       else if(CharToSend == "t")
+                               b = 0x74;
+                       else if(CharToSend == "Z")
+                               b = 0x5A;
                        else
                                return "ERROR";
 
diff --git a/src/execute/event.cs b/src/execute/event.cs
index 1ae20ff..8420620 100644
--- a/src/execute/event.cs
+++ b/src/execute/event.cs
@@ -149,9 +149,16 @@ public class EventExecute
        protected bool totallyCancelledMulti2;
        protected bool totallyCancelledMulti3;
        protected bool totallyCancelledMulti4;
-       
 
 
+       //for reaction time     
+       //on animation lights and discriminative should be false
+       public bool StartIn = true;
+       public string DiscriminativeCharToSend;
+       public int DiscriminativeStartTime;
+       public SerialPort SP;
+       
+
        //protected EventExecuteWindow eventExecuteWin;
        //protected ChronoJumpWindow app1;
        
diff --git a/src/execute/reactionTime.cs b/src/execute/reactionTime.cs
index 7f9727a..ead7fe0 100644
--- a/src/execute/reactionTime.cs
+++ b/src/execute/reactionTime.cs
@@ -96,18 +96,29 @@ public class ReactionTimeExecute : EventExecute
                //boolean to know if chronopic has been disconnected    
                chronopicDisconnected = false;
 
+               LogB.Error("at Manage!");
+
                if (simulated) 
                        platformState = Chronopic.Plataforma.ON;
                else
                        platformState = chronopicInitialValue(cp);
+       
+               bool canStart = false;
+               if ( 
+                               (StartIn && platformState == Chronopic.Plataforma.ON) ||
+                               (! StartIn && platformState == Chronopic.Plataforma.OFF) )
+                       canStart = true;
+                       
                
-               
-               if (platformState==Chronopic.Plataforma.ON) {
-                       feedbackMessage = Catalog.GetString("You are IN, RELEASE when prepared!");
+               if (canStart) {
+                       feedbackMessage = Catalog.GetString("You are IN, RELEASE when prepared!"); //TODO: 
change this
                        needShowFeedbackMessage = true; 
                        Util.PlaySound(Constants.SoundTypes.CAN_START, volumeOn);
 
-                       loggedState = States.ON;
+                       if(StartIn)
+                               loggedState = States.ON;
+                       else
+                               loggedState = States.OFF;
 
                        //prepare reactionTime for being cancelled if desired
                        cancel = false;
@@ -115,7 +126,7 @@ public class ReactionTimeExecute : EventExecute
 
                        //in simulated mode, make the jump start just when we arrive to waitEvent at the 
first time
                        //mark now that we have leaved platform:
-                       if (simulated)
+                       if (simulated) //TODO: check loggedState and StartIn
                                platformState = Chronopic.Plataforma.OFF;
                        
                        //start thread
@@ -126,10 +137,11 @@ public class ReactionTimeExecute : EventExecute
                        LogB.ThreadStart(); 
                        thread.Start(); 
                } 
-               else if (platformState==Chronopic.Plataforma.OFF) {
+               else if (! canStart && (platformState == Chronopic.Plataforma.ON || platformState == 
Chronopic.Plataforma.OFF) )
+               {
                        ConfirmWindow confirmWin;               
                        confirmWin = ConfirmWindow.Show( 
-                                       Catalog.GetString("You are OUT, come inside and press the 'accept' 
button"), "", "");
+                                       Catalog.GetString("You are OUT, come inside and press the 'accept' 
button"), "", ""); //TODO:change this
                        //System.Media.SystemSounds.Beep.Play();
                        Util.PlaySound(Constants.SoundTypes.BAD, volumeOn);
 
@@ -139,29 +151,62 @@ public class ReactionTimeExecute : EventExecute
                        //if confirmWin.Button_cancel is pressed retuen
                        confirmWin.Button_cancel.Clicked += new EventHandler(cancel_event_before_start);
                }
-               else { //UNKNOW (Chronopic disconnected, port changed, ...)
+               else { //UNKNOW (Chronopic disconnected, port changed, ...) platformStart == some error
                        chronopicHasBeenDisconnected();
                }
        }
 
-       
        protected override void waitEvent ()
        {
+               if(DiscriminativeCharToSend != "") {
+                       Thread.Sleep(DiscriminativeStartTime * 1000); //TODO: this hangs the interface, find 
a better way. Now should work (PulseGTK has been called)
+
+                       ChronopicAuto cs = new ChronopicStartReactionTimeAnimation();
+                       cs.CharToSend = DiscriminativeCharToSend;
+                       cs.Write(SP, DiscriminativeStartTime);
+
+                       LogB.Information("opening port");       
+                       SP.Open();
+
+                       LogB.Information("reading one");        
+                       byte[] buffer = new byte[256];
+                       SP.Read(buffer,0,256);
+                       LogB.Information("readed");     
+
+                       LogB.Information("reading two");        
+                       buffer = new byte[256];
+                       SP.Read(buffer,0,256);
+                       LogB.Information("readed");     
+
+                       LogB.Information("closing port");       
+                       SP.Close();
+                       //TODO: end discriminative stuff!!!!
+               }
+
                double timestamp = 0;
                bool success = false;
                
                bool ok;
-               
+       
+               LogB.Information("Inside waitEvent");   
                do {
                        if(simulated)
                                ok = true;
                        else 
                                ok = cp.Read_event(out timestamp, out platformState);
+               
+                       LogB.Information("Inside do");  
+                       LogB.Information("cancel == "); 
+                       LogB.Information(cancel.ToString());    
+                       LogB.Information("ok == ");     
+                       LogB.Information(ok.ToString());        
                        
                        //if (ok) {
                        if (ok && !cancel) {
+                               LogB.Information("ok!");        
                                if (platformState == Chronopic.Plataforma.ON && loggedState == States.OFF) 
                                {
+                                       //LogB.Information("condition guai! hem entrat!");      
                                        //has landed
                                        if(simulated)
                                                timestamp = simulatedTimeLast * 1000; //conversion to 
milliseconds
@@ -189,6 +234,7 @@ public class ReactionTimeExecute : EventExecute
                                }
                                else if (platformState == Chronopic.Plataforma.OFF && loggedState == 
States.ON) 
                                {
+                                       //LogB.Information("condition hem sortit");     
                        
                                        //it's out, was inside (= has released)
                                        
diff --git a/src/gui/chronojump.cs b/src/gui/chronojump.cs
index cd8cca6..7596112 100644
--- a/src/gui/chronojump.cs
+++ b/src/gui/chronojump.cs
@@ -206,10 +206,10 @@ public partial class ChronoJumpWindow
        [Widget] Gtk.Button button_delete_selected_reaction_time;
        [Widget] Gtk.SpinButton spinbutton_animation_lights_speed;
        [Widget] Gtk.SpinButton spinbutton_flicker_lights_speed;
-       [Widget] Gtk.RadioButton radiobutton_reaction_time_disc_lr;
-       [Widget] Gtk.RadioButton radiobutton_reaction_time_disc_ly;
-       [Widget] Gtk.RadioButton radiobutton_reaction_time_disc_lg;
-       [Widget] Gtk.RadioButton radiobutton_reaction_time_disc_bz;
+       [Widget] Gtk.CheckButton check_reaction_time_disc_red;
+       [Widget] Gtk.CheckButton check_reaction_time_disc_yellow;
+       [Widget] Gtk.CheckButton check_reaction_time_disc_green;
+       [Widget] Gtk.CheckButton check_reaction_time_disc_buzzer;
        [Widget] Gtk.SpinButton spinbutton_discriminative_lights_minimum;
        [Widget] Gtk.SpinButton spinbutton_discriminative_lights_maximum;
 
@@ -4519,9 +4519,20 @@ public partial class ChronoJumpWindow
 
                if (!chronopicWin.Connected) 
                        currentEventExecute.SimulateInitValues(rand);
-               
-               currentEventExecute.Manage();
+       
+               if(extra_window_radio_reaction_time_discriminative.Active) {
+                       //TODO: do also for animation_lights and flickr
+                       currentEventExecute.StartIn = false;
 
+                       currentEventExecute.DiscriminativeCharToSend = discriminativeCharToSend;
+                       currentEventExecute.DiscriminativeStartTime = discriminativeStartTime;
+                       currentEventExecute.SP = chronopicWin.SP;
+               } else {
+                       currentEventExecute.DiscriminativeCharToSend = "";
+                       currentEventExecute.DiscriminativeStartTime = 0;
+               }
+               currentEventExecute.Manage(); //check that platform is ok
+               
                currentEventExecute.FakeButtonUpdateGraph.Clicked += 
                        new EventHandler(on_event_execute_update_graph_in_progress_clicked);
                currentEventExecute.FakeButtonEventEnded.Clicked += new 
EventHandler(on_event_execute_EventEnded);
diff --git a/src/gui/reactionTime.cs b/src/gui/reactionTime.cs
index c49c709..220feac 100644
--- a/src/gui/reactionTime.cs
+++ b/src/gui/reactionTime.cs
@@ -163,6 +163,8 @@ public partial class ChronoJumpWindow
                ChronopicAuto cs = new ChronopicStartReactionTimeAnimation();
                cs.CharToSend = "l";
                cs.Write(chronopicWin.SP,speed);
+
+               on_button_execute_test_clicked(o, args);
        }
        
        private void on_button_flicker_lights_start_clicked (object o, EventArgs args) {
@@ -170,22 +172,78 @@ public partial class ChronoJumpWindow
                ChronopicAuto cs = new ChronopicStartReactionTimeAnimation();
                cs.CharToSend = "f";
                cs.Write(chronopicWin.SP,speed);
+
+               on_button_execute_test_clicked(o, args);
        }
 
-       private void on_button_discriminative_lights_start_clicked (object o, EventArgs args) {
-               //int speed = Convert.ToInt32(spinbutton_flicker_lights_speed.Value); //TODO
-               ChronopicAuto cs = new ChronopicStartReactionTimeAnimation();
-               if(radiobutton_reaction_time_disc_lr.Active == true)
-                       cs.CharToSend = "d";
-               else if(radiobutton_reaction_time_disc_ly.Active == true)
-                       cs.CharToSend = "D";
-               else if(radiobutton_reaction_time_disc_lg.Active == true)
-                       cs.CharToSend = "i";
-               else if(radiobutton_reaction_time_disc_bz.Active == true)
-                       cs.CharToSend = "I";
-               cs.Write(chronopicWin.SP,0); //TODO
+       private string discriminativeCharToSend;
+       private int discriminativeStartTime;
+
+       private void on_button_discriminative_lights_start_clicked (object o, EventArgs args) 
+       {
+               //TODO: check if nothing activated, Start should be unsensitive
+
+               if(check_reaction_time_disc_buzzer.Active == true) //all this are with buzzer
+               {
+                       if(check_reaction_time_disc_red.Active == true) {
+                               if(check_reaction_time_disc_yellow.Active == true) {
+                                       if(check_reaction_time_disc_green.Active == true)
+                                               discriminativeCharToSend = "X";         //all lights
+                                       else
+                                               discriminativeCharToSend = "U";         //red + yellow
+                               } else { //! yellow
+                                       if(check_reaction_time_disc_green.Active == true)
+                                               discriminativeCharToSend = "V";         //red + green
+                                       else
+                                               discriminativeCharToSend = "R";         //red
+                               }
+                       } else {        // ! red
+                               if(check_reaction_time_disc_yellow.Active == true) {
+                                       if(check_reaction_time_disc_green.Active == true)
+                                               discriminativeCharToSend = "W";         //yellow + green
+                                       else
+                                               discriminativeCharToSend = "S";         //yellow
+                               } else {        // ! yellow
+                                       if(check_reaction_time_disc_green.Active == true)
+                                               discriminativeCharToSend = "T";                 //green
+                                       else
+                                               discriminativeCharToSend = "Z";                 //only buzzer
+                               }
+                       }
+               } else {                                        //all this are without buzzer
+                       if(check_reaction_time_disc_red.Active == true) {
+                               if(check_reaction_time_disc_yellow.Active == true) {
+                                       if(check_reaction_time_disc_green.Active == true)
+                                               discriminativeCharToSend = "x";         //all lights
+                                       else
+                                               discriminativeCharToSend = "u";         //red + yellow
+                               } else { //! yellow
+                                       if(check_reaction_time_disc_green.Active == true)
+                                               discriminativeCharToSend = "v";         //red + green
+                                       else
+                                               discriminativeCharToSend = "r";         //red
+                               }
+                       } else {        // ! red
+                               if(check_reaction_time_disc_yellow.Active == true) {
+                                       if(check_reaction_time_disc_green.Active == true)
+                                               discriminativeCharToSend = "w";         //yellow + green
+                                       else
+                                               discriminativeCharToSend = "s";         //yellow
+                               } else // ! yellow
+                                       discriminativeCharToSend = "t";                 //green
+                       }
+               }
+               
+               discriminativeStartTime = Convert.ToInt32(spinbutton_discriminative_lights_minimum.Value);
+                                               
+               LogB.Information("discriminativeCharToSend");
+               LogB.Information(discriminativeCharToSend);
+               
+               on_button_execute_test_clicked(o, args);
        }
 
+
+
        //---- unused
        
        /*



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