This repository has been archived by the owner on Aug 9, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
120 lines (92 loc) · 1.93 KB
/
main.cpp
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
#define ARDUINO_MAIN
#include "Arduino.h"
#include "src/include/GameLogic.hpp"
//Weak empty variant initialization function.
//May be redefined by variant files.
void initVariant() __attribute__((weak));
void initVariant() {}
extern USBDeviceClass USBDevice;
extern "C" void __libc_init_array(void);
void clearSerialInputBuffer() {
while(Serial.available()) {
Serial.read();
}
}
void Initialize() {
Serial.begin(9600);
while(!Serial) {
delay(100);
}
clearSerialInputBuffer();
Serial.println(F("Initialized!"));
/*
Read preferences
Read game options
*/
}
void MenuLoop() {
/*
Read saved in-progress games
Display menu LED configuration
Listen for button presses
Change LEDs
Determine new game or restore
Detect "done" step to exit menu
Export chosen states to SetupGame
*/
}
void SetupGame(glichess::GameLogic*& gameLogic) {
gameLogic = new glichess::GameLogic;
/*
Connect to partner
Construct the game loop using its associated XML doc
Validate that all prerequisites are met for the chosen config
Display starting positions
Exit when physical game state matches internal state
*/
}
void GameLoop(glichess::GameLogic*& gameLogic) {
bool quit = false;
do {
/*
Input
Debounce
Game Logic
Save Game State to SD Card
Output
Network
*/
if(arduino::serialEventRun) {
arduino::serialEventRun();
}
} while(!quit);
}
void ShutDownGame(glichess::GameLogic*& gameLogic) {
Serial.println(F("Shutdown!"));
/*
Record win/loss streak
Send network disconnect messages
*/
if(arduino::serialEventRun) {
arduino::serialEventRun();
}
delete gameLogic;
gameLogic = nullptr;
}
int main(void) {
init();
__libc_init_array();
initVariant();
delay(1);
#if defined(USBCON)
USBDevice.init();
USBDevice.attach();
#endif
glichess::GameLogic* gameLogic = nullptr;
Initialize();
MenuLoop();
SetupGame(gameLogic);
GameLoop(gameLogic);
ShutDownGame(gameLogic);
return 0;
}