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.
88 lines
2.2 KiB
88 lines
2.2 KiB
#include "scenes.h"
|
|
#include "liquid.h"
|
|
#include "../graphics/nokia.h"
|
|
#include "../analog.h"
|
|
#include <malloc.h>
|
|
#include <stdio.h>
|
|
|
|
/**
|
|
* The struct is allocated bigger than 'Scene' to accommodate private fields.
|
|
* Since the base struct is located at the beginning, it can be cast and passed around as Scene.
|
|
*/
|
|
struct RootScene {
|
|
struct Scene base;
|
|
int32_t pos;
|
|
uint32_t timer_phase;
|
|
uint32_t timer_prescale;
|
|
};
|
|
|
|
static struct SceneEvent Root_onInput(struct RootScene *self, struct InputEvent event) {
|
|
switch (event.kind) {
|
|
case InputEventKind_Wheel:
|
|
self->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 RootScene *self) {
|
|
self->timer_prescale += 1;
|
|
|
|
if (self->timer_prescale == 100) {
|
|
self->timer_prescale = 0;
|
|
self->timer_phase += 1;
|
|
self->timer_phase = self->timer_phase & 0b11; // 0..3
|
|
|
|
return SceneEvent_Repaint();
|
|
}
|
|
|
|
return SceneEvent_None();
|
|
}
|
|
|
|
static void Root_paint(struct RootScene *self)
|
|
{
|
|
LCD_clearDisplay(0);
|
|
const char *header = "???";
|
|
switch (self->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, 31, 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, 14, 0, 2);
|
|
|
|
LCD_setStr("×↑↓←→⏰⌛☸⏎🌡°🔙▶◀", 2, 33, 1);
|
|
LCD_updateDisplay();
|
|
}
|
|
|
|
struct Scene *NewScene_Root(void) {
|
|
struct RootScene *scene = calloc(1, sizeof(struct RootScene));
|
|
|
|
scene->base.onInput = (Scene_onInput_t) Root_onInput;
|
|
scene->base.paint = (Scene_paint_t) Root_paint;
|
|
scene->base.onTick = (Scene_onTick_t) Root_onTick;
|
|
return (struct Scene *) scene;
|
|
}
|
|
|