mirror of
https://github.com/mikecarper/MeshCore.git
synced 2026-09-14 21:47:39 +00:00
Keep STM32 text conversion compatible with current Arduino cores
This commit is contained in:
@@ -94,6 +94,7 @@ jobs:
|
||||
run: |
|
||||
python3 -B test/test_companion_usb_default.py
|
||||
python3 -B test/test_esp32_usb_serial_hygiene.py
|
||||
python3 -B test/test_stm32_float_conversion.py
|
||||
|
||||
- name: Verify message reader buttons, touch targets, and footer layouts
|
||||
working-directory: test
|
||||
|
||||
@@ -118,7 +118,13 @@ static void _ftoa(float f, char *p, int *status)
|
||||
*p++ = '0';
|
||||
else
|
||||
{
|
||||
#if defined(STM32_PLATFORM)
|
||||
// STM32 Arduino exposes utoa, but recent cores no longer declare ltoa.
|
||||
// The sign was emitted above and this magnitude fits a 32-bit unsigned int.
|
||||
utoa(static_cast<unsigned int>(int_part), p, 10);
|
||||
#else
|
||||
ltoa(int_part, p, 10);
|
||||
#endif
|
||||
while (*p)
|
||||
p++;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,49 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Compile the real text helpers with STM32's utoa-only Arduino API."""
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
|
||||
|
||||
class Stm32FloatConversionTest(unittest.TestCase):
|
||||
def test_signed_values_and_limits_without_ltoa(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
root = Path(directory)
|
||||
(root / "Arduino.h").write_text("""
|
||||
#pragma once
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
inline char* utoa(unsigned int value, char* output, int base) {
|
||||
if (base != 10) abort();
|
||||
sprintf(output, "%u", value);
|
||||
return output;
|
||||
}
|
||||
""")
|
||||
(root / "test.cpp").write_text("""
|
||||
#include <cassert>
|
||||
#include <cstring>
|
||||
#include "helpers/TxtDataHelpers.h"
|
||||
int main() {
|
||||
assert(strcmp(StrHelper::ftoa(0), "0.0") == 0);
|
||||
assert(strcmp(StrHelper::ftoa(1), "1.0") == 0);
|
||||
assert(strcmp(StrHelper::ftoa(-2.5f), "-2.5") == 0);
|
||||
assert(strcmp(StrHelper::ftoa(62.5f), "62.5") == 0);
|
||||
assert(strcmp(StrHelper::ftoa(1.125f), "1.125") == 0);
|
||||
assert(strcmp(StrHelper::ftoa(2147483520.0f), "2147483520.0") == 0);
|
||||
assert(strcmp(StrHelper::ftoa(-2147483520.0f), "-2147483520.0") == 0);
|
||||
assert(strcmp(StrHelper::ftoa(2147483648.0f), "0") == 0);
|
||||
assert(strcmp(StrHelper::ftoa(1e-12f), "0") == 0);
|
||||
}
|
||||
""")
|
||||
binary = root / "test"
|
||||
subprocess.run(["g++", "-std=c++17", "-DSTM32_PLATFORM", "-I", str(root),
|
||||
"-I", str(ROOT / "src"), str(root / "test.cpp"),
|
||||
str(ROOT / "src/helpers/TxtDataHelpers.cpp"), "-o", str(binary)], check=True)
|
||||
subprocess.run([str(binary)], check=True)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user