change sstream to fmt

This commit is contained in:
Martin Brodbeck 2022-06-03 14:33:42 +02:00
parent c56c52e458
commit 7a79ff85b5
5 changed files with 17 additions and 15 deletions

3
.gitmodules vendored
View file

@ -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

View file

@ -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)

1
modules/fmt Submodule

@ -0,0 +1 @@
Subproject commit b6f4ceaed0a0a24ccf575fab6c56dd50ccf6f1a9

View file

@ -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}

View file

@ -1,5 +1,6 @@
#include <sstream>
#include <string>
#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);
}
}