-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSerialCommands.h
More file actions
executable file
·63 lines (50 loc) · 1.79 KB
/
Copy pathSerialCommands.h
File metadata and controls
executable file
·63 lines (50 loc) · 1.79 KB
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
/**************************************************************************/
/*!
@file SerialCommands.h
@author Ruben v. Rooij
@license BSD (see license.txt)
This is library sends and receives commands on the arduino serial
port. It's based on tasasaki's example on the Arduino form.
*/
/**************************************************************************/
#if ARDUINO >= 100
#include "Arduino.h"
#else
#include "WProgram.h"
#endif
#define MAX_COMMAND_LEN (20)
#define MAX_PARAMETER_LEN (255)
#define MAX_COMMANDS_COUNT (10)
#define TO_UPPER(x) (((x >= 'a') && (x <= 'z')) ? ((x) - ('a' - 'A')) : (x))
enum { COMMAND, PARAM };
typedef struct {
char *name;
void (*function)(void);
} command_t;
class SerialCommands {
public:
SerialCommands();
void begin(command_t commandTable[]);
void receive();
void sendCommand(char *commandName);
void sendCommandWithParam(char *commandName, char *param);
void sendCommandWithBool(char *commandName, bool param);
void sendCommandWithInt(char *commandName, int param);
void sendCommandWithIntArrayAsCharacter(char *commandName, uint8_t param[], int arrLength);
void sendCommandWithIntArrayAsNumeric(char *commandName, uint8_t param[], int arrLength);
void printAllCommands();
//uint8_t getP
uint8_t gParamVal[MAX_PARAMETER_LEN + 1];
long gParamValLong; // Stored param value as a long
String gParamValChar; // Stored param value as a string
;
private:
uint8_t it_cmd;
uint8_t it_param;
uint8_t state;
char gCommandBuffer[MAX_COMMAND_LEN + 1];
char gParamBuffer[MAX_PARAMETER_LEN + 1];
command_t gCommandTable[MAX_COMMANDS_COUNT+1];
int buildCommand(char nextChar);
void processCommand();
};