From 61c1c733e9450f1a5d0a96b2450c89d8903ffe82 Mon Sep 17 00:00:00 2001 From: "Adrian A. Baumann" Date: Thu, 21 May 2026 22:15:15 +0200 Subject: [PATCH] fix: replace sscanf %f with %s+atof for AVR compatibility in parsers --- Gaugecontroller/Gaugecontroller.ino | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/Gaugecontroller/Gaugecontroller.ino b/Gaugecontroller/Gaugecontroller.ino index ce1164a..d4e2bd2 100644 --- a/Gaugecontroller/Gaugecontroller.ino +++ b/Gaugecontroller/Gaugecontroller.ino @@ -453,8 +453,9 @@ bool parseSet(const String& line) { // Parses `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 ` 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 ` 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;