summaryrefslogtreecommitdiff
path: root/src/tangara/ui/ui_fsm.cpp
diff options
context:
space:
mode:
authorjacqueline <me@jacqueline.id.au>2024-07-24 15:29:45 +1000
committerjacqueline <me@jacqueline.id.au>2024-07-24 15:29:45 +1000
commit0cc75366848e9205ac88884afcc128925024ccec (patch)
tree82fcd90d7f427c5f40112b8d8aa6293535372702 /src/tangara/ui/ui_fsm.cpp
parenteb5d0d50cd5a8d807897c08438e932083e5197c2 (diff)
downloadtangara-fw-0cc75366848e9205ac88884afcc128925024ccec.tar.gz
Add a settings screen with power+battery info
Mostly for debugging, but also u can toggle fast charging off and on now
Diffstat (limited to 'src/tangara/ui/ui_fsm.cpp')
-rw-r--r--src/tangara/ui/ui_fsm.cpp34
1 files changed, 28 insertions, 6 deletions
diff --git a/src/tangara/ui/ui_fsm.cpp b/src/tangara/ui/ui_fsm.cpp
index cd39dc9c..38e9b8e1 100644
--- a/src/tangara/ui/ui_fsm.cpp
+++ b/src/tangara/ui/ui_fsm.cpp
@@ -101,6 +101,15 @@ static auto lvgl_delay_cb(uint32_t ms) -> void {
lua::Property UiState::sBatteryPct{0};
lua::Property UiState::sBatteryMv{0};
lua::Property UiState::sBatteryCharging{false};
+lua::Property UiState::sPowerChargeState{"unknown"};
+lua::Property UiState::sPowerFastChargeEnabled{
+ false, [](const lua::LuaValue& val) {
+ if (!std::holds_alternative<bool>(val)) {
+ return false;
+ }
+ sServices->samd().SetFastChargeEnabled(std::get<bool>(val));
+ return true;
+ }};
lua::Property UiState::sBluetoothEnabled{
false, [](const lua::LuaValue& val) {
@@ -406,6 +415,13 @@ void UiState::react(const system_fsm::BatteryStateChanged& ev) {
sBatteryPct.setDirect(static_cast<int>(ev.new_state.percent));
sBatteryMv.setDirect(static_cast<int>(ev.new_state.millivolts));
sBatteryCharging.setDirect(ev.new_state.is_charging);
+ sPowerChargeState.setDirect(
+ drivers::Samd::chargeStatusToString(ev.new_state.raw_status));
+
+ // FIXME: Avoid calling these event handlers before boot.
+ if (sServices) {
+ sPowerFastChargeEnabled.setDirect(sServices->nvs().FastCharge());
+ }
}
void UiState::react(const audio::QueueUpdate&) {
@@ -414,7 +430,8 @@ void UiState::react(const audio::QueueUpdate&) {
sQueueSize.setDirect(static_cast<int>(queue_size));
int current_pos = queue.currentPosition();
- // If there is nothing in the queue, the position should be 0, otherwise, add one because lua
+ // If there is nothing in the queue, the position should be 0, otherwise, add
+ // one because lua
if (queue_size > 0) {
current_pos++;
}
@@ -564,11 +581,14 @@ void Lua::entry() {
auto& registry = lua::Registry::instance(*sServices);
sLua = registry.uiThread();
- registry.AddPropertyModule("power", {
- {"battery_pct", &sBatteryPct},
- {"battery_millivolts", &sBatteryMv},
- {"plugged_in", &sBatteryCharging},
- });
+ registry.AddPropertyModule("power",
+ {
+ {"battery_pct", &sBatteryPct},
+ {"battery_millivolts", &sBatteryMv},
+ {"plugged_in", &sBatteryCharging},
+ {"charge_state", &sPowerChargeState},
+ {"fast_charge", &sPowerFastChargeEnabled},
+ });
registry.AddPropertyModule(
"bluetooth", {
{"enabled", &sBluetoothEnabled},
@@ -663,6 +683,8 @@ void Lua::entry() {
}
sBluetoothKnownDevices.setDirect(bt.knownDevices());
+ sPowerFastChargeEnabled.setDirect(sServices->nvs().FastCharge());
+
if (sServices->sd() == drivers::SdState::kMounted) {
sLua->RunScript("/sdcard/config.lua");
}