mirror of
https://github.com/arendst/Tasmota.git
synced 2025-08-03 16:07:43 +00:00
Refactor ds18x20.ino
This commit is contained in:
parent
2d1bc97843
commit
fa826d33d9
@ -321,10 +321,9 @@
|
||||
//#define USE_ADC_VCC // Display Vcc in Power status. Disable for use as Analog input on selected devices
|
||||
|
||||
// -- One wire sensors ----------------------------
|
||||
// WARNING: Select none for default one DS18B20 sensor or enable the following option for multiple sensors
|
||||
#define USE_DS18x20 // Optional for more than one DS18x20 sensors with id sort, single scan and read retry (+1k3 code)
|
||||
// #define W1_PARASITE_POWER // If using USE_DS18x20 then optimize for parasite powered sensors
|
||||
// #define DS18B20_INTERNAL_PULLUP // Use INPUT_PULLUP internal pullup resistors for single DS18B20
|
||||
// #define W1_PARASITE_POWER // Optimize for parasite powered sensors
|
||||
// #define DS18B20_INTERNAL_PULLUP // Use INPUT_PULLUP internal pullup resistor
|
||||
|
||||
// -- I2C sensors ---------------------------------
|
||||
#define USE_I2C // I2C using library wire (+10k code, 0k2 mem, 124 iram)
|
||||
|
@ -74,7 +74,11 @@ uint8_t OneWireReset(void)
|
||||
uint8_t retries = 125;
|
||||
|
||||
//noInterrupts();
|
||||
#ifdef DS18B20_INTERNAL_PULLUP
|
||||
pinMode(ds18x20_pin, INPUT_PULLUP);
|
||||
#else
|
||||
pinMode(ds18x20_pin, INPUT);
|
||||
#endif
|
||||
do {
|
||||
if (--retries == 0) {
|
||||
return 0;
|
||||
@ -84,7 +88,11 @@ 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
|
||||
delayMicroseconds(70);
|
||||
uint8_t r = !digitalRead(ds18x20_pin);
|
||||
//interrupts();
|
||||
@ -113,7 +121,11 @@ 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
|
||||
delayMicroseconds(10);
|
||||
uint8_t r = digitalRead(ds18x20_pin);
|
||||
//interrupts();
|
||||
@ -432,7 +444,7 @@ void Ds18x20Show(bool json)
|
||||
|
||||
if (json) {
|
||||
if (1 == ds18x20_sensors) {
|
||||
ResponseAppend_P(PSTR(",\"%s\":{\"" D_JSON_TEMPERATURE "\":%s}"), ds18x20_types, temperature);
|
||||
ResponseAppend_P(JSON_SNS_TEMP, ds18x20_types, temperature);
|
||||
} else {
|
||||
char address[17];
|
||||
for (uint32_t j = 0; j < 6; j++) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user