From e7a851f19762dc323966014bbb3d654aee013f4e Mon Sep 17 00:00:00 2001 From: Theo Arends <11044339+arendst@users.noreply.github.com> Date: Sun, 28 Mar 2021 14:38:16 +0200 Subject: [PATCH] Refactor Hall Effect --- tasmota/xdrv_99_debug.ino | 22 ++++++++++++++++++++++ tasmota/xsns_87_esp32_halleffect.ino | 13 +++++-------- 2 files changed, 27 insertions(+), 8 deletions(-) diff --git a/tasmota/xdrv_99_debug.ino b/tasmota/xdrv_99_debug.ino index f99815d36..d7e82b053 100644 --- a/tasmota/xdrv_99_debug.ino +++ b/tasmota/xdrv_99_debug.ino @@ -217,6 +217,28 @@ void DebugFreeMem(void) #endif // ESP8266 - ESP32 +/*******************************************************************************************/ +/* + Usage: + + DebugTimer(1); + + Code snippit to time + + DebugTimer(0); +*/ + +void DebugTimer(bool start) { + static uint32_t timer = 0; + + if (start) { + timer = micros(); + } else { + timer = ((int32_t)(micros() - timer)); + AddLog(LOG_LEVEL_DEBUG, PSTR("DBG: ExecTime %d uS"), timer); + } +} + /*******************************************************************************************/ void DebugRtcDump(char* parms) diff --git a/tasmota/xsns_87_esp32_halleffect.ino b/tasmota/xsns_87_esp32_halleffect.ino index 0295ca2ce..01d28fed6 100644 --- a/tasmota/xsns_87_esp32_halleffect.ino +++ b/tasmota/xsns_87_esp32_halleffect.ino @@ -37,8 +37,11 @@ struct { void HallEffectInit(void) { if (PinUsed(GPIO_HALLEFFECT) && PinUsed(GPIO_HALLEFFECT, 1)) { - HEData.present = (((36 == Pin(GPIO_HALLEFFECT)) && (39 == Pin(GPIO_HALLEFFECT, 1))) || - ((39 == Pin(GPIO_HALLEFFECT)) && (36 == Pin(GPIO_HALLEFFECT, 1)))); + if (((36 == Pin(GPIO_HALLEFFECT)) && (39 == Pin(GPIO_HALLEFFECT, 1))) || + ((39 == Pin(GPIO_HALLEFFECT)) && (36 == Pin(GPIO_HALLEFFECT, 1)))) { + HEData.present = true; + hallRead(); + } } } @@ -48,17 +51,11 @@ const char HTTP_SNS_HALL_EFFECT[] PROGMEM = "{s}" D_HALL_EFFECT "{m}%d{e}"; #endif // USE_WEBSERVER void HallEffectShow(bool json) { - -// 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