]> www.fi.muni.cz Git - tinyboard.git/commitdiff
Error reporting via status LED
authorJan "Yenya" Kasprzak <kas@fi.muni.cz>
Wed, 1 May 2013 20:48:32 +0000 (22:48 +0200)
committerJan "Yenya" Kasprzak <kas@fi.muni.cz>
Wed, 1 May 2013 20:48:32 +0000 (22:48 +0200)
projects/step-up/control.c
projects/step-up/lights.h
projects/step-up/pwmled.c

index c877c87ae82fc2482551cd9ab4211edbd88a76b7..99190cc45f2947e4b382e83cf1197b10b9613375 100644 (file)
@@ -24,23 +24,48 @@ static pattern_t slow_pattern[] = {
        PATTERN_END
 };
 
-static unsigned char light_mode, shutdown_in_progress;
+static unsigned char light_mode;
+static union {
+       unsigned char errors;
+       struct {
+               unsigned char shutdown_in_progress : 1;
+               unsigned char pwmled_error : 1;
+               unsigned char battery_low : 1;
+       };
+} e;
+
+void set_error(unsigned char err)
+{
+       switch(err) {
+       case ERR_BATTERY:
+               e.battery_low = 1;
+               pwmled_set_target(0);
+               pattern_reload();
+               break;
+       case ERR_PWMLED:
+               e.pwmled_error = 1;
+               break;
+       }
+}
 
 void init_control()
 {
        light_mode = 1;
-       shutdown_in_progress = 0;
+       e.errors = 0;
        short_press();
 }
 
 void long_press_start()
 {
-       shutdown_in_progress = 1;
+       e.shutdown_in_progress = 1;
        pattern_reload();
 }
 
 void short_press()
 {
+       if (e.battery_low)
+               return;
+
        if (++light_mode >= 2*N_PWMLED_MODES)
                light_mode = 0;
 
@@ -52,15 +77,18 @@ void short_press()
 
 void long_press()
 {
-       shutdown_in_progress = 0;
+       e.shutdown_in_progress = 0;
        pattern_reload();
 }
 
 pattern_t *pwmled_pattern_select()
 {
-       if (shutdown_in_progress)
+       if (e.shutdown_in_progress)
                return NULL;
 
+       if (e.battery_low)
+               return slow_pattern;
+
        if (light_mode == 0) {
                return slow_pattern;
        } else if (light_mode < N_PWMLED_MODES) {
@@ -72,9 +100,15 @@ pattern_t *pwmled_pattern_select()
 
 pattern_t *status_led_pattern_select()
 {
-       if (shutdown_in_progress)
+       if (e.shutdown_in_progress)
                return on_pattern;
 
+       if (e.pwmled_error)
+               return number_pattern(3, 1);
+
+       if (e.battery_low)
+               return number_pattern(1, 1);
+
        return number_pattern(light_mode+1, 0);
 }
 
index 9cbc0c957228bd8ffe9da9e0e97662de82f1c4e6..04373789696f45f2aae5908ad260f36b0a47fb11 100644 (file)
@@ -77,6 +77,9 @@ void brake_on();
 void brake_off();
 pattern_t *pwmled_pattern_select();
 pattern_t *status_led_pattern_select();
+#define ERR_BATTERY 1
+#define ERR_PWMLED  2
+void set_error(unsigned char err);
 
 /* main.c */
 void power_down();
index 24fbe87cc8b6d93f2e6604af7744aeb22befd483..e7b702747de7ceb02d5707e55cdd3e9753d345ad 100644 (file)
@@ -74,6 +74,8 @@ static inline void pwmled_err()
 
        log_byte(0xF1);
        log_flush();
+
+       set_error(ERR_PWMLED);
 }