From 7a79ff85b58f45b0926b563b6ac11cdb308a053c Mon Sep 17 00:00:00 2001 From: Martin Brodbeck Date: Fri, 3 Jun 2022 14:33:42 +0200 Subject: [PATCH] change sstream to fmt --- .gitmodules | 3 +++ CMakeLists.txt | 1 + modules/fmt | 1 + src/CMakeLists.txt | 2 +- src/gbmanager.cpp | 25 +++++++++++-------------- 5 files changed, 17 insertions(+), 15 deletions(-) create mode 160000 modules/fmt diff --git a/.gitmodules b/.gitmodules index f7e01f0..7dce60a 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "modules/pico-onewire"] path = modules/pico-onewire url = https://github.com/adamboardman/pico-onewire.git +[submodule "modules/fmt"] + path = modules/fmt + url = https://github.com/fmtlib/fmt.git diff --git a/CMakeLists.txt b/CMakeLists.txt index 362656f..10d1e65 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -18,4 +18,5 @@ project(gbmanager VERSION "1.0.0" LANGUAGES C CXX ASM) pico_sdk_init() add_subdirectory(modules/pico-onewire) +add_subdirectory(modules/fmt) add_subdirectory(src) \ No newline at end of file diff --git a/modules/fmt b/modules/fmt new file mode 160000 index 0000000..b6f4cea --- /dev/null +++ b/modules/fmt @@ -0,0 +1 @@ +Subproject commit b6f4ceaed0a0a24ccf575fab6c56dd50ccf6f1a9 diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index bdddc2f..a5256dc 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -22,7 +22,7 @@ else() endif() # Add the standard library to the build -target_link_libraries(${CMAKE_PROJECT_NAME} pico_stdlib pico_one_wire) +target_link_libraries(${CMAKE_PROJECT_NAME} pico_stdlib pico_one_wire fmt::fmt-header-only) # Add any user requested libraries target_link_libraries(${CMAKE_PROJECT_NAME} diff --git a/src/gbmanager.cpp b/src/gbmanager.cpp index a932d61..f6c8445 100644 --- a/src/gbmanager.cpp +++ b/src/gbmanager.cpp @@ -1,5 +1,6 @@ -#include +#include +#include "../modules/fmt/include/fmt/format.h" #include "../modules/pico-onewire/api/one_wire.h" #include "hardware/i2c.h" #include "pico/stdlib.h" @@ -28,7 +29,7 @@ absolute_time_t lastPressed = get_absolute_time(); using std::string; -void buttonPressedCallback(uint gpio, uint32_t events) { +void buttonPressedCallback(uint gpio, [[maybe_unused]] uint32_t events) { absolute_time_t now = get_absolute_time(); if (absolute_time_diff_us(lastPressed, now) < 750000) { return; @@ -76,14 +77,14 @@ int main() { float temp_act{0}; float temp_diff{0.5}; - std::stringstream lcdText{}; + string lcdText{}; bool isHeating = false; string heatInfo{""}; string systemInfo{""}; - lcdText << " G" << CUSTOM_CHAR_AE << "rbox Manager\n (Ver. " - << PROJECT_VERSION << ")"; - myLCD.sendString(lcdText.str()); + lcdText = fmt::format(" G{}rbox Manager\n (Ver. {})", CUSTOM_CHAR_AE, + PROJECT_VERSION); + myLCD.sendString(lcdText); sleep_ms(3000); while (true) { @@ -103,14 +104,10 @@ int main() { relais.activate(isHeating); - lcdText.str(""); - lcdText.clear(); - lcdText.precision(4); - lcdText << "ACT: " << temp_act << CUSTOM_CHAR_DEG << "C " << heatInfo - << "\n" - << "TGT: " << temp_tgt << CUSTOM_CHAR_DEG << "C " << systemInfo; - + lcdText = fmt::format("ACT: {:05.2f} {}C {}\nACT: {:05.2f} {}C {}", + temp_act, CUSTOM_CHAR_DEG, heatInfo, temp_tgt, + CUSTOM_CHAR_DEG, systemInfo); myLCD.setCursor(0, 0); - myLCD.sendString(lcdText.str()); + myLCD.sendString(lcdText); } } \ No newline at end of file