fix: replace sscanf %f with %s+atof for AVR compatibility in parsers
This commit is contained in:
@@ -453,8 +453,9 @@ bool parseSet(const String& line) {
|
|||||||
// Parses `SPEED <id> <speed>` and updates the max step rate.
|
// Parses `SPEED <id> <speed>` and updates the max step rate.
|
||||||
// Replies: `OK`, `ERR BAD_ID`, `ERR BAD_SPEED`.
|
// Replies: `OK`, `ERR BAD_ID`, `ERR BAD_SPEED`.
|
||||||
bool parseSpeed(const String& line) {
|
bool parseSpeed(const String& line) {
|
||||||
int id; float speed;
|
int id; char token[20];
|
||||||
if (sscanf(line.c_str(), "SPEED %d %f", &id, &speed) == 2) {
|
if (sscanf(line.c_str(), "SPEED %d %19s", &id, token) == 2) {
|
||||||
|
float speed = atof(token);
|
||||||
if (id < 0 || id >= GAUGE_COUNT) { sendReply("ERR BAD_ID"); return true; }
|
if (id < 0 || id >= GAUGE_COUNT) { sendReply("ERR BAD_ID"); return true; }
|
||||||
if (speed <= 0.0f) { sendReply("ERR BAD_SPEED"); return true; }
|
if (speed <= 0.0f) { sendReply("ERR BAD_SPEED"); return true; }
|
||||||
gauges[id].maxSpeed = speed;
|
gauges[id].maxSpeed = speed;
|
||||||
@@ -467,8 +468,9 @@ bool parseSpeed(const String& line) {
|
|||||||
// Parses `ACCEL <id> <accel>` and updates the acceleration limit.
|
// Parses `ACCEL <id> <accel>` and updates the acceleration limit.
|
||||||
// Replies: `OK`, `ERR BAD_ID`, `ERR BAD_ACCEL`.
|
// Replies: `OK`, `ERR BAD_ID`, `ERR BAD_ACCEL`.
|
||||||
bool parseAccel(const String& line) {
|
bool parseAccel(const String& line) {
|
||||||
int id; float accel;
|
int id; char token[20];
|
||||||
if (sscanf(line.c_str(), "ACCEL %d %f", &id, &accel) == 2) {
|
if (sscanf(line.c_str(), "ACCEL %d %19s", &id, token) == 2) {
|
||||||
|
float accel = atof(token);
|
||||||
if (id < 0 || id >= GAUGE_COUNT) { sendReply("ERR BAD_ID"); return true; }
|
if (id < 0 || id >= GAUGE_COUNT) { sendReply("ERR BAD_ID"); return true; }
|
||||||
if (accel <= 0.0f) { sendReply("ERR BAD_ACCEL"); return true; }
|
if (accel <= 0.0f) { sendReply("ERR BAD_ACCEL"); return true; }
|
||||||
gauges[id].accel = accel;
|
gauges[id].accel = accel;
|
||||||
@@ -545,9 +547,11 @@ bool parseHome(const String& line) {
|
|||||||
// Parses `SWEEP <id> <accel> <speed>` and enables or disables end-to-end motion.
|
// Parses `SWEEP <id> <accel> <speed>` and enables or disables end-to-end motion.
|
||||||
// Replies: `OK`, `ERR BAD_ID`.
|
// Replies: `OK`, `ERR BAD_ID`.
|
||||||
bool parseSweep(const String& line) {
|
bool parseSweep(const String& line) {
|
||||||
int id; float accel, speed;
|
int id; char accelTok[20], speedTok[20];
|
||||||
if (sscanf(line.c_str(), "SWEEP %d %f %f", &id, &accel, &speed) == 3) {
|
if (sscanf(line.c_str(), "SWEEP %d %19s %19s", &id, accelTok, speedTok) == 3) {
|
||||||
if (id < 0 || id >= GAUGE_COUNT) { sendReply("ERR BAD_ID"); return true; }
|
if (id < 0 || id >= GAUGE_COUNT) { sendReply("ERR BAD_ID"); return true; }
|
||||||
|
float accel = atof(accelTok);
|
||||||
|
float speed = atof(speedTok);
|
||||||
Gauge& g = gauges[id];
|
Gauge& g = gauges[id];
|
||||||
if (accel <= 0.0f || speed <= 0.0f) {
|
if (accel <= 0.0f || speed <= 0.0f) {
|
||||||
g.sweepEnabled = false;
|
g.sweepEnabled = false;
|
||||||
|
|||||||
Reference in New Issue
Block a user