-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathserial_commands.h
70 lines (56 loc) · 2.84 KB
/
serial_commands.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
// The parser - calls the appropriate function; leaves argument parsing to that function
#ifndef SERIAL_COMMANDS_
#define SERIAL_COMMANDS_
typedef void cmdHandler_t(); // All handlers take nothing and return nothing
struct cmd_table_t {
const char* cmd; // command
cmdHandler_t* cmdHandler; // handler function
const char* help; // help text
} ;
// Define the command set
extern cmdHandler_t cmd_batt, cmd_res, cmd_adcref, cmd_adccal, cmd_temp, cmd_showcal, cmd_factor, cmd_offset, cmd_cal,
cmd_activate, cmd_write, cmd_read, cmd_defaults, cmd_comment, cmd_help;
const cmd_table_t PROGMEM cmd_table[] = {
{"\n", cmd_help, "- - Calibration ----------------------------------"},
{"showcal", cmd_showcal, "Show the calibration currently in use."},
{"factor", cmd_factor, "<float> Enter a new cal factor (should not be necessary)."},
{"offset", cmd_offset, "<float> Enter a new calibration offset (follow with activate)."},
{"calibrate", cmd_cal, "Start tool-based calibration. Requires the Keiser cal tool."},
{"activate", cmd_activate, "Make the new calibration values active. Requires confirmation."},
{"write", cmd_write, "Write currently active calibration to the calibration file. Requires confirmation."},
{"read", cmd_read, "Read calibration from the calibration file."},
{"defaults", cmd_defaults, "Set calibration to hard-coded defaults. Requires confirmation."},
{"\n", cmd_help, "- - Utility and debugging -------------------------"},
{"batt", cmd_batt, "Show battery status."},
{"res", cmd_res, "<optional int> Monitor ADC readings - indicated number (default 20)."},
{"adcref", cmd_adcref, "Toggle the analog reference between default 3.6V and Vdd."},
{"adccal", cmd_adccal, "Calibrate the ADC offset."},
{"temp", cmd_temp, "Show the chip temperature (relevant to ADC offset)"},
{"c", cmd_comment, "Enter a comment (shows in the terminal log."},
{"\n", cmd_help, "- - Help ------------------------------------------"},
{"help", cmd_help, "This list."}
} ;
#define AWAITING_NONE 0xFF // Code for not waiting for any confirmation. Must not point to a command table entry that requires conf.
const int n_cmds = sizeof(cmd_table) / sizeof (cmd_table_t);
// The above supports a single fixed command set.
// The following allows multiple command sets to be defined.
// A command set is a command count and a pointer to a dispatch table
struct cmd_set_t {
const int n_cmds;
const cmd_table_t* cmd_table;
};
// The command set for the top-level commands
cmd_set_t cmd_set = {
sizeof(cmd_table) / sizeof(cmd_table_t),
cmd_table
};
// Pointer to the command set in use
cmd_set_t* curr_cmd_set;
/* How to
void test()
{
curr_cmd_set = &cmd_set; // Activate a command set
curr_cmd_set->cmd_table[1].cmdHandler(); // Call a member of the set in use
}
*/
#endif