@@ -1667,91 +1667,73 @@ void DisplayLogBufferInit(void)
16671667\*********************************************************************************************/
16681668
16691669enum SensorQuantity {
1670- JSON_TEMPERATURE,
1671- JSON_HUMIDITY, JSON_LIGHT, JSON_NOISE, JSON_AIRQUALITY,
1670+ JSON_TEMPERATURE, JSON_DEWPOINT, JSON_HEATINDEX,
16721671 JSON_PRESSURE, JSON_PRESSUREATSEALEVEL,
1672+ JSON_POWERFACTOR, JSON_COUNTER, JSON_ANALOG_INPUT, JSON_UV_LEVEL,
1673+ JSON_HUMIDITY, JSON_LIGHT, JSON_NOISE, JSON_AIRQUALITY,
16731674 JSON_ILLUMINANCE,
16741675 JSON_GAS,
16751676 JSON_YESTERDAY, JSON_TOTAL, JSON_TODAY,
16761677 JSON_PERIOD,
1677- JSON_POWERFACTOR, JSON_COUNTER, JSON_ANALOG_INPUT, JSON_UV_LEVEL,
16781678 JSON_CURRENT,
16791679 JSON_VOLTAGE,
16801680 JSON_POWERUSAGE,
16811681 JSON_CO2,
16821682 JSON_FREQUENCY };
16831683const char kSensorQuantity [] PROGMEM =
1684- D_JSON_TEMPERATURE " |" // degrees
1685- D_JSON_HUMIDITY " |" D_JSON_LIGHT " |" D_JSON_NOISE " |" D_JSON_AIRQUALITY " |" // percentage
1684+ D_JSON_TEMPERATURE " |" D_JSON_DEWPOINT " |" D_JSON_HEATINDEX " |" // degrees
16861685 D_JSON_PRESSURE " |" D_JSON_PRESSUREATSEALEVEL " |" // hPa
1686+ D_JSON_POWERFACTOR " |" D_JSON_COUNTER " |" D_JSON_ANALOG_INPUT " |" D_JSON_UV_LEVEL " |" // No unit
1687+ D_JSON_HUMIDITY " |" D_JSON_LIGHT " |" D_JSON_NOISE " |" D_JSON_AIRQUALITY " |" // percentage
16871688 D_JSON_ILLUMINANCE " |" // lx
16881689 D_JSON_GAS " |" // kOhm
16891690 D_JSON_YESTERDAY " |" D_JSON_TOTAL " |" D_JSON_TODAY " |" // kWh
16901691 D_JSON_PERIOD " |" // Wh
1691- D_JSON_POWERFACTOR " |" D_JSON_COUNTER " |" D_JSON_ANALOG_INPUT " |" D_JSON_UV_LEVEL " |" // No unit
16921692 D_JSON_CURRENT " |" // Ampere
16931693 D_JSON_VOLTAGE " |" // Volt
16941694 D_JSON_POWERUSAGE " |" // Watt
16951695 D_JSON_CO2 " |" // ppm
1696- D_JSON_FREQUENCY ; // Hz
1697-
1698- void DisplayJsonValue (const char * topic, const char * device, const char * mkey, const char * value)
1699- {
1700- char quantity[TOPSZ];
1701- char buffer[Settings->display_cols [0 ] +1 ];
1702- char spaces[Settings->display_cols [0 ]];
1703- char source[Settings->display_cols [0 ] - Settings->display_cols [1 ]];
1704- char svalue[Settings->display_cols [1 ] +1 ];
1705-
1696+ D_JSON_FREQUENCY; // Hz
1697+ const char kSensorUnit [] PROGMEM =
1698+ " |||" // degrees Celsius or Fahrenheit
1699+ " ||" // pressure hPa or mmHg
1700+ " ||||" // No unit
1701+ " %|%|%|%|" // percentage
1702+ D_UNIT_LUX " |" // lx
1703+ D_UNIT_KILOOHM " |" // kOhm
1704+ D_UNIT_KILOWATTHOUR " |" D_UNIT_KILOWATTHOUR " |" D_UNIT_KILOWATTHOUR " |" // kWh
1705+ D_UNIT_WATTHOUR " |" // Wh
1706+ D_UNIT_AMPERE " |" // A
1707+ D_UNIT_VOLT " |" // V
1708+ D_UNIT_WATT " |" // W
1709+ D_UNIT_PARTS_PER_MILLION " |" // ppm
1710+ D_UNIT_HERTZ; // Hz
1711+
1712+ void DisplayJsonValue (const char * topic, const char * device, const char * mkey, const char * value) {
17061713 SHOW_FREE_MEM (PSTR (" DisplayJsonValue" ));
17071714
1708- memset (spaces, 0x20 , sizeof (spaces));
1709- spaces[sizeof (spaces) -1 ] = ' \0 ' ;
1710- snprintf_P (source, sizeof (source), PSTR (" %s%s%s%s" ), topic, (strlen (topic))?" /" :" " , mkey, spaces); // pow1/Voltage or Voltage if topic is empty (local sensor)
1711-
1712- int quantity_code = GetCommandCode (quantity, sizeof (quantity), mkey, kSensorQuantity );
1713- if ((-1 == quantity_code) || !strcmp_P (mkey, S_RSLT_POWER)) { // Ok: Power, Not ok: POWER
1714- return ;
1715- }
1716- if (JSON_TEMPERATURE == quantity_code) {
1717- snprintf_P (svalue, sizeof (svalue), PSTR (" %s~%s" ), value, disp_temp);
1715+ char temp[TOPSZ];
1716+ int quantity_code = GetCommandCode (temp, sizeof (temp), mkey, kSensorQuantity );
1717+ if ((-1 == quantity_code) || !strcmp_P (mkey, S_RSLT_POWER)) { // Ok: Power, Not ok: POWER
1718+ return ; // Display value not supported
17181719 }
1719- else if ((quantity_code >= JSON_HUMIDITY) && (quantity_code <= JSON_AIRQUALITY)) {
1720- snprintf_P (svalue, sizeof (svalue), PSTR (" %s%%" ), value);
1721- }
1722- else if ((quantity_code >= JSON_PRESSURE) && (quantity_code <= JSON_PRESSUREATSEALEVEL)) {
1723- snprintf_P (svalue, sizeof (svalue), PSTR (" %s%s" ), value, disp_pres);
1724- }
1725- else if (JSON_ILLUMINANCE == quantity_code) {
1726- snprintf_P (svalue, sizeof (svalue), PSTR (" %s" D_UNIT_LUX), value);
1727- }
1728- else if (JSON_GAS == quantity_code) {
1729- snprintf_P (svalue, sizeof (svalue), PSTR (" %s" D_UNIT_KILOOHM), value);
1730- }
1731- else if ((quantity_code >= JSON_YESTERDAY) && (quantity_code <= JSON_TODAY)) {
1732- snprintf_P (svalue, sizeof (svalue), PSTR (" %s" D_UNIT_KILOWATTHOUR), value);
1733- }
1734- else if (JSON_PERIOD == quantity_code) {
1735- snprintf_P (svalue, sizeof (svalue), PSTR (" %s" D_UNIT_WATTHOUR), value);
1736- }
1737- else if ((quantity_code >= JSON_POWERFACTOR) && (quantity_code <= JSON_UV_LEVEL)) {
1738- snprintf_P (svalue, sizeof (svalue), PSTR (" %s" ), value);
1739- }
1740- else if (JSON_CURRENT == quantity_code) {
1741- snprintf_P (svalue, sizeof (svalue), PSTR (" %s" D_UNIT_AMPERE), value);
1742- }
1743- else if (JSON_VOLTAGE == quantity_code) {
1744- snprintf_P (svalue, sizeof (svalue), PSTR (" %s" D_UNIT_VOLT), value);
1745- }
1746- else if (JSON_POWERUSAGE == quantity_code) {
1747- snprintf_P (svalue, sizeof (svalue), PSTR (" %s" D_UNIT_WATT), value);
1720+
1721+ char svalue[Settings->display_cols [1 ] +1 ]; // Max sized unit string
1722+ if (quantity_code <= JSON_HEATINDEX) { // Temperature
1723+ snprintf_P (svalue, sizeof (svalue), PSTR (" %s~%s" ), value, disp_temp); // Used by DisplayLogBuffer replace degrees character (276 octal)
17481724 }
1749- else if (JSON_CO2 == quantity_code ) {
1750- snprintf_P (svalue, sizeof (svalue), PSTR (" %s" D_UNIT_PARTS_PER_MILLION ), value);
1725+ else if (quantity_code <= JSON_PRESSUREATSEALEVEL ) { // Pressure
1726+ snprintf_P (svalue, sizeof (svalue), PSTR (" %s%s " ), value, disp_pres); // hPa or mmHg
17511727 }
1752- else if (JSON_FREQUENCY == quantity_code) {
1753- snprintf_P (svalue, sizeof (svalue), PSTR (" %s" D_UNIT_HERTZ ), value);
1728+ else {
1729+ snprintf_P (svalue, sizeof (svalue), PSTR (" %s%s " ), value, GetTextIndexed (temp, sizeof (temp), quantity_code, kSensorUnit ) );
17541730 }
1731+
1732+ char buffer[Settings->display_cols [0 ] +1 ]; // Max sized buffer string
1733+ memset (buffer, 0x20 , sizeof (buffer)); // Temporarily use for spaces
1734+ buffer[sizeof (buffer) -1 ] = ' \0 ' ;
1735+ char source[Settings->display_cols [0 ] - Settings->display_cols [1 ]]; // Max sized source string
1736+ snprintf_P (source, sizeof (source), PSTR (" %s%s%s%s" ), topic, (strlen (topic))?" /" :" " , mkey, buffer); // pow1/Voltage or Voltage if topic is empty (local sensor)
17551737 snprintf_P (buffer, sizeof (buffer), PSTR (" %s %s" ), source, svalue);
17561738
17571739// AddLog(LOG_LEVEL_DEBUG, PSTR(D_LOG_DEBUG "mkey [%s], source [%s], value [%s], quantity_code %d, log_buffer [%s]"), mkey, source, value, quantity_code, buffer);
@@ -1879,7 +1861,6 @@ void DisplayLocalSensor(void)
18791861
18801862#endif // USE_DISPLAY_MODES1TO5
18811863
1882-
18831864/* ********************************************************************************************\
18841865 * Public
18851866\*********************************************************************************************/
0 commit comments