summaryrefslogtreecommitdiff
path: root/src/system_fsm/booting.cpp
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2023-08-22 15:55:25 +1000
committerjacqueline <me@jacqueline.id.au>2023-08-22 15:55:25 +1000
commitee949829d98c3b8df685319559a5798aad74bf13 (patch)
tree68cbf80bdc61a2bdb7572d33e47c7f6230555406 /src/system_fsm/booting.cpp
parent9c105cf613fb849268d619dc887dc2b54dcd4ec6 (diff)
downloadtangara-fw-ee949829d98c3b8df685319559a5798aad74bf13.tar.gz
Add battery % with change events
Diffstat (limited to 'src/system_fsm/booting.cpp')
-rw-r--r--src/system_fsm/booting.cpp18
1 files changed, 18 insertions, 0 deletions
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 <stdint.h>
+
#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();