-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontroller.h
65 lines (48 loc) · 1.57 KB
/
controller.h
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
#ifndef CONTROLLER_H
#define CONTROLLER_H
#include <Map>
#include <Wire.h>
#include <ArduinoLog.h>
#include "constants.h"
#include "things.h"
#ifdef NEOPIXELS
#include <NeoPixelBus.h>
#endif
/**
* The controller class handles all high-level functionality as well as
* serial communication.
* Its constructor can be seen as a replacement for the Arduino setup() function,
* and its update() function as a replacement for the Arduino loop() function.
*
* For simplicity and ease of maintenance, the various components (valves, pumps and
* pressure regulators) are represented by different classes that all inherit from
* the Thing class. This way, the Controller simply has a list of pointers to Things,
* and can call setValue and getValue to set and get the current state of each component.
* This is implemented as a Map, to easily associate a ComponentID (which is communicated
* via the serial link) to each instance.
*/
class Controller
{
public:
Controller ();
virtual ~Controller ();
void update();
void xioPinMode(int pin, int mode);
void xioDigitalWrite(int pin, int value);
private:
void handleSerialData();
void sendComponentValue(ComponentID component);
void sendAllComponentValues();
void pressureControl();
unsigned long mTimer;
unsigned long mPressureControlTimer;
XIO mXioBoard;
bool mXIORefreshRequested;
std::map<ComponentID, Thing*> mComponents;
#ifdef NEOPIXELS
public:
void initNeoPixelStrip();
void setNeoPixel(int index, const RgbColor& color);
#endif // def NEOPIXELS
};
#endif