Commit 60ed332d authored by Michael Nelson's avatar Michael Nelson

Debounce all input, fix light staying on when signalling during bg

parent 789a2d2b
......@@ -41,6 +41,7 @@
#define BLINK_RATE 250
#define RUNNING_LIGHT_BLINK_RATE 920
#define HOLD_DOWN_TIME 500
#define DEBOUNCE_COOLDOWN_TIME 200
// State
int fg_mode = MODE_OFF;
......@@ -61,6 +62,7 @@ bool input_hold_both_hit = false;
// Time accumulator variables
int cycle_time = 0;
int new_input_blocked = 0;
int left_hold_time = 0;
int right_hold_time = 0;
int both_hold_time = 0;
......@@ -84,6 +86,11 @@ void setup()
/* Serial.println("Started."); */
}
void debounce_subsequent_input()
{
new_input_blocked = DEBOUNCE_COOLDOWN_TIME;
}
void blink_frame(bool left, bool right, int tone_divisor = 2)
{
if (cycle_time > BLINK_RATE)
......@@ -165,37 +172,53 @@ void read_dual_buttons()
right_hold_time++;
else
{
if (left_hold_time && !hold_waiting)
if (left_hold_time && !new_input_blocked && !hold_waiting)
{
input_single_left_hit = true;
debounce_subsequent_input();
}
if (right_hold_time && !hold_waiting)
if (right_hold_time && !new_input_blocked && !hold_waiting)
{
input_single_right_hit = true;
debounce_subsequent_input();
}
if (both_hold_time && !hold_waiting)
if (both_hold_time && !new_input_blocked && !hold_waiting)
{
input_single_both_hit = true;
debounce_subsequent_input();
}
both_hold_time = 0;
left_hold_time = 0;
right_hold_time = 0;
if (hold_waiting)
debounce_subsequent_input();
hold_waiting = false;
}
if (left_hold_time == HOLD_DOWN_TIME)
if (left_hold_time == HOLD_DOWN_TIME && !new_input_blocked)
{
input_hold_left_hit = true;
hold_waiting = true;
debounce_subsequent_input();
}
else if (right_hold_time == HOLD_DOWN_TIME)
else if (right_hold_time == HOLD_DOWN_TIME && !new_input_blocked)
{
input_hold_right_hit = true;
hold_waiting = true;
debounce_subsequent_input();
}
else if (both_hold_time == HOLD_DOWN_TIME)
else if (both_hold_time == HOLD_DOWN_TIME && !new_input_blocked)
{
input_hold_both_hit = true;
hold_waiting = true;
debounce_subsequent_input();
}
}
......@@ -258,8 +281,7 @@ void loop()
set_up_mode();
// Reset all lights going directly from one direction to the next.
if ((fg_mode != last_fg_mode && fg_mode != MODE_OFF) ||
(bg_mode != last_bg_mode && bg_mode != MODE_OFF))
if (fg_mode != last_fg_mode || bg_mode != last_bg_mode)
reset_all();
if (fg_mode == FG_MODE_BLINK_L)
......@@ -279,4 +301,7 @@ void loop()
last_fg_mode = fg_mode;
last_bg_mode = bg_mode;
if (new_input_blocked > 0)
new_input_blocked--;
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment