diff options
Diffstat (limited to 'firmware/drivers/button.c')
-rw-r--r-- | firmware/drivers/button.c | 103 |
1 files changed, 52 insertions, 51 deletions
diff --git a/firmware/drivers/button.c b/firmware/drivers/button.c index 7e1ab47952..4bbc69f607 100644 --- a/firmware/drivers/button.c +++ b/firmware/drivers/button.c | |||
@@ -86,70 +86,71 @@ static void button_tick(void) | |||
86 | { | 86 | { |
87 | queue_post(&button_queue, BUTTON_REL | diff, NULL); | 87 | queue_post(&button_queue, BUTTON_REL | diff, NULL); |
88 | } | 88 | } |
89 | 89 | else | |
90 | if ( btn ) | ||
91 | { | 90 | { |
92 | /* normal keypress */ | 91 | if ( btn ) |
93 | if ( btn != lastbtn ) | ||
94 | { | ||
95 | post = true; | ||
96 | repeat = false; | ||
97 | repeat_speed = REPEAT_INTERVAL_START; | ||
98 | |||
99 | } | ||
100 | else /* repeat? */ | ||
101 | { | 92 | { |
102 | if ( repeat ) | 93 | /* normal keypress */ |
94 | if ( btn != lastbtn ) | ||
103 | { | 95 | { |
104 | count--; | 96 | post = true; |
105 | if (count == 0) { | 97 | repeat = false; |
106 | post = true; | 98 | repeat_speed = REPEAT_INTERVAL_START; |
107 | /* yes we have repeat */ | 99 | |
108 | repeat_speed--; | 100 | } |
109 | if (repeat_speed < REPEAT_INTERVAL_FINISH) | 101 | else /* repeat? */ |
110 | repeat_speed = REPEAT_INTERVAL_FINISH; | 102 | { |
111 | count = repeat_speed; | 103 | if ( repeat ) |
112 | 104 | { | |
113 | repeat_count++; | 105 | count--; |
114 | 106 | if (count == 0) { | |
115 | /* Shutdown if we have a device which doesn't shut | 107 | post = true; |
116 | down easily with the OFF key */ | 108 | /* yes we have repeat */ |
109 | repeat_speed--; | ||
110 | if (repeat_speed < REPEAT_INTERVAL_FINISH) | ||
111 | repeat_speed = REPEAT_INTERVAL_FINISH; | ||
112 | count = repeat_speed; | ||
113 | |||
114 | repeat_count++; | ||
115 | |||
116 | /* Shutdown if we have a device which doesn't shut | ||
117 | down easily with the OFF key */ | ||
117 | #ifdef HAVE_POWEROFF_ON_PB5 | 118 | #ifdef HAVE_POWEROFF_ON_PB5 |
118 | if(btn == BUTTON_OFF && !charger_inserted() && | 119 | if(btn == BUTTON_OFF && !charger_inserted() && |
119 | repeat_count > POWEROFF_COUNT) | 120 | repeat_count > POWEROFF_COUNT) |
120 | power_off(); | 121 | power_off(); |
121 | #endif | 122 | #endif |
123 | } | ||
122 | } | 124 | } |
123 | } | 125 | else |
124 | else | ||
125 | { | ||
126 | if (count++ > REPEAT_START) | ||
127 | { | 126 | { |
128 | post = true; | 127 | if (count++ > REPEAT_START) |
129 | repeat = true; | 128 | { |
130 | repeat_count = 0; | 129 | post = true; |
131 | /* initial repeat */ | 130 | repeat = true; |
132 | count = REPEAT_INTERVAL_START; | 131 | repeat_count = 0; |
132 | /* initial repeat */ | ||
133 | count = REPEAT_INTERVAL_START; | ||
134 | } | ||
133 | } | 135 | } |
134 | } | 136 | } |
137 | if ( post ) | ||
138 | { | ||
139 | if(repeat) | ||
140 | queue_post(&button_queue, BUTTON_REPEAT | btn, NULL); | ||
141 | else | ||
142 | queue_post(&button_queue, btn, NULL); | ||
143 | backlight_on(); | ||
144 | |||
145 | reset_poweroff_timer(); | ||
146 | } | ||
135 | } | 147 | } |
136 | if ( post ) | 148 | else |
137 | { | 149 | { |
138 | if(repeat) | 150 | repeat = false; |
139 | queue_post(&button_queue, BUTTON_REPEAT | btn, NULL); | 151 | count = 0; |
140 | else | ||
141 | queue_post(&button_queue, btn, NULL); | ||
142 | backlight_on(); | ||
143 | |||
144 | reset_poweroff_timer(); | ||
145 | } | 152 | } |
146 | } | 153 | } |
147 | else | ||
148 | { | ||
149 | repeat = false; | ||
150 | count = 0; | ||
151 | } | ||
152 | |||
153 | lastbtn = btn & ~(BUTTON_REL | BUTTON_REPEAT); | 154 | lastbtn = btn & ~(BUTTON_REL | BUTTON_REPEAT); |
154 | tick = 0; | 155 | tick = 0; |
155 | } | 156 | } |