detect no battery

This commit is contained in:
King Kévin 2016-04-13 21:00:59 +02:00
parent 281c9924f6
commit ec57456537
1 changed files with 12 additions and 7 deletions

9
main.c
View File

@ -312,13 +312,13 @@ static void clock_hours(void)
*/
static void process_command(char* str)
{
/* split command */
// split command
const char* delimiter = " ";
char* word = strtok(str,delimiter);
if (!word) {
goto error;
}
/* parse command */
// parse command
if (0==strcmp(word,"help")) {
printf("available commands:\n");
printf("time [HH:MM:SS]\n");
@ -417,10 +417,14 @@ int main(void)
while (!adc_eoc(ADC1)); // wait until conversion finished
uint16_t battery_value = adc_read_regular(ADC1); // read converted battery voltage
float battery_voltage = battery_value*1.2/ref_value; // calculate battery voltage
if (battery_voltage<1.0) {
printf("no battery detected\n");
} else {
if (battery_voltage<2.4) {
printf("/!\\ low ");
}
printf("battery voltage: %.2fV\n", battery_voltage);
}
// show voltage on LEDs
if (battery_voltage<1.0) { // battery probable not connected
@ -500,6 +504,7 @@ int main(void)
adc_start_conversion_regular(ADC1); // start measuring ambient luminosity
}
if ((rtc_get_counter_val()%ticks_second)==0) { // one second passed
printf("tick: %lu\n", rtc_get_counter_val());
led_toggle(); // LED activity to show we are not stuck
}
if ((rtc_get_counter_val()%ticks_minute)==0) { // one minute passed