]> rtime.felk.cvut.cz Git - eurobot/public.git/commitdiff
eb_demo: Change stat button handling.
authorMichal Vokac <vokac.m@gmail.com>
Wed, 28 Dec 2011 20:05:54 +0000 (21:05 +0100)
committerMichal Vokac <vokac.m@gmail.com>
Wed, 28 Dec 2011 20:05:54 +0000 (21:05 +0100)
Now release of button is not needed for start to be processed.
After holding button for 100ms homing/stop is done.
After holding button for 1 second, start is send.

src/eb_demo/def.h
src/eb_demo/main.c

index 9da3136fc685cce966df86994ac9eedd99f06b94..f47fce796e83c2dc41ead4e199a117e75e902e5d 100644 (file)
@@ -24,4 +24,9 @@ enum {
         SHORT_PRESS
 } button_states;
 
+enum {
+        PRESSED = 1,
+        RELEASED = 0
+} button;
+
 #endif
index 364d1bb29f89021ec53402f7b4a00cc5c41195f3..afa9d1ec96cd3ce9dcd4ff3f3506bd0e1bbc96ac 100644 (file)
@@ -192,13 +192,13 @@ void blink_led()
        if(timer_msec >= led_time + 500) {
                 led_time = timer_msec;
                 deb_led_change(LEDG);
-                send_rs_str("pos: ");
-                send_rs_int(fsm_crane.act_pos);
-                send_rs_str(" L: ");
-                send_rs_int(fsm_crane.sharp_L);
-                send_rs_str(" R: ");
-                send_rs_int(fsm_crane.sharp_R);
-                send_rs_str("\n");
+//                 send_rs_str("pos: ");
+//                 send_rs_int(fsm_crane.act_pos);
+//                 send_rs_str(" L: ");
+//                 send_rs_int(fsm_crane.sharp_L);
+//                 send_rs_str(" R: ");
+//                 send_rs_int(fsm_crane.sharp_R);
+//                 send_rs_str("\n");
        }
 }
 
@@ -220,33 +220,40 @@ void start_handling(void)
         /* it is necassary initialize this to value 1
         If the initial value is zero - SHORT_PRESS signal is generated when power supply is applied
         => but we do not want this after power on */
-        static bool last_start_button = 1;
+        static bool last_start_button = 0;
 
         static bool start_condition = 0;
 
-        int release_delay = 0;
+        int hold_time = 0;
 
         static char start_state = POWER_ON;
 
-        start_button = (IO0PIN & (1<<START_PIN)) == 0;
+        start_button = (IO0PIN & (1<<START_PIN)) == 0 ? PRESSED : RELEASED;
 
         if (timer_msec >= handle_button_time + 10) {
-                if (start_button != last_start_button && start_button == 1) {
+                if (start_button != last_start_button && start_button == PRESSED) {
                         // button presed
                         last_start_button = start_button;
                         pressed_time = timer_msec; // save time when button is presed
-                } else if (start_button != last_start_button && start_button == 0) {
+                        send_rs_str("button pressed\n");
+                } else if (start_button != last_start_button && start_button == RELEASED) {
                         // button released
                         last_start_button = start_button;
-                        release_delay = timer_msec - pressed_time;
+                        pressed_time = 0;
+                        send_rs_str("button released\n");
+                } else if (start_button == PRESSED) {
+                        // button hold
+                        send_rs_str("button hold\n");
+                        last_start_button = start_button;
+                        
+                        hold_time = timer_msec - pressed_time;
 
                         // check how long the button was pressed
-                        if ((release_delay) >= 2000) {
-                                start_condition = LONG_PRESS;
-                                pressed_time = 0;
-                        } else if ((release_delay) >= 100){
+                        if (hold_time >= 100) {
                                 start_condition = SHORT_PRESS;
-                                pressed_time = 0;
+                        }
+                        if (hold_time >= 1000){
+                                start_condition = LONG_PRESS;
                         }
                 }
                 handle_button_time = timer_msec;