-
Notifications
You must be signed in to change notification settings - Fork 0
/
klivetechinterface.h
67 lines (57 loc) · 1.68 KB
/
klivetechinterface.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
#ifndef KliveTechInterface_H
#define KliveTechInterface_H
#include <string>
#include <vector>
#include "BluetoothSerial.h"
#include "ArduinoJson.h"
using namespace std;
enum ActionParameterType
{
Integer,
String,
Bool
};
enum OperationNumber{
ExecuteAction,
GetActions
};
struct Actions
{
ActionParameterType type;
const char *name;
const char *paramDescription;
std::function<void(int)> intFunction;
std::function<void(const char *)> StringFunction;
std::function<void(bool)> BoolFunction;
};
struct OmnipotentResponse
{
OperationNumber operation;
int ID;
const char *data;
bool ResponseExpected;
};
class KliveTech
{
public:
BluetoothSerial SerialBT;
void CreateKliveTechGadget(const char *name);
void CallLoop();
void CreateActionWithIntegerParam(const char *actname, std::function<void(int)> func, const char *paramDescription);
void CreateActionWithStringParam(const char *actname, std::function<void(const char *)> func, const char *paramDescription);
void CreateActionWithBoolParam(const char *actname, std::function<void(bool)> func, const char *paramDescription);
private:
vector<Actions> possibleActions;
std::string startCommand = "{startComm}";
std::string endCommand = "{endComm}";
void SendData(const char *data);
const char *FormulateResponse(int ID, JsonObject obj, const char *status, bool isResponseExpected);
OmnipotentResponse DeserializeResponse(const char *response);
bool hasEnding(std::string const &fullString, std::string const &ending);
const char *ReadCommand();
inline const char *const BoolToString(bool b)
{
return b ? "true" : "false";
}
};
#endif