2 #include <stdlib.h> // for NULL
6 static pattern_t panic_pattern[] = {
7 { 3, D_1 }, // FIXME: will be 4, but let's be safe while testing
32 pattern_t on1_pattern [] = {
37 static pattern_t on2_pattern [] = {
42 static pattern_t on3_pattern [] = {
47 static pattern_t brake_pattern [] = {
53 static pattern_t normal2_pattern[] = {
65 static pattern_t normal3_pattern[] = {
77 static pattern_t normal4_pattern[] = {
89 static pattern_t slow1_pattern[] = {
95 static pattern_t slow2_pattern[] = {
101 static pattern_t slow3_pattern[] = {
107 static unsigned char dim_mode, towbar_mode, braking;
120 led_set_pattern(N_PWMLEDS, status_led_pattern_select());
121 led_set_pattern(0, pwmled0_pattern_select());
128 led_set_pattern(N_PWMLEDS, status_led_pattern_select());
129 led_set_pattern(0, pwmled0_pattern_select());
132 void toggle_dim_mode()
134 dim_mode = !dim_mode;
138 void set_panic_mode()
141 led_set_pattern(0, panic_pattern);
143 led_set_pattern(1, panic_pattern);
144 led_set_pattern(2, panic_pattern);
145 led_set_pattern(4, panic_pattern);
148 pattern_t *pwmled0_pattern_select()
150 if (battery_critical)
157 return brake_pattern;
159 switch (ambient_zone) {
160 case 0: return dim_mode ? NULL : number_pattern(2, 1);
161 case 1: return dim_mode ? slow1_pattern : normal2_pattern;
162 case 2: return dim_mode ? slow2_pattern : normal3_pattern;
164 default: return dim_mode ? slow3_pattern : normal4_pattern;
168 pattern_t *pwmled1_pattern_select()
173 if (battery_critical)
178 switch (ambient_zone) {
181 return dim_mode ? on2_pattern : on1_pattern;
182 case 2: return dim_mode ? NULL : on2_pattern;
184 default: return dim_mode ? NULL : on3_pattern;
187 switch (ambient_zone) {
188 case 0: return dim_mode ? slow1_pattern : normal2_pattern;
189 case 1: return dim_mode ? slow2_pattern : normal3_pattern;
190 case 2: return dim_mode ? NULL : normal4_pattern;
192 default: return NULL;
197 pattern_t *pwmled2_pattern_select()
200 if (battery_critical)
204 switch (ambient_zone) {
205 case 0: return dim_mode ? on2_pattern : on3_pattern;
206 case 1: return dim_mode ? slow1_pattern : normal2_pattern;
210 return dim_mode ? slow2_pattern : normal3_pattern;
214 pattern_t *status_led_pattern_select()
219 if (buttons_setup_in_progress())
220 return buttons_setup_status0_pattern_select();
222 // FIXME: do something sane
223 return number_pattern(battery_gauge(), 0);
226 pattern_t *illumination_led_pattern_select()
228 if (battery_critical)
231 switch (ambient_zone) {
232 case 0: return dim_mode
233 ? number_pattern(1, 1)
235 case 1: return dim_mode
236 ? number_pattern(2, 1)
237 : number_pattern(3, 1);
238 case 2: return dim_mode
239 ? number_pattern(1, 0)
240 : number_pattern(2, 0);
242 default: return dim_mode
243 ? number_pattern(3, 0)
244 : number_pattern(4, 0);
248 pattern_t *laser_pattern_select()
250 if (!dim_mode && ambient_zone <= 1)
251 return number_pattern(2, 1);