fix: replace sscanf %f with %s+atof for AVR compatibility in parsers

This commit is contained in:
2026-05-21 22:15:15 +02:00
parent e1849f0dd1
commit 61c1c733e9

View File

@@ -453,8 +453,9 @@ bool parseSet(const String& line) {
// Parses `SPEED <id> <speed>` and updates the max step rate.
// Replies: `OK`, `ERR BAD_ID`, `ERR BAD_SPEED`.
bool parseSpeed(const String& line) {
int id; float speed;
if (sscanf(line.c_str(), "SPEED %d %f", &id, &speed) == 2) {
int id; char token[20];
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 (speed <= 0.0f) { sendReply("ERR BAD_SPEED"); return true; }
gauges[id].maxSpeed = speed;
@@ -467,8 +468,9 @@ bool parseSpeed(const String& line) {
// Parses `ACCEL <id> <accel>` and updates the acceleration limit.
// Replies: `OK`, `ERR BAD_ID`, `ERR BAD_ACCEL`.
bool parseAccel(const String& line) {
int id; float accel;
if (sscanf(line.c_str(), "ACCEL %d %f", &id, &accel) == 2) {
int id; char token[20];
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 (accel <= 0.0f) { sendReply("ERR BAD_ACCEL"); return true; }
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.
// Replies: `OK`, `ERR BAD_ID`.
bool parseSweep(const String& line) {
int id; float accel, speed;
if (sscanf(line.c_str(), "SWEEP %d %f %f", &id, &accel, &speed) == 3) {
int id; char accelTok[20], speedTok[20];
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; }
float accel = atof(accelTok);
float speed = atof(speedTok);
Gauge& g = gauges[id];
if (accel <= 0.0f || speed <= 0.0f) {
g.sweepEnabled = false;