add bitmap conversion from aseprite ico, add boot animation

This commit is contained in:
2020-01-05 16:46:53 +01:00
parent 6db58e14a7
commit d7cd0e9cfa
37 changed files with 593 additions and 81 deletions
+36
View File
@@ -0,0 +1,36 @@
#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"
struct BootScene {
struct Scene base;
uint32_t cnt;
};
static struct SceneEvent Boot_onTick(struct BootScene *self) {
self->cnt += 10; // ms
if (self->cnt == 2000) {
return SceneEvent_Close(0, NULL);
}
return SceneEvent_None();
}
static void Boot_paint(struct BootScene *self)
{
LCD_clearDisplay(0);
LCD_setBitmap(Bitmap_Get("boot_logo")->bytes);
}
struct Scene *NewScene_Boot(void) {
struct BootScene *scene = calloc(1, sizeof(struct BootScene));
scene->base.paint = (Scene_paint_t) Boot_paint;
scene->base.onTick = (Scene_onTick_t) Boot_onTick;
return (struct Scene *) scene;
}
+92
View File
@@ -0,0 +1,92 @@
#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 Demo_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 Demo_onTick(struct DemoScene *self) {
// top text anim
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 Demo_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, 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);
}
struct Scene *NewScene_Demo(void) {
struct DemoScene *scene = calloc(1, sizeof(struct DemoScene));
scene->base.onInput = (Scene_onInput_t) Demo_onInput;
scene->base.paint = (Scene_paint_t) Demo_paint;
scene->base.onTick = (Scene_onTick_t) Demo_onTick;
return (struct Scene *) scene;
}
+17 -63
View File
@@ -1,5 +1,6 @@
#include <malloc.h>
#include <stdio.h>
#include <graphics/bitmaps.h>
#include "scenes.h"
#include "liquid.h"
@@ -13,78 +14,31 @@
*/
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)
static struct SceneEvent Root_init(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;
return SceneEvent_OpenChild(NewScene_Boot(), 1);
}
struct SceneEvent Root_onChildReturn(
struct RootScene *self,
uint32_t tag,
int32_t status,
void *data)
{
if (tag == 1) {
return SceneEvent_OpenChild(NewScene_Demo(), 0);
}
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();
// this should be unreachable
return SceneEvent_None();
}
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;
scene->base.init = (Scene_init_t) Root_init;
scene->base.onChildReturn = (Scene_onChildReturn_t) Root_onChildReturn;
return (struct Scene *) scene;
}
+2
View File
@@ -8,6 +8,8 @@
#define REFLOWER_SCENES_H
struct Scene *NewScene_Root(void);
struct Scene *NewScene_Boot(void);
struct Scene *NewScene_Demo(void);
struct Scene *NewScene_Car(void);
#endif //REFLOWER_SCENES_H