From 0930f4679cc894ad8209e61baff2f0b21eed3ff5 Mon Sep 17 00:00:00 2001 From: to-scho Date: Tue, 18 Jan 2022 15:12:19 +0100 Subject: [PATCH 1/2] fix mode 2 detection of sr04 --- tasmota/xsns_22_sr04.ino | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tasmota/xsns_22_sr04.ino b/tasmota/xsns_22_sr04.ino index 7a1b10670..93c9a9190 100644 --- a/tasmota/xsns_22_sr04.ino +++ b/tasmota/xsns_22_sr04.ino @@ -53,7 +53,7 @@ uint8_t Sr04TModeDetect(void) if (sonar_serial->begin(9600)) { DEBUG_SENSOR_LOG(PSTR("SR4: Detect mode")); - if (sr04_trig_pin != -1) { + if (! PinUsed(GPIO_SR04_TRIG)) { sr04_type = (Sr04TMiddleValue(Sr04TMode3Distance(), Sr04TMode3Distance(), Sr04TMode3Distance()) != NO_ECHO) ? 3 : 1; } else { sr04_type = 2; @@ -65,7 +65,7 @@ uint8_t Sr04TModeDetect(void) if (sr04_type < 2) { delete sonar_serial; sonar_serial = nullptr; - if (-1 == sr04_trig_pin) { + if (! PinUsed(GPIO_SR04_TRIG)) { sr04_trig_pin = Pin(GPIO_SR04_ECHO); // if GPIO_SR04_TRIG is not configured use single PIN mode with GPIO_SR04_ECHO only } sonar = new NewPing(sr04_trig_pin, sr04_echo_pin, SR04_MAX_SENSOR_DISTANCE); From 6b8fc2d550e73a6cafe06607949a2b04f8b1ac19 Mon Sep 17 00:00:00 2001 From: to-scho Date: Tue, 18 Jan 2022 15:42:45 +0100 Subject: [PATCH 2/2] fix for wrong stupid logic --- tasmota/xsns_22_sr04.ino | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tasmota/xsns_22_sr04.ino b/tasmota/xsns_22_sr04.ino index 93c9a9190..9bdf2e54c 100644 --- a/tasmota/xsns_22_sr04.ino +++ b/tasmota/xsns_22_sr04.ino @@ -53,7 +53,7 @@ uint8_t Sr04TModeDetect(void) if (sonar_serial->begin(9600)) { DEBUG_SENSOR_LOG(PSTR("SR4: Detect mode")); - if (! PinUsed(GPIO_SR04_TRIG)) { + if (PinUsed(GPIO_SR04_TRIG)) { sr04_type = (Sr04TMiddleValue(Sr04TMode3Distance(), Sr04TMode3Distance(), Sr04TMode3Distance()) != NO_ECHO) ? 3 : 1; } else { sr04_type = 2;