-
Notifications
You must be signed in to change notification settings - Fork 0
/
ArduboyIRController.ino
69 lines (58 loc) · 1.71 KB
/
ArduboyIRController.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
#include "common.h"
/* Defines */
#define IDLE_TIMEOUT (FPS * 5)
#define callInitFunc(idx) ((void (*)(void)) pgm_read_ptr((void *) &moduleTable[idx].initFunc))()
#define callUpdateFunc(idx) ((MODE_T (*)(void)) pgm_read_ptr((void *) &moduleTable[idx].updateFunc))()
#define callDrawFunc(idx) ((void (*)(void)) pgm_read_ptr((void *) &moduleTable[idx].drawFunc))()
/* Typedefs */
typedef struct
{
void(*initFunc)(void);
MODE_T(*updateFunc)(void);
void(*drawFunc)(void);
} MODULE_FUNCS;
/* Local Variables */
PROGMEM static const MODULE_FUNCS moduleTable[] = {
{ initSender, updateSender, drawSender },
{ initReceiver, updateReceiver, drawReceiver },
};
static MODE_T mode;
static uint8_t idleCount;
/*---------------------------------------------------------------------------*/
void setup()
{
arduboy.beginNoLogo();
arduboy.setFrameRate(FPS);
arduboy.setRGBled(0, 0, 0);
idleCount = 0;
mode = MODE_SENDER;
callInitFunc(mode);
}
void loop()
{
if (!(arduboy.nextFrame())) return;
MODE_T nextMode = callUpdateFunc(mode);
bool isActed = (arduboy.buttonsState() != 0 || isInvalid);
if (isInvalid) {
arduboy.clear();
callDrawFunc(mode);
arduboy.display();
isInvalid = false;
}
if (isActed) {
if (idleCount == IDLE_TIMEOUT) {
arduboy.sendLCDCommand(0x81);
arduboy.sendLCDCommand(0xCF);
}
idleCount = 0;
} else {
if (idleCount < IDLE_TIMEOUT && ++idleCount == IDLE_TIMEOUT) {
arduboy.sendLCDCommand(0x81);
arduboy.sendLCDCommand(0x00);
}
}
if (mode != nextMode) {
mode = nextMode;
callInitFunc(mode);
}
}