From 393f56827696297da734b01ffd37439c3306467c Mon Sep 17 00:00:00 2001 From: Bohdan Kmit Date: Wed, 30 Oct 2019 21:58:38 +0200 Subject: [PATCH] Add Setoption74 to runtime configuration of internal pullup resistor usage for single DS18x20 sensor --- tasmota/settings.h | 2 +- tasmota/xsns_05_ds18x20.ino | 18 +++--------------- 2 files changed, 4 insertions(+), 16 deletions(-) diff --git a/tasmota/settings.h b/tasmota/settings.h index efcdadcaa..c64820103 100644 --- a/tasmota/settings.h +++ b/tasmota/settings.h @@ -87,7 +87,7 @@ typedef union { // Restricted by MISRA-C Rule 18.4 bu uint32_t dds2382_model : 1; // bit 21 (v6.6.0.14) - SetOption71 - Select different Modbus registers for Active Energy (#6531) uint32_t hardware_energy_total : 1; // bit 22 (v6.6.0.15) - SetOption72 - Enable / Disable hardware energy total counter as reference (#6561) uint32_t cors_enabled : 1; // bit 23 (v7.0.0.1) - SetOption73 - Enable HTTP CORS - uint32_t spare24 : 1; + uint32_t ds18x20_internal_pullup : 1; // bit 24 (v7.0.0.1) - SetOption74 - Enable internal pullup for single DS18x20 sensor uint32_t spare25 : 1; uint32_t spare26 : 1; uint32_t spare27 : 1; diff --git a/tasmota/xsns_05_ds18x20.ino b/tasmota/xsns_05_ds18x20.ino index ca052c2f2..bb3362042 100644 --- a/tasmota/xsns_05_ds18x20.ino +++ b/tasmota/xsns_05_ds18x20.ino @@ -74,11 +74,7 @@ uint8_t OneWireReset(void) uint8_t retries = 125; //noInterrupts(); -#ifdef DS18B20_INTERNAL_PULLUP - pinMode(ds18x20_pin, INPUT_PULLUP); -#else - pinMode(ds18x20_pin, INPUT); -#endif + pinMode(ds18x20_pin, Settings.flag3.ds18x20_internal_pullup ? INPUT_PULLUP : INPUT); do { if (--retries == 0) { return 0; @@ -88,11 +84,7 @@ uint8_t OneWireReset(void) pinMode(ds18x20_pin, OUTPUT); digitalWrite(ds18x20_pin, LOW); delayMicroseconds(480); -#ifdef DS18B20_INTERNAL_PULLUP - pinMode(ds18x20_pin, INPUT_PULLUP); -#else - pinMode(ds18x20_pin, INPUT); -#endif + pinMode(ds18x20_pin, Settings.flag3.ds18x20_internal_pullup ? INPUT_PULLUP : INPUT); delayMicroseconds(70); uint8_t r = !digitalRead(ds18x20_pin); //interrupts(); @@ -121,11 +113,7 @@ uint8_t OneWireReadBit(void) pinMode(ds18x20_pin, OUTPUT); digitalWrite(ds18x20_pin, LOW); delayMicroseconds(3); -#ifdef DS18B20_INTERNAL_PULLUP - pinMode(ds18x20_pin, INPUT_PULLUP); -#else - pinMode(ds18x20_pin, INPUT); -#endif + pinMode(ds18x20_pin, Settings.flag3.ds18x20_internal_pullup ? INPUT_PULLUP : INPUT); delayMicroseconds(10); uint8_t r = digitalRead(ds18x20_pin); //interrupts();