};
#endif
-volatile unsigned char braking;
+volatile err_flags_t err_flags;
static unsigned char dim_mode, towbar_mode;
void init_control()
{
dim_mode = 0;
towbar_mode = 0;
- braking = 0;
+ err_flags.any_flag = 0;
+#ifdef notyet
+ err_flags.booting = 1;
+#endif
pwmled_select_brightness();
}
void brake_on()
{
- braking = 1;
+ err_flags.braking = 1;
gpio_set(0, 1);
led_set_pattern(N_STATUS_LED, status_led_pattern_select());
pwmleds_update_mode();
void brake_off()
{
- braking = 0;
+ err_flags.braking = 0;
gpio_set(0, 0);
led_set_pattern(N_STATUS_LED, status_led_pattern_select());
pwmleds_update_mode();
void set_panic_mode()
{
- led_set_pattern(0, panic_pattern);
- led_set_pattern(N_ILLUM_LED, panic_pattern);
+ // if error, clean it up
+ if (err_flags.booting)
+ err_flags.booting = 0;
+ else if (err_flags.err_pwmled2)
+ err_flags.err_pwmled2 = 0;
+ else if (err_flags.err_pwmled1)
+ err_flags.err_pwmled1 = 0;
+ else if (err_flags.err_pwmled0)
+ err_flags.err_pwmled0 = 0;
+ else if (err_flags.err_battery)
+ err_flags.err_battery = 0;
+ else {
+ led_set_pattern(0, panic_pattern);
+ led_set_pattern(N_ILLUM_LED, panic_pattern);
+ }
}
pattern_t *pwmled_pattern_select()
#ifdef TEST_PATTERN
return tmp_pattern;
#endif
- if (battery_critical)
+ if (err_flags.err_battery)
return slow_pattern;
switch (ambient_zone) {
pattern_t *status_led_pattern_select()
{
- if (braking)
+ if (err_flags.booting)
+ return number_pattern(1, 1);
+
+ if (err_flags.err_pwmled2)
+ return number_pattern(5, 1);
+
+ if (err_flags.err_pwmled1)
+ return number_pattern(4, 1);
+
+ if (err_flags.err_pwmled0)
+ return number_pattern(3, 1);
+
+ if (err_flags.err_battery)
+ return number_pattern(2, 1);
+
+ if (err_flags.braking)
return on_pattern;
if (buttons_setup_in_progress())
if (buttons_setup_in_progress())
return buttons_setup_status1_pattern_select();
- if (battery_critical)
+ if (err_flags.err_battery)
return NULL;
switch (ambient_zone) {
{
uint16_t brightness = PWMLED_BRIGHTNESS(0, 2, 1, 0, 2); // default
- if (battery_critical) {
+ if (err_flags.err_battery) {
brightness = PWMLED_BRIGHTNESS(0, 0, 0, 0, 0);
} else if (ambient_zone == 0) {
if (dim_mode)
pattern_t *buttons_setup_status1_pattern_select();
/* battery.c */
-extern volatile unsigned char battery_critical;
void battery_adc();
void init_battery();
unsigned char battery_gauge();
/* control.c */
extern pattern_t on_pattern[];
-extern volatile unsigned char braking;
+typedef union {
+ unsigned char any_flag;
+ struct {
+ unsigned char booting : 1;
+ unsigned char braking : 1;
+ unsigned char err_battery : 1;
+ unsigned char err_pwmled0 : 1;
+ unsigned char err_pwmled1 : 1;
+ unsigned char err_pwmled2 : 1;
+ };
+} err_flags_t;
+extern volatile err_flags_t err_flags;
void init_control();
void brake_on();