#include #include #include #include #include #include #include "liquid.h" #include "graphics/drawing.h" #include "graphics/display_spec.h" #include "scenes.h" #include "scene_menu.h" struct Priv { Scene_paint_t basePaint; }; static struct SceneEvent onSelect(struct MenuScene *self) { if (self->selected == 0) { struct NumberSceneOpts *opts = calloc(1, sizeof(struct NumberSceneOpts)); strcpy(opts->unit, "°C"); strcpy(opts->label, "Setpoint"); opts->value = (int) roundf(fire_get_setpoint(false)); opts->min = 0; opts->max = 350; return SceneEvent_OpenChild(NewScene_Number(opts), 0); } if (self->selected == 1) { fire_enable(!fire_enabled()); return SceneEvent_Repaint(); } return SceneEvent_None(); } static void priv_deinit(struct MenuScene *self) { free(self->extra); self->extra = NULL; } static struct SceneEvent onChildReturn(struct MenuScene *self, uint32_t tag, int32_t status, void *data) { if (tag == 0) { fire_setlevel((float) status); } return SceneEvent_Repaint(); } #define XLINE 38 void print_labels(struct MenuItem *items) { snprintf(items[0].label, MENUITEM_LABEL_LEN, "▶%.0f°C", fire_get_setpoint(false)); if (fire_enabled()) { strncpy(items[1].label, "▶STOP", MENUITEM_LABEL_LEN); } else { strncpy(items[1].label, "▶START", MENUITEM_LABEL_LEN); } } static void paint(struct MenuScene *self) { struct Priv *priv = self->extra; print_labels(self->items); LCD_clearDisplay(0); LCD_setLine(XLINE-1, 0, XLINE-1, LCD_HEIGHT, BLACK); char buf[10]; sprintf(buf, "%.0f", analog_read()); // TODO centering LCD_setStrEx(buf, 0, 0, BLACK, (struct TextStyle) {.size = FONT_DOUBLE}); LCD_setStrEx("°C", 0, 17, BLACK, (struct TextStyle) {.size = FONT_BOLD}); if (fire_enabled()) { strcpy(buf, "RUN"); } else { strcpy(buf, "Off"); } LCD_setStrEx(buf, 0, 30, BLACK, (struct TextStyle) {.size = FONT_BOLD}); priv->basePaint((struct Scene *) self); } struct Scene *NewScene_MenuTest() { struct MenuItem *items = calloc(2, sizeof(struct MenuItem)); print_labels(items); struct MenuScene * scene = NewScene_Menu(items, 2); scene->onSelect = onSelect; scene->x = XLINE; scene->ncols = 8; // private data added by the subclass struct Priv *priv = calloc(1, sizeof(struct Priv)); priv->basePaint = scene->base.paint; scene->base.paint = (Scene_paint_t) paint; scene->extra = priv; scene->extra_deinit = (Scene_deinit_t) priv_deinit; // add a child return handler (base does not use this) scene->base.onChildReturn = (Scene_onChildReturn_t) onChildReturn; return (struct Scene *) scene; }