]> www.fi.muni.cz Git - heater.git/blobdiff - firmware/main.c
firmware: different visual feedback
[heater.git] / firmware / main.c
index 0aa1c4abdfb3be3c77dece344f54abc84d24083b..0d45ac93d9a6429bc040486f173f93a2f7d9b0bc 100644 (file)
@@ -33,9 +33,8 @@
  * Status LED:
  * When powering up by a button press, the LED goes on to provide a visual
  * feedback, and is switched off after the button is released.
  * Status LED:
  * When powering up by a button press, the LED goes on to provide a visual
  * feedback, and is switched off after the button is released.
- * After a button press, the # of blinks of the LED reflects the
- * chosen output power level for some time. Afterwards, it displays
- * the battery level.
+ * It displays the current power level and current battery voltage
+ * using # of blinks with different blinking lengths.
  * When the battery is completely exhausted, the output power is switched
  * off, the LED keeps blinking for some time, and then the whole system is
  * switched off to avoid deep discharge of the battery.
  * When the battery is completely exhausted, the output power is switched
  * off, the LED keeps blinking for some time, and then the whole system is
  * switched off to avoid deep discharge of the battery.
 #define WAKEUP_POLL 50 // msec
 #define WAKEUP_LIMIT 5 // times WAKEUP_POLL
 
 #define WAKEUP_POLL 50 // msec
 #define WAKEUP_LIMIT 5 // times WAKEUP_POLL
 
+// #define BUTTONS_REVERSE
+
+#ifdef BUTTONS_REVERSE
+#      define BUTTON1  PB0
+#      define BUTTON2  PB1
+#else
+#      define BUTTON1  PB1
+#      define BUTTON2  PB0
+#endif /* !BUTTONS_REVERSE */
+
 /* which state (output on or output off) are we measuring now */
 static volatile unsigned char adc_type, adc_drop;
 #define ADC_RUNAVG_SHIFT 5     // running average shift on batt_on, batt_off
 /* which state (output on or output off) are we measuring now */
 static volatile unsigned char adc_type, adc_drop;
 #define ADC_RUNAVG_SHIFT 5     // running average shift on batt_on, batt_off
@@ -107,9 +116,7 @@ static unsigned char power_levels[] = {
 #define N_POWER_LEVELS (sizeof(power_levels) / sizeof(power_levels[0]))
 
 static unsigned char power_level = 0; // selected power level
 #define N_POWER_LEVELS (sizeof(power_levels) / sizeof(power_levels[0]))
 
 static unsigned char power_level = 0; // selected power level
-static unsigned char power_level_changed; // for visual feedback
 
 
-#define LED_PWRCHANGE_COUNT    5
 #define LED_BATTEMPTY_COUNT    60
 
 /* timing by WDT */
 #define LED_BATTEMPTY_COUNT    60
 
 /* timing by WDT */
@@ -267,9 +274,9 @@ static void buttons_susp()
 static unsigned char buttons_pressed()
 {
        return (
 static unsigned char buttons_pressed()
 {
        return (
-               (PINB & _BV(PB0) ? 0 : 1)
+               (PINB & _BV(BUTTON1) ? 0 : 1)
                |
                |
-               (PINB & _BV(PB1) ? 0 : 2)
+               (PINB & _BV(BUTTON2) ? 0 : 2)
        );
 }
 
        );
 }
 
@@ -379,10 +386,12 @@ static unsigned char battery_level()
 static void status_led_next_pattern()
 {
        static unsigned char battery_exhausted;
 static void status_led_next_pattern()
 {
        static unsigned char battery_exhausted;
+       static unsigned char display_power_level;
 
 
-       if (power_level_changed) {
-               power_level_changed--;
+       if (display_power_level) {
                n_blinks = power_level + 1;
                n_blinks = power_level + 1;
+               blink_on_time = 1;
+               blink_off_time = 2;
        } else {
                unsigned char b_level = battery_level();
                if (b_level) {
        } else {
                unsigned char b_level = battery_level();
                if (b_level) {
@@ -395,11 +404,12 @@ static void status_led_next_pattern()
                }
 
                n_blinks = b_level + 1;
                }
 
                n_blinks = b_level + 1;
+               blink_on_time = 3;
+               blink_off_time = 0;
        }
 
        }
 
-       blink_on_time = 2;
-       blink_off_time = 1;
        blink_counter = 10;
        blink_counter = 10;
+       display_power_level = !display_power_level;
 }
 
 static void timer_blink()
 }
 
 static void timer_blink()
@@ -422,9 +432,6 @@ static void timer_blink()
 static void button_pressed(unsigned char button, unsigned char long_press)
 {
        // ignore simlultaneous button 1 and 2 press
 static void button_pressed(unsigned char button, unsigned char long_press)
 {
        // ignore simlultaneous button 1 and 2 press
-       // Note: we set power_level_changed after each button press,
-       // even when the power is at maximum, to provide visual feedback
-       // with status LED.
        if (long_press) {
                if (button == 1) {
                        power_down();
        if (long_press) {
                if (button == 1) {
                        power_down();
@@ -446,7 +453,6 @@ static void button_pressed(unsigned char button, unsigned char long_press)
                        }
                }
        }
                        }
                }
        }
-       power_level_changed = LED_PWRCHANGE_COUNT;
        status_led_next_pattern();
 }
 
        status_led_next_pattern();
 }