v2 firmware: HA command channel, battery screen, dynamic Home buttons, tilt-dimmer
Watch-side features developed on the AMOLED-2.06 and shared across all boards:
- BLE command channel (…0005, notify watch→PC) via ble_send_command(); the
watch stays "dumb" and the daemon maps commands to Home Assistant.
- Battery detail screen + protective low-voltage cutoff; power HAL gains
battery_mv() / shutdown(), with battery_est.{h,cpp} for the time-left anchor.
- Home screen: dynamic 2-column button grid driven by the desktop config
(RX "btns" labels); tap notifies {"cmd":"btn","i":N}.
- Dimmer screen: IMU tilt-joystick over the light's brightness / color temp.
imu_hal_read_accel() added to the HAL (real on 2.06/2.16, no-op elsewhere);
streams absolute {"cmd":"bri"|"ct","v":..}; daemon seeds the dial via "dim".
Per-board tilt axis is calibrated with the DIM_CALIB overlay (off by default).
Multi-board fix: enable LV_FONT_MONTSERRAT_20/28 on the 2.16, 1.8 and C6 envs.
Shared ui.cpp uses these glyphs for the launcher tiles and back chevron, so
those three boards had failed to compile since the Phase-2 UI landed. All four
envs now build clean. README: correct the Windows pairing name to "Clawdmeter".
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
+619
-55
@@ -2,9 +2,11 @@
|
||||
#include "splash.h"
|
||||
#include <lvgl.h>
|
||||
#include <string.h>
|
||||
#include <math.h>
|
||||
#include "logo.h"
|
||||
#include "icons.h"
|
||||
#include "hal/board_caps.h"
|
||||
#include "hal/imu_hal.h"
|
||||
|
||||
// Custom fonts (scaled for 314 PPI, ~1.9x from original 165 PPI)
|
||||
LV_FONT_DECLARE(font_tiempos_56);
|
||||
@@ -124,12 +126,16 @@ static lv_obj_t* battery_img;
|
||||
static lv_obj_t* logo_img;
|
||||
static lv_image_dsc_t battery_dscs[5]; // empty, low, medium, full, charging
|
||||
|
||||
// Latest battery telemetry, pushed by ui_update_battery() and read by the
|
||||
// battery detail screen. minutes_left: >=0 minutes, -1 estimating, -2 charging.
|
||||
static int g_bat_pct = -1;
|
||||
static int g_bat_mv = 0;
|
||||
static int g_bat_min = -2;
|
||||
static bool g_bat_charging = false;
|
||||
|
||||
// ---- v2 navigation: launcher, stub & bluetooth screens ----
|
||||
static lv_obj_t* nav_back_btn; // top-left back chevron (shown off the home screen)
|
||||
static lv_obj_t* menu_container; // app launcher (scrollable tile grid)
|
||||
static lv_obj_t* stub_container; // generic "coming soon" screen, retitled per app
|
||||
static lv_obj_t* stub_title;
|
||||
static lv_obj_t* stub_icon;
|
||||
static lv_obj_t* bt_container; // BLE connection info
|
||||
static lv_obj_t* bt_status_lbl;
|
||||
static lv_obj_t* bt_name_lbl;
|
||||
@@ -144,6 +150,25 @@ static lv_obj_t* np_icon_lbl; // play / pause / music glyph
|
||||
static lv_obj_t* np_title_lbl; // track title (scrolls if long)
|
||||
static lv_obj_t* np_artist_lbl; // track artist
|
||||
static lv_obj_t* np_status_lbl; // "Playing" / "Paused"
|
||||
static lv_obj_t* battery_container; // battery detail (voltage + time left)
|
||||
static lv_obj_t* bat_pct_lbl; // big percentage hero
|
||||
static lv_obj_t* bat_bar; // horizontal charge bar
|
||||
static lv_obj_t* bat_volt_lbl; // "3.92 V"
|
||||
static lv_obj_t* bat_time_lbl; // "~2h 15m left" / "Charging" / "Estimating…"
|
||||
static lv_obj_t* bat_note_lbl; // protective-cutoff note
|
||||
static lv_obj_t* homeassist_container; // Home control: config-driven buttons (Phase 7 M2)
|
||||
static lv_obj_t* ha_status_lbl; // bottom feedback line ("Sent: <label>")
|
||||
static lv_obj_t* ha_empty_lbl; // hint shown when no buttons are configured
|
||||
static lv_obj_t* ha_btn_grid; // flex grid holding the button tiles
|
||||
static lv_obj_t* ha_btns[UI_MAX_BUTTONS]; // pre-created tiles (shown/hidden by count)
|
||||
static lv_obj_t* ha_btn_lbls[UI_MAX_BUTTONS]; // each tile's text label
|
||||
static char ha_btn_text[UI_MAX_BUTTONS][20]; // copied labels (Cyrillic-safe, NUL-terminated)
|
||||
static int ha_btn_count = 0; // how many tiles are currently shown
|
||||
static lv_obj_t* dimmer_container; // tilt-to-dim light control (Phase 6 step 3 / M3)
|
||||
static lv_obj_t* dim_arc; // value dial (brightness % or color-temp K)
|
||||
static lv_obj_t* dim_value_lbl; // big number in the dial center
|
||||
static lv_obj_t* dim_param_lbl; // "Brightness" / "Temp"
|
||||
static lv_obj_t* dim_status_lbl; // hint / armed state line
|
||||
|
||||
// App registry — the launcher renders one tile per entry, so adding a screen is
|
||||
// one line here plus its builder. Order = tile order. "Animations" reuses the
|
||||
@@ -160,6 +185,7 @@ static const AppEntry APPS[] = {
|
||||
{ SCREEN_SESSION, "Session", LV_SYMBOL_LIST },
|
||||
{ SCREEN_NOWPLAYING, "Now Playing", LV_SYMBOL_PLAY },
|
||||
{ SCREEN_HOMEASSIST, "Home", LV_SYMBOL_HOME },
|
||||
{ SCREEN_DIMMER, "Dimmer", LV_SYMBOL_SETTINGS },
|
||||
{ SCREEN_BLUETOOTH, "Bluetooth", LV_SYMBOL_BLUETOOTH },
|
||||
};
|
||||
#define APP_COUNT (sizeof(APPS) / sizeof(APPS[0]))
|
||||
@@ -263,6 +289,8 @@ static void format_tokens(long long n, char* buf, size_t len) {
|
||||
static void global_click_cb(lv_event_t* e);
|
||||
static void logo_click_cb(lv_event_t* e);
|
||||
static void nav_back_cb(lv_event_t* e);
|
||||
static void battery_click_cb(lv_event_t* e);
|
||||
static void battery_screen_refresh(void);
|
||||
|
||||
static lv_obj_t* make_panel(lv_obj_t* parent, int x, int y, int w, int h) {
|
||||
lv_obj_t* panel = lv_obj_create(parent);
|
||||
@@ -453,13 +481,7 @@ static void init_usage_screen(lv_obj_t* scr) {
|
||||
lv_obj_align(lbl_anim, LV_ALIGN_BOTTOM_MID, 0, -15);
|
||||
}
|
||||
|
||||
// ======== v2: launcher, stub & bluetooth screens ========
|
||||
|
||||
static const AppEntry* app_for_screen(screen_t s) {
|
||||
for (size_t i = 0; i < APP_COUNT; i++)
|
||||
if (APPS[i].screen == s) return &APPS[i];
|
||||
return nullptr;
|
||||
}
|
||||
// ======== v2: launcher & bluetooth screens ========
|
||||
|
||||
// Centered screen title for the navigation screens. The back chevron lives in
|
||||
// the shared top-left chrome (nav_back_btn), so only the title is drawn here.
|
||||
@@ -542,34 +564,6 @@ static void init_menu_screen(lv_obj_t* scr) {
|
||||
lv_obj_add_flag(menu_container, LV_OBJ_FLAG_HIDDEN);
|
||||
}
|
||||
|
||||
// One generic "coming soon" screen, retitled per app in stub_show_for(). The
|
||||
// four future apps (Soundpad/Session/Now Playing/Home) point here until built.
|
||||
static void init_stub_screen(lv_obj_t* scr) {
|
||||
stub_container = lv_obj_create(scr);
|
||||
lv_obj_set_size(stub_container, L.scr_w, L.scr_h);
|
||||
lv_obj_set_pos(stub_container, 0, 0);
|
||||
lv_obj_set_style_bg_opa(stub_container, LV_OPA_TRANSP, 0);
|
||||
lv_obj_set_style_border_width(stub_container, 0, 0);
|
||||
lv_obj_set_style_pad_all(stub_container, 0, 0);
|
||||
lv_obj_clear_flag(stub_container, LV_OBJ_FLAG_SCROLLABLE);
|
||||
|
||||
stub_title = make_screen_title(stub_container, "");
|
||||
|
||||
stub_icon = lv_label_create(stub_container);
|
||||
lv_label_set_text(stub_icon, LV_SYMBOL_SETTINGS);
|
||||
lv_obj_set_style_text_font(stub_icon, &lv_font_montserrat_28, 0);
|
||||
lv_obj_set_style_text_color(stub_icon, COL_DIM, 0);
|
||||
lv_obj_align(stub_icon, LV_ALIGN_CENTER, 0, -20);
|
||||
|
||||
lv_obj_t* soon = lv_label_create(stub_container);
|
||||
lv_label_set_text(soon, "coming soon");
|
||||
lv_obj_set_style_text_font(soon, &font_styrene_20, 0);
|
||||
lv_obj_set_style_text_color(soon, COL_DIM, 0);
|
||||
lv_obj_align(soon, LV_ALIGN_CENTER, 0, 30);
|
||||
|
||||
lv_obj_add_flag(stub_container, LV_OBJ_FLAG_HIDDEN);
|
||||
}
|
||||
|
||||
static void init_bt_screen(lv_obj_t* scr) {
|
||||
bt_container = lv_obj_create(scr);
|
||||
lv_obj_set_size(bt_container, L.scr_w, L.scr_h);
|
||||
@@ -609,14 +603,6 @@ static void bt_refresh(void) {
|
||||
lv_label_set_text_fmt(bt_mac_lbl, "%s", ble_get_mac_address());
|
||||
}
|
||||
|
||||
static void stub_show_for(screen_t s) {
|
||||
const AppEntry* app = app_for_screen(s);
|
||||
if (app) {
|
||||
lv_label_set_text(stub_title, app->label);
|
||||
lv_label_set_text(stub_icon, app->symbol);
|
||||
}
|
||||
}
|
||||
|
||||
// ---- Soundpad: 6 pads → HID F13..F18 (the host maps them to a soundboard) ----
|
||||
// F13..F24 are HID usage IDs 0x68..0x73; the report-map keycode ceiling was
|
||||
// raised to 0x73 in ble.cpp so these transmit.
|
||||
@@ -791,6 +777,506 @@ static void init_nowplaying_screen(lv_obj_t* scr) {
|
||||
lv_obj_add_flag(nowplaying_container, LV_OBJ_FLAG_HIDDEN);
|
||||
}
|
||||
|
||||
// Home control (Phase 7 M2): a grid of buttons defined by the desktop config.
|
||||
// The watch is dumb — each tile only carries its index; on tap it notifies
|
||||
// {"cmd":"btn","i":N} and the daemon maps the index → action/entity → Home
|
||||
// Assistant call. Labels arrive in the RX payload's "btns" array (ui_set_buttons).
|
||||
static void ha_btn_click_cb(lv_event_t* e) {
|
||||
int idx = (int)(intptr_t)lv_event_get_user_data(e);
|
||||
char cmd[24];
|
||||
snprintf(cmd, sizeof cmd, "{\"cmd\":\"btn\",\"i\":%d}", idx);
|
||||
ble_send_command(cmd);
|
||||
if (ha_status_lbl && idx >= 0 && idx < ha_btn_count)
|
||||
lv_label_set_text_fmt(ha_status_lbl, "Sent: %s", ha_btn_text[idx]);
|
||||
}
|
||||
|
||||
static lv_obj_t* make_ha_button(lv_obj_t* parent, int idx, int w, int h) {
|
||||
lv_obj_t* btn = lv_obj_create(parent);
|
||||
lv_obj_set_size(btn, w, h);
|
||||
lv_obj_set_style_bg_color(btn, COL_PANEL, 0);
|
||||
lv_obj_set_style_bg_opa(btn, LV_OPA_COVER, 0);
|
||||
lv_obj_set_style_radius(btn, 16, 0);
|
||||
lv_obj_set_style_border_width(btn, 0, 0);
|
||||
lv_obj_set_style_border_width(btn, 3, LV_STATE_PRESSED); // accent ring on press
|
||||
lv_obj_set_style_border_color(btn, COL_ACCENT, LV_STATE_PRESSED);
|
||||
lv_obj_clear_flag(btn, LV_OBJ_FLAG_SCROLLABLE);
|
||||
lv_obj_add_flag(btn, LV_OBJ_FLAG_CLICKABLE);
|
||||
lv_obj_add_event_cb(btn, ha_btn_click_cb, LV_EVENT_CLICKED, (void*)(intptr_t)idx);
|
||||
|
||||
lv_obj_t* lbl = lv_label_create(btn);
|
||||
lv_obj_set_width(lbl, w - 16);
|
||||
lv_label_set_long_mode(lbl, LV_LABEL_LONG_DOT);
|
||||
lv_obj_set_style_text_align(lbl, LV_TEXT_ALIGN_CENTER, 0);
|
||||
lv_obj_set_style_text_font(lbl, &font_styrene_cyr_20, 0); // Cyrillic-capable (labels may be RU)
|
||||
lv_obj_set_style_text_color(lbl, COL_TEXT, 0);
|
||||
lv_label_set_text(lbl, "");
|
||||
lv_obj_center(lbl);
|
||||
ha_btn_lbls[idx] = lbl;
|
||||
return btn;
|
||||
}
|
||||
|
||||
static void init_homeassist_screen(lv_obj_t* scr) {
|
||||
homeassist_container = lv_obj_create(scr);
|
||||
lv_obj_set_size(homeassist_container, L.scr_w, L.scr_h);
|
||||
lv_obj_set_pos(homeassist_container, 0, 0);
|
||||
lv_obj_set_style_bg_opa(homeassist_container, LV_OPA_TRANSP, 0);
|
||||
lv_obj_set_style_border_width(homeassist_container, 0, 0);
|
||||
lv_obj_set_style_pad_all(homeassist_container, 0, 0);
|
||||
lv_obj_clear_flag(homeassist_container, LV_OBJ_FLAG_SCROLLABLE);
|
||||
|
||||
make_screen_title(homeassist_container, "Home");
|
||||
|
||||
// Button grid — same 2-column wrap/scroll pattern as the launcher & soundpad.
|
||||
int avail_h = L.scr_h - L.content_y - L.margin - 34; // leave room for the status line
|
||||
ha_btn_grid = lv_obj_create(homeassist_container);
|
||||
lv_obj_set_size(ha_btn_grid, L.content_w, avail_h);
|
||||
lv_obj_set_pos(ha_btn_grid, L.margin, L.content_y);
|
||||
lv_obj_set_style_bg_opa(ha_btn_grid, LV_OPA_TRANSP, 0);
|
||||
lv_obj_set_style_border_width(ha_btn_grid, 0, 0);
|
||||
lv_obj_set_style_pad_all(ha_btn_grid, 0, 0);
|
||||
lv_obj_set_style_pad_row(ha_btn_grid, 12, 0);
|
||||
lv_obj_set_style_pad_column(ha_btn_grid, 12, 0);
|
||||
lv_obj_set_flex_flow(ha_btn_grid, LV_FLEX_FLOW_ROW_WRAP);
|
||||
lv_obj_set_flex_align(ha_btn_grid, LV_FLEX_ALIGN_START, LV_FLEX_ALIGN_CENTER, LV_FLEX_ALIGN_START);
|
||||
lv_obj_set_scroll_dir(ha_btn_grid, LV_DIR_VER);
|
||||
lv_obj_set_scrollbar_mode(ha_btn_grid, LV_SCROLLBAR_MODE_AUTO);
|
||||
|
||||
int btn_w = (L.content_w - 16) / 2; // 2 columns, 4px slack
|
||||
int btn_h = (avail_h - 2 * 12) / 3 - 1; // up to 3 rows (6 buttons)
|
||||
for (int i = 0; i < UI_MAX_BUTTONS; i++) {
|
||||
ha_btns[i] = make_ha_button(ha_btn_grid, i, btn_w, btn_h);
|
||||
lv_obj_add_flag(ha_btns[i], LV_OBJ_FLAG_HIDDEN); // revealed by ui_set_buttons()
|
||||
}
|
||||
|
||||
// Placeholder shown until the daemon pushes a button set.
|
||||
ha_empty_lbl = lv_label_create(homeassist_container);
|
||||
lv_obj_set_width(ha_empty_lbl, L.content_w);
|
||||
lv_label_set_long_mode(ha_empty_lbl, LV_LABEL_LONG_WRAP);
|
||||
lv_obj_set_style_text_align(ha_empty_lbl, LV_TEXT_ALIGN_CENTER, 0);
|
||||
lv_obj_set_style_text_font(ha_empty_lbl, &font_styrene_20, 0);
|
||||
lv_obj_set_style_text_color(ha_empty_lbl, COL_DIM, 0);
|
||||
lv_label_set_text(ha_empty_lbl, "Add buttons in the\ndesktop app");
|
||||
lv_obj_align(ha_empty_lbl, LV_ALIGN_CENTER, 0, -10);
|
||||
|
||||
// Bottom feedback line — shows "Sent: <label>" on press.
|
||||
ha_status_lbl = lv_label_create(homeassist_container);
|
||||
lv_label_set_text(ha_status_lbl, "");
|
||||
lv_obj_set_style_text_font(ha_status_lbl, &font_styrene_cyr_20, 0);
|
||||
lv_obj_set_style_text_color(ha_status_lbl, COL_DIM, 0);
|
||||
lv_obj_align(ha_status_lbl, LV_ALIGN_BOTTOM_MID, 0, -8);
|
||||
|
||||
// Start in the "no buttons yet" state (grid hidden, placeholder shown).
|
||||
lv_obj_add_flag(ha_btn_grid, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_add_flag(homeassist_container, LV_OBJ_FLAG_HIDDEN);
|
||||
}
|
||||
|
||||
// Apply the button labels pushed by the daemon (RX "btns"). Copies the strings
|
||||
// (the source JSON is freed right after the parse), reveals that many tiles,
|
||||
// hides the rest, and toggles the placeholder. A no-op when nothing changed, so
|
||||
// the ~60s refresh never churns the UI or restarts press animations.
|
||||
void ui_set_buttons(const char* const* labels, int count) {
|
||||
if (!homeassist_container) return;
|
||||
if (count < 0) count = 0;
|
||||
if (count > UI_MAX_BUTTONS) count = UI_MAX_BUTTONS;
|
||||
|
||||
bool changed = (count != ha_btn_count);
|
||||
for (int i = 0; i < count && !changed; i++) {
|
||||
const char* s = labels[i] ? labels[i] : "";
|
||||
if (strncmp(ha_btn_text[i], s, sizeof(ha_btn_text[i])) != 0) changed = true;
|
||||
}
|
||||
if (!changed) return;
|
||||
|
||||
ha_btn_count = count;
|
||||
for (int i = 0; i < UI_MAX_BUTTONS; i++) {
|
||||
if (i < count) {
|
||||
strlcpy(ha_btn_text[i], labels[i] ? labels[i] : "", sizeof(ha_btn_text[i]));
|
||||
lv_label_set_text(ha_btn_lbls[i], ha_btn_text[i]);
|
||||
lv_obj_clear_flag(ha_btns[i], LV_OBJ_FLAG_HIDDEN);
|
||||
} else {
|
||||
ha_btn_text[i][0] = '\0';
|
||||
lv_obj_add_flag(ha_btns[i], LV_OBJ_FLAG_HIDDEN);
|
||||
}
|
||||
}
|
||||
if (count > 0) {
|
||||
lv_obj_add_flag(ha_empty_lbl, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_clear_flag(ha_btn_grid, LV_OBJ_FLAG_HIDDEN);
|
||||
} else {
|
||||
lv_obj_clear_flag(ha_empty_lbl, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_add_flag(ha_btn_grid, LV_OBJ_FLAG_HIDDEN);
|
||||
}
|
||||
}
|
||||
|
||||
// ======== Tilt-dimmer (Phase 6 step 3 / M3) ========
|
||||
//
|
||||
// The wrist is a one-axis joystick. While "armed", the watch reads its IMU each
|
||||
// loop, measures how far the chosen device axis has tilted away from the neutral
|
||||
// pose captured at arm time, and ramps the working value at a rate proportional
|
||||
// to that tilt (zero inside a small deadzone, capped at full tilt). The working
|
||||
// value drives the on-screen dial and is streamed to the daemon as an absolute
|
||||
// {"cmd":"bri"|"ct","v":..} write, throttled to ~5 Hz. Holding the wrist still
|
||||
// for a few seconds, or tapping the screen, commits and locks; BOOT re-arms;
|
||||
// PWR switches which parameter (brightness ⇄ color temperature) the tilt drives.
|
||||
|
||||
enum { DIM_BRI = 0, DIM_CT = 1 };
|
||||
|
||||
// --- tuning ---------------------------------------------------------------
|
||||
static const float DIM_DEADZONE_DEG = 8.0f; // ignore tilt smaller than this
|
||||
static const float DIM_MAX_DEG = 45.0f; // tilt for full-speed ramp
|
||||
static const float DIM_BRI_RATE = 45.0f; // %/s at full tilt
|
||||
static const float DIM_CT_RATE_FRAC = 0.45f; // fraction of the K-range/s at full tilt
|
||||
static const uint32_t DIM_SEND_MS = 180; // BLE write cap (~5.5 Hz)
|
||||
static const uint32_t DIM_AUTOLOCK_MS = 3500; // stillness this long → auto-commit
|
||||
|
||||
// Which device axis drives the dimmer and its sign. Tilt is the change in
|
||||
// asin(normalized gravity[axis]) from neutral. Calibrated on hardware — flip
|
||||
// these after watching the live read-out below. 0=X, 1=Y, 2=Z.
|
||||
#define DIM_AXIS 1
|
||||
#define DIM_SIGN (+1.0f)
|
||||
// While 1, the armed status line shows the live gravity vector + selected-axis
|
||||
// tilt so the axis/sign above can be chosen on the bench. Set to 0 once locked.
|
||||
// (Flip to 1 when calibrating the tilt axis on a new board.)
|
||||
#define DIM_CALIB 0
|
||||
|
||||
// --- state ----------------------------------------------------------------
|
||||
static int dim_param = DIM_BRI;
|
||||
static bool dim_armed = false;
|
||||
static bool dim_capture_pending = false; // capture neutral on the next good read
|
||||
static bool dim_have_snapshot = false;
|
||||
static bool dim_light_on = false;
|
||||
static float dim_bri = 50.0f; // working brightness % (1..100)
|
||||
static float dim_ct = 3000.0f; // working color temp (K)
|
||||
static int dim_min_k = 2000;
|
||||
static int dim_max_k = 6500;
|
||||
static float dim_neutral_deg = 0.0f; // selected-axis angle at neutral
|
||||
static uint32_t dim_last_tick_ms = 0;
|
||||
static uint32_t dim_last_send_ms = 0;
|
||||
static uint32_t dim_still_since_ms = 0;
|
||||
static int dim_last_sent_val = -99999;
|
||||
|
||||
static float dim_axis_angle_deg(float x, float y, float z) {
|
||||
float n = sqrtf(x * x + y * y + z * z);
|
||||
if (n < 0.01f) return 0.0f;
|
||||
float a = (DIM_AXIS == 0 ? x : (DIM_AXIS == 1 ? y : z)) / n;
|
||||
if (a > 1.0f) a = 1.0f;
|
||||
if (a < -1.0f) a = -1.0f;
|
||||
return DIM_SIGN * asinf(a) * 57.2958f;
|
||||
}
|
||||
|
||||
static void dim_update_status(void) {
|
||||
if (!dim_status_lbl) return;
|
||||
if (dim_armed) {
|
||||
lv_obj_set_style_text_color(dim_status_lbl, COL_ACCENT, 0);
|
||||
lv_label_set_text(dim_status_lbl, "Tilt to adjust - tap to set");
|
||||
} else if (!dim_have_snapshot) {
|
||||
lv_obj_set_style_text_color(dim_status_lbl, COL_DIM, 0);
|
||||
lv_label_set_text(dim_status_lbl, "Connecting...");
|
||||
} else {
|
||||
lv_obj_set_style_text_color(dim_status_lbl, COL_DIM, 0);
|
||||
lv_label_set_text(dim_status_lbl, "BOOT to adjust - PWR switches");
|
||||
}
|
||||
}
|
||||
|
||||
static void dim_refresh_dial(void) {
|
||||
if (!dim_arc) return;
|
||||
if (dim_param == DIM_BRI) {
|
||||
int v = (int)lroundf(dim_bri);
|
||||
lv_arc_set_range(dim_arc, 0, 100);
|
||||
lv_arc_set_value(dim_arc, v);
|
||||
lv_label_set_text_fmt(dim_value_lbl, "%d%%", v);
|
||||
lv_label_set_text(dim_param_lbl, "Brightness");
|
||||
} else {
|
||||
int v = (int)lroundf(dim_ct);
|
||||
lv_arc_set_range(dim_arc, dim_min_k, dim_max_k);
|
||||
lv_arc_set_value(dim_arc, v);
|
||||
lv_label_set_text_fmt(dim_value_lbl, "%dK", v);
|
||||
lv_label_set_text(dim_param_lbl, "Temp");
|
||||
}
|
||||
}
|
||||
|
||||
// Push the working value to the daemon. `force` ignores the change-dedupe so a
|
||||
// commit lands exactly on the displayed number.
|
||||
static void dim_send_current(bool force) {
|
||||
char cmd[40];
|
||||
if (dim_param == DIM_BRI) {
|
||||
int v = (int)lroundf(dim_bri);
|
||||
if (!force && v == dim_last_sent_val) return;
|
||||
snprintf(cmd, sizeof cmd, "{\"cmd\":\"bri\",\"v\":%d}", v);
|
||||
dim_last_sent_val = v;
|
||||
} else {
|
||||
int v = (int)lroundf(dim_ct);
|
||||
if (!force && abs(v - dim_last_sent_val) < 20) return; // ~20K granularity
|
||||
snprintf(cmd, sizeof cmd, "{\"cmd\":\"ct\",\"v\":%d}", v);
|
||||
dim_last_sent_val = v;
|
||||
}
|
||||
ble_send_command(cmd);
|
||||
dim_light_on = true; // setting brightness/temp implicitly turns the light on
|
||||
}
|
||||
|
||||
static void dim_commit(void) {
|
||||
if (!dim_armed) return;
|
||||
dim_armed = false;
|
||||
dim_capture_pending = false;
|
||||
dim_send_current(true); // land HA exactly on the shown value
|
||||
dim_update_status();
|
||||
}
|
||||
|
||||
// Tap anywhere on the dial area commits (only meaningful while armed). The back
|
||||
// chevron and battery icon sit above this container and take their own taps.
|
||||
static void dim_tap_cb(lv_event_t* e) {
|
||||
(void)e;
|
||||
if (dim_armed) dim_commit();
|
||||
}
|
||||
|
||||
static void init_dimmer_screen(lv_obj_t* scr) {
|
||||
dimmer_container = lv_obj_create(scr);
|
||||
lv_obj_set_size(dimmer_container, L.scr_w, L.scr_h);
|
||||
lv_obj_set_pos(dimmer_container, 0, 0);
|
||||
lv_obj_set_style_bg_opa(dimmer_container, LV_OPA_TRANSP, 0);
|
||||
lv_obj_set_style_border_width(dimmer_container, 0, 0);
|
||||
lv_obj_set_style_pad_all(dimmer_container, 0, 0);
|
||||
lv_obj_clear_flag(dimmer_container, LV_OBJ_FLAG_SCROLLABLE);
|
||||
lv_obj_add_flag(dimmer_container, LV_OBJ_FLAG_CLICKABLE); // tap → commit
|
||||
lv_obj_add_event_cb(dimmer_container, dim_tap_cb, LV_EVENT_CLICKED, NULL);
|
||||
|
||||
make_screen_title(dimmer_container, "Dimmer");
|
||||
|
||||
int arc_sz = (L.scr_h >= 460) ? 280 : 240;
|
||||
dim_arc = lv_arc_create(dimmer_container);
|
||||
lv_obj_set_size(dim_arc, arc_sz, arc_sz);
|
||||
lv_obj_align(dim_arc, LV_ALIGN_CENTER, 0, 4);
|
||||
lv_arc_set_rotation(dim_arc, 135);
|
||||
lv_arc_set_bg_angles(dim_arc, 0, 270);
|
||||
lv_arc_set_range(dim_arc, 0, 100);
|
||||
lv_arc_set_value(dim_arc, 50);
|
||||
lv_obj_remove_style(dim_arc, NULL, LV_PART_KNOB); // display-only: no draggable knob
|
||||
lv_obj_clear_flag(dim_arc, LV_OBJ_FLAG_CLICKABLE); // taps fall through to the container
|
||||
lv_obj_clear_flag(dim_arc, LV_OBJ_FLAG_SCROLLABLE);
|
||||
lv_obj_set_style_arc_color(dim_arc, COL_BAR_BG, LV_PART_MAIN);
|
||||
lv_obj_set_style_arc_color(dim_arc, COL_ACCENT, LV_PART_INDICATOR);
|
||||
lv_obj_set_style_arc_width(dim_arc, 14, LV_PART_MAIN);
|
||||
lv_obj_set_style_arc_width(dim_arc, 14, LV_PART_INDICATOR);
|
||||
|
||||
dim_value_lbl = lv_label_create(dimmer_container);
|
||||
lv_obj_set_style_text_font(dim_value_lbl, &font_styrene_48, 0);
|
||||
lv_obj_set_style_text_color(dim_value_lbl, COL_TEXT, 0);
|
||||
lv_label_set_text(dim_value_lbl, "50%");
|
||||
lv_obj_align(dim_value_lbl, LV_ALIGN_CENTER, 0, -6);
|
||||
|
||||
dim_param_lbl = lv_label_create(dimmer_container);
|
||||
lv_obj_set_style_text_font(dim_param_lbl, &font_styrene_20, 0);
|
||||
lv_obj_set_style_text_color(dim_param_lbl, COL_DIM, 0);
|
||||
lv_label_set_text(dim_param_lbl, "Brightness");
|
||||
lv_obj_align(dim_param_lbl, LV_ALIGN_CENTER, 0, 36);
|
||||
|
||||
dim_status_lbl = lv_label_create(dimmer_container);
|
||||
lv_obj_set_width(dim_status_lbl, L.content_w);
|
||||
lv_obj_set_style_text_align(dim_status_lbl, LV_TEXT_ALIGN_CENTER, 0);
|
||||
lv_obj_set_style_text_font(dim_status_lbl, &font_styrene_16, 0);
|
||||
lv_obj_set_style_text_color(dim_status_lbl, COL_DIM, 0);
|
||||
lv_label_set_text(dim_status_lbl, "Connecting...");
|
||||
lv_obj_align(dim_status_lbl, LV_ALIGN_BOTTOM_MID, 0, -16);
|
||||
|
||||
lv_obj_add_flag(dimmer_container, LV_OBJ_FLAG_HIDDEN);
|
||||
}
|
||||
|
||||
// The daemon pushes the light's live state (RX "dim"). Seed the working value
|
||||
// and dial from it — but only while LOCKED, so a heartbeat that arrives mid-
|
||||
// adjust can't yank the value out from under the user's wrist.
|
||||
void ui_dimmer_set_snapshot(bool on, int bri_pct, int ct_kelvin, int min_k, int max_k) {
|
||||
dim_have_snapshot = true;
|
||||
dim_light_on = on;
|
||||
if (min_k > 0) dim_min_k = min_k;
|
||||
if (max_k > dim_min_k) dim_max_k = max_k;
|
||||
if (!dim_armed) {
|
||||
if (bri_pct >= 0) dim_bri = (float)bri_pct;
|
||||
if (ct_kelvin > 0) dim_ct = (float)ct_kelvin;
|
||||
if (dim_ct < dim_min_k) dim_ct = dim_min_k;
|
||||
if (dim_ct > dim_max_k) dim_ct = dim_max_k;
|
||||
dim_refresh_dial();
|
||||
if (current_screen == SCREEN_DIMMER) dim_update_status();
|
||||
}
|
||||
}
|
||||
|
||||
void ui_dimmer_arm(void) {
|
||||
if (current_screen != SCREEN_DIMMER) return;
|
||||
dim_armed = true;
|
||||
dim_capture_pending = true; // neutral pose captured on the next good read
|
||||
dim_last_tick_ms = lv_tick_get();
|
||||
dim_still_since_ms = 0;
|
||||
dim_last_send_ms = 0;
|
||||
dim_last_sent_val = -99999;
|
||||
dim_update_status();
|
||||
}
|
||||
|
||||
void ui_dimmer_switch_param(void) {
|
||||
if (current_screen != SCREEN_DIMMER) return;
|
||||
dim_param = (dim_param == DIM_BRI) ? DIM_CT : DIM_BRI;
|
||||
dim_armed = false; // re-arm with BOOT for the newly selected param
|
||||
dim_capture_pending = false;
|
||||
dim_last_sent_val = -99999;
|
||||
if (dim_param == DIM_CT && dim_ct <= 0) dim_ct = (dim_min_k + dim_max_k) / 2.0f;
|
||||
dim_refresh_dial();
|
||||
dim_update_status();
|
||||
}
|
||||
|
||||
bool ui_dimmer_is_armed(void) { return dim_armed && current_screen == SCREEN_DIMMER; }
|
||||
|
||||
void ui_dimmer_tick(void) {
|
||||
if (current_screen != SCREEN_DIMMER || !dim_armed) return;
|
||||
|
||||
float x, y, z;
|
||||
if (!imu_hal_read_accel(&x, &y, &z)) return;
|
||||
float ang_abs = dim_axis_angle_deg(x, y, z);
|
||||
|
||||
if (dim_capture_pending) {
|
||||
dim_neutral_deg = ang_abs; // this pose is "centered"
|
||||
dim_capture_pending = false;
|
||||
dim_last_tick_ms = lv_tick_get();
|
||||
return;
|
||||
}
|
||||
|
||||
float ang = ang_abs - dim_neutral_deg; // signed tilt from neutral
|
||||
|
||||
#if DIM_CALIB
|
||||
// LVGL's lv_label_set_text_fmt has no %f, so format with the C library first.
|
||||
char dbg[48];
|
||||
snprintf(dbg, sizeof dbg, "x%+.2f y%+.2f z%+.2f tilt%+.0f", x, y, z, ang);
|
||||
lv_label_set_text(dim_status_lbl, dbg);
|
||||
lv_obj_set_style_text_color(dim_status_lbl, COL_ACCENT, 0);
|
||||
#endif
|
||||
|
||||
uint32_t now = lv_tick_get();
|
||||
uint32_t dt_ms = now - dim_last_tick_ms;
|
||||
dim_last_tick_ms = now;
|
||||
if (dt_ms > 500) dt_ms = 0; // first/stale tick — don't integrate a big jump
|
||||
float dt = dt_ms / 1000.0f;
|
||||
|
||||
float mag = fabsf(ang) - DIM_DEADZONE_DEG;
|
||||
float rate = 0.0f; // -1..+1 normalized
|
||||
if (mag > 0.0f) {
|
||||
float frac = mag / (DIM_MAX_DEG - DIM_DEADZONE_DEG);
|
||||
if (frac > 1.0f) frac = 1.0f;
|
||||
rate = (ang > 0.0f ? 1.0f : -1.0f) * frac;
|
||||
}
|
||||
|
||||
if (rate == 0.0f) { // inside the deadzone → hold; auto-lock on stillness
|
||||
if (dim_still_since_ms == 0) dim_still_since_ms = now;
|
||||
else if (now - dim_still_since_ms >= DIM_AUTOLOCK_MS) dim_commit();
|
||||
return;
|
||||
}
|
||||
dim_still_since_ms = 0;
|
||||
|
||||
if (dim_param == DIM_BRI) {
|
||||
dim_bri += rate * DIM_BRI_RATE * dt;
|
||||
if (dim_bri < 1.0f) dim_bri = 1.0f;
|
||||
if (dim_bri > 100.0f) dim_bri = 100.0f;
|
||||
} else {
|
||||
float span = (float)(dim_max_k - dim_min_k);
|
||||
dim_ct += rate * DIM_CT_RATE_FRAC * span * dt;
|
||||
if (dim_ct < dim_min_k) dim_ct = dim_min_k;
|
||||
if (dim_ct > dim_max_k) dim_ct = dim_max_k;
|
||||
}
|
||||
dim_refresh_dial();
|
||||
|
||||
if (now - dim_last_send_ms >= DIM_SEND_MS) {
|
||||
dim_send_current(false);
|
||||
dim_last_send_ms = now;
|
||||
}
|
||||
}
|
||||
|
||||
// Battery detail — opened by tapping the battery icon (not in the launcher).
|
||||
// Shows the gauge percentage, the raw cell voltage, and a rough "time left"
|
||||
// projected from the discharge rate (battery_est in main.cpp). The bottom note
|
||||
// states the protective auto-off threshold and reddens as the cell nears it.
|
||||
static lv_color_t batt_color(int pct) {
|
||||
if (pct < 0) return COL_DIM; // unknown
|
||||
if (pct <= 15) return COL_RED;
|
||||
if (pct <= 35) return COL_AMBER;
|
||||
return COL_GREEN; // low % is bad here — inverse of the usage bars
|
||||
}
|
||||
|
||||
static void init_battery_screen(lv_obj_t* scr) {
|
||||
battery_container = lv_obj_create(scr);
|
||||
lv_obj_set_size(battery_container, L.scr_w, L.scr_h);
|
||||
lv_obj_set_pos(battery_container, 0, 0);
|
||||
lv_obj_set_style_bg_opa(battery_container, LV_OPA_TRANSP, 0);
|
||||
lv_obj_set_style_border_width(battery_container, 0, 0);
|
||||
lv_obj_set_style_pad_all(battery_container, 0, 0);
|
||||
lv_obj_clear_flag(battery_container, LV_OBJ_FLAG_SCROLLABLE);
|
||||
|
||||
make_screen_title(battery_container, "Battery");
|
||||
|
||||
bat_pct_lbl = lv_label_create(battery_container);
|
||||
lv_label_set_text(bat_pct_lbl, "--%");
|
||||
lv_obj_set_style_text_font(bat_pct_lbl, &font_tiempos_56, 0);
|
||||
lv_obj_set_style_text_color(bat_pct_lbl, COL_TEXT, 0);
|
||||
lv_obj_align(bat_pct_lbl, LV_ALIGN_TOP_MID, 0, L.content_y + 10);
|
||||
|
||||
bat_bar = make_bar(battery_container, L.margin, L.content_y + 115, L.content_w, 22);
|
||||
|
||||
bat_volt_lbl = lv_label_create(battery_container);
|
||||
lv_label_set_text(bat_volt_lbl, "--.-- V");
|
||||
lv_obj_set_style_text_font(bat_volt_lbl, &font_styrene_28, 0);
|
||||
lv_obj_set_style_text_color(bat_volt_lbl, COL_DIM, 0);
|
||||
lv_obj_align(bat_volt_lbl, LV_ALIGN_TOP_MID, 0, L.content_y + 155);
|
||||
|
||||
bat_time_lbl = lv_label_create(battery_container);
|
||||
lv_label_set_text(bat_time_lbl, "Estimating time left\xE2\x80\xA6");
|
||||
lv_obj_set_style_text_font(bat_time_lbl, &font_styrene_28, 0);
|
||||
lv_obj_set_style_text_color(bat_time_lbl, COL_ACCENT, 0);
|
||||
lv_obj_align(bat_time_lbl, LV_ALIGN_TOP_MID, 0, L.content_y + 205);
|
||||
|
||||
bat_note_lbl = lv_label_create(battery_container);
|
||||
lv_label_set_text(bat_note_lbl, "Auto-off below 3.0 V");
|
||||
lv_obj_set_style_text_font(bat_note_lbl, &font_styrene_16, 0);
|
||||
lv_obj_set_style_text_color(bat_note_lbl, COL_DIM, 0);
|
||||
lv_obj_align(bat_note_lbl, LV_ALIGN_BOTTOM_MID, 0, -36);
|
||||
|
||||
lv_obj_add_flag(battery_container, LV_OBJ_FLAG_HIDDEN);
|
||||
}
|
||||
|
||||
static void battery_screen_refresh(void) {
|
||||
if (!battery_container) return;
|
||||
char buf[48];
|
||||
|
||||
if (g_bat_pct < 0) {
|
||||
lv_label_set_text(bat_pct_lbl, "--%");
|
||||
} else {
|
||||
snprintf(buf, sizeof buf, "%d%%", g_bat_pct);
|
||||
lv_label_set_text(bat_pct_lbl, buf);
|
||||
}
|
||||
lv_obj_set_style_text_color(bat_pct_lbl, batt_color(g_bat_pct), 0);
|
||||
|
||||
lv_bar_set_value(bat_bar, (g_bat_pct < 0) ? 0 : g_bat_pct, LV_ANIM_OFF);
|
||||
lv_obj_set_style_bg_color(bat_bar, batt_color(g_bat_pct), LV_PART_INDICATOR);
|
||||
|
||||
if (g_bat_mv <= 0) {
|
||||
lv_label_set_text(bat_volt_lbl, "--.-- V");
|
||||
} else {
|
||||
snprintf(buf, sizeof buf, "%d.%02d V", g_bat_mv / 1000, (g_bat_mv % 1000) / 10);
|
||||
lv_label_set_text(bat_volt_lbl, buf);
|
||||
}
|
||||
|
||||
if (g_bat_charging) {
|
||||
lv_label_set_text(bat_time_lbl, LV_SYMBOL_CHARGE " Charging");
|
||||
lv_obj_set_style_text_color(bat_time_lbl, COL_GREEN, 0);
|
||||
} else if (g_bat_min < 0) {
|
||||
lv_label_set_text(bat_time_lbl, "Estimating time left...");
|
||||
lv_obj_set_style_text_color(bat_time_lbl, COL_DIM, 0);
|
||||
} else {
|
||||
int h = g_bat_min / 60, m = g_bat_min % 60;
|
||||
if (h > 0) snprintf(buf, sizeof buf, "~%dh %dm left", h, m);
|
||||
else snprintf(buf, sizeof buf, "~%dm left", m);
|
||||
lv_label_set_text(bat_time_lbl, buf);
|
||||
lv_obj_set_style_text_color(bat_time_lbl, COL_ACCENT, 0);
|
||||
}
|
||||
|
||||
// Reddens as the cell nears the cutoff. 3.0 V mirrors LOW_V_CUTOFF_MV in
|
||||
// main.cpp; below 3.2 V is the "getting close" warn band.
|
||||
bool near_cutoff = (!g_bat_charging && g_bat_mv > 0 && g_bat_mv < 3200);
|
||||
lv_obj_set_style_text_color(bat_note_lbl, near_cutoff ? COL_RED : COL_DIM, 0);
|
||||
}
|
||||
|
||||
// ======== Public API ========
|
||||
|
||||
void ui_init(void) {
|
||||
@@ -812,11 +1298,13 @@ void ui_init(void) {
|
||||
|
||||
// v2 screens — created hidden, shown on navigation.
|
||||
init_menu_screen(scr);
|
||||
init_stub_screen(scr);
|
||||
init_bt_screen(scr);
|
||||
init_soundpad_screen(scr);
|
||||
init_session_screen(scr);
|
||||
init_nowplaying_screen(scr);
|
||||
init_homeassist_screen(scr);
|
||||
init_dimmer_screen(scr);
|
||||
init_battery_screen(scr);
|
||||
|
||||
logo_img = lv_image_create(scr);
|
||||
lv_image_set_src(logo_img, &logo_dsc);
|
||||
@@ -832,13 +1320,16 @@ void ui_init(void) {
|
||||
lv_obj_set_style_text_color(nav_back_btn, COL_TEXT, 0);
|
||||
lv_obj_set_pos(nav_back_btn, L.margin + 4, L.title_y + 10); // clear of the rounded top-left corner
|
||||
lv_obj_add_flag(nav_back_btn, LV_OBJ_FLAG_CLICKABLE);
|
||||
lv_obj_set_ext_click_area(nav_back_btn, 18);
|
||||
lv_obj_set_ext_click_area(nav_back_btn, 40); // generous tap zone — the bare chevron was hard to hit
|
||||
lv_obj_add_event_cb(nav_back_btn, nav_back_cb, LV_EVENT_CLICKED, NULL);
|
||||
lv_obj_add_flag(nav_back_btn, LV_OBJ_FLAG_HIDDEN);
|
||||
|
||||
battery_img = lv_image_create(scr);
|
||||
lv_image_set_src(battery_img, &battery_dscs[0]);
|
||||
lv_obj_set_pos(battery_img, L.scr_w - 48 - L.margin, L.title_y);
|
||||
lv_obj_add_flag(battery_img, LV_OBJ_FLAG_CLICKABLE); // tap → battery detail
|
||||
lv_obj_set_ext_click_area(battery_img, 16); // generous tap target near the corner
|
||||
lv_obj_add_event_cb(battery_img, battery_click_cb, LV_EVENT_CLICKED, NULL);
|
||||
}
|
||||
|
||||
void ui_update(const UsageData* data) {
|
||||
@@ -982,10 +1473,15 @@ void ui_tick_anim(void) {
|
||||
}
|
||||
|
||||
static screen_t prev_non_splash_screen = SCREEN_USAGE;
|
||||
static screen_t screen_before_battery = SCREEN_USAGE; // where the battery tap came from
|
||||
static void apply_battery_visibility(void) {
|
||||
if (!battery_img) return;
|
||||
if (current_screen == SCREEN_SPLASH) lv_obj_add_flag(battery_img, LV_OBJ_FLAG_HIDDEN);
|
||||
else lv_obj_clear_flag(battery_img, LV_OBJ_FLAG_HIDDEN);
|
||||
// Hidden on the splash, and on the battery detail itself (no point offering a
|
||||
// tap target for the screen you're already on).
|
||||
if (current_screen == SCREEN_SPLASH || current_screen == SCREEN_BATTERY)
|
||||
lv_obj_add_flag(battery_img, LV_OBJ_FLAG_HIDDEN);
|
||||
else
|
||||
lv_obj_clear_flag(battery_img, LV_OBJ_FLAG_HIDDEN);
|
||||
}
|
||||
|
||||
// Tapping the splash/animations screen returns to the home (usage) screen.
|
||||
@@ -1000,9 +1496,20 @@ static void logo_click_cb(lv_event_t* e) {
|
||||
ui_show_screen(SCREEN_MENU);
|
||||
}
|
||||
|
||||
// Back chevron: from the launcher → home; from any app screen → launcher.
|
||||
// The battery icon (top-right, on every non-splash screen) opens the detail
|
||||
// screen. Remember where we came from so the back chevron returns there.
|
||||
static void battery_click_cb(lv_event_t* e) {
|
||||
(void)e;
|
||||
if (current_screen == SCREEN_SPLASH || current_screen == SCREEN_BATTERY) return;
|
||||
screen_before_battery = current_screen;
|
||||
ui_show_screen(SCREEN_BATTERY);
|
||||
}
|
||||
|
||||
// Back chevron: from the battery detail → wherever it was opened from; from the
|
||||
// launcher → home; from any other app screen → launcher.
|
||||
static void nav_back_cb(lv_event_t* e) {
|
||||
(void)e;
|
||||
if (current_screen == SCREEN_BATTERY) { ui_show_screen(screen_before_battery); return; }
|
||||
ui_show_screen(current_screen == SCREEN_MENU ? SCREEN_USAGE : SCREEN_MENU);
|
||||
}
|
||||
|
||||
@@ -1024,13 +1531,19 @@ static void update_nav_chrome(screen_t screen) {
|
||||
void ui_show_screen(screen_t screen) {
|
||||
lv_obj_add_flag(usage_container, LV_OBJ_FLAG_HIDDEN);
|
||||
if (menu_container) lv_obj_add_flag(menu_container, LV_OBJ_FLAG_HIDDEN);
|
||||
if (stub_container) lv_obj_add_flag(stub_container, LV_OBJ_FLAG_HIDDEN);
|
||||
if (bt_container) lv_obj_add_flag(bt_container, LV_OBJ_FLAG_HIDDEN);
|
||||
if (soundpad_container) lv_obj_add_flag(soundpad_container, LV_OBJ_FLAG_HIDDEN);
|
||||
if (session_container) lv_obj_add_flag(session_container, LV_OBJ_FLAG_HIDDEN);
|
||||
if (nowplaying_container) lv_obj_add_flag(nowplaying_container, LV_OBJ_FLAG_HIDDEN);
|
||||
if (homeassist_container) lv_obj_add_flag(homeassist_container, LV_OBJ_FLAG_HIDDEN);
|
||||
if (dimmer_container) lv_obj_add_flag(dimmer_container, LV_OBJ_FLAG_HIDDEN);
|
||||
if (battery_container) lv_obj_add_flag(battery_container, LV_OBJ_FLAG_HIDDEN);
|
||||
splash_hide();
|
||||
|
||||
// Leaving the dimmer disarms it so the wrist can't keep driving the light
|
||||
// from another screen.
|
||||
if (current_screen == SCREEN_DIMMER && screen != SCREEN_DIMMER) dim_armed = false;
|
||||
|
||||
switch (screen) {
|
||||
case SCREEN_SPLASH: splash_show(); break;
|
||||
case SCREEN_USAGE: lv_obj_clear_flag(usage_container, LV_OBJ_FLAG_HIDDEN); break;
|
||||
@@ -1040,8 +1553,18 @@ void ui_show_screen(screen_t screen) {
|
||||
case SCREEN_NOWPLAYING: lv_obj_clear_flag(nowplaying_container, LV_OBJ_FLAG_HIDDEN); break;
|
||||
case SCREEN_BLUETOOTH: bt_refresh(); lv_obj_clear_flag(bt_container, LV_OBJ_FLAG_HIDDEN); break;
|
||||
case SCREEN_HOMEASSIST:
|
||||
stub_show_for(screen);
|
||||
lv_obj_clear_flag(stub_container, LV_OBJ_FLAG_HIDDEN);
|
||||
lv_obj_clear_flag(homeassist_container, LV_OBJ_FLAG_HIDDEN);
|
||||
break;
|
||||
case SCREEN_DIMMER:
|
||||
dim_armed = false;
|
||||
dim_refresh_dial();
|
||||
dim_update_status();
|
||||
ble_send_command("{\"cmd\":\"dimreq\"}"); // ask the daemon for a fresh light snapshot
|
||||
lv_obj_clear_flag(dimmer_container, LV_OBJ_FLAG_HIDDEN);
|
||||
break;
|
||||
case SCREEN_BATTERY:
|
||||
battery_screen_refresh();
|
||||
lv_obj_clear_flag(battery_container, LV_OBJ_FLAG_HIDDEN);
|
||||
break;
|
||||
default: break;
|
||||
}
|
||||
@@ -1071,7 +1594,12 @@ void ui_update_ble_status(ble_state_t state, const char* name, const char* mac)
|
||||
update_view_state();
|
||||
}
|
||||
|
||||
void ui_update_battery(int percent, bool charging) {
|
||||
void ui_update_battery(int percent, int voltage_mv, int minutes_left, bool charging) {
|
||||
g_bat_pct = percent;
|
||||
g_bat_mv = voltage_mv;
|
||||
g_bat_min = minutes_left;
|
||||
g_bat_charging = charging;
|
||||
|
||||
int idx;
|
||||
if (charging) {
|
||||
idx = 4;
|
||||
@@ -1088,4 +1616,40 @@ void ui_update_battery(int percent, bool charging) {
|
||||
}
|
||||
lv_image_set_src(battery_img, &battery_dscs[idx]);
|
||||
apply_battery_visibility();
|
||||
|
||||
// Keep the detail screen live while it's the one on display.
|
||||
if (current_screen == SCREEN_BATTERY) battery_screen_refresh();
|
||||
}
|
||||
|
||||
void ui_show_low_battery(void) {
|
||||
// Top layer so it covers whatever screen was active, including the splash.
|
||||
lv_obj_t* ov = lv_obj_create(lv_layer_top());
|
||||
lv_obj_set_size(ov, L.scr_w, L.scr_h);
|
||||
lv_obj_set_pos(ov, 0, 0);
|
||||
lv_obj_set_style_bg_color(ov, COL_BG, 0);
|
||||
lv_obj_set_style_bg_opa(ov, LV_OPA_COVER, 0);
|
||||
lv_obj_set_style_border_width(ov, 0, 0);
|
||||
lv_obj_set_style_pad_all(ov, 0, 0);
|
||||
lv_obj_clear_flag(ov, LV_OBJ_FLAG_SCROLLABLE);
|
||||
|
||||
lv_obj_t* icon = lv_label_create(ov);
|
||||
lv_label_set_text(icon, LV_SYMBOL_WARNING);
|
||||
lv_obj_set_style_text_font(icon, &lv_font_montserrat_28, 0);
|
||||
lv_obj_set_style_text_color(icon, COL_RED, 0);
|
||||
lv_obj_align(icon, LV_ALIGN_CENTER, 0, -70);
|
||||
|
||||
lv_obj_t* t = lv_label_create(ov);
|
||||
lv_label_set_text(t, "Battery critically low");
|
||||
lv_obj_set_style_text_font(t, L.bt_status_font, 0);
|
||||
lv_obj_set_style_text_color(t, COL_TEXT, 0);
|
||||
lv_obj_align(t, LV_ALIGN_CENTER, 0, -10);
|
||||
|
||||
lv_obj_t* s = lv_label_create(ov);
|
||||
lv_obj_set_width(s, L.content_w);
|
||||
lv_label_set_long_mode(s, LV_LABEL_LONG_WRAP);
|
||||
lv_obj_set_style_text_align(s, LV_TEXT_ALIGN_CENTER, 0);
|
||||
lv_label_set_text(s, "Shutting down to protect the cell");
|
||||
lv_obj_set_style_text_font(s, L.bt_device_font, 0);
|
||||
lv_obj_set_style_text_color(s, COL_DIM, 0);
|
||||
lv_obj_align(s, LV_ALIGN_CENTER, 0, 55);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user