diff options
Diffstat (limited to 'sw/main.cpp')
-rw-r--r-- | sw/main.cpp | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/sw/main.cpp b/sw/main.cpp index 894693a..69e554a 100644 --- a/sw/main.cpp +++ b/sw/main.cpp @@ -22,6 +22,8 @@ * SOFTWARE. */ +#include "config.h" + #include <stdlib.h> #include <stdint.h> #include <stdio.h> @@ -268,10 +270,15 @@ static void send_capacity(uint32_t capacity, const timer_t& time) uart_puts(timestamp_buf); } -static void send_voltage(uint32_t millivolts, bool bat_plus, const timer_t& time) +enum class adc_voltage_id { + V_BAT_PLUS, + V_BAT_MINUS, +}; + +static void send_voltage(uint32_t millivolts, adc_voltage_id voltage_id, const timer_t& time) { snprintf(timestamp_buf, sizeof(timestamp_buf), "VBAT%c,%ld,%ld" ENDL, - bat_plus ? '+' : '-', + voltage_id == adc_voltage_id::V_BAT_PLUS ? '+' : '-', time.get_seconds_atomic(), millivolts); uart_puts(timestamp_buf); } @@ -399,7 +406,7 @@ int main() // One second blink interval pins_set_status(time_now.seconds_ % 2 == 0); -#if 0 +#if ENABLE_STORE_TO_EEPROM /* EEPROM has an endurance of at least 100'000 write/erase cycles. * (Datasheet 8.4 EEPROM Data Memory) * Storing every five hours gives us several years of endurance. @@ -479,7 +486,7 @@ int main() // Datasheet 24.9.3 says ADCL must be read first const uint8_t adcl = ADCL; const uint16_t adc_value_0 = ((uint16_t)ADCH << 8) | adcl; - send_voltage(ADC_VALUE_TO_MILLIVOLT(adc_value_0) * 4, true, time_now); + send_voltage(ADC_VALUE_TO_MILLIVOLT(adc_value_0) * 4, adc_voltage_id::V_BAT_PLUS, time_now); SET_ADMUX(1); // Start ADC conversion ADCSRA |= _BV(ADSC); @@ -495,7 +502,7 @@ int main() const uint16_t adc_value_1 = ((uint16_t)ADCH << 8) | adcl; adc_state = adc_state_t::IDLE; - send_voltage(ADC_VALUE_TO_MILLIVOLT(adc_value_1) * 4, false, time_now); + send_voltage(ADC_VALUE_TO_MILLIVOLT(adc_value_1) * 4, adc_voltage_id::V_BAT_MINUS, time_now); } break; } |