2 #include <avr/interrupt.h>
4 #include <util/delay.h>
8 static uint16_t button_start[N_BUTTONS];
9 static unsigned char button_pressed[N_BUTTONS];
10 static unsigned char just_waked_up;
12 static unsigned char user_params[MAX_USER_PARAMS] = { 0, 0, 0 };
13 static unsigned char user_params_max[MAX_USER_PARAMS] = { 3, 2, 2 };
15 static unsigned char user_params_state = 0;
17 * Here 0 means "no setup currently in progress",
18 * 1 .. MAX_USER_PARAMS means "now short presses increase or decrease
19 * the value of user_params[user_params_state-1]"
22 static uint16_t user_params_starttime;
24 static void do_sleep();
26 static void toggle_bright_mode()
31 static void set_panic_mode()
36 unsigned char get_user_param(unsigned char param)
38 if (param < MAX_USER_PARAMS)
39 return user_params[param];
40 return 0; // FIXME: internal error?
43 static inline void short_press(unsigned char button)
47 if (user_params_state == 0) {
55 param = user_params_state-1;
58 if (user_params[param])
61 user_params[param] = user_params_max[param];
65 if (user_params[param] >= user_params_max[param])
66 user_params[param] = 0;
68 // FIXME: notify somebody about user_params change?
70 // set_status_led(2, user_params[param]);
72 user_params_starttime = jiffies;
75 static inline void long_press(unsigned char button)
82 // button 1 - cycle through states
85 if (user_params_state >= MAX_USER_PARAMS)
86 user_params_state = 1;
88 // set_status_led(1, state);
89 user_params_starttime = jiffies;
96 DDRA &= ~(_BV(PA3) | _BV(PA4));
97 PORTA |= _BV(PA3) | _BV(PA4);
99 for (i=0; i < N_BUTTONS; i++) {
101 button_pressed[i] = 0;
107 static void do_sleep()
113 gpio_before_poweroff(); // Set the status LED on again
115 while((PINA & _BV(PA3)) == 0)
116 ; // wait for button release
120 susp_gpio(); // disable the status LED
125 void timer_check_buttons()
127 unsigned char pin = PINA;
129 unsigned char port_states[N_BUTTONS] = {
134 for (i = 0; i < N_BUTTONS; i++) {
135 if (!port_states[i]) { // is pressed
136 if (i == 0 && just_waked_up)
138 if (button_pressed[i] == 0) {
139 // begin of button press
140 button_pressed[i] = 1;
141 button_start[i] = jiffies;
146 } else if (button_pressed[i] == 1) {
147 // been already pressed
148 uint16_t duration = jiffies - button_start[i];
151 button_pressed[i] = 2;
155 } else { // is not pressed
158 if (button_pressed[i]) { // just depressed
159 uint16_t duration = jiffies - button_start[i];
165 button_pressed[i] = 0;
166 if (duration > 6 && duration < 30)