]> www.fi.muni.cz Git - bike-lights.git/commitdiff
Error flags, error reporting
authorJan "Yenya" Kasprzak <kas@fi.muni.cz>
Fri, 19 Jul 2013 16:16:20 +0000 (18:16 +0200)
committerJan "Yenya" Kasprzak <kas@fi.muni.cz>
Fri, 19 Jul 2013 16:16:20 +0000 (18:16 +0200)
- all error flags are in the bit array err_flags, including braking and
  booting (this is unused yet, the idea is to report successful boot and
  pwmled init somehow).
- error status is reported as num_pattern(err, 1) by the status LED
- error status (if any) can be cleared by pressing the button 1
  (which takes precedence over the panic mode)

firmware/battery.c
firmware/control.c
firmware/lights.h
firmware/pattern.c
firmware/pwmled.c

index 542d20e76e4325beb29d7366517e41bae5e32d2c..4763f0563334f99423d99a6e2f9893cabe034a27 100644 (file)
@@ -114,7 +114,9 @@ unsigned char battery_gauge()
 
 #if 0
        if (battery_adcval && rv == 1)
-               battery_critical = 1;
+               err_flags.err_battery = 1;
+       else
+               err_flags.err_battery = 0;
 #endif
 
 #if 0
index c351ca80b0fef5a386ce493a866dc65c98a0bb70..a0d2451a5df08cd0b095c7438b05bc714bd613c3 100644 (file)
@@ -75,21 +75,24 @@ pattern_t test_pattern[] = {
 };
 #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();
@@ -97,7 +100,7 @@ void brake_on()
 
 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();
@@ -112,8 +115,21 @@ void toggle_dim_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()
@@ -121,7 +137,7 @@ 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) {
@@ -136,7 +152,22 @@ pattern_t *pwmled_pattern_select()
 
 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())
@@ -151,7 +182,7 @@ pattern_t *illumination_led_pattern_select()
        if (buttons_setup_in_progress())
                return buttons_setup_status1_pattern_select();
 
-       if (battery_critical)
+       if (err_flags.err_battery)
                return NULL;
 
        switch (ambient_zone) {
@@ -183,7 +214,7 @@ void pwmled_select_brightness()
 {
        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)
index 71051e945e6f7f21b79efb5ed359d89dc730f8b9..3af09cd9c2555dd93a72670f852e413981b778dd 100644 (file)
@@ -124,14 +124,24 @@ pattern_t *buttons_setup_status0_pattern_select();
 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();
index 83a932e2e0abc21b5fb075920b985bfeff7bf4f8..b4edcc4309a4df77b3a5a57f79c1307b255e3712 100644 (file)
@@ -110,7 +110,7 @@ void pwmleds_update_mode()
        mode1 = (mode >> 2) & 1;
        mode2 = (mode >> 3) & 3;
 
-       if (braking && !battery_critical) {
+       if (err_flags.braking && !err_flags.err_battery) {
                mode0 = 2;
                if (mode2 == 2)
                        mode2 = 3;
index 7c4324c0170bb6b2fa6d56b60877a1e46feabee1..30b10f1d307c0c501ac57fc49ff0e587b860ffdb 100644 (file)
@@ -225,6 +225,12 @@ static inline void pwmled_err(unsigned char n)
        log_byte(n);
        log_word(jiffies);
        log_flush();
+
+       switch (n) {
+       case 0: err_flags.err_pwmled0 = 1; break;
+       case 1: err_flags.err_pwmled1 = 1; break;
+       case 2: err_flags.err_pwmled2 = 1; break;
+       }
 }