+ 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
+ }
+ }
+ } 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()
+{
+ handle_button(0, button_state.btn1, prev_state.btn1);
+
+ // when button 1 is on, all other states are unreadable
+ if (button_state.btn1) {
+ prev_state.btn1 = button_state.btn1;
+ } else {
+ handle_button(1, button_state.btn2, prev_state.btn2);
+ handle_brake(button_state.brake, prev_state.brake);
+ prev_state.all = button_state.all;
+ }