diff --git a/CHANGELOG.md b/CHANGELOG.md index a18085c11..44082a12d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,7 +8,7 @@ All notable changes to this project will be documented in this file. - Support for BP1658CJ RGBCW led bulbs like Orein OS0100411267 by Cossid (#17011) ### Breaking Changed -- Redesign distance sensors HRXL and DYP to use cm instead of mm (#17021) +- Redesign distance sensors VL53LXX, TOF10120, HRXL and DYP to use cm instead of mm (#17021) ### Changed - Default Flash Mode changed from ``DOUT`` to ``DIO`` for ESP8266/ESP8285 diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 6f94c9821..9f3513302 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -123,7 +123,7 @@ The latter links can be used for OTA upgrades too like ``OtaUrl http://ota.tasmo - ESP32 Support for DMX ArtNet Led matrix animations [#16984](https://github.com/arendst/Tasmota/issues/16984) ### Breaking Changed -- Redesign distance sensors HRXL and DYP to use cm instead of mm [#17021](https://github.com/arendst/Tasmota/issues/17021) +- Redesign distance sensors VL53LXX, TOF10120, HRXL and DYP to use cm instead of mm [#17021](https://github.com/arendst/Tasmota/issues/17021) ### Changed - ESP32 Framework (Core) from v2.0.5 to v2.0.5.2 diff --git a/tasmota/include/i18n.h b/tasmota/include/i18n.h index 5fe199aaa..ff4546996 100644 --- a/tasmota/include/i18n.h +++ b/tasmota/include/i18n.h @@ -886,6 +886,7 @@ const float kSpeedConversionFactor[] = {1, // none const char HTTP_SNS_F_TEMP[] PROGMEM = "{s}%s " D_TEMPERATURE "{m}%*_f " D_UNIT_DEGREE "%c{e}"; const char HTTP_SNS_F_VOLTAGE[] PROGMEM = "{s}%s " D_VOLTAGE "{m}%*_f " D_UNIT_VOLT "{e}"; const char HTTP_SNS_F_CURRENT_MA[] PROGMEM = "{s}%s " D_CURRENT "{m}%*_f " D_UNIT_MILLIAMPERE "{e}"; +const char HTTP_SNS_F_DISTANCE_CM[] PROGMEM = "{s}%s " D_DISTANCE "{m}%1_f " D_UNIT_CENTIMETER "{e}"; const char HTTP_SNS_HUM[] PROGMEM = "{s}%s " D_HUMIDITY "{m}%s " D_UNIT_PERCENT "{e}"; const char HTTP_SNS_DEW[] PROGMEM = "{s}%s " D_DEWPOINT "{m}%s " D_UNIT_DEGREE "%c{e}"; const char HTTP_SNS_PRESSURE[] PROGMEM = "{s}%s " D_PRESSURE "{m}%s " "%s{e}"; @@ -899,9 +900,6 @@ const char HTTP_SNS_GPM[] PROGMEM = "{s}%s " D_FLOW_RATE "{ const char HTTP_SNS_MOISTURE[] PROGMEM = "{s}%s " D_MOISTURE "{m}%d " D_UNIT_PERCENT "{e}"; const char HTTP_SNS_RANGE_CHR[] PROGMEM = "{s}%s " D_RANGE "{m}%s" "{e}"; const char HTTP_SNS_RANGE[] PROGMEM = "{s}%s " D_RANGE "{m}%d" "{e}"; -const char HTTP_SNS_DISTANCE[] PROGMEM = "{s}%s " D_DISTANCE "{m}%d " D_UNIT_MILLIMETER "{e}"; -const char HTTP_SNS_DISTANCE_CM[] PROGMEM = "{s}%s " D_DISTANCE "{m}%s " D_UNIT_CENTIMETER "{e}"; -const char HTTP_SNS_F_DISTANCE_CM[] PROGMEM = "{s}%s " D_DISTANCE "{m}%1_f " D_UNIT_CENTIMETER "{e}"; const char HTTP_SNS_HALL_EFFECT[] PROGMEM = "{s}%s " D_HALL_EFFECT "{m}%d" "{e}"; const char HTTP_SNS_VOLTAGE[] PROGMEM = "{s}" D_VOLTAGE "{m}%s " D_UNIT_VOLT "{e}"; const char HTTP_SNS_CURRENT[] PROGMEM = "{s}" D_CURRENT "{m}%s " D_UNIT_AMPERE "{e}"; diff --git a/tasmota/tasmota_xsns_sensor/xsns_45_vl53l0x.ino b/tasmota/tasmota_xsns_sensor/xsns_45_vl53l0x.ino index 63b10b55c..84eda3ef6 100644 --- a/tasmota/tasmota_xsns_sensor/xsns_45_vl53l0x.ino +++ b/tasmota/tasmota_xsns_sensor/xsns_45_vl53l0x.ino @@ -190,53 +190,38 @@ void Vl53l0Every_250MSecond(void) { void Vl53l0Every_Second(void) { if (abs(Vl53l0x_data[0].distance - Vl53l0x_data[0].distance_prev) > 8) { Vl53l0x_data[0].distance_prev = Vl53l0x_data[0].distance; - DomoticzSensor(DZ_ILLUMINANCE, Vl53l0x_data[0].distance); + float distance = (float)Vl53l0x_data[0].distance / 10; // cm + DomoticzFloatSensor(DZ_ILLUMINANCE, distance); } } #endif // USE_DOMOTICZ void Vl53l0Show(boolean json) { for (uint32_t i = 0; i < VL53LXX_MAX_SENSORS; i++) { - if (PinUsed(GPIO_VL53LXX_XSHUT1, i) || (!VL53L0X_xshut)) { - if (json) { - if (Vl53l0x_data[i].distance == 9999) { - if (VL53L0X_xshut) { - ResponseAppend_P(PSTR(",\"VL53L0X_%d\":{\"" D_JSON_DISTANCE "\":null}"), i+1); - } else { - ResponseAppend_P(PSTR(",\"VL53L0X\":{\"" D_JSON_DISTANCE "\":null}")); // For backwards compatibility when not using XSHUT GPIOs - } - } else { - if (VL53L0X_xshut) { - ResponseAppend_P(PSTR(",\"VL53L0X_%d\":{\"" D_JSON_DISTANCE "\":%d}"), i+1, Vl53l0x_data[i].distance); - } else { - ResponseAppend_P(PSTR(",\"VL53L0X\":{\"" D_JSON_DISTANCE "\":%d}"), Vl53l0x_data[i].distance); // For backwards compatibility when not using XSHUT GPIOs - } - } -#ifdef USE_WEBSERVER - } else { - if (Vl53l0x_data[i].distance == 9999) { - if (VL53L0X_xshut) { - WSContentSend_PD("{s}%s_%d " D_DISTANCE "{m}%s {e}", PSTR("VL53L0X"), i+1, PSTR(D_OUT_OF_RANGE)); - } else { - WSContentSend_PD("{s}%s " D_DISTANCE "{m}%s {e}", PSTR("VL53L0X"), PSTR(D_OUT_OF_RANGE)); // For backwards compatibility when not using XSHUT GPIOs - } - } else { - if (VL53L0X_xshut) { - WSContentSend_PD("{s}%s_%d " D_DISTANCE "{m}%d " D_UNIT_MILLIMETER "{e}", PSTR("VL53L0X"), i+1, Vl53l0x_data[i].distance); - } else { - WSContentSend_PD(HTTP_SNS_DISTANCE, PSTR("VL53L0X"), Vl53l0x_data[i].distance); // For backwards compatibility when not using XSHUT GPIOs - } - } -#endif - } + char types[12] = "VL53L0X"; + if (VL53L0X_xshut) { + snprintf_P(types, sizeof(types), PSTR("VL53L0X%c%d"), IndexSeparator(), i +1); + } + if (PinUsed(GPIO_VL53LXX_XSHUT1, i) || (!VL53L0X_xshut)) { + float distance = (Vl53l0x_data[i].distance == 9999) ? NAN : (float)Vl53l0x_data[i].distance / 10; // cm + if (json) { + ResponseAppend_P(PSTR(",\"%s\":{\"" D_JSON_DISTANCE "\":%1_f}"), types, &distance); +#ifdef USE_WEBSERVER + } else { + WSContentSend_PD(HTTP_SNS_F_DISTANCE_CM, types, &distance); +#endif + } + } + if (VL53L0X_device[i].timeoutOccurred()) { + AddLog(LOG_LEVEL_DEBUG, PSTR(D_LOG_I2C "Timeout waiting for %s"), types); } - if (VL53L0X_device[i].timeoutOccurred()) { AddLog(LOG_LEVEL_DEBUG, PSTR(D_LOG_I2C D_TIMEOUT_WAITING_FOR D_SENSOR " VL53L0X %d"), i+1); } if (!VL53L0X_xshut) { break; } } #ifdef USE_DOMOTICZ - if ((json) && (0 == TasmotaGlobal.tele_period)){ - DomoticzSensor(DZ_ILLUMINANCE, Vl53l0x_data[0].distance); - } + if (json && (0 == TasmotaGlobal.tele_period)){ + float distance = (float)Vl53l0x_data[0].distance / 10; // cm + DomoticzFloatSensor(DZ_ILLUMINANCE, distance); + } #endif // USE_DOMOTICZ } diff --git a/tasmota/tasmota_xsns_sensor/xsns_77_vl53l1x.ino b/tasmota/tasmota_xsns_sensor/xsns_77_vl53l1x.ino index 810eaa229..d2f188a0f 100644 --- a/tasmota/tasmota_xsns_sensor/xsns_77_vl53l1x.ino +++ b/tasmota/tasmota_xsns_sensor/xsns_77_vl53l1x.ino @@ -123,39 +123,30 @@ void Vl53l1Every_250MSecond(void) { #ifdef USE_DOMOTICZ void Vl53l1Every_Second(void) { - char distance[FLOATSZ]; - dtostrfd((float)vl53l1x_data[0].distance / 10, 1, distance); - DomoticzSensor(DZ_ILLUMINANCE, distance); + float distance = (float)vl53l1x_data[0].distance / 10; // cm + DomoticzFloatSensor(DZ_ILLUMINANCE, distance); } #endif // USE_DOMOTICZ void Vl53l1Show(bool json) { uint32_t i, xshut; for (i = 0, xshut = 1 ; i < VL53LXX_MAX_SENSORS ; i++, xshut <<= 1) { + char types[12] = "VL53L1X"; + if (VL53L0X_xshut) { + snprintf_P(types, sizeof(types), PSTR("VL53L1X%c%d"), IndexSeparator(), i +1); + } + float distance = (float)vl53l1x_data[i].distance / 10; // cm if (xshut & VL53L1X_detected) { if (json) { - if (0 == VL53L1X_xshut) { - ResponseAppend_P(PSTR(",\"VL53L1X\":{\"" D_JSON_DISTANCE "\":%d}"), vl53l1x_data[i].distance); - } - else { - ResponseAppend_P(PSTR(",\"VL53L1X%c%d\":{\"" D_JSON_DISTANCE "\":%d}"), IndexSeparator(), i+1, vl53l1x_data[i].distance); - } + ResponseAppend_P(PSTR(",\"%s\":{\"" D_JSON_DISTANCE "\":%1_f}"), types, &distance); #ifdef USE_DOMOTICZ if (0 == TasmotaGlobal.tele_period) { Vl53l1Every_Second(); } #endif // USE_DOMOTICZ #ifdef USE_WEBSERVER - } - else { - if (0 == VL53L1X_xshut) { - WSContentSend_PD(HTTP_SNS_DISTANCE, PSTR("VL53L1X"), vl53l1x_data[i].distance); - } - else { - char tmpstr[12]; - sprintf(tmpstr, PSTR("VL53L1X%c%d"), IndexSeparator(), i+1); - WSContentSend_PD(HTTP_SNS_DISTANCE, tmpstr, vl53l1x_data[i].distance); - } + } else { + WSContentSend_PD(HTTP_SNS_F_DISTANCE_CM, types, &distance); #endif } } // if detected diff --git a/tasmota/tasmota_xsns_sensor/xsns_84_tof10120.ino b/tasmota/tasmota_xsns_sensor/xsns_84_tof10120.ino index 233a8cde8..36bd30842 100644 --- a/tasmota/tasmota_xsns_sensor/xsns_84_tof10120.ino +++ b/tasmota/tasmota_xsns_sensor/xsns_84_tof10120.ino @@ -84,15 +84,15 @@ void Tof10120Every_250MSecond(void) { #ifdef USE_DOMOTICZ void Tof10120Every_Second(void) { - char distance[FLOATSZ]; - dtostrfd((float)tof10120_sensor.distance / 10, 1, distance); - DomoticzSensor(DZ_ILLUMINANCE, distance); + float distance = (float)tof10120_sensor.distance / 10; // cm + DomoticzFloatSensor(DZ_ILLUMINANCE, distance); } #endif // USE_DOMOTICZ void Tof10120Show(bool json) { + float distance = (float)tof10120_sensor.distance / 10; // cm if (json) { - ResponseAppend_P(PSTR(",\"TOF10120\":{\"" D_JSON_DISTANCE "\":%d}"), tof10120_sensor.distance); + ResponseAppend_P(PSTR(",\"TOF10120\":{\"" D_JSON_DISTANCE "\":%1_f}"), &distance); #ifdef USE_DOMOTICZ if (0 == TasmotaGlobal.tele_period) { Tof10120Every_Second(); @@ -100,7 +100,7 @@ void Tof10120Show(bool json) { #endif // USE_DOMOTICZ #ifdef USE_WEBSERVER } else { - WSContentSend_PD(HTTP_SNS_DISTANCE, PSTR("TOF10120"), tof10120_sensor.distance); + WSContentSend_PD(HTTP_SNS_F_DISTANCE_CM, PSTR("TOF10120"), &distance); #endif } }