Refactor CLI submodule

Move command parsing to doCommand
Parse command with splitString instead of stringToken
Trim commands
Move cliTestMotor to the bottom
Rename parseInput to handleInput, which is more clear
Move motor test function to motors.ino
Remove parameters table functionality to simplify the code
This commit is contained in:
Oleg Kalachev
2025-02-28 22:49:37 +03:00
parent 67e4a95697
commit 6058e8ecab
8 changed files with 54 additions and 86 deletions

View File

@@ -33,9 +33,17 @@ class __FlashStringHelper;
// https://www.arduino.cc/reference/en/language/variables/data-types/stringobject/
class String: public std::string {
public:
String(const char *str = "") : std::string(str ? str : "") {}
long toInt() const { return atol(this->c_str()); }
float toFloat() const { return atof(this->c_str()); }
bool isEmpty() const { return this->empty(); }
void toCharArray(char *buf, unsigned int bufsize, unsigned int index = 0) const {
strlcpy(buf, this->c_str() + index, bufsize);
}
void trim() {
this->erase(0, this->find_first_not_of(" \t\n\r"));
this->erase(this->find_last_not_of(" \t\n\r") + 1);
}
};
class Print;

View File

@@ -34,7 +34,8 @@ void controlTorque();
void showTable();
void sendMotors();
bool motorsActive();
void cliTestMotor(uint8_t n);
void doCommand(String str);
void normalizeRC();
void printRCCal();
void processMavlink();
void sendMavlink();

View File

@@ -79,7 +79,7 @@ public:
attitude.setYaw(this->model->WorldPose().Yaw());
control();
parseInput();
handleInput();
processMavlink();
applyMotorForces();