diff --git a/lighthub/inputs.cpp b/lighthub/inputs.cpp index bd60610..b7aec11 100644 --- a/lighthub/inputs.cpp +++ b/lighthub/inputs.cpp @@ -512,11 +512,14 @@ void Input::onContactChanged(int newValue) { aJsonObject *emit = aJson.getObjectItem(inputObj, "emit"); if (emit) { #ifdef WITH_DOMOTICZ - if (getIdxField()) { - (newValue)? publishDataToDomoticz(0, emit, "{\"command\":\"switchlight\",\"idx\":%s,\"switchcmd\":\"On\"}", getIdxField()) - : publishDataToDomoticz(0,emit,"{\"command\":\"switchlight\",\"idx\":%s,\"switchcmd\":\"Off\"}",getIdxField()); - } else + if (getIdxField()) { (newValue) ? publishDataToDomoticz(0, emit, "{\"command\":\"switchlight\",\"idx\":%s,\"switchcmd\":\"On\"}", + : publishDataToDomoticz(0,emit,"{\"command\":\"switchlight\",\"idx\":%s,\"switchcmd\":\"Off\"}",getIdxField()); getIdxField()) + : publishDataToDomoticz(0, emit, + "{\"command\":\"switchlight\",\"idx\":%s,\"switchcmd\":\"Off\"}", + getIdxField()); + } else #endif +{ char addrstr[MQTT_TOPIC_LENGTH]; strncpy(addrstr,emit->valuestring,sizeof(addrstr)); if (!strchr(addrstr,'/')) setTopic(addrstr,sizeof(addrstr),T_OUT,emit->valuestring); @@ -545,7 +548,7 @@ if (!strchr(addrstr,'/')) setTopic(addrstr,sizeof(addrstr),T_OUT,emit->valuestri } } } - +} void Input::onAnalogChanged(int newValue) { debugSerial << F("IN:") << (pin) << F("=") << newValue << endl; diff --git a/lighthub/main.cpp b/lighthub/main.cpp index f2189c2..0868c52 100644 --- a/lighthub/main.cpp +++ b/lighthub/main.cpp @@ -714,26 +714,6 @@ if (WiFi.status() != WL_CONNECTED) #endif } -#ifdef ARDUINO_ARCH_STM32 -void softRebootFunc() { - //nvic_sys_reset(); - Serial.println("not implemented"); -} -#endif - -#if defined(ARDUINO_ARCH_AVR) || defined(__SAM3X8E__) -void (*softRebootFunc)(void) = 0; - -void printCurentLanConfig(); - -#endif - -#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32) -void softRebootFunc(){ - debugSerial<idle(&owIdle); + if (oneWire) oneWire->idle(&owIdle); #endif mqttClient.setCallback(mqttCallback); diff --git a/lighthub/owTerm.cpp b/lighthub/owTerm.cpp index 11546f9..118907c 100644 --- a/lighthub/owTerm.cpp +++ b/lighthub/owTerm.cpp @@ -26,7 +26,7 @@ e-mail anklimov@gmail.com #include "options.h" -OneWire *net = NULL; +OneWire *oneWire = NULL; DeviceAddress *term = NULL; @@ -46,12 +46,12 @@ int owUpdate() { Serial.println(F("Searching")); - if (net) net->reset_search(); + if (oneWire) oneWire->reset_search(); for (short i = 0; i < t_count; i++) wstat[i] &= ~SW_FIND; //absent - while (net && net->wireSearch(term[t_count]) > 0 && (t_count < t_max) && finish > millis()) { + while (oneWire && oneWire->wireSearch(term[t_count]) > 0 && (t_count < t_max) && finish > millis()) { short ifind = -1; - if (net->crc8(term[t_count], 7) == term[t_count][7]) { + if (oneWire->crc8(term[t_count], 7) == term[t_count][7]) { for (short i = 0; i < t_count; i++) if (!memcmp(term[i], term[t_count], 8)) { ifind = i; @@ -68,7 +68,7 @@ int owUpdate() { debugSerial.println(); if (term[t_count][0] == 0x28) { sensors->setResolution(term[t_count], TEMPERATURE_PRECISION); - net->setStrongPullup(); + oneWire->setStrongPullup(); // sensors.requestTemperaturesByAddress(term[t_count]); } t_count++; @@ -84,20 +84,20 @@ int owUpdate() { int owSetup(owChangedType owCh) { #ifndef OWIRE_DISABLE //// todo - move memory allocation to here - if (net) return true; // Already initialized + if (oneWire) return true; // Already initialized #ifdef DS2482_100_I2C_TO_1W_BRIDGE debugSerial<checkPresence()) { + if (oneWire->checkPresence()) { debugSerial.println(F("DS2482-100 present")); - net->deviceReset(); + oneWire->deviceReset(); #ifdef APU_OFF debugSerial.println(F("APU off")); #else - net->setActivePullup(); + oneWire->setActivePullup(); #endif debugSerial.println(F("\tChecking for 1-Wire devices...")); - if (net->wireReset()) + if (oneWire->wireReset()) debugSerial.println(F("\tReset done")); sensors->begin(); @@ -191,7 +191,7 @@ void owAdd(DeviceAddress addr) { debugSerial.println(); if (term[t_count][0] == 0x28) { sensors->setResolution(term[t_count], TEMPERATURE_PRECISION); - net->setStrongPullup(); + oneWire->setStrongPullup(); // sensors.requestTemperaturesByAddress(term[t_count]); } t_count++; diff --git a/lighthub/owTerm.h b/lighthub/owTerm.h index 34d6ac5..ea1028e 100644 --- a/lighthub/owTerm.h +++ b/lighthub/owTerm.h @@ -70,7 +70,7 @@ typedef void (*owChangedType) (int , DeviceAddress, float) ; #include #endif -extern OneWire *net; +extern OneWire *oneWire; extern DallasTemperature *sensors; extern DeviceAddress *term ; diff --git a/lighthub/utils.cpp b/lighthub/utils.cpp index 1031ed8..8f0fed1 100644 --- a/lighthub/utils.cpp +++ b/lighthub/utils.cpp @@ -21,6 +21,7 @@ e-mail anklimov@gmail.com #include "utils.h" #include "options.h" #include "stdarg.h" +#include #if defined(__SAM3X8E__) || defined(ARDUINO_ARCH_STM32) #include @@ -429,5 +430,73 @@ void printUlongValueToStr(char *valstr, unsigned long value) { valstr[i]='\0'; } + +void scan_i2c_bus() { + byte error, address; + int nDevices; + + debugSerial<<("Scanning...\n"); + + nDevices = 0; + for(address = 1; address < 127; address++ ) + { + // The i2c_scanner uses the return value of + // the Write.endTransmisstion to see if + // a device did acknowledge to the address. + Wire.beginTransmission(address); + error = Wire.endTransmission(); + + if (error == 0) + { + debugSerial<<("\nI2C device found at address 0x"); + if (address<16) + debugSerial<<("0"); + debugSerial<<(address,HEX); + debugSerial<<(" !"); + + nDevices++; + } + else if (error==4) + { + debugSerial<<("\nUnknow error at address 0x"); + if (address<16) + debugSerial<<("0"); + debugSerial<<(address,HEX); + } + } + if (nDevices == 0) + debugSerial<<("No I2C devices found\n"); + else + debugSerial<<("done\n"); +} + + +#if defined(__SAM3X8E__) +void softRebootFunc() { + RSTC->RSTC_CR = 0xA5000005; +} +#endif + +#if defined(NRF5) || defined (ARDUINO_ARCH_STM32) +void softRebootFunc() { + debugSerial<<"Not implemented"<