-
Notifications
You must be signed in to change notification settings - Fork 23
/
Copy pathquarto.ino
91 lines (77 loc) · 2.08 KB
/
quarto.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include "common.h"
#if ARDUBOY_LIB_VER < ARDUBOY_LIB_VER_TGT
#error Unexpected version of Arduboy Library
#endif // It may work even if you use other version. So comment out the above line.
/* Defines */
#define callInitFunc(idx) ((void (*)(void)) pgm_read_word((uint16_t) &moduleTable[idx]))()
#define callUpdateFunc(idx) ((MODE_T (*)(void)) pgm_read_word((uint16_t) &moduleTable[idx] + 2))()
#define callDrawFunc(idx) ((void (*)(void)) pgm_read_word((uint16_t) &moduleTable[idx] + 4))()
/* Typedefs */
typedef struct
{
void(*initFunc)(void);
MODE_T(*updateFunc)(void);
void(*drawFunc)(void);
} MODULE_FUNCS;
/* Local Variables */
PROGMEM static const MODULE_FUNCS moduleTable[] = {
{ initLogo, updateLogo, drawLogo },
{ initTitle, updateTitle, drawTitle },
{ initGame, updateGame, drawGame },
};
static MODE_T mode;
/* For Debugging */
#ifdef DEBUG
bool dbgPrintEnabled = true;
char dbgRecvChar = '\0';
static void dbgCheckSerialRecv(void)
{
int recv;
while ((recv = Serial.read()) != -1) {
switch (recv) {
case 'd':
dbgPrintEnabled = !dbgPrintEnabled;
Serial.print("Debug output ");
Serial.println(dbgPrintEnabled ? "ON" : "OFF");
break;
case 'r':
clearRecord();
break;
}
if (recv >= ' ' && recv <= '~') {
dbgRecvChar = recv;
}
}
}
#endif
/*---------------------------------------------------------------------------*/
void setup()
{
#ifdef DEBUG
Serial.begin(115200);
#endif
arduboy.beginNoLogo();
arduboy.setFrameRate(FPS);
//arduboy.setTextColor(WHITE, WHITE);
mode = MODE_LOGO;
callInitFunc(mode);
}
void loop()
{
#ifdef DEBUG
dbgCheckSerialRecv();
#endif
if (!(arduboy.nextFrame())) return;
MODE_T nextMode = callUpdateFunc(mode);
callDrawFunc(mode);
#ifdef DEBUG
dbgRecvChar = '\0';
#endif
arduboy.display();
if (mode != nextMode) {
mode = nextMode;
dprint(F("mode="));
dprintln(mode);
callInitFunc(mode);
}
}