Refactor Hall Effect

This commit is contained in:
Theo Arends 2021-03-28 14:38:16 +02:00
parent 47fcdd9e8e
commit e7a851f197
2 changed files with 27 additions and 8 deletions

View File

@ -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)

View File

@ -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