From 1bf6a13d7c7b076b10dc13577ca52bb4bfee29ff Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Sun, 8 Sep 2024 17:32:35 +0200 Subject: [PATCH] Bump version v14.2.0.4 - Add HX711 optional calibration precision option on command ``Sensor34 2 `` where `` is 1 to 10 (#13983) --- CHANGELOG.md | 15 ++++++++- RELEASENOTES.md | 4 ++- tasmota/include/tasmota_types.h | 3 +- tasmota/include/tasmota_version.h | 2 +- tasmota/tasmota_support/settings.ino | 5 ++- tasmota/tasmota_xsns_sensor/xsns_34_hx711.ino | 32 +++++++++++++------ 6 files changed, 46 insertions(+), 15 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a8bbe48c..e8d4a65a6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -3,7 +3,20 @@ All notable changes to this project will be documented in this file. ## [Unreleased] - Development -## [14.2.0.3] +## [14.2.0.4] +### Added +- HX711 optional calibration precision option on command ``Sensor34 2 `` where `` is 1 to 10 (#13983) + +### Breaking Changed + +### Changed + +### Fixed +- Shutter missing HOLD on shutterbutton (#22108) + +### Removed + +## [14.2.0.3] 20240908 ### Added - Command ``SetOption69 1`` to enable Serial Bridge inverted Receive (#22000) - Support nexus protocol and calculation of separation limit to rc-switch library (#21886) diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 2b0138936..ffe951a9a 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -119,9 +119,10 @@ The latter links can be used for OTA upgrades too like ``OtaUrl https://ota.tasm [Complete list](BUILDS.md) of available feature and sensors. -## Changelog v14.2.0.3 +## Changelog v14.2.0.4 ### Added - Command ``SetOption69 1`` to enable Serial Bridge inverted Receive [#22000](https://github.com/arendst/Tasmota/issues/22000) +- HX711 optional calibration precision option on command ``Sensor34 2 `` where `` is 1 to 10 [#13983](https://github.com/arendst/Tasmota/issues/13983) - Energy command ``PowerSet 60,230`` to calibrate both Current and Power with known resistive load of 60W at 230V using calibrated Voltage - Energy command ``CurrentSet 60,230`` to calibrate both Power and Current with known resistive load of 60W at 230V using calibrated Voltage - Energy Log level 4 message when (Calculated) Apparent Power is less than Active Power indicating wrong calibration [#20653](https://github.com/arendst/Tasmota/issues/20653) @@ -145,6 +146,7 @@ The latter links can be used for OTA upgrades too like ``OtaUrl https://ota.tasm - Crash when calling TasmotaSerial destructor when initialized with incorrect arguments [#22036](https://github.com/arendst/Tasmota/issues/22036) - Energy calculation [#20653](https://github.com/arendst/Tasmota/issues/20653) - Shutter timing registers overflow [#21966](https://github.com/arendst/Tasmota/issues/21966) +- Shutter missing HOLD on shutterbutton [#22108](https://github.com/arendst/Tasmota/issues/22108) - PZEM continue energy monitoring when one phase fails [#21968](https://github.com/arendst/Tasmota/issues/21968) - BearSSL panic on ESP8266 in rare conditions [#22017](https://github.com/arendst/Tasmota/issues/22017) - LVGL Added OpenHASP icons to font `montserrat-28` [#22048](https://github.com/arendst/Tasmota/issues/22048) diff --git a/tasmota/include/tasmota_types.h b/tasmota/include/tasmota_types.h index 8e22f4fc6..4a05f8570 100755 --- a/tasmota/include/tasmota_types.h +++ b/tasmota/include/tasmota_types.h @@ -698,8 +698,9 @@ typedef struct { uint16_t mqtt_socket_timeout; // 52E uint8_t mqtt_wifi_timeout; // 530 uint8_t ina219_mode; // 531 + uint8_t weight_precision; // 532 ex_pulse_timer free since 11.0.0.3 - uint16_t ex_pulse_timer[7]; // 532 ex_pulse_timer free since 11.0.0.3 + uint8_t free_533[13]; // 533 uint16_t tcp_baudrate; // 540 uint16_t button_debounce; // 542 diff --git a/tasmota/include/tasmota_version.h b/tasmota/include/tasmota_version.h index 01493cea3..0db0efe01 100644 --- a/tasmota/include/tasmota_version.h +++ b/tasmota/include/tasmota_version.h @@ -22,6 +22,6 @@ #define TASMOTA_SHA_SHORT // Filled by Github sed -const uint32_t TASMOTA_VERSION = 0x0E020003; // 14.2.0.3 +const uint32_t TASMOTA_VERSION = 0x0E020004; // 14.2.0.4 #endif // _TASMOTA_VERSION_H_ diff --git a/tasmota/tasmota_support/settings.ino b/tasmota/tasmota_support/settings.ino index c1aa52a59..5404dba9d 100644 --- a/tasmota/tasmota_support/settings.ino +++ b/tasmota/tasmota_support/settings.ino @@ -1738,7 +1738,7 @@ void SettingsDelta(void) { Settings->web_time_end = 0; } if (Settings->version < 0x0B000003) { // 11.0.0.3 - memcpy(Settings->pulse_timer, Settings->ex_pulse_timer, 16); + memcpy(Settings->pulse_timer, (uint16_t*)&Settings->weight_precision, 16); } if (Settings->version < 0x0B000006) { // 11.0.0.6 Settings->weight_absconv_a = 0; @@ -1832,6 +1832,9 @@ void SettingsDelta(void) { if (Settings->version < 0x0E020003) { // 14.2.0.3 Settings->flag3.sb_receive_invert = 0; // SetOption69 - (Serial) Invert Serial receive on SerialBridge } + if (Settings->version < 0x0E020004) { // 14.2.0.4 + Settings->weight_precision = 0; // Initialized by HX711 driver + } Settings->version = TASMOTA_VERSION; SettingsSave(1); diff --git a/tasmota/tasmota_xsns_sensor/xsns_34_hx711.ino b/tasmota/tasmota_xsns_sensor/xsns_34_hx711.ino index f6c78d83c..35bd1a6f9 100644 --- a/tasmota/tasmota_xsns_sensor/xsns_34_hx711.ino +++ b/tasmota/tasmota_xsns_sensor/xsns_34_hx711.ino @@ -44,7 +44,7 @@ #define HX_SCALE 120 // Default result of measured weight / reference weight when scale is 1 #endif #ifndef HX711_CAL_PRECISION -#define HX711_CAL_PRECISION 1 // When calibration is to course, raise this value. +#define HX711_CAL_PRECISION 1 // When calibration is to course, raise this value. #endif @@ -60,6 +60,7 @@ #define D_JSON_WEIGHT_RAW_ABS "AbsRaw" #define D_JSON_WEIGHT_REF "Ref" #define D_JSON_WEIGHT_CAL "Cal" +#define D_JSON_WEIGHT_PREC "Prec" #define D_JSON_WEIGHT_MAX "Max" #define D_JSON_WEIGHT_ITEM "Item" #define D_JSON_WEIGHT_CHANGE "Change" @@ -182,6 +183,7 @@ void SetWeightDelta(void) { * Sensor34 1 - Reset display to 0 * Sensor34 2 - Start calibration * Sensor34 2 - Set reference weight and start calibration + * Sensor34 2 - Set reference weight with larger precision (1..10) and start calibration * Sensor34 3 - Set reference weight * Sensor34 4 - Set calibrated scale value * Sensor34 5 - Set max weight @@ -207,7 +209,7 @@ bool HxCommand(void) { for (uint32_t ca = 0; ca < XdrvMailbox.data_len; ca++) { if ((' ' == XdrvMailbox.data[ca]) || ('=' == XdrvMailbox.data[ca])) { XdrvMailbox.data[ca] = ','; } } - bool any_value = (strchr(XdrvMailbox.data, ',') != nullptr); + bool any_value = (ArgC() > 1); if (any_value) { value = strtol(ArgV(argument, 2), nullptr, 10); } switch (XdrvMailbox.payload) { @@ -219,14 +221,20 @@ bool HxCommand(void) { show_parms = false; break; case 2: // Calibrate - if (any_value) { Settings->weight_reference = value; } + if (any_value) { + Settings->weight_reference = value; + if (ArgC() > 2) { + value = strtol(ArgV(argument, 3), nullptr, 10); + Settings->weight_precision = (value && (value < 11)) ? value : HX711_CAL_PRECISION; + } + } Hx.scale = 1; // Uncalibrated Hx.sample_count = 0; Hx.offset = 0; // Disable tare while calibrating Hx.calibrate_step = HX_CAL_START; Hx.calibrate_timer = 1; // HxCalibrationStateTextJson(3); // D_HX_CAL_REMOVE - HxCalibrationStateTextJson(2); // D_HX_CAL_REMOVE + HxCalibrationStateTextJson(2); // D_HX_CAL_REFERENCE show_parms = false; break; case 3: // WeightRef to user reference @@ -234,8 +242,8 @@ bool HxCommand(void) { break; case 4: // WeightCal to user calculated value if (any_value) { - Settings->weight_calibration = value; - Hx.scale = Settings->weight_calibration; + Settings->weight_calibration = value; // Allow zero for re-init + Hx.scale = (value) ? Settings->weight_calibration : 1; // Fix divide by zero } break; case 5: // WeightMax @@ -278,10 +286,13 @@ bool HxCommand(void) { if (show_parms) { char item[33]; dtostrfd((float)Settings->weight_item / 10, 1, item); - Response_P(PSTR("{\"Sensor34\":{\"" D_JSON_WEIGHT_REF "\":%d,\"" D_JSON_WEIGHT_CAL "\":%d,\"" D_JSON_WEIGHT_MAX "\":%d,\"" + Response_P(PSTR("{\"Sensor34\":{\"" + D_JSON_WEIGHT_REF "\":%d,\"" D_JSON_WEIGHT_CAL "\":%d,\"" D_JSON_WEIGHT_PREC "\":%d,\"" + D_JSON_WEIGHT_MAX "\":%d,\"" D_JSON_WEIGHT_ITEM "\":%s,\"" D_JSON_WEIGHT_CHANGE "\":\"%s\",\"" D_JSON_WEIGHT_DELTA "\":%d,\"" D_JSON_WEIGHT_TARE "\":%d,\"" D_JSON_WEIGHT_ABSC_A "\":%d,\"" D_JSON_WEIGHT_ABSC_B "\":%d}}"), - Settings->weight_reference, Settings->weight_calibration, Settings->weight_max * 1000, + Settings->weight_reference, Settings->weight_calibration, Settings->weight_precision, + Settings->weight_max * 1000, item, GetStateText(Settings->SensorBits1.hx711_json_weight_change), Settings->weight_change, Settings->weight_user_tare, Settings->weight_absconv_a, Settings->weight_absconv_b); } @@ -310,7 +321,8 @@ void HxInit(void) { if (HxIsReady(8 * HX_TIMEOUT)) { // Can take 600 milliseconds after power on if (!Settings->weight_max) { Settings->weight_max = HX_MAX_WEIGHT / 1000; } - if (!Settings->weight_calibration) { Settings->weight_calibration = HX_SCALE; } + if (!Settings->weight_precision) { Settings->weight_precision = HX711_CAL_PRECISION; } + if (!Settings->weight_calibration) { Settings->weight_calibration = HX_SCALE * Settings->weight_precision; } if (!Settings->weight_reference) { Settings->weight_reference = HX_REFERENCE; } Hx.scale = Settings->weight_calibration; HxTareInit(); @@ -344,7 +356,7 @@ void HxEvery100mSecond(void) { for (uint32_t i = 2; i < HX_SAMPLES -2; i++) { sum_raw += Hx.reads[i]; } - Hx.raw_absolute = (sum_raw / (HX_SAMPLES -4)) * HX711_CAL_PRECISION; // Uncalibrated value + Hx.raw_absolute = (sum_raw / (HX_SAMPLES -4)) * Settings->weight_precision; // Uncalibrated value Hx.raw = Hx.raw_absolute / Hx.scale; // grams if ((0 == Settings->weight_user_tare) && Hx.tare_flg) { // Reset scale based on current load