Manually merged pull request "Is dev #39

anklimov:develop from livello:is-dev
 -Domotics fixed
 -i2c bus scan
 -Soft reboot on most platforms (except NRF & STM32)
This commit is contained in:
2019-04-02 12:06:50 +03:00
parent e65241e201
commit 8bf3c86a92
7 changed files with 100 additions and 43 deletions

View File

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

View File

@@ -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<<F("ESP.restart();");
ESP.restart();
}
#endif
void resetHard() {
#ifdef RESET_PIN
@@ -836,7 +816,7 @@ void cmdFunctionKill(int arg_cnt, char **args) {
void cmdFunctionReboot(int arg_cnt, char **args) {
debugSerial<<F("Soft rebooting...");
//// softRebootFunc();
softRebootFunc();
}
void applyConfig() {
@@ -1310,6 +1290,8 @@ void setup_main() {
setupCmdArduino();
printFirmwareVersionAndBuildOptions();
scan_i2c_bus();
#ifdef SD_CARD_INSERTED
sd_card_w5100_setup();
#endif
@@ -1339,7 +1321,7 @@ void setup_main() {
//owReady = 0;
#ifdef _owire
if (net) net->idle(&owIdle);
if (oneWire) oneWire->idle(&owIdle);
#endif
mqttClient.setCallback(mqttCallback);

View File

@@ -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<<F("DS2482_100_I2C_TO_1W_BRIDGE init")<<endl;
net = new OneWire;
oneWire = new OneWire;
#else
debugSerial.print(F("One wire setup on PIN:"));
debugSerial.println(QUOTE(USE_1W_PIN));
net = new OneWire (USE_1W_PIN);
oneWire = new OneWire (USE_1W_PIN);
#endif
// Pass our oneWire reference to Dallas Temperature.
sensors = new DallasTemperature(net);
sensors = new DallasTemperature(oneWire);
term = new DeviceAddress[t_max];
//regs = new int [t_max];
@@ -106,17 +106,17 @@ int owSetup(owChangedType owCh) {
#ifdef DS2482_100_I2C_TO_1W_BRIDGE
Wire.begin();
if (net->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++;

View File

@@ -70,7 +70,7 @@ typedef void (*owChangedType) (int , DeviceAddress, float) ;
#include <Wire.h>
#endif
extern OneWire *net;
extern OneWire *oneWire;
extern DallasTemperature *sensors;
extern DeviceAddress *term ;

View File

@@ -21,6 +21,7 @@ e-mail anklimov@gmail.com
#include "utils.h"
#include "options.h"
#include "stdarg.h"
#include <wire.h>
#if defined(__SAM3X8E__) || defined(ARDUINO_ARCH_STM32)
#include <malloc.h>
@@ -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"<<endl;
}
#endif
#if defined(ARDUINO_ARCH_ESP8266) || defined(ARDUINO_ARCH_ESP32)
void softRebootFunc(){
debugSerial<<F("ESP.restart();");
ESP.restart();
}
#endif
#if defined(ARDUINO_ARCH_AVR)
void softRebootFunc(){
void (*RebootFunc)(void) = 0;
RebootFunc();
}
#endif
#pragma message(VAR_NAME_VALUE(debugSerial))
#pragma message(VAR_NAME_VALUE(SERIAL_BAUD))

View File

@@ -17,6 +17,8 @@ GIT: https://github.com/anklimov/lighthub
e-mail anklimov@gmail.com
*/
#pragma once
#define Q(x) #x
#define QUOTE(x) Q(x)
#define VALUE_TO_STRING(x) #x
@@ -55,3 +57,5 @@ char *inet_ntoa_r(IPAddress addr, char *buf, int buflen);
void printIPAddress(IPAddress ipAddress);
char* setTopic(char* buf, int8_t buflen, topicType tt, char* suffix = NULL);
void printUlongValueToStr(char *valstr, unsigned long value);
void scan_i2c_bus();
void softRebootFunc();

View File

@@ -395,7 +395,6 @@ lib_ignore =
DS2482_OneWire
ModbusMaster
Syslog
Wire
EEPROM
ClosedCube HDC1080
SparkFun CCS811 Arduino Library