2 #include <stdlib.h> // for NULL
6 static pattern_t panic_pattern[] = {
7 { PWM_PAT(2, 0, 0), D_1 },
8 { PWM_PAT(0, 0, 2), D_1 },
9 { PWM_PAT(0, 0, 0), D_1 },
10 { PWM_PAT(2, 0, 0), D_1 },
11 { PWM_PAT(0, 0, 2), D_1 },
12 { PWM_PAT(0, 0, 0), D_1 },
13 { PWM_PAT(2, 0, 0), D_1 },
14 { PWM_PAT(0, 0, 2), D_1 },
15 { PWM_PAT(0, 0, 0), D_1 },
16 { PWM_PAT(2, 0, 0), D_1 },
17 { PWM_PAT(0, 0, 2), D_1 },
18 { PWM_PAT(0, 0, 0), D_1 },
19 { PWM_PAT(2, 0, 0), D_1 },
20 { PWM_PAT(0, 0, 2), D_1 },
21 { PWM_PAT(0, 0, 0), D_1 },
22 { PWM_PAT(2, 0, 0), D_1 },
23 { PWM_PAT(0, 0, 2), D_1 },
24 { PWM_PAT(0, 0, 0), D_1 },
25 { PWM_PAT(2, 0, 0), D_1 },
26 { PWM_PAT(0, 0, 2), D_1 },
27 { PWM_PAT(0, 0, 0), D_1 },
31 static pattern_t slow_pattern[] = {
32 { PWM_PAT(1, 0, 0), D_1 },
33 { PWM_PAT(0, 0, 1), D_1 },
34 { PWM_PAT(0, 0, 0), D_13 },
38 static pattern_t fast_pattern[] = {
39 { PWM_PAT(2, 0, 0), D_1 },
40 { PWM_PAT(0, 0, 2), D_1 },
41 { PWM_PAT(2, 0, 0), D_1 },
42 { PWM_PAT(0, 0, 2), D_1 },
43 { PWM_PAT(0, 0, 0), D_8 },
44 { PWM_PAT(1, 0, 0), D_1 },
45 { PWM_PAT(0, 0, 1), D_1 },
46 { PWM_PAT(1, 0, 0), D_1 },
47 { PWM_PAT(0, 0, 1), D_1 },
48 { PWM_PAT(0, 0, 0), D_8 },
52 static pattern_t night_pattern[] = {
53 { PWM_PAT(3, 0, 1), D_3 },
54 { PWM_PAT(2, 0, 0), D_8 },
55 { PWM_PAT(3, 0, 1), D_1 },
56 { PWM_PAT(2, 0, 0), D_2 },
57 { PWM_PAT(3, 0, 1), D_1 },
58 { PWM_PAT(2, 0, 0), D_8 },
62 pattern_t on_pattern[] = {
67 // #define TEST_PATTERN 1
69 pattern_t test_pattern[] = {
70 { PWM_PAT(1, 0, 0), D_13 },
71 { PWM_PAT(2, 0, 0), D_13 },
72 { PWM_PAT(0, 0, 1), D_13 },
73 { PWM_PAT(0, 0, 2), D_13 },
78 volatile unsigned char braking;
79 static unsigned char dim_mode, towbar_mode;
87 pwmled_select_brightness();
94 led_set_pattern(N_STATUS_LED, status_led_pattern_select());
95 pwmleds_update_mode();
102 led_set_pattern(N_STATUS_LED, status_led_pattern_select());
103 pwmleds_update_mode();
106 void toggle_dim_mode()
108 dim_mode = !dim_mode;
109 pwmled_select_brightness();
113 void set_panic_mode()
115 led_set_pattern(0, panic_pattern);
116 led_set_pattern(N_ILLUM_LED, panic_pattern);
119 pattern_t *pwmled_pattern_select()
124 if (battery_critical)
127 switch (ambient_zone) {
128 case 0: return night_pattern;
133 return dim_mode ? slow_pattern : fast_pattern;
137 pattern_t *status_led_pattern_select()
142 if (buttons_setup_in_progress())
143 return buttons_setup_status0_pattern_select();
145 // FIXME: do something sane
146 return number_pattern(battery_gauge(), 0);
149 pattern_t *illumination_led_pattern_select()
151 if (buttons_setup_in_progress())
152 return buttons_setup_status1_pattern_select();
154 if (battery_critical)
157 switch (ambient_zone) {
158 case 0: return dim_mode
159 ? number_pattern(1, 1)
161 case 1: return dim_mode
162 ? number_pattern(2, 1)
163 : number_pattern(3, 1);
164 case 2: return dim_mode
165 ? number_pattern(1, 0)
166 : number_pattern(2, 0);
168 default: return dim_mode
169 ? number_pattern(3, 0)
170 : number_pattern(4, 0);
174 pattern_t *laser_pattern_select()
176 if (!dim_mode && ambient_zone <= 1)
177 return number_pattern(2, 1);
182 void pwmled_select_brightness()
184 uint16_t brightness = PWMLED_BRIGHTNESS(0, 2, 1, 0, 2); // default
186 if (battery_critical) {
187 brightness = PWMLED_BRIGHTNESS(0, 0, 0, 0, 0);
188 } else if (ambient_zone < 2) {
190 brightness = PWMLED_BRIGHTNESS(0, 1, 0, 0, 1);
192 brightness = PWMLED_BRIGHTNESS(0, 2, 1, 0, 2);
193 } else if (ambient_zone == 2) {
194 brightness = PWMLED_BRIGHTNESS(1, 3, 2, 1, 3);
195 } else if (ambient_zone == 3) {
196 brightness = PWMLED_BRIGHTNESS(2, 4, 2, 2, 4);
199 pwmled_set_brightness(brightness);