-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathNibble-Launcher.ino
81 lines (62 loc) · 1.63 KB
/
Nibble-Launcher.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
#include <Arduino.h>
#include <CircuitOS.h>
#include <Nibble.h>
#include <Loop/LoopManager.h>
#include <Support/Context.h>
#include <Input/Input.h>
#include <Input/I2cExpander.h>
#include <Audio/Piezo.h>
#include "src/Launcher.h"
#include "src/Services/BatteryService.h"
#include "src/Services/SleepService.h"
#include "src/HardwareTest.h"
#include "src/SerialID.h"
#include <ESP8266WiFi.h>
Launcher* launcher;
BatteryService* batteryService;
SleepService* sleepService;
Display* display;
void setup(){
Serial.begin(115200);
Serial.println();
Nibble.begin();
display = Nibble.getDisplay();
WiFi.mode(WIFI_OFF);
WiFi.forceSleepBegin();
#ifdef DEBUG_FLAG
uint8_t portRead = 0;
if(Nibble.getExpander()){
for(uint8_t i = 0; i < 7; i++){
Nibble.getExpander()->pinMode(i, INPUT_PULLUP);
}
portRead = Nibble.getExpander()->portRead();
}else{
Nibble.getInput()->loop(0);
for(int i = 0; i < 7; i++){
portRead |= (~Nibble.getInput()->getButtonState(i) & 1) << i;
}
}
portRead = portRead & 0b01111111;
if(!portRead && !settings()->calibrated)
{
LoopManager::addListener(new SerialID);
HardwareTest test(*Nibble.getDisplay());
test.start();
}
#endif
Piezo.setMute(!settings()->audio);
batteryService = new BatteryService(*display);
sleepService = new SleepService(*display);
LoopManager::addListener(batteryService);
LoopManager::addListener(Input::getInstance());
launcher = new Launcher(display, batteryService);
runningContext = launcher;
launcher->unpack();
launcher->start();
sleepService->start();
LoopManager::addListener(sleepService);
Nibble.setBacklight(true);
}
void loop(){
LoopManager::loop();
}