-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathOpaq_command.h
58 lines (44 loc) · 1.21 KB
/
Opaq_command.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
/*
* Opaq_command allows us to execute commands from diferent modules/plugins, and
* recovery actions that can be taked outside of the opaq controller by using
* the terminal.
*/
#ifndef OPAQCOMMAND_H
#define OPAQCOMMAND_H
#include <Arduino.h>
#include <LinkedList.h>
#include <Scheduler.h>
#include <Scheduler/Semaphore.h>
#include <atomic>
#include <functional>
#include "opaq.h"
#ifdef DEBUG_ESP_OPAQCOMMAND
#define DEBUG_MSG_COMMAND(...) DEBUG_ESP_PORT.printf(__VA_ARGS__)
#else
#define DEBUG_MSG_COMMAND(...)
#endif
struct oq_cmd {
// oq_cmd() : args (LinkedList<String>()) {};
// oq_cmd(const oq_cmd &c) { *this = c; };
std::function<void(LinkedList<String> &args)> exec;
LinkedList<String> args;
// oq_cmd& operator=(const oq_cmd& a) { exec = a.exec; args = a.args; };
};
class Opaq_command {
private:
static std::atomic<bool> ll;
LinkedList<oq_cmd> queue;
Semaphore cmd_lock;
public:
Opaq_command() : queue(LinkedList<oq_cmd>()), cmd_lock(Semaphore()){};
void begin();
void end();
void send(oq_cmd &cmd);
void exec();
void handler();
void terminal();
void lock() { cmd_lock.wait(); }
void unlock() { cmd_lock.signal(); }
};
extern Opaq_command command;
#endif // OPAQCOMMAND_H