SimpleFOClibrary  2.1
Commander.h
Go to the documentation of this file.
1 #ifndef COMMANDS_H
2 #define COMMANDS_H
3 
4 #include "Arduino.h"
5 #include "../common/base_classes/FOCMotor.h"
6 #include "../common/pid.h"
7 #include "../common/lowpass_filter.h"
8 #include "commands.h"
9 
10 // Commander verbose display to the user type
12  nothing = 0, // display nothing - good for monitoring
13  on_request, // display only on user request
14  user_friendly // display textual messages to the user
15 };
16 
17 
18 // callback function pointer definiton
19 typedef void (* CommandCallback)(char*);
20 
33 class Commander
34 {
35  public:
42  Commander(Stream &serial);
43  Commander();
44 
54  void run();
66  void run(Stream &reader);
78  void run(char* user_input);
79 
86  void add(char id , CommandCallback onCommand, char* label = nullptr);
87 
88  // printing variables
90  uint8_t decimal_places = 3;
91 
92  // monitoring functions
93  Stream* com_port = nullptr;
94 
140  void motor(FOCMotor* motor, char* user_cmd);
141 
148  void lpf(LowPassFilter* lpf, char* user_cmd);
160  void pid(PIDController* pid, char* user_cmd);
167  void scalar(float* value, char* user_cmd);
168 
169  private:
170  // Subscribed command callback variables
171  CommandCallback call_list[20];
172  char call_ids[20];
173  char* call_label[20];
174  int call_count = 0;
175 
176  // helping variable for serial communication reading
177  char received_chars[20] = {0};
178  int rec_cnt = 0;
179 
180  // serial printing functions
185  void printVerbose(const char* message);
191  void printVerbose(const __FlashStringHelper *message);
197  void print(const float number);
198  void print(const int number);
199  void print(const char* message);
200  void print(const __FlashStringHelper *message);
201  void print(const char message);
202  void println(const float number);
203  void println(const int number);
204  void println(const char* message);
205  void println(const __FlashStringHelper *message);
206  void println(const char message);
207 
208  void printError();
209 };
210 
211 
212 #endif
Commander
Definition: Commander.h:34
FOCMotor
Definition: FOCMotor.h:58
Commander::add
void add(char id, CommandCallback onCommand, char *label=nullptr)
Definition: Commander.cpp:12
VerboseMode
VerboseMode
Definition: Commander.h:11
Commander::Commander
Commander()
Definition: Commander.cpp:7
user_friendly
@ user_friendly
Definition: Commander.h:14
Commander::decimal_places
uint8_t decimal_places
number of decimal places to be used when displaying numbers
Definition: Commander.h:90
on_request
@ on_request
Definition: Commander.h:13
Commander::run
void run()
Definition: Commander.cpp:20
Commander::verbose
VerboseMode verbose
flag signaling that the commands should output user understanable text
Definition: Commander.h:89
Commander::lpf
void lpf(LowPassFilter *lpf, char *user_cmd)
Definition: Commander.cpp:364
Commander::pid
void pid(PIDController *pid, char *user_cmd)
Definition: Commander.cpp:327
CommandCallback
void(* CommandCallback)(char *)
command callback function pointer
Definition: Commander.h:19
Commander::scalar
void scalar(float *value, char *user_cmd)
Definition: Commander.cpp:381
PIDController
Definition: pid.h:12
nothing
@ nothing
Definition: Commander.h:12
commands.h
Commander::com_port
Stream * com_port
Serial terminal variable if provided.
Definition: Commander.h:93
Commander::motor
void motor(FOCMotor *motor, char *user_cmd)
Definition: Commander.cpp:102
LowPassFilter
Definition: lowpass_filter.h:12