-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcontrol.h
145 lines (133 loc) · 5.3 KB
/
control.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
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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
/*
* Generic base class for controls
*
* It makes some assumptions - e.g. max 3 float inputs, which if wrong may require refactoring.
*
*/
#ifndef CONTROL_H
#define CONTROL_H
#include "_settings.h" // Settings for what to include etc
#include <Arduino.h>
#include <vector>
#include "_base.h"
#if defined(CONTROL_HYSTERISIS_DEBUG) || defined(CONTROL_MPQ_DEBUG)
#define CONTROL_DEBUG
#endif
// TODO_25 move IO...OUT to _base.h and _base.cpp
class IO {
public:
char const *name; // Name of this IO within the sensor, i.e. can duplicate across sensors
char const *topicLeaf; // Topic always listens|sends to - null (unusual) if only listens on wire
char const *color; // String passed to UX
bool const wireable; // True if can wire this to/from others
char const *wireLeaf; // Topic listens for change to wiredTopic, will always be wire_<sensor.name>_<io.name>
const String *wiredPath; // Topic also listening|sending to when wired
IO();
IO(const char * const n, const char * const tl, char const *color, const bool w = true);
virtual void setup(const char * const sensorname);
virtual bool dispatchLeaf(const String &topicleaf, const String &payload); // Just checks control
virtual bool dispatchPath(const String &topicPath, const String &payload);
#ifdef CONTROL_DEBUG
virtual void debug(const char* const where);
#endif
virtual float floatValue(); // Can build these for other types and combos e.g. returning bool from a float etc
virtual void set(const float newvalue); // Similarly - setting into types from variety of values
virtual String* advertisement();
};
class IN : public IO {
public:
IN(char const * const name, char const * const topicLeaf, char const *color, const bool wireable);
virtual String* advertisement();
virtual float floatValue();
virtual bool boolValue();
virtual bool dispatchLeaf(const String &topicleaf, const String &payload); // Just checks control
};
class OUT : public IO {
public:
OUT(char const * const name, char const * const topicLeaf, char const *color, const bool wireable);
virtual String* advertisement();
virtual float floatValue();
virtual bool boolValue();
virtual void sendWired();
virtual bool dispatchLeaf(const String &topicleaf, const String &payload); // Just checks control
};
class INfloat : public IN {
public:
float value;
float min;
float max;
INfloat();
INfloat(char const * const name, float v, char const * const topicLeaf, float min, float max, char const * const color, const bool wireable);
INfloat(const INfloat &other);
float floatValue(); // This is so that other subclasses e.g. INuint16 can still return a float if required
bool boolValue();
// Copy assignment operator
/*
INfloat& operator=(const INfloat &other) {
Serial.print("XXXXXX IN assignment __FILE__"); Serial.println(__LINE__); // Debugging here, because dont think this is used
if (this != &other) {
value = other.value;
name = other.name;
wireable = other.wireable
topicLeaf = other.topicLeaf;
wireLeaf = other.wireLeaf;
wiredPath = other.wiredPath;
}
return *this;
}
*/
bool dispatchLeaf(const String &topicLeaf, const String &payload);
bool dispatchPath(const String &topicPath, const String &payload);
virtual void setup(const char * const sensorname);
void debug(const char* const where);
String* advertisement();
};
class OUTfloat : public OUT {
public:
float value;
float min;
float max;
OUTfloat();
OUTfloat(char const * const name, float v, char const * const topicLeaf, float min, float max, char const * const color, const bool wireable);
OUTfloat(const OUTfloat &other);
float floatValue(); // This is so that other subclasses e.g. OUTuint16 can still return a float if required
bool boolValue();
void sendWired();
void set(const float newvalue);
void debug(const char* const where);
String* advertisement();
};
class OUTbool : public OUT {
public:
bool value;
OUTbool();
OUTbool(char const * const name, bool v, char const * const topicLeaf, char const * const color, const bool wireable);
OUTbool(const OUTbool &other);
float floatValue(); // This is so that other subclasses e.g. OUTuint16 can still return a float if required
bool boolValue();
void set(const bool newvalue);
void sendWired();
void debug(const char* const where);
String* advertisement();
};
class Control : public Frugal_Base {
public:
const char * const name;
typedef std::function<void(Control*)> TCallback;
std::vector<IN*> inputs; // Vector of inputs
std::vector<OUT*> outputs; // Vector of outputs
std::vector<TCallback> actions; // Vector of actions
Control(const char * const name, std::vector<IN*> i, std::vector<OUT*> o, std::vector<TCallback> a);
void setup();
void dispatch(const String &topicPath, const String &payload);
String* advertisement();
static void setupAll();
static void loopAll();
static void dispatchAll(const String &topicPath, const String &payload);
static String* advertisementAll();
#ifdef CONTROL_DEBUG
void debug(const char* const blah);
#endif //CONTROL_DEBUG
};
extern std::vector<Control*> controls;
#endif //CONTROL_H