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/liquid/scene_root.c

85 lines
1.9 KiB

#include "scenes.h"
#include "liquid.h"
#include "../nokia.h"
#include "../analog.h"
#include <malloc.h>
#include <stdio.h>
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 = "ICE";
break;
case 1:
header = " COLD";
break;
case 2:
header = "COCA";
break;
case 3:
header = " COLA";
break;
}
LCD_setStr(header, 20, 3, 1);
LCD_setRect(0, 15, 83, 35, 1, 1);
char buf[10];
sprintf(buf, "%3d", priv->pos);
LCD_setStr(buf, 2, 17, 0);
sprintf(buf, "%.0f C", analog_read());
LCD_setStr(buf, 2, 26, 0);
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;
}