From 47fcdd9e8e02393a3b8241d243d92d51260762ce Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Sun, 28 Mar 2021 12:25:30 +0200 Subject: [PATCH] Increase Hall Effect sample rate to 32 --- tasmota/xsns_87_esp32_halleffect.ino | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/tasmota/xsns_87_esp32_halleffect.ino b/tasmota/xsns_87_esp32_halleffect.ino index ee4cc1eb2..0295ca2ce 100644 --- a/tasmota/xsns_87_esp32_halleffect.ino +++ b/tasmota/xsns_87_esp32_halleffect.ino @@ -21,9 +21,15 @@ #ifdef USE_HALLEFFECT /*********************************************************************************************\ * ESP32 internal Hall Effect sensor connected to both GPIO36 and GPIO39 + * + * To enable set + * GPIO36 as HallEffect 1 + * GPIO39 as HallEffect 2 \*********************************************************************************************/ -#define XSNS_87 87 +#define XSNS_87 87 + +#define HALLEFFECT_SAMPLE_COUNT 32 // 32 takes about 12 mS at 80MHz CPU frequency struct { bool present = false; @@ -42,7 +48,17 @@ const char HTTP_SNS_HALL_EFFECT[] PROGMEM = "{s}" D_HALL_EFFECT "{m}%d{e}"; #endif // USE_WEBSERVER void HallEffectShow(bool json) { - int value = hallRead(); + +// DebugStartTime(); + + int value = 0; + for (uint32_t i = 0; i < HALLEFFECT_SAMPLE_COUNT; i++) { + value += hallRead(); + } + value /= HALLEFFECT_SAMPLE_COUNT; + +// DebugStopTime(); + if (json) { ResponseAppend_P(PSTR(",\"" D_JSON_HALLEFFECT "\":%d"), value); #ifdef USE_DOMOTICZ