#include "scenes.h" #include "liquid.h" #include "../graphics/nokia.h" #include "../analog.h" #include #include struct private { int32_t pos; uint32_t timer_phase; uint32_t timer_prescale; }; static struct SceneEvent Root_onInput(struct Scene *scene, struct InputEvent event) { struct private *priv = scene->private; switch (event.kind) { case InputEventKind_Wheel: priv->pos += event.wheel.delta; break; case InputEventKind_Button: if (event.button.state) { return SceneEvent_OpenChild(NewScene_Car(), 0); } break; } return SceneEvent_Repaint(); } static struct SceneEvent Root_onTick(struct Scene *scene) { struct private *priv = scene->private; priv->timer_prescale += 1; if (priv->timer_prescale == 100) { priv->timer_prescale = 0; priv->timer_phase += 1; priv->timer_phase = priv->timer_phase & 0b11; // 0..3 return SceneEvent_Repaint(); } return SceneEvent_None(); } static void Root_paint(struct Scene *scene) { struct private *priv = scene->private; LCD_clearDisplay(0); const char *header = "???"; switch (priv->timer_phase) { case 0: header = "Drink water"; break; case 1: header = " Drink water"; break; case 2: header = " Drink water"; break; case 3: header = " Drink water"; break; } LCD_setStrEx(header, 0, 3, 1, 3); LCD_setRect(0, 12, 83, 33, 1, 1); char buf[10]; // sprintf(buf, "%3d", priv->pos); // LCD_setStr(buf, 2, 15, 0); sprintf(buf, "🌑%.0fΒ°C", analog_read()); LCD_setStrEx(buf, 2, 15, 0, 2); LCD_setStr("Γ—β†‘β†“β†β†’β°βŒ›β˜ΈβŽπŸŒ‘Β°πŸ”™β–Άβ—€", 2, 33, 1); LCD_updateDisplay(); } struct Scene *NewScene_Root(void) { struct Scene *scene = SCENE_SAFE_ALLOC(struct private); scene->onInput = Root_onInput; scene->paint = Root_paint; scene->onTick = Root_onTick; return scene; }