-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
113 lines (92 loc) · 3.21 KB
/
main.cpp
File metadata and controls
113 lines (92 loc) · 3.21 KB
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
#include <Arduino.h>
#include <Button2.h>
#include <Wire.h>
// Controller and services
#include "Controller.h"
#include "LightService.h"
#include "DistanceService.h"
#include "CommunicationService.h"
// Modes
#include "Alert.h"
#include "StaticMode.h"
#include "ColorPickerMode.h"
#include "RainbowMode.h"
#include "RandomGlowMode.h"
//#include "BeaconMode.h"
//#include "CandleMode.h"
//#include "SunsetMode.h"
//#include "StrobeMode.h"
//#include "MiniGame.h"
// Config
#include "GlowConfig.h"
// Services
Button2 button;
LightService lightService;
CommunicationService communicationService;
DistanceService distanceService(&communicationService);
// Controller
Controller controller(&distanceService, &communicationService);
// Light modes
Alert alertMode(&lightService, &distanceService, &communicationService);
StaticMode staticMode(&lightService, &distanceService, &communicationService);
ColorPickerMode colorPickerMode(&lightService, &distanceService, &communicationService);
RainbowMode rainbowMode(&lightService, &distanceService, &communicationService);
RandomGlowMode randomGlowMode(&lightService, &distanceService, &communicationService);
//BeaconMode beaconMode(&lightService, &distanceService, &communicationService);
//CandleMode candleMode(&lightService, &distanceService, &communicationService);
//SunsetMode sunsetMode(&lightService, &distanceService, &communicationService);
//StrobeMode strobeMode(&lightService, &distanceService, &communicationService);
//MiniGame miniGame(&lightService, &distanceService, &communicationService);
/*
* This is the main setup function; it is called only once during startup.
*/
void setup() {
Serial.begin(115200);
// Setup I2C for the distance sensor
Wire.begin(DISTANCE_SENSOR_SDA, DISTANCE_SENSOR_SCL);
Serial.println("[INFO] Starting Glow");
// Setup services
lightService.setup();
distanceService.setup();
communicationService.setup();
button.begin(BUTTON_PIN);
// Set debounce time (this is the time the button needs to be stable before a press is registered)
button.setLongClickTime(500);
// The modes need to be added to the controller and the order will be the order of the modes
controller.addMode(&staticMode);
controller.addMode(&colorPickerMode);
controller.addMode(&rainbowMode);
controller.addMode(&randomGlowMode);
//controller.addMode(&beaconMode);
//controller.addMode(&candleMode);
//controller.addMode(&sunsetMode);
//controller.addMode(&strobeMode);
//controller.addMode(&miniGame);
// Set alert mode
controller.setAlertMode(&alertMode);
// Setup controller
controller.setup();
// Configure button handlers
button.setLongClickHandler([](Button2 &btn) {
controller.nextMode();
});
button.setClickHandler([](Button2 &btn) {
controller.nextOption();
});
// This click can be used for custom actions in the current mode
button.setDoubleClickHandler([](Button2 &btn) {
controller.customClick();
});
Serial.println("[INFO] GlowLight started");
}
/*
* This is the main loop function; it is called repeatedly by the system.
*/
void loop() {
// The services and controller need to be looped
button.loop();
controller.loop();
lightService.loop();
distanceService.loop();
communicationService.loop();
}