]> www.fi.muni.cz Git - tinyboard.git/blobdiff - projects/step-up/buttons.c
Experimental step-up driver for chain of 5630 LEDs.
[tinyboard.git] / projects / step-up / buttons.c
index 4101a2f5885c3920c76a7b6568dbcfa3db8fd789..a25379734db3fa868770d873edbc230c2633cebd 100644 (file)
@@ -7,26 +7,26 @@
 #include "lights.h"
 
 #define WAKEUP_LIMIT   5       // times 100 ms
-#define SHORT_PRESS_MIN        10      // in jiffies (100 Hz ticks)
-#define SHORT_PRESS_MAX 50
-#define LONG_PRESS_MIN 100
+#define SHORT_PRESS_MIN        2       // in jiffies (16 Hz ticks)
+#define SHORT_PRESS_MAX 5
+#define LONG_PRESS_MIN 10
 static uint16_t button_start;
 static unsigned char prev_state;
 
 void status_led_on_off(unsigned char mode)
 {
        if (mode)
-               PORTB |= _BV(PORTB0);
+               PORTB |= _BV(PORTB1);
        else
-               PORTB &= ~_BV(PORTB0);
+               PORTB &= ~_BV(PORTB1);
 }
 
 void init_buttons()
 {
-       DDRB &= ~_BV(DDB1);
-       DDRB |= _BV(DDB0);
-       PORTB |= _BV(PORTB1); // enable internal pull-up
-       PORTB &= ~_BV(PORTB0); // status led off
+       DDRB &= ~_BV(DDB0);
+       DDRB |= _BV(DDB1);
+       PORTB |= _BV(PORTB0); // enable internal pull-up
+       PORTB &= ~_BV(PORTB1); // status led off
        GIMSK &= ~_BV(PCIE); // disable pin-change IRQs
        PCMSK = 0; // disable pin-change IRQs on all pins of port B
 
@@ -36,19 +36,19 @@ void init_buttons()
 
 void susp_buttons()
 {
-       DDRB &= ~(_BV(DDB1)); // set as input
-       PORTB |= _BV(PORTB1);  // enable internal pull-up
-       PORTB &= ~_BV(PORTB0); // set to zero
+       DDRB &= ~(_BV(DDB0)); // set as input
+       PORTB |= _BV(PORTB0);  // enable internal pull-up
+       PORTB &= ~_BV(PORTB1); // set to zero
 
        GIMSK |= _BV(PCIE);
 
-       PCMSK = _BV(PCINT1);
+       PCMSK = _BV(PCINT0);
                // disable pin-change IRQs on all pins except PB1
 }
 
 void timer_check_buttons()
 {
-       unsigned char cur = !(PINB & _BV(PINB1));
+       unsigned char cur = !(PINB & _BV(PINB0));
        unsigned char prev = prev_state;
 
        prev_state = cur;
@@ -67,7 +67,7 @@ void timer_check_buttons()
        } else if (!cur && prev) {            // --- just released ---
                uint16_t duration = jiffies - button_start;
 
-               if (duration > SHORT_PRESS_MIN && duration < SHORT_PRESS_MAX) {
+               if (duration >= SHORT_PRESS_MIN && duration < SHORT_PRESS_MAX) {
                        short_press();
                } else if (duration > LONG_PRESS_MIN) {
                        // set_status_led(button, NULL);
@@ -118,8 +118,8 @@ unsigned char buttons_wait_for_release()
 
                _delay_ms(100);
 
-               pin = PINB & _BV(PINB1);
-       } while (!(pin & _BV(PINB1)));
+               pin = PINB & _BV(PINB0);
+       } while (!(pin & _BV(PINB0)));
 
        status_led_on_off(0);