-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy paththings.h
99 lines (76 loc) · 2.24 KB
/
things.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
#ifndef THINGS_H
#define THINGS_H
#include <Wire.h>
#include <ArduinoLog.h>
#include "constants.h"
/**
* Abstract class describing an electro/pneumatic component, i.e valve, pump,
* pressure controller. I can't think of a term that encompasses all of these,
* hence the current name.
* The point of this class structure is to offer a very simple interface to any
* component, through the setValue and getValue functions.
*
* All values passed to/by these functions are bytes, i.e of type uint8_t. The
* enums defined in constants.h provide values for pumps and valves (ON / OFF
* and OPEN / CLOSED, resp.). For the pressure regulators, the setpoint and measured
* values are an integer between 0 and 255, with 255 being the maximum pressure
* supported by that regulator.
*/
class Thing
{
public:
Thing ();
virtual ~Thing ();
virtual void setValue(uint8_t) = 0;
virtual uint8_t getValue() = 0;
};
class Valve : public Thing
{
public:
Valve (int pin, bool normallyOpen);
virtual ~Valve ();
virtual void setValue(uint8_t);
virtual uint8_t getValue();
protected:
int mPin;
bool mNormallyOpen;
uint8_t mValue; // CLOSED or OPEN
};
class Pump : public Thing
{
public:
Pump (int pin);
virtual ~Pump ();
virtual void setValue(uint8_t);
virtual uint8_t getValue();
protected:
int mPin;
uint8_t mValue; // ON or OFF
};
class PressureController : public Thing
{
public:
enum interfaceType {
analog,
i2c
};
// Use this constructor for analog (Parker-Hannifin) pressure controllers
PressureController (int setPointPin, int measurementPin,
int setPointMaxValue, int measurementMaxValue);
// Use this constructor for i2c pressure controllers
PressureController (int i2cAddress);
virtual ~PressureController ();
virtual void setValue(uint8_t);
virtual uint8_t getValue();
uint8_t setPointValue() { return mSetPointValue; }
protected:
int mSetPointPin;
int mMeasurementPin;
uint8_t mSetPointValue;
uint8_t mMeasuredValue;
int mSetPointMaxValue;
int mMeasurementMaxValue;
interfaceType mInterface; // a touch redundant. we could just check whether i2cAddress == -1
int mI2cAddress;
};
#endif