-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathGarageDoorController.h
64 lines (52 loc) · 1.61 KB
/
GarageDoorController.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
#ifndef GARAGEDOORCONTROLLER_H
#define GARAGEDOORCONTROLLER_H
// ARDUINO LIBRARIES
#include <Arduino.h>
#include <Client.h>
#include <Bounce2.h>
#include <ArduinoJson.h>
// INCLUDES
#include "compile.h"
#include "config.h"
#include "src/HashMap.h"
#include "src/Utilities/Utilities.h"
#include "src/HttpWebServer/HttpWebServer.h"
class GarageDoorController
{
public:
GarageDoorController();
~GarageDoorController();
enum DoorState {
DOORSTATE_OPEN = 0,
DOORSTATE_CLOSED = 1,
DOORSTATE_OPENING = 2,
DOORSTATE_CLOSING = 3,
DOORSTATE_STOPPED_OPENING = 4,
DOORSTATE_STOPPED_CLOSING = 5,
DOORSTATE_UNKNOWN = -1
};
bool SensorOpen;
bool SensorClosed;
bool LightInput;
bool LightOutput;
bool LightState;
bool LightRequested;
uint32_t DoorTimeOpenSince = 0;
uint32_t DoorTimeLastOperated = 0;
enum DoorState DoorState = DOORSTATE_UNKNOWN;
enum DoorState DoorStateLastKnown = DOORSTATE_UNKNOWN;
void setup();
void loop();
void operateDoor(bool state);
void switchLight(bool state);
void getJsonStatus(char *const dest, size_t destSize);
char *stringFromDoorState(enum DoorState doorState);
uint16_t requestHandler(Client &client, const char *requestMethod, const char *requestUrl, HashMap<char *, char *, 24> &requestQuery);
private:
Bounce *_sensorOpenDebouncer;
Bounce *_sensorClosedDebouncer;
Bounce *_lightInputDebouncer;
void _monitorInputs();
void _operateDoor(uint8_t pin, uint8_t cycles);
};
#endif // GARAGEDOORCONTROLLER_H