diff --git a/README.md b/README.md
index dfd0f87..79256cd 100644
--- a/README.md
+++ b/README.md
@@ -13,7 +13,7 @@ It has been written to complement grblHAL and has features such as proper keyboa
---
-Latest build date is 20240526, see the [changelog](changelog.md) for details.
+Latest build date is 20240527, see the [changelog](changelog.md) for details.
__NOTE:__ Build 20240222 has moved the probe input to the ioPorts pool of inputs and will be allocated from it when configured.
The change is major and _potentially dangerous_, it may damage your probe, so please _verify correct operation_ after installing this, or later, builds.
diff --git a/changelog.md b/changelog.md
index 42d416a..797f502 100644
--- a/changelog.md
+++ b/changelog.md
@@ -1,5 +1,13 @@
## grblHAL changelog
+Build 20240527
+
+Core:
+
+* "Hardened" NGC parameter name case swapping, changed to use float precision according to metric/inches setting for parameter reporting.
+
+---
+
Build 20240526
Core:
@@ -11,7 +19,7 @@ Available for gcode run from local filesystem such as on a SD card or in littlef
* Improved handling of G92 when G92 offset is changed while motion is ongoing.
Position and WCO offset in the realtime report will now be the actual realtime values and not
-the values based on the parser state which may be quite a bit ahead of the machine. Ref. [issue #241](https://github.com/grblHAL/core/discussions/241#discussioncomment-9463390).
+the values based on the parser state which may be quite a bit ahead of the machine. Ref. [discussion #241](https://github.com/grblHAL/core/discussions/241#discussioncomment-9463390).
* Fix for [issue #521](https://github.com/grblHAL/core/issues/521), crash when running G65 macro on ESP32.
diff --git a/gcode.c b/gcode.c
index e3cc3b2..96c6b7f 100644
--- a/gcode.c
+++ b/gcode.c
@@ -620,7 +620,7 @@ char *gc_normalize_block (char *block, char **message)
if(c == '#') {
char_counter--;
if(read_parameter(comment, &char_counter, &value) == Status_OK)
- len += strlen(trim_float(ftoa(value, 6)));
+ len += strlen(trim_float(ftoa(value, ngc_float_decimals())));
else
len += 3; // "N/A"
} else
@@ -637,7 +637,7 @@ char *gc_normalize_block (char *block, char **message)
if(c == '#') {
char_counter--;
if(read_parameter(comment, &char_counter, &value) == Status_OK)
- strcat(s3, trim_float(ftoa(value, 6)));
+ strcat(s3, trim_float(ftoa(value, ngc_float_decimals())));
else
strcat(s3, "N/A");
s3 = strchr(s3, '\0');
diff --git a/grbl.h b/grbl.h
index 972e12f..b75fbb0 100644
--- a/grbl.h
+++ b/grbl.h
@@ -42,7 +42,7 @@
#else
#define GRBL_VERSION "1.1f"
#endif
-#define GRBL_BUILD 20240526
+#define GRBL_BUILD 20240527
#define GRBL_URL "https://github.com/grblHAL"
diff --git a/ngc_params.c b/ngc_params.c
index 8364ab7..5763db8 100644
--- a/ngc_params.c
+++ b/ngc_params.c
@@ -572,21 +572,20 @@ float ngc_named_param_get_by_id (ncg_name_param_id_t id)
}
// Lowercase name, remove control characters and spaces
-// Assumes names stored in flash are lowercase...
-static char *ngc_name_tolower (char *name)
+static char *ngc_name_tolower (char *s)
{
- char c, *s1 = name, *s2 = name;
- bool convert = false;
+ static char name[NGC_MAX_PARAM_LENGTH + 1];
- while((c = *s1++) && c > ' ')
- convert = (c & 0x20) == 0 || c <= ' ';
+ uint_fast8_t len = 0;
+ char c, *s1 = s, *s2 = name;
- if(convert) {
- s1 = name;
- while((c = *s1++) && c > ' ')
- *s2++ = LCAPS(c);
- *s2 = '\0';
+ while((c = *s1++) && len < NGC_MAX_PARAM_LENGTH) {
+ if(c > ' ') {
+ *s2++ = LCAPS(c);
+ len++;
+ }
}
+ *s2 = '\0';
return name;
}
@@ -596,7 +595,7 @@ bool ngc_named_param_get (char *name, float *value)
bool found = false;
uint_fast8_t idx = sizeof(ngc_named_ro_param) / sizeof(ngc_named_ro_param_t);
- ngc_name_tolower(name);
+ name = ngc_name_tolower(name);
*value = 0.0f;
@@ -625,7 +624,7 @@ bool ngc_named_param_exists (char *name)
bool ok = false;
uint_fast8_t idx = sizeof(ngc_named_ro_param) / sizeof(ngc_named_ro_param_t);
- ngc_name_tolower(name);
+ name = ngc_name_tolower(name);
// Check if name is supplied, return false if not.
if((*name == '_' ? *(name + 1) : *name) == '\0')
@@ -657,7 +656,7 @@ bool ngc_named_param_set (char *name, float value)
bool ok = false;
uint_fast8_t idx = sizeof(ngc_named_ro_param) / sizeof(ngc_named_ro_param_t);
- ngc_name_tolower(name);
+ name = ngc_name_tolower(name);
// Check if name is supplied, return false if not.
if((*name == '_' ? *(name + 1) : *name) == '\0')
@@ -798,4 +797,9 @@ uint_fast8_t ngc_call_level (void)
return (uint_fast8_t)(call_level + 1);
}
+uint8_t ngc_float_decimals (void)
+{
+ return settings.flags.report_inches ? N_DECIMAL_COORDVALUE_INCH : N_DECIMAL_COORDVALUE_MM;
+}
+
#endif // NGC_PARAMETERS_ENABLE
diff --git a/ngc_params.h b/ngc_params.h
index 198695b..2af01d7 100644
--- a/ngc_params.h
+++ b/ngc_params.h
@@ -87,6 +87,7 @@ typedef enum {
NGCParam_Last
} ncg_name_param_id_t;
+uint8_t ngc_float_decimals (void);
bool ngc_param_get (ngc_param_id_t id, float *value);
bool ngc_param_set (ngc_param_id_t id, float value);
bool ngc_param_is_rw (ngc_param_id_t id);
diff --git a/report.c b/report.c
index 1162a12..aafa32c 100644
--- a/report.c
+++ b/report.c
@@ -553,7 +553,7 @@ status_code_t report_ngc_parameter (ngc_param_id_t id)
hal.stream.write(uitoa(id));
if(ngc_param_get(id, &value)) {
hal.stream.write("=");
- hal.stream.write(ftoa(value, 3));
+ hal.stream.write(trim_float(ftoa(value, ngc_float_decimals())));
} else
hal.stream.write("=N/A");
hal.stream.write("]" ASCII_EOL);
@@ -570,7 +570,7 @@ status_code_t report_named_ngc_parameter (char *arg)
hal.stream.write(arg);
if(ngc_named_param_get(arg, &value)) {
hal.stream.write("=");
- hal.stream.write(ftoa(value, 3));
+ hal.stream.write(trim_float(ftoa(value, ngc_float_decimals())));
} else
hal.stream.write("=N/A");
hal.stream.write("]" ASCII_EOL);