-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathyaclLib.h
More file actions
94 lines (85 loc) · 2.92 KB
/
yaclLib.h
File metadata and controls
94 lines (85 loc) · 2.92 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
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
/*
* yaclLib.h
*
* Created on: 11 03 2019
* Author: Cricri042
*/
#ifndef YACLLIB_H_
#define YACLLIB_H_
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <Arduino.h>
//this following macro is good for debugging, e.g. print2("myVar= ", myVar);
#define print2(x, y) (stream.print(x), stream.println(y))
#define NELEMS(x) (sizeof(x) / sizeof((x)[0]))
#define ENGINE cmdEngine
#define YACL_USE_YACLLIB yaclLibSpace::yaclLib* ENGINE;
#define YACL_CMDS_LIST yaclLibSpace::cmdLineCommand
#define YACL_INIT_CMDS(s, c) cmdEngine = new yaclLibSpace::yaclLib(s, c, NELEMS(c));
#define YACL_CHECK_CMDS cmdEngine->checkCommands()
#define YACL_GETINT ENGINE->readNumber()
#define YACL_GETLONG ENGINE->readLong()
#define YACL_GETFLOAT ENGINE->readFloat()
#define YACL_GETSTR ENGINE->readWord()
#define YACL_OK ENGINE->readOk()
#define YACL_PRINT(x) ENGINE->stream.print(x)
#define YACL_PRINTLN(x) ENGINE->stream.println(x)
#define YACL_PRINT2(x, y) ENGINE->stream.print(x, y)
#define YACL_PRINTLN2(x, y) ENGINE->stream.println(x, y)
#define YACL_WRITE(x) ENGINE->stream.write(x)
#define YACL_TOKEN ENGINE->token()
namespace yaclLibSpace {
const unsigned int CR = '\r';
const unsigned int LF = '\n';
const unsigned int BS = '\b';
const unsigned int NULLCHAR = '\0';
const unsigned int SPACE = ' ';
const unsigned int COMMAND_BUFFER_LENGTH = 32;
typedef void (*num_func)();
extern num_func functions[];
typedef struct cmdLineCommand {
char* tokens;
num_func userFunc;
} cmdLineCommand;
// Generic template
template<class T>
inline Print &operator <<(Print &stream, T arg)
{ stream.print(arg); return stream; }
class yaclLib : public Stream {
public:
yaclLib(Stream& dev, cmdLineCommand* cmds, size_t s);
~yaclLib();
Stream &stream;
/***************************************************************************
getCommandLineFromSerialPort()
Return the string of the next command. Commands are delimited by return"
Handle BackSpace character
Make all chars lowercase
****************************************************************************/
bool getCommandLineFromSerialPort();
int readNumber();
long readLong();
float readFloat();
char* readWord();
char* token() { return cmdToken; };
bool checkCommands();
bool readOk() { return ok; }
virtual void flush() { /* Empty implementation for backward compatibility */ }
private:
int read();
int available();
int peek();
size_t write(uint8_t b);
cmdLineCommand* commands;
size_t userFuncSize;
char commandLine[COMMAND_BUFFER_LENGTH + 1]; //Read commands into this buffer from Serial. +1 in length for a termination char
bool ok;
const char *delimiters = " "; //commands must be separated by space
char *cmdToken = "";
int isNumericString(char *s);
void nullCommand(char *ptrToCommandName);
bool DoMyCommand();
};
} /* namespace yaclLibSpace */
#endif /* YACLLIB_H_ */