IMPROVEMENT: use format library here

This commit is contained in:
Robin Dietzel 2023-01-13 15:25:59 +01:00
parent 31ae2b6664
commit 85c4d24e3b
6 changed files with 14 additions and 9 deletions

View File

@ -7,6 +7,6 @@
// Auto generated header file containing the last git revision // Auto generated header file containing the last git revision
#define GIT_HASH "e0a068f" #define GIT_HASH "c9c911b"
#endif //FLOATPUMP_GIT_REVISION_TEMPLATE_H #endif //FLOATPUMP_GIT_REVISION_TEMPLATE_H

View File

@ -81,6 +81,7 @@ void CheckRefillConditions(Config_Store &cfg, io::PressureChannel &tankLevel, io
//Check whether refilling is necessary //Check whether refilling is necessary
if(HAL_GetTick() > (c_RefillCooldown + (cfg.RefillCooldown.getValue() * 60*1000))) { if(HAL_GetTick() > (c_RefillCooldown + (cfg.RefillCooldown.getValue() * 60*1000))) {
S_refillcooldown = 0;
if (tankLevel.getPercent() < cfg.RefillBelow.getValue()) { if (tankLevel.getPercent() < cfg.RefillBelow.getValue()) {
if (cfg.RefillBlockEnable.getValue() && !rblock) { if (cfg.RefillBlockEnable.getValue() && !rblock) {
refillPump.switchRelay(io::RelayChannel::state::ON); refillPump.switchRelay(io::RelayChannel::state::ON);
@ -266,8 +267,7 @@ int main(void) {
display.LCDSetCursor(0, 0); display.LCDSetCursor(0, 0);
display.LCDSendCString( display.LCDSendCString(
const_cast<char *>(std::string("Tank: " + std::to_string(tankLevel0.getPercent()) + " %").c_str())); const_cast<char *>(fmt::format("Fuellstand {:3} % ", tankLevel0.getPercent()).c_str()));
display.LCDSetCursor(0, 1); display.LCDSetCursor(0, 1);
if (S_tankempty) { if (S_tankempty) {
display.LCDSendCString(const_cast<char *>(std::string("Tank Wassermangel ").c_str())); display.LCDSendCString(const_cast<char *>(std::string("Tank Wassermangel ").c_str()));
@ -290,7 +290,11 @@ int main(void) {
display.LCDSetCursor(0, 3); display.LCDSetCursor(0, 3);
if (S_refillcooldown > 0) { if (S_refillcooldown > 0) {
int remaining_mins = S_refillcooldown / 60;
if(remaining_mins > 0)
display.LCDSendCString(const_cast<char *>(fmt::format("Nsp. wartet: {:3} min", S_refillcooldown / 60).c_str())); display.LCDSendCString(const_cast<char *>(fmt::format("Nsp. wartet: {:3} min", S_refillcooldown / 60).c_str()));
else
display.LCDSendCString(const_cast<char *>(fmt::format("Nsp. wartet: {:3} s ", S_refillcooldown).c_str()));
} else if (S_refillempty) { } else if (S_refillempty) {
display.LCDSendCString(const_cast<char *>(std::string("Nachspeisung mangel ").c_str())); display.LCDSendCString(const_cast<char *>(std::string("Nachspeisung mangel ").c_str()));
HAL_GPIO_WritePin(LED3_GPIO_Port, LED3_Pin, GPIO_PIN_RESET); HAL_GPIO_WritePin(LED3_GPIO_Port, LED3_Pin, GPIO_PIN_RESET);

View File

@ -7,6 +7,7 @@
#include <string> #include <string>
#include "Menu_Entry_Type_Delegate.h" #include "Menu_Entry_Type_Delegate.h"
#include "fmt/core.h"
namespace floatpump { namespace floatpump {
namespace menu { namespace menu {

View File

@ -6,6 +6,7 @@
#define FLOATPUMP_MENU_ENTRY_TYPE_PERCENT_H #define FLOATPUMP_MENU_ENTRY_TYPE_PERCENT_H
#include "Menu_Entry_Type_Delegate.h" #include "Menu_Entry_Type_Delegate.h"
#include "fmt/core.h"
namespace floatpump::menu { namespace floatpump::menu {

View File

@ -13,10 +13,9 @@ namespace floatpump {
std::string Menu_Entry_Type_Numeric::toString() { std::string Menu_Entry_Type_Numeric::toString() {
if (m_entered) { if (m_entered) {
return "# " + std::to_string(*m_value); return fmt::format("> {{:5}", *m_value);
} else { } else {
return " " + std::to_string(*m_value); return fmt::format(" {{:5}", *m_value); }
}
} }
void Menu_Entry_Type_Numeric::u_press() { void Menu_Entry_Type_Numeric::u_press() {

View File

@ -6,9 +6,9 @@
std::string floatpump::menu::Menu_Entry_Type_Percent::toString() { std::string floatpump::menu::Menu_Entry_Type_Percent::toString() {
if (m_entered) { if (m_entered) {
return std::string("# " + std::to_string(*m_value) + "%"); return fmt::format("> {:3} %", *m_value);
} else { } else {
return std::string(" " + std::to_string(*m_value) + "%"); return fmt::format(" {:3} %", *m_value);
} }
} }