This repository has been archived by the owner on Oct 9, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
DDP.h
105 lines (82 loc) · 2.45 KB
/
DDP.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
/*
DDP library for Arduino
http://www.arduino.cc/en/Hacking/LibraryTutorial
*/
#ifndef DDP_h
#define DDP_h
#include <Arduino.h>
#include <Ethernet.h>
#include "./libs/Arduino-Websocket/WebSocketClient.h"
//#include "./libs/ArduinoWebsocketClient/WebSocketClient.h"
#include "./libs/ArduinoJson/ArduinoJson.h"
class DDP {
public:
DDP();
/**************************************************************************
* WebSocket
*************************************************************************/
bool setup(String host, String path = "/", int port = 80);
bool handshake();
void output();
void waitFor();
/**************************************************************************
* DDP
*************************************************************************/
bool connect();
//void connect(String session = "", int version = 1, int support[] = DDP_Versions);
// Listen
void listen();
/* Heartbeats ************************************************************/
void ping(String id = "");
void pong(String id = "");
/* Managing data *********************************************************/
// client -> server
void sub();
void unsub();
// server -> client
void nosub();
void added();
void changed();
void removed();
void ready();
// addedBefore();
// movedBefore()
/* Remote procedure calls ************************************************/
// client -> server
void method(int readR, int readG, int readB);
// server-> client
void result();
void updated();
/* Sub *******************************************************************/
bool subsReady();
/* RGB *******************************************************************/
int getR();
int getG();
int getB();
private:
int _pause = 1000;
int _timer = 1;
WebSocketClient _webSocketClient;
EthernetClient _client;
String _host;
String _path;
int _port;
String _session;
StaticJsonBuffer<200> _jsonBuffer;
JsonObject& _root = _jsonBuffer.createObject();
/* Subscription */
bool _readyR = false;
bool _readyG = false;
bool _readyB = false;
bool _addedR = false;
bool _addedG = false;
bool _addedB = false;
// R, G, B
int _r = 0;
int _g = 0;
int _b = 0;
//const int DDP_Versions[] = {1};
//int _value;
//void _doSomethingSecret(void);
};
#endif