esp32 firmware for a toaster reflow oven WIP!!!!!
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
reflower/main/scenes/scene_manual_menu.c

119 lines
3.0 KiB

#include <malloc.h>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include "analog.h"
#include "firehazard.h"
#include "graphics/bitmaps.h"
#include "liquid.h"
#include "graphics/drawing.h"
#include "graphics/display_spec.h"
#include "scenes.h"
#include "scene_menu.h"
struct Priv {
int _placeholder;
//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);
}
else if (self->selected == 1) {
fire_enable(!fire_enabled());
return SceneEvent_Repaint();
}
else if (self->selected == 2) {
return SceneEvent_OpenChild(NewScene_PopupTest(), 1);
}
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 40
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);
}
strncpy(items[2].label, "▶Item with popup", MENUITEM_LABEL_LEN);
}
static void paint(struct MenuScene *self)
{
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, XLINE/2, 0, BLACK, (struct TextStyle) {.size = FONT_DOUBLE, .align = ALIGN_CENTER});
LCD_setStrEx("°C", XLINE/2, 17, BLACK, (struct TextStyle) {.align = ALIGN_CENTER}); //.size = FONT_BOLD,
const struct BitmapImage *img;
if (fire_enabled()) {
img = Bitmap_Get("flame");
} else {
img = Bitmap_Get("no_flame");
}
LCD_setBitmap(img, XLINE/2-24/2, 26, false, BLACK);
MenuScene_Paint(self);
}
struct Scene *NewScene_MenuManual() {
struct MenuItem *items = calloc(3, sizeof(struct MenuItem));
print_labels(items);
struct MenuScene * scene = NewScene_Menu(items, 3);
scene->onSelect = onSelect;
scene->x = XLINE;
scene->ncols = 7;
// private data added by the subclass
scene->base.paint = (Scene_paint_t) paint;
struct Priv *priv = calloc(1, sizeof(struct Priv));
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;
}