#ifndef UI_MANAGER_H #define UI_MANAGER_H #include #include #include "ha_data.h" #include "lvgl.h" #include "thermostat.h" /* * The screen layout. * * This file is compiled into the desktop simulator as well as the firmware * (see sim/README.md), so it must never touch a driver, a socket or ESP-IDF * directly. Data arrives as ha_data_t; commands leave through the callback * below. Everything in between is drawing. */ void ui_init(void); /* Safe to call from any task -- these take the LVGL lock internally. */ /* Redraw every panel from `data`. Cheap to call when nothing changed: every * label goes through a comparison first, so an unchanged value costs no * invalidation and therefore no flush. */ void ui_update(const ha_data_t *data); void ui_set_status(const char *status); /* * Mark the displayed readings as no longer trustworthy. Dims the temperature * so a value that stopped updating is visibly distinct from a live one, * rather than sitting there at full styling looking current. */ void ui_set_stale(bool stale); /* * Called when the user operates a light tile. * * `index` indexes HA_LIGHTS. `brightness` is 0-255, or -1 for a plain on/off * with no brightness change (a tile tap, or any switch-domain entity). * * Runs on the LVGL task with the LVGL lock held, so the implementation must * not block: hand the command to another task rather than doing HTTP here. */ typedef void (*ui_light_cmd_cb_t)(int index, bool on, int16_t brightness); void ui_set_light_cb(ui_light_cmd_cb_t cb); /* Redraw the thermostat card from `st`. Same cheapness rules as ui_update. */ void ui_update_thermostat(const therm_status_t *st); typedef enum { UI_THERM_SETPOINT_UP = 0, UI_THERM_SETPOINT_DOWN, UI_THERM_MODE_TOGGLE, UI_THERM_FAN_TOGGLE, } ui_therm_cmd_t; /* * Called when the user operates a thermostat control. * * Runs on the LVGL task with the lock held, so it must not block -- but * unlike the light commands there is no network here, so the handler can * apply the change and call ui_update_thermostat() straight back. The LVGL * lock is recursive, so that re-entry is fine. */ typedef void (*ui_therm_cmd_cb_t)(ui_therm_cmd_t cmd); void ui_set_therm_cb(ui_therm_cmd_cb_t cb); #endif