forked from DustinWatts/FreeTouchDeck
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathFTAction.h
107 lines (102 loc) · 3.98 KB
/
FTAction.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
#pragma once
#include "globals.hpp"
#include "System.h"
namespace FreeTouchDeck
{
class FTAction;
class ActionsSequences;
enum class ActionTypes
{
NONE = 0,
KEYBOARD,
LOCAL,
ENDLIST
};
inline ActionTypes &operator++(ActionTypes &state, int)
{
int i = static_cast<int>(state) + 1;
i = i >= (int)ActionTypes::ENDLIST ? (int)ActionTypes::NONE : i;
state = static_cast<ActionTypes>(i);
return state;
}
const char *enum_to_string(ActionTypes type);
typedef std::vector<uint8_t> KeyValue_t;
typedef std::map<const char *, KeyValue_t> KeyMap_t;
typedef std::vector<FTAction *> ActionsList;
typedef std::vector<std::string> ParametersList_t;
typedef std::vector<std::string> ActionQueueType_t;
extern ActionQueueType_t UserActionsKeyboardQueue;
class FTAction
{
public:
ActionTypes Type;
bool NeedsRelease;
bool NeedsDoubleBytes;
uint16_t HoldTime=0;
KeyValue_t Values;
ParametersList_t Parameters;
static const char *JsonLabelType;
static const char *JsonLabelValue;
static const char *JsonLabelSymbol;
FTAction();
FTAction(char *jsonActionType, char *jsonValueStr);
FTAction(const ParametersList_t ¶meters);
FTAction(const char *keyName, const KeyValue_t &values);
FTAction(const KeyValue_t &values);
static bool SplitParameters(const char *parmString, ParametersList_t ¶meters);
static void InitConstants();
void ParseModifierKey(char *modifier);
~FTAction();
static bool IsValidKey(const char *name, char **foundValue);
static bool ParseToken(const char *token, std::vector<FTAction *> &sequences);
static bool KeyNeedsRelease(const char *keyName);
static bool KeyIsDoubleBytes(const char *keyName);
void Execute();
static void Stop();
const char *toString();
std::string& GetParameter(int index);
const char *ActionName();
const char *FirstParameter();
const char *SecondParameter();
const char *ThirdParameter();
std::string& ActionNameStr();
std::string& FirstParameterStr();
std::string& SecondParameterStr();
std::string& ThirdParameterStr();
static std::string& GetParameter(int index, ParametersList_t ¶meters);
static ActionTypes GetType(cJSON *jsonActionType, ParametersList_t ¶meters);
bool SplitActionParameter(char *name, size_t nameSize, char *parameter, size_t parameterSize);
static bool SplitActionParameter(const char *value, char *name, size_t nameSize, char *parameter, size_t parameterSize);
inline bool IsScreen()
{
bool KeyboardLocalAction=false;
for(const std::string &e : UserActionsKeyboardQueue)
{
if(e==ActionNameStr())
{
KeyboardLocalAction=true;
break;
}
}
// Screen queue if not Keyboard event and acction name not in the Keyboard queue list
return Type != ActionTypes::KEYBOARD && !KeyboardLocalAction;
}
static FTAction rebootSystem;
bool CallActionCallback(bool checkOnly = false);
static bool CallActionCallback(ParametersList_t ¶meters, FTAction *action, bool checkOnly);
static bool IsActionCallback(ParametersList_t ¶meters);
static bool Stopped;
};
typedef std::function<bool(FTAction *)> ActionCallbackFn_t;
typedef std::map<std::string, ActionCallbackFn_t> ActionCallbackMap_t;
extern const ActionCallbackMap_t UserActions;
extern bool QueueAction(FTAction *action);
extern FTAction *PopQueue();
void EmptyQueue();
cJSON * UserActionsJson();
cJSON *KeyNamesJson();
size_t QueueSize();
extern bool QueueLock(TickType_t xTicksToWait);
extern void QueueUnlock();
extern FTAction *PopScreenQueue();
}