+unsigned char buttons_wait_for_release()
+{
+ uint16_t wake_count = 0;
+ unsigned char pin;
+
+ do {
+ if (wake_count++ > WAKEUP_LIMIT)
+ gpio_set(0, 1); // inform the user
+
+ _delay_ms(100);
+
+ pin = PINA & _BV(PA4);
+ } while (!(pin & _BV(PA4)));
+
+ gpio_set(0, 0);
+
+ return wake_count > WAKEUP_LIMIT;
+}
+
+void button_adc(uint16_t adcval)
+{
+#if 0
+ static unsigned char count=250;
+#endif
+ PORTA &= ~_BV(PA3); // disable +5V to the hall probe
+ // adc.c will re-enable it again
+
+ button_state.btn1 = 0;
+ button_state.btn2 = 0;
+ button_state.brake = 0;
+
+ if (adcval == 0x3FF) {
+ button_state.brake = 1;
+ } else if (adcval > 0x240) {
+ button_state.brake = 1;
+ button_state.btn2 = 1;
+ } else if (adcval > 0x180) {
+ // nothing
+ } else if (adcval > 0xc0) {
+ button_state.btn2 = 1;
+ } else {
+ button_state.btn1 = 1;
+ }
+
+#if 0
+ if (--count)
+ return;
+
+ count = 250;
+ log_word(adcval);
+ log_flush();
+#endif
+}
+
+ISR(PCINT_vect)
+{
+ // empty - let it wake us from sleep, but do nothing else
+}
+