-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathArmstrong-Firmware.ino
74 lines (56 loc) · 1.09 KB
/
Armstrong-Firmware.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
#include <Arduino.h>
#include <Armstrong.h>
#include <CircuitOS.h>
#include <Loop/LoopManager.h>
#include "src/ColorService.h"
#include "src/SlotStorage.h"
#include "src/State.h"
#include "src/JigHWTest.h"
bool checkWheelson(){
uint32_t sum = 0;
const int count = 15;
for(int i = 0; i < count; i++){
sum += analogRead(PIN_WHEELSON);
}
return (sum / count) > 800;
}
bool checkJig(){
char buf[7];
int wp = 0;
uint32_t start = millis();
while(millis() - start < 500){
while(Serial.available()){
buf[wp] = Serial.read();
wp = (wp + 1) % 7;
for(int i = 0; i < 7; i++){
int match = 0;
static const char* target = "JIGTEST";
for(int j = 0; j < 7; j++){
match += buf[(i + j) % 7] == target[j];
}
if(match == 7) return true;
}
}
}
return false;
}
void setup(){
Serial.begin(115200);
if(checkJig()){
printf("Jig\n");
auto test = new JigHWTest();
test->start();
for(;;);
}
Armstrong.begin();
new ColorService;
if(checkWheelson()){
State::enterI2C();
}else{
Storage.load();
State::enterRecord();
}
}
void loop(){
LoopManager::loop();
}