Low battery bugfix:
[heater.git] / firmware / main.c
index 95cf70a..65801e8 100644 (file)
@@ -79,9 +79,10 @@ static volatile uint16_t batt_on, batt_off; // measured voltage
                                * (1024UL * (mV)) \
                                / (6UL * ADC_1100MV_VALUE)) >> 8))
 static unsigned char batt_levels[] = {
-       MV_TO_ADC8(3350),
-       MV_TO_ADC8(3700),
-       MV_TO_ADC8(3900),
+       MV_TO_ADC8(3000), // below this, do not enable load, and switch off
+       MV_TO_ADC8(3150), // below this, switch off after some time
+       MV_TO_ADC8(3450), // battery low
+       MV_TO_ADC8(3800), // battery ok, above that almost full
 };
 #define BATT_N_LEVELS  (sizeof(batt_levels) / sizeof(batt_levels[0]))
 
@@ -395,7 +396,7 @@ static void status_led_next_pattern()
                }
        } else {
                unsigned char b_level = battery_level();
-               if (b_level) {
+               if (b_level > 1) {
                        battery_exhausted = 0;
                } else if (battery_exhausted) {
                        if (!--battery_exhausted)
@@ -404,8 +405,8 @@ static void status_led_next_pattern()
                        battery_exhausted = LED_BATTEMPTY_COUNT;
                }
 
-               n_blinks = b_level + 1;
-               blink_on_time = 4;
+               n_blinks = b_level ? b_level : 1;
+               blink_on_time = b_level ? 4 : 2;
                blink_off_time = 0;
        }
 
@@ -563,6 +564,10 @@ int main()
                                log_byte(batt_on >> 8);
 #endif
                        }
+                       if (jiffies == 0) {
+                               log_byte(batt_on >> 8);
+                               log_byte(batt_off >> 8);
+                       }
                        log_flush();
                }
        }