From ee949829d98c3b8df685319559a5798aad74bf13 Mon Sep 17 00:00:00 2001 From: jacqueline Date: Tue, 22 Aug 2023 15:55:25 +1000 Subject: Add battery % with change events --- src/system_fsm/booting.cpp | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'src/system_fsm/booting.cpp') diff --git a/src/system_fsm/booting.cpp b/src/system_fsm/booting.cpp index 27f2b9c9..78653592 100644 --- a/src/system_fsm/booting.cpp +++ b/src/system_fsm/booting.cpp @@ -4,6 +4,8 @@ * SPDX-License-Identifier: GPL-3.0-only */ +#include + #include "assert.h" #include "audio_fsm.hpp" #include "bluetooth.hpp" @@ -12,6 +14,10 @@ #include "esp_err.h" #include "esp_log.h" #include "event_queue.hpp" +#include "freertos/FreeRTOS.h" +#include "freertos/portmacro.h" +#include "freertos/projdefs.h" +#include "freertos/timers.h" #include "gpios.hpp" #include "lvgl/lvgl.h" #include "nvs.hpp" @@ -32,6 +38,12 @@ namespace states { static const char kTag[] = "BOOT"; +static const TickType_t kBatteryCheckPeriod = pdMS_TO_TICKS(60 * 1000); + +static void battery_timer_cb(TimerHandle_t timer) { + events::System().Dispatch(internal::BatteryTimerFired{}); +} + auto Booting::entry() -> void { ESP_LOGI(kTag, "beginning tangara boot"); ESP_LOGI(kTag, "installing early drivers"); @@ -62,6 +74,12 @@ auto Booting::entry() -> void { return; } + ESP_LOGI(kTag, "battery is at %u%% (= %lu mV)", sBattery->Percent(), + sBattery->Millivolts()); + TimerHandle_t battery_timer = xTimerCreate("battery", kBatteryCheckPeriod, + true, NULL, battery_timer_cb); + xTimerStart(battery_timer, portMAX_DELAY); + ESP_LOGI(kTag, "starting bluetooth"); sBluetooth.reset(new drivers::Bluetooth(sNvs.get())); // sBluetooth->Enable(); -- cgit v1.2.3