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");
}
}
/* 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;