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.
93 lines
2.4 KiB
93 lines
2.4 KiB
#include <malloc.h>
|
|
#include <stdio.h>
|
|
#include <graphics/bitmaps.h>
|
|
|
|
#include "scenes.h"
|
|
#include "liquid.h"
|
|
#include "analog.h"
|
|
#include "graphics/nokia.h"
|
|
#include "graphics/drawing.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 DemoScene {
|
|
struct Scene base;
|
|
int32_t pos;
|
|
uint32_t timer_phase;
|
|
uint32_t timer_prescale;
|
|
};
|
|
|
|
static struct SceneEvent onInput(struct DemoScene *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 onTick(struct DemoScene *self, uint32_t millis) {
|
|
// top text anim
|
|
self->timer_prescale += millis;
|
|
|
|
if (self->timer_prescale == 1000) {
|
|
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 paint(struct DemoScene *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, 3, 1, BLACK, (struct TextStyle) {.size = FONT_BOLD});
|
|
|
|
LCD_setRect(0, 12, 83, 31, true, BLACK);
|
|
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, WHITE, (struct TextStyle) {.size = FONT_DOUBLE});
|
|
|
|
LCD_setStr("×↑↓←→⏰⌛☸⏎🌡°🔙▶◀", 2, 33, BLACK);
|
|
}
|
|
|
|
struct Scene *NewScene_Demo(void) {
|
|
struct DemoScene *scene = calloc(1, sizeof(struct DemoScene));
|
|
|
|
scene->base.onInput = (Scene_onInput_t) onInput;
|
|
scene->base.paint = (Scene_paint_t) paint;
|
|
scene->base.onTick = (Scene_onTick_t) onTick;
|
|
scene->base.onInput = (Scene_onInput_t) onInput;
|
|
return (struct Scene *) scene;
|
|
}
|
|
|