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_number.c

66 lines
1.7 KiB

#include <malloc.h>
#include <stdio.h>
#include "scenes.h"
#include "liquid.h"
#include "graphics/drawing.h"
#include "scene_number.h"
struct NumberScene {
struct Scene base;
struct NumberSceneOpts *opts;
};
static struct SceneEvent onInput(struct NumberScene *self, struct InputEvent event) {
struct NumberSceneOpts *opts = self->opts;
switch (event.kind) {
case InputEventKind_Wheel:
opts->value += event.wheel.delta;
if (opts->value < opts->min) {
opts->value = opts->min;
}
else if (opts->value > opts->max) {
opts->value = opts->max;
}
return SceneEvent_Repaint();
case InputEventKind_Button:
if (event.button.state) {
return SceneEvent_Close(opts->value, NULL);
}
// fall through
default:
return SceneEvent_None();
}
}
static void paint(struct NumberScene *self)
{
struct NumberSceneOpts *opts = self->opts;
LCD_clearDisplay(0);
LCD_setStrEx(opts->label, 1, 1, BLACK, FONT_BOLD);
char buf[10];
snprintf(buf, 10, "%d%s", opts->value, opts->unit);
LCD_setStrEx(buf, 1, 9, BLACK, FONT_DOUBLE);
}
static void deinit(struct NumberScene *self)
{
free(self->opts);
self->opts = NULL;
}
struct Scene *NewScene_Number(struct NumberSceneOpts *opts) {
struct NumberScene *scene = calloc(1, sizeof(struct NumberScene));
if (!scene) return NULL;
scene->opts = opts;
scene->base.onInput = (Scene_onInput_t) onInput;
scene->base.paint = (Scene_paint_t) paint;
scene->base.deinit = (Scene_deinit_t) deinit;
return (struct Scene *) scene;
}