-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcontroller.cpp
More file actions
46 lines (38 loc) · 1.07 KB
/
controller.cpp
File metadata and controls
46 lines (38 loc) · 1.07 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
#include <EEPROM.h>
#include "controller.h"
#include "color_effect.h"
#include "fade_effect.h"
#include "serial_cli_controller.h"
Effect *Controller::effects[] = { new ColorEffect(), new FadeEffect() };
const int Controller::effectCount = sizeof(Controller::effects) / sizeof(Effect*);
Effect *Controller::currentEffect;
Controller *Controller::controllers[] = { new SerialCLIController() };
const int Controller::controllerCount = sizeof(Controller::controllers) / sizeof(Controller*);
Controller::Controller()
{
}
void Controller::init()
{
// Load the current effect from NVRAM
byte effect = EEPROM.read(2);
if( effect != 255 ) // LED OFF
{
currentEffect = effects[effect];
currentEffect->start();
}
// Load the duration from NVRAM
EEPROM.get(3, Effect::m_duration);
for(int i = 0; i < controllerCount; ++i)
{
controllers[i]->init();
}
}
void Controller::update()
{
for(int i = 0; i < controllerCount; ++i)
{
controllers[i]->update();
}
if(currentEffect->running())
currentEffect->update();
}