fix for software 1-wire driver

This commit is contained in:
2020-05-09 04:03:21 +03:00
parent d4536e403c
commit 6277a44b1d
4 changed files with 46 additions and 14 deletions

17
lighthub/lighthub.ino.cpp Normal file
View File

@@ -0,0 +1,17 @@
# 1 "/var/folders/kt/8psth65x03v6tw_phdhbj12r0000gn/T/tmpzcgFX2"
#include <Arduino.h>
# 1 "/Users/andrey/Documents/Arduino/lighthub/lighthub/lighthub.ino"
#include "main.h"
void setup();
void loop();
#line 2 "/Users/andrey/Documents/Arduino/lighthub/lighthub/lighthub.ino"
void setup(){
setup_main();
}
void loop(){
loop_main();
}

View File

@@ -1489,9 +1489,9 @@ void setup_main() {
delay(20); delay(20);
//owReady = 0; //owReady = 0;
#ifdef _owire #ifdef _owire
if (oneWire) oneWire->idle(&owIdle); setupOwIdle(&owIdle);
#endif #endif
mqttClient.setCallback(mqttCallback); mqttClient.setCallback(mqttCallback);

View File

@@ -72,7 +72,9 @@ int owUpdate() {
debugSerial.println(); debugSerial.println();
if (term[t_count][0] == 0x28) { if (term[t_count][0] == 0x28) {
sensors->setResolution(term[t_count], TEMPERATURE_PRECISION); sensors->setResolution(term[t_count], TEMPERATURE_PRECISION);
#ifdef DS2482_100_I2C_TO_1W_BRIDGE
oneWire->setStrongPullup(); oneWire->setStrongPullup();
#endif
// sensors.requestTemperaturesByAddress(term[t_count]); // sensors.requestTemperaturesByAddress(term[t_count]);
} }
t_count++; t_count++;
@@ -127,7 +129,7 @@ int owSetup(owChangedType owCh) {
return false; return false;
#else #else
// software driver // software driver
oneWire->deviceReset(); oneWire->reset();
delay(500); delay(500);
return true; return true;
#endif //DS2482-100 #endif //DS2482-100
@@ -138,13 +140,14 @@ return false;
int sensors_loop(void) { int sensors_loop(void) {
#ifdef DS2482_100_I2C_TO_1W_BRIDGE
if (oneWire->getError() == DS2482_ERROR_SHORT) if (oneWire->getError() == DS2482_ERROR_SHORT)
{ {
debugSerial<<F("1-wire shorted")<<endl; debugSerial<<F("1-wire shorted")<<endl;
oneWire->wireReset(); oneWire->wireReset();
return 10000; return 10000;
} }
#endif
if (!sensors) if (!sensors)
{ {
@@ -202,9 +205,18 @@ void owAdd(DeviceAddress addr) {
debugSerial<<F("dev#")<<t_count<<F(" Addr:"); debugSerial<<F("dev#")<<t_count<<F(" Addr:");
PrintBytes(term[t_count], 8,0); PrintBytes(term[t_count], 8,0);
debugSerial.println(); debugSerial.println();
#ifdef DS2482_100_I2C_TO_1W_BRIDGE
if (term[t_count][0] == 0x28) if (term[t_count][0] == 0x28)
oneWire->setStrongPullup(); oneWire->setStrongPullup();
#endif
t_count++; t_count++;
#endif #endif
} }
#endif #endif
void setupOwIdle (void (*ptr)())
{
#ifdef DS2482_100_I2C_TO_1W_BRIDGE
if (oneWire) oneWire->idle(ptr);
#endif
}

View File

@@ -1,4 +1,4 @@
/* Copyright © 2017-2018 Andrey Klimov. All rights reserved. /* Copyright © 2017-2020 Andrey Klimov. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. you may not use this file except in compliance with the License.
@@ -19,6 +19,7 @@ e-mail anklimov@gmail.com
*/ */
//define APU_OFF //define APU_OFF
#pragma once
#define SW_AUX0 0x40 #define SW_AUX0 0x40
#define SW_AUX1 0x80 #define SW_AUX1 0x80
@@ -52,23 +53,25 @@ e-mail anklimov@gmail.com
#ifndef OWIRE_DISABLE #ifndef OWIRE_DISABLE
#ifndef ARDUINO_ARCH_STM32F1
#include <DS2482_OneWire.h>
#endif
#include <DallasTemperature.h> #include <DallasTemperature.h>
#include "aJSON.h" #include "aJSON.h"
extern aJsonObject *owArr; extern aJsonObject *owArr;
typedef void (*owChangedType) (int , DeviceAddress, float) ; typedef void (*owChangedType) (int , DeviceAddress, float) ;
#ifndef USE_1W_PIN #ifndef USE_1W_PIN
#define DS2482_100_I2C_TO_1W_BRIDGE // HW driver #define DS2482_100_I2C_TO_1W_BRIDGE // HW driver
#include <Wire.h>
#ifndef ARDUINO_ARCH_STM32F1
#include <DS2482_OneWire.h>
#endif
#else
#include <OneWire.h> //Software driver
#define wireReset reset
#define wireSearch search
#endif #endif
#ifdef DS2482_100_I2C_TO_1W_BRIDGE
#include <Wire.h>
#endif
extern OneWire *oneWire; extern OneWire *oneWire;
@@ -86,7 +89,7 @@ extern owChangedType owChanged;
int owUpdate(); int owUpdate();
int owSetup(owChangedType owCh); int owSetup(owChangedType owCh);
void owLoop(); void owLoop();
void owIdle(void) ; void setupOwIdle(void (*)()) ;
int owFind(DeviceAddress addr); int owFind(DeviceAddress addr);
void owAdd (DeviceAddress addr); void owAdd (DeviceAddress addr);