2 #include <stdlib.h> // for NULL
6 static pattern_t panic_pattern[] = {
7 { 3, 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 normal2_pattern[] = {
59 static pattern_t normal3_pattern[] = {
71 static pattern_t normal4_pattern[] = {
83 static pattern_t slow1_pattern[] = {
89 static pattern_t slow2_pattern[] = {
95 static pattern_t slow3_pattern[] = {
101 static unsigned char dim_mode, towbar_mode, braking;
114 led_set_pattern(N_PWMLEDS, status_led_pattern_select());
115 // TODO brighten rear light
122 led_set_pattern(N_PWMLEDS, status_led_pattern_select());
123 // TODO dim rear light
126 void toggle_dim_mode()
128 dim_mode = !dim_mode;
132 void set_panic_mode()
135 led_set_pattern(0, panic_pattern);
137 led_set_pattern(1, panic_pattern);
138 led_set_pattern(2, panic_pattern);
139 led_set_pattern(4, panic_pattern);
142 pattern_t *pwmled0_pattern_select()
144 if (battery_critical)
150 switch (ambient_zone) {
151 case 0: return dim_mode ? NULL : on3_pattern;
152 case 1: return dim_mode ? NULL : normal3_pattern;
153 case 2: return dim_mode ? slow3_pattern : normal3_pattern;
155 default: return dim_mode ? slow3_pattern : normal4_pattern;
159 pattern_t *pwmled1_pattern_select()
164 if (battery_critical)
169 switch (ambient_zone) {
172 return dim_mode ? on2_pattern : on1_pattern;
173 case 2: return dim_mode ? NULL : on2_pattern;
175 default: return dim_mode ? NULL : on3_pattern;
178 switch (ambient_zone) {
179 case 0: return dim_mode ? slow1_pattern : normal2_pattern;
180 case 1: return dim_mode ? slow2_pattern : normal3_pattern;
181 case 2: return dim_mode ? NULL : normal4_pattern;
183 default: return NULL;
188 pattern_t *pwmled2_pattern_select()
191 if (battery_critical)
195 switch (ambient_zone) {
196 case 0: return dim_mode ? on2_pattern : on3_pattern;
197 case 1: return dim_mode ? slow1_pattern : normal2_pattern;
201 return dim_mode ? slow2_pattern : normal3_pattern;
205 pattern_t *status_led_pattern_select()
210 if (buttons_setup_in_progress())
211 return buttons_setup_status0_pattern_select();
213 // FIXME: do something sane
214 return number_pattern(battery_gauge(), 0);
217 pattern_t *illumination_led_pattern_select()
219 if (battery_critical)
222 switch (ambient_zone) {
223 case 0: return dim_mode
224 ? number_pattern(1, 1)
226 case 1: return dim_mode
227 ? number_pattern(2, 1)
228 : number_pattern(3, 1);
229 case 2: return dim_mode
230 ? number_pattern(1, 0)
231 : number_pattern(2, 0);
233 default: return dim_mode
234 ? number_pattern(3, 0)
235 : number_pattern(4, 0);
239 pattern_t *laser_pattern_select()
241 if (!dim_mode && ambient_zone <= 1)
242 return number_pattern(2, 1);