static void handle_brake(unsigned char cur, unsigned char prev)
{
+ uint16_t duration;
+
if (cur && !prev) { // --- just pressed ---
button_start[2] = jiffies;
+ return;
} else if (!cur && prev) { // --- just released ---
button_start[2] = jiffies;
- } else { // --- no change ---
- uint16_t duration = jiffies - button_start[2];
-
- if (duration > 6) {
- if (cur) {
- if (button_state.brake_working
- && !button_state.brake_reported) {
- button_state.brake_reported = 1;
- brake_on();
- }
- } else {
- button_state.brake_working = 1;
- if (button_state.brake_reported) {
- button_state.brake_reported = 0;
+ return;
+ }
+ // --- no change ---
+ duration = jiffies - button_start[2];
+
+ if (duration <= 3)
+ return;
+
+ if (cur) {
+ if (button_state.brake_working) {
+ static unsigned int brake_time;
+ if (button_state.brake_reported) {
+ if (brake_time) {
+ brake_time--;
+ } else {
brake_off();
+ button_state.brake_working = 0;
+ button_state.brake_reported = 0;
}
+ } else {
+ button_state.brake_reported = 1;
+ brake_on();
+ brake_time = 255; // avoid longer than ~16s
}
- button_start[2] = jiffies - 7; // avoid overflow
+ }
+ } else {
+ button_state.brake_working = 1;
+ if (button_state.brake_reported) {
+ button_state.brake_reported = 0;
+ brake_off();
}
}
+
+ button_start[2] = jiffies - 7; // avoid overflow
}
void timer_check_buttons()