mirror of
https://github.com/emsesp/EMS-ESP32.git
synced 2025-12-07 16:29:51 +03:00
tidied up print_value so its consistent across all types
This commit is contained in:
@@ -371,21 +371,21 @@ void Boiler::show_values(uuid::console::Shell & shell) {
|
||||
|
||||
print_value(shell, 2, F("Warm water mix temperature"), wwMixTemperature_, F_(degrees), 10);
|
||||
print_value(shell, 2, F("Warm water buffer boiler temperature"), wwBufferBoilerTemperature_, F_(degrees), 10);
|
||||
print_value(shell, 2, F("Warm Water disinfection temperature"), wWDisinfectTemp_, F_(degrees), 1);
|
||||
print_value(shell, 2, F("Warm Water selected temperature"), wWSelTemp_, F_(degrees), 1);
|
||||
print_value(shell, 2, F("Warm Water set temperature"), wWSetTmp_, F_(degrees), 1);
|
||||
print_value(shell, 2, F("Warm Water disinfection temperature"), wWDisinfectTemp_, F_(degrees));
|
||||
print_value(shell, 2, F("Warm Water selected temperature"), wWSelTemp_, F_(degrees));
|
||||
print_value(shell, 2, F("Warm Water set temperature"), wWSetTmp_, F_(degrees));
|
||||
print_value(shell, 2, F("Warm Water current temperature (intern)"), wWCurTmp_, F_(degrees), 10);
|
||||
print_value(shell, 2, F("Warm water storage temperature (intern)"), wwStorageTemp1_, F_(degrees), 10);
|
||||
print_value(shell, 2, F("Warm Water current temperature (extern)"), wWCurTmp2_, F_(degrees), 10);
|
||||
print_value(shell, 2, F("Warm water storage temperature (extern)"), wwStorageTemp2_, F_(degrees), 10);
|
||||
print_value(shell, 2, F("Warm Water current tap water flow"), wWCurFlow_, F("l/min"), 10);
|
||||
print_value(shell, 2, F("Warm Water # starts"), wWStarts_, nullptr, 1);
|
||||
print_value(shell, 2, F("Warm Water # starts"), wWStarts_, nullptr);
|
||||
if (Helpers::hasValue(wWWorkM_)) {
|
||||
shell.printfln(F(" Warm Water active time: %d days %d hours %d minutes"), wWWorkM_ / 1440, (wWWorkM_ % 1440) / 60, wWWorkM_ % 60);
|
||||
}
|
||||
print_value(shell, 2, F("Warm Water charging"), wWHeat_, nullptr, EMS_VALUE_BOOL);
|
||||
print_value(shell, 2, F("Warm Water disinfecting"), wWDesinfecting_, nullptr, EMS_VALUE_BOOL);
|
||||
print_value(shell, 2, F("Selected flow temperature"), selFlowTemp_, F_(degrees), 1);
|
||||
print_value(shell, 2, F("Selected flow temperature"), selFlowTemp_, F_(degrees));
|
||||
print_value(shell, 2, F("Current flow temperature"), curFlowTemp_, F_(degrees), 10);
|
||||
print_value(shell, 2, F("Max boiler temperature"), boilTemp_, F_(degrees), 10);
|
||||
print_value(shell, 2, F("Return temperature"), retTemp_, F_(degrees), 10);
|
||||
@@ -394,8 +394,8 @@ void Boiler::show_values(uuid::console::Shell & shell) {
|
||||
print_value(shell, 2, F("Fan"), fanWork_, nullptr, EMS_VALUE_BOOL);
|
||||
print_value(shell, 2, F("Ignition"), ignWork_, nullptr, EMS_VALUE_BOOL);
|
||||
|
||||
print_value(shell, 2, F("Burner selected max power"), selBurnPow_, F_(percent), 1);
|
||||
print_value(shell, 2, F("Burner current power"), curBurnPow_, F_(percent), 1);
|
||||
print_value(shell, 2, F("Burner selected max power"), selBurnPow_, F_(percent));
|
||||
print_value(shell, 2, F("Burner current power"), curBurnPow_, F_(percent));
|
||||
print_value(shell, 2, F("Flame current"), flameCurr_, F("uA"), 10);
|
||||
print_value(shell, 2, F("System pressure"), sysPress_, F("bar"), 10);
|
||||
if (Helpers::hasValue(serviceCode_)) {
|
||||
@@ -405,9 +405,9 @@ void Boiler::show_values(uuid::console::Shell & shell) {
|
||||
}
|
||||
|
||||
// UBAParameters
|
||||
print_value(shell, 2, F("Heating temperature setting on the boiler"), heating_temp_, F_(degrees), 1);
|
||||
print_value(shell, 2, F("Boiler circuit pump modulation max power"), pump_mod_max_, F_(percent), 1);
|
||||
print_value(shell, 2, F("Boiler circuit pump modulation min power"), pump_mod_min_, F_(percent), 1);
|
||||
print_value(shell, 2, F("Heating temperature setting on the boiler"), heating_temp_, F_(degrees));
|
||||
print_value(shell, 2, F("Boiler circuit pump modulation max power"), pump_mod_max_, F_(percent));
|
||||
print_value(shell, 2, F("Boiler circuit pump modulation min power"), pump_mod_min_, F_(percent));
|
||||
|
||||
// UBAMonitorSlow
|
||||
if (Helpers::hasValue(extTemp_)) {
|
||||
@@ -415,9 +415,9 @@ void Boiler::show_values(uuid::console::Shell & shell) {
|
||||
}
|
||||
|
||||
print_value(shell, 2, F("Exhaust temperature"), exhaustTemp_, F_(degrees), 10);
|
||||
print_value(shell, 2, F("Pump modulation"), pumpMod_, F_(percent), 1);
|
||||
print_value(shell, 2, F("Pump modulation2"), pumpMod2_, F_(percent), 1);
|
||||
print_value(shell, 2, F("Burner # starts"), burnStarts_, nullptr, 1);
|
||||
print_value(shell, 2, F("Pump modulation"), pumpMod_, F_(percent));
|
||||
print_value(shell, 2, F("Pump modulation2"), pumpMod2_, F_(percent));
|
||||
print_value(shell, 2, F("Burner # starts"), burnStarts_, nullptr);
|
||||
if (Helpers::hasValue(burnWorkMin_)) {
|
||||
shell.printfln(F(" Total burner operating time: %d days %d hours %d minutes"), burnWorkMin_ / 1440, (burnWorkMin_ % 1440) / 60, burnWorkMin_ % 60);
|
||||
}
|
||||
|
||||
@@ -75,14 +75,14 @@ void Mixing::show_values(uuid::console::Shell & shell) {
|
||||
}
|
||||
|
||||
if (type_ == Type::WWC) {
|
||||
print_value(shell, 2, F("Warm Water Circuit"), hc_, nullptr, 1);
|
||||
print_value(shell, 2, F("Warm Water Circuit"), hc_, nullptr);
|
||||
} else {
|
||||
print_value(shell, 2, F("Heating Circuit"), hc_, nullptr, 1);
|
||||
print_value(shell, 2, F("Heating Circuit"), hc_, nullptr);
|
||||
}
|
||||
print_value(shell, 4, F("Current flow temperature"), flowTemp_, F_(degrees), 10);
|
||||
print_value(shell, 4, F("Setpoint flow temperature"), flowSetTemp_, F_(degrees), 1);
|
||||
print_value(shell, 4, F("Current pump modulation"), pumpMod_, F_(percent), 1);
|
||||
print_value(shell, 4, F("Current valve status"), status_, nullptr, 1);
|
||||
print_value(shell, 4, F("Setpoint flow temperature"), flowSetTemp_, F_(degrees));
|
||||
print_value(shell, 4, F("Current pump modulation"), pumpMod_, F_(percent));
|
||||
print_value(shell, 4, F("Current valve status"), status_, nullptr);
|
||||
}
|
||||
|
||||
// publish values via MQTT
|
||||
|
||||
@@ -65,7 +65,7 @@ void Solar::show_values(uuid::console::Shell & shell) {
|
||||
print_value(shell, 2, F("Collector temperature (TS1)"), collectorTemp_, F_(degrees), 10);
|
||||
print_value(shell, 2, F("Bottom temperature (TS2)"), bottomTemp_, F_(degrees), 10);
|
||||
print_value(shell, 2, F("Bottom temperature (TS5)"), bottomTemp2_, F_(degrees), 10);
|
||||
print_value(shell, 2, F("Pump modulation"), pumpModulation_, F_(percent), 1);
|
||||
print_value(shell, 2, F("Pump modulation"), pumpModulation_, F_(percent));
|
||||
print_value(shell, 2, F("Valve (VS2) status"), valveStatus_, nullptr, EMS_VALUE_BOOL);
|
||||
print_value(shell, 2, F("Pump (PS1) active"), pump_, nullptr, EMS_VALUE_BOOL);
|
||||
|
||||
@@ -74,7 +74,7 @@ void Solar::show_values(uuid::console::Shell & shell) {
|
||||
}
|
||||
|
||||
print_value(shell, 2, F("Energy last hour"), energyLastHour_, F_(wh), 10);
|
||||
print_value(shell, 2, F("Energy today"), energyToday_, F_(wh), 0);
|
||||
print_value(shell, 2, F("Energy today"), energyToday_, F_(wh));
|
||||
print_value(shell, 2, F("Energy total"), energyTotal_, F_(kwh), 10);
|
||||
}
|
||||
|
||||
|
||||
@@ -822,12 +822,12 @@ void Thermostat::show_values(uuid::console::Shell & shell) {
|
||||
if (datetime_.size()) {
|
||||
shell.printfln(F(" Clock: %s"), datetime_.c_str());
|
||||
if (Helpers::hasValue(ibaClockOffset_) && flags == EMS_DEVICE_FLAG_RC30_1) {
|
||||
print_value(shell, 2, F("Offset clock"), ibaClockOffset_, nullptr, 1); // offset (in sec) to clock, 0xff = -1 s, 0x02 = 2 s
|
||||
print_value(shell, 2, F("Offset clock"), ibaClockOffset_, nullptr); // offset (in sec) to clock, 0xff = -1 s, 0x02 = 2 s
|
||||
}
|
||||
}
|
||||
|
||||
if (flags == EMS_DEVICE_FLAG_RC35) {
|
||||
print_value(shell, 2, F("Damped Outdoor temperature"), dampedoutdoortemp_, F_(degrees), 1);
|
||||
print_value(shell, 2, F("Damped Outdoor temperature"), dampedoutdoortemp_, F_(degrees));
|
||||
print_value(shell, 2, F("Temp sensor 1"), tempsensor1_, F_(degrees), 10);
|
||||
print_value(shell, 2, F("Temp sensor 2"), tempsensor2_, F_(degrees), 10);
|
||||
}
|
||||
@@ -873,7 +873,7 @@ void Thermostat::show_values(uuid::console::Shell & shell) {
|
||||
}
|
||||
|
||||
if (Helpers::hasValue(ibaMinExtTemperature_)) {
|
||||
print_value(shell, 2, F("Min ext. temperature"), ibaMinExtTemperature_, F_(degrees), 0); // min ext temp for heating curve, in deg.
|
||||
print_value(shell, 2, F("Min ext. temperature"), ibaMinExtTemperature_, F_(degrees)); // min ext temp for heating curve, in deg.
|
||||
}
|
||||
|
||||
if (Helpers::hasValue(ibaBuildingType_)) {
|
||||
@@ -940,13 +940,13 @@ void Thermostat::show_values(uuid::console::Shell & shell) {
|
||||
print_value(shell, 4, F("Offset temperature"), hc->offsettemp, F_(degrees), 2);
|
||||
}
|
||||
if (Helpers::hasValue(hc->designtemp)) {
|
||||
print_value(shell, 4, F("Design temperature"), hc->designtemp, F_(degrees), 0);
|
||||
print_value(shell, 4, F("Design temperature"), hc->designtemp, F_(degrees));
|
||||
}
|
||||
if (Helpers::hasValue(hc->summertemp)) {
|
||||
print_value(shell, 4, F("Summer temperature"), hc->summertemp, F_(degrees), 0);
|
||||
print_value(shell, 4, F("Summer temperature"), hc->summertemp, F_(degrees));
|
||||
}
|
||||
if (Helpers::hasValue(hc->targetflowtemp)) {
|
||||
print_value(shell, 4, F("Target flow temperature"), hc->targetflowtemp, F_(degrees), 1);
|
||||
print_value(shell, 4, F("Target flow temperature"), hc->targetflowtemp, F_(degrees));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -124,11 +124,22 @@ class EMSdevice {
|
||||
void fetch_values();
|
||||
void toggle_fetch(uint16_t telegram_id, bool toggle);
|
||||
|
||||
// prints a ems device value to the console, handling the correct rendering of the type
|
||||
// padding is # white space
|
||||
// name is the name of the parameter
|
||||
// suffix is any string to be appended after the value
|
||||
// format:
|
||||
// for ints its 0=no division, 255=handle as boolean, other divide by the value given and render with a decimal point
|
||||
// for floats its the precision in number of decimal places from 0 to 8
|
||||
template <typename Value>
|
||||
static void
|
||||
print_value(uuid::console::Shell & shell, uint8_t padding, const __FlashStringHelper * name, Value & value, const __FlashStringHelper * suffix, const uint8_t p) {
|
||||
static void print_value(uuid::console::Shell & shell,
|
||||
uint8_t padding,
|
||||
const __FlashStringHelper * name,
|
||||
Value & value,
|
||||
const __FlashStringHelper * suffix,
|
||||
const uint8_t format = 0) {
|
||||
char buffer[15];
|
||||
if (Helpers::render_value(buffer, value, p) == nullptr) {
|
||||
if (Helpers::render_value(buffer, value, format) == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -33,6 +33,7 @@ char * Helpers::hextoa(char * result, const uint8_t value) {
|
||||
}
|
||||
|
||||
#ifdef EMSESP_STANDALONE
|
||||
// special function to work outside of ESP's libraries
|
||||
char * Helpers::ultostr(char * ptr, uint32_t value, const uint8_t base) {
|
||||
unsigned long t = 0, res = 0;
|
||||
unsigned long tmp = value;
|
||||
@@ -68,7 +69,6 @@ char * Helpers::ultostr(char * ptr, uint32_t value, const uint8_t base) {
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* itoa for 2 byte signed (short) integers
|
||||
* written by Lukás Chmela, Released under GPLv3. http://www.strudel.org.uk/itoa/ version 0.4
|
||||
@@ -122,10 +122,8 @@ char * Helpers::smallitoa(char * result, const uint16_t value) {
|
||||
}
|
||||
|
||||
// convert unsigned int (single byte) to text value and returns it
|
||||
// format: 2=divide by 2, 10=divide by 10, 255=handle as a Boolean
|
||||
// format: 255=boolean, 0=no formatting, otherwise divide by format
|
||||
char * Helpers::render_value(char * result, uint8_t value, uint8_t format) {
|
||||
result[0] = '\0';
|
||||
|
||||
// special check if its a boolean
|
||||
if (format == EMS_VALUE_BOOL) {
|
||||
if (value == EMS_VALUE_BOOL_OFF) {
|
||||
@@ -142,31 +140,30 @@ char * Helpers::render_value(char * result, uint8_t value, uint8_t format) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
char s2[5] = {0};
|
||||
if (!format) {
|
||||
itoa(result, value, 10); // format = 0
|
||||
return result;
|
||||
}
|
||||
|
||||
switch (format) {
|
||||
case 2:
|
||||
char s2[5];
|
||||
|
||||
// special case for / 2
|
||||
if (format == 2) {
|
||||
strlcpy(result, itoa(s2, value >> 1, 10), 5);
|
||||
strlcat(result, ".", 5);
|
||||
strlcat(result, ((value & 0x01) ? "5" : "0"), 5);
|
||||
break;
|
||||
|
||||
case 10:
|
||||
strlcpy(result, itoa(s2, value / 10, 10), 5);
|
||||
strlcat(result, ".", 5);
|
||||
strlcat(result, itoa(s2, value % 10, 10), 5);
|
||||
break;
|
||||
|
||||
default:
|
||||
itoa(result, value, 10);
|
||||
break;
|
||||
return result;
|
||||
}
|
||||
|
||||
strlcpy(result, itoa(s2, value / format, 10), 5);
|
||||
strlcat(result, ".", 5);
|
||||
strlcat(result, itoa(s2, value % format, 10), 5);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
// convert float to char
|
||||
// format is the precision
|
||||
// float: convert float to char
|
||||
// format is the precision, 0 to 8
|
||||
char * Helpers::render_value(char * result, const float value, const uint8_t format) {
|
||||
long p[] = {0, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000};
|
||||
|
||||
@@ -183,23 +180,21 @@ char * Helpers::render_value(char * result, const float value, const uint8_t for
|
||||
return ret;
|
||||
}
|
||||
|
||||
// convert short (two bytes) to text string and returns string
|
||||
// decimals: 0 = no division, 10=divide value by 10, 2=divide by 2, 100=divide value by 100
|
||||
// negative values are assumed stored as 1-compliment (https://medium.com/@LeeJulija/how-integers-are-stored-in-memory-using-twos-complement-5ba04d61a56c)
|
||||
// int16: convert short (two bytes) to text string and returns string
|
||||
// format: 0=no division, other divide by the value given and render with a decimal point
|
||||
char * Helpers::render_value(char * result, const int16_t value, const uint8_t format) {
|
||||
result[0] = '\0';
|
||||
|
||||
if (!hasValue(value)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
// just print it if mo conversion required
|
||||
if ((format == 0) || (format == 1)) {
|
||||
// just print it if mo conversion required (format = 0)
|
||||
if (!format) {
|
||||
itoa(result, value, 10);
|
||||
return result;
|
||||
}
|
||||
|
||||
int16_t new_value = value;
|
||||
result[0] = '\0';
|
||||
|
||||
// check for negative values
|
||||
if (new_value < 0) {
|
||||
@@ -216,7 +211,6 @@ char * Helpers::render_value(char * result, const int16_t value, const uint8_t f
|
||||
strlcat(result, itoa(s2, new_value / 2, 10), 10);
|
||||
strlcat(result, ".", 10);
|
||||
strlcat(result, ((new_value & 0x01) ? "5" : "0"), 10);
|
||||
|
||||
} else {
|
||||
strlcat(result, itoa(s2, new_value / format, 10), 10);
|
||||
strlcat(result, ".", 10);
|
||||
@@ -226,44 +220,34 @@ char * Helpers::render_value(char * result, const int16_t value, const uint8_t f
|
||||
return result;
|
||||
}
|
||||
|
||||
// convert unsigned short (two bytes) to text string and prints it
|
||||
// format: 0 = no division, 10=divide value by 10, 2=divide by 2, 100=divide value by 100
|
||||
// uint16: convert unsigned short (two bytes) to text string and prints it
|
||||
char * Helpers::render_value(char * result, const uint16_t value, const uint8_t format) {
|
||||
result[0] = '\0';
|
||||
|
||||
if (!hasValue(value)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return (render_value(result, (int16_t)value, format)); // use same code, force it to a signed int
|
||||
}
|
||||
|
||||
// convert signed byte to text string and prints it
|
||||
// format: 0 = no division, 10=divide value by 10, 2=divide by 2, 100=divide value by 100
|
||||
// int8: convert signed byte to text string and prints it
|
||||
char * Helpers::render_value(char * result, const int8_t value, const uint8_t format) {
|
||||
result[0] = '\0';
|
||||
|
||||
if (!hasValue(value)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
return (render_value(result, (int16_t)value, format)); // use same code, force it to a signed int
|
||||
}
|
||||
|
||||
// render long (4 byte) unsigned values
|
||||
// format = 0 for normal, any other value for divide by format
|
||||
// uint32: render long (4 byte) unsigned values
|
||||
char * Helpers::render_value(char * result, const uint32_t value, const uint8_t format) {
|
||||
result[0] = '\0';
|
||||
|
||||
if (!hasValue(value)) {
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
char s[20] = {0};
|
||||
char s[20];
|
||||
result[0] = '\0';
|
||||
|
||||
#ifndef EMSESP_STANDALONE
|
||||
if (format <= 1) {
|
||||
strlcat(result, ltoa(value, s, 10), 20);
|
||||
if (!format) {
|
||||
strlcat(result, ltoa(value, s, 10), 20); // format is 0
|
||||
} else {
|
||||
strlcat(result, ltoa(value / format, s, 10), 20);
|
||||
strlcat(result, ".", 20);
|
||||
@@ -271,8 +255,8 @@ char * Helpers::render_value(char * result, const uint32_t value, const uint8_t
|
||||
}
|
||||
|
||||
#else
|
||||
if (format <= 1) {
|
||||
strlcat(result, ultostr(s, value, 10), 20);
|
||||
if (!format) {
|
||||
strlcat(result, ultostr(s, value, 10), 20); // format is 0
|
||||
} else {
|
||||
strncat(result, ultostr(s, value / format, 10), 20);
|
||||
strlcat(result, ".", 20);
|
||||
|
||||
@@ -43,12 +43,12 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & command) {
|
||||
uint16_t test3u = EMS_VALUE_USHORT_NOTSET;
|
||||
int16_t test4u = EMS_VALUE_SHORT_NOTSET;
|
||||
|
||||
EMSdevice::print_value(shell, 2, F("Selected flow temperature1"), test1, F_(degrees), 1); // 12
|
||||
EMSdevice::print_value(shell, 2, F("Selected flow temperature2"), test2, F_(degrees), 1); // -12
|
||||
EMSdevice::print_value(shell, 2, F("Selected flow temperature1"), test1, F_(degrees)); // 12
|
||||
EMSdevice::print_value(shell, 2, F("Selected flow temperature2"), test2, F_(degrees)); // -12
|
||||
EMSdevice::print_value(shell, 2, F("Selected flow temperature3"), test3, F_(degrees), 10); // 45.6
|
||||
EMSdevice::print_value(shell, 2, F("Selected flow temperature4"), test4, F_(degrees), 10); // -45.6
|
||||
EMSdevice::print_value(shell, 2, F("Selected flow temperature5"), test5, nullptr, EMS_VALUE_BOOL); // on
|
||||
EMSdevice::print_value(shell, 2, F("Selected flow temperature6"), test6, F_(degrees), 1); //
|
||||
EMSdevice::print_value(shell, 2, F("Selected flow temperature6"), test6, F_(degrees)); //
|
||||
EMSdevice::print_value(shell, 2, F("Selected flow temperature7"), test7, F_(degrees), 2); // 89.43
|
||||
EMSdevice::print_value(shell, 2, F("Warm Water comfort setting"), F("Intelligent"));
|
||||
char s[100];
|
||||
@@ -57,8 +57,8 @@ void Test::run_test(uuid::console::Shell & shell, const std::string & command) {
|
||||
|
||||
shell.println();
|
||||
|
||||
EMSdevice::print_value(shell, 2, F("Selected flow temperature1u"), test1u, F_(degrees), 1);
|
||||
EMSdevice::print_value(shell, 2, F("Selected flow temperature2u"), test2u, F_(degrees), 1);
|
||||
EMSdevice::print_value(shell, 2, F("Selected flow temperature1u"), test1u, F_(degrees));
|
||||
EMSdevice::print_value(shell, 2, F("Selected flow temperature2u"), test2u, F_(degrees));
|
||||
EMSdevice::print_value(shell, 2, F("Selected flow temperature3u"), test3u, F_(degrees), 10);
|
||||
EMSdevice::print_value(shell, 2, F("Selected flow temperature4u"), test4u, F_(degrees), 10);
|
||||
EMSdevice::print_value(shell, 2, F("Selected flow temperature5u"), test5u, F_(degrees), EMS_VALUE_BOOL);
|
||||
|
||||
Reference in New Issue
Block a user