forked from cusap/mycelium-library
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmycelium.h
131 lines (105 loc) · 2.48 KB
/
mycelium.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
#pragma once
/* mycelium library by Dhvanil Shah
*/
// This will load the definition for common Particle variable types
#include "Particle.h"
#include "Adafruit_DHT.h"
#define SEC_TO_MILLIS 1000UL
#define SEC_ONE_DAY 86400
#define BATT_OP 0x01
#define LIQUID_LEVEL 0x02
// #define TDS 0x04
// #define PH 0x08
#define LIGHTS 0x01
#define PUMP 0x02
// #define FAN 0x04
struct System
{
uint8_t r;
uint8_t g;
uint8_t b;
float timezone;
time_t timeUpdated;
int cycleDay;
};
struct ActionRequest
{
String action = "";
String color = "";
String id = "";
unsigned int timeout = 0;
int priority = 0;
bool active = false;
};
typedef struct
{
int lowThres;
int highThresh;
int lastReading;
int (*check)();
bool activeIssue;
String name;
} Sensor;
// This is your main class that users will import into their application
class Mycelium
{
public:
/**
* Constructor
*/
Mycelium(String type, String product);
/**
* Begin Method
* Must be called inside of setup
* @param type - Defines the type of hydroponics
* @param bitmask - Defines the specificities of the system
*/
void begin();
/**
* Example method
*/
void process();
int attachLights(int (*on)(int), void (*off)());
int attachPump(int (*on)(int), void (*off)());
// Sensors
// Basic format:int attach<SENSORNAME>(int (*check)(), int low, int high)
int attachBattery();
int attachLiquidLevel(int (*check)(), int low, int high);
void mycelHandler(const char *event, const char *data);
private:
/**
* Private global variables
*/
String hydroponicMethod;
String productName;
int actuatorBitmask;
int sensorBitmask;
int (*turnOnLights)(int);
void (*turnOffLights)();
int (*turnOnPump)(int);
void (*turnOffPump)();
// struct Sensor liquidLevelSensor;
int batteryPercentage;
Sensor sensorArray[8];
// System Health Check
struct System health;
Timer *healthTimer;
void healthCheck();
// Basic Light/Pump operations
Timer *lightsTimer;
Timer *pumpTimer;
int setLights(String command);
int setPump(String command);
// Configures device core information such as RGB color and time zone
int configure(String command);
// Check Sensors
int checkSensors();
String activeIssue;
// MESH REQUESTS
struct ActionRequest blankRequest;
struct ActionRequest activeRequest;
Timer *actionTimeout;
ActionRequest requestFormatter(const char *data);
ActionRequest requestCreator(String action, int timeout);
void resetAction();
};