templates, I2C/1Wire reset tune, bins

This commit is contained in:
2023-11-18 00:57:12 +03:00
parent 5235bb67c1
commit 18fbc783b5
20 changed files with 53296 additions and 53081 deletions

View File

@@ -127,8 +127,8 @@ int owSetup() {
if (oneWire) return true; // Already initialized
#ifdef DS2482_100_I2C_TO_1W_BRIDGE
debugSerial<<F("DS2482_100_I2C_TO_1W_BRIDGE init")<<endl;
debugSerial<<F("Free:")<<freeRam()<<endl;
debugSerial<<F("1WT: DS2482_100_I2C_TO_1W_BRIDGE init")<<endl;
//debugSerial<<F("Free:")<<freeRam()<<endl;
oneWire = new OneWire;
#else
debugSerial.print(F("One wire setup on PIN:"));
@@ -146,7 +146,7 @@ if (!oneWire)
#ifdef DS2482_100_I2C_TO_1W_BRIDGE
Wire.begin();
if (oneWire->checkPresence()) {
infoSerial.println(F("1WT: DS2482-100 present"));
infoSerial.println(F("1WT: DS2482-100 present, reset"));
oneWire->deviceReset();
#ifdef APU_OFF
debugSerial.println(F("APU off"));
@@ -154,11 +154,11 @@ if (!oneWire)
oneWire->setActivePullup();
#endif
debugSerial.println(F("\tChecking for 1-Wire devices..."));
// debugSerial.println(F("\tChecking for 1-Wire devices..."));
if (oneWire->wireReset())
debugSerial.println(F("\tReset done"));
debugSerial.println(F("1WT: Bus Reset done"));
else
debugSerial.println(F("\tDS2482 reset error"));
debugSerial.println(F("1WT: Bus reset error"));
//return true;
}
else
@@ -229,22 +229,22 @@ int sensors_loop(void) {
i2cReset();
break;
case DS2482_ERROR_TIMEOUT:
errorSerial<<F("1WT: timeout")<<endl;
oneWire->wireReset();
return INTERVAL_1W;
case DS2482_ERROR_TIMEOUT: //Busy over time
errorSerial<<F("1WT: BUSY timeout")<<endl;
i2cReset();
break;
default:
errorSerial<<F("1WT: error")<<endl;
oneWire->wireReset();
return INTERVAL_1W;
break;
}
/*
if (!oneWire->checkPresence())
{
infoSerial.println(F("1WT: lost DS2482-100"));
i2cReset();
}
*/
#endif

View File

@@ -2,6 +2,8 @@
#define _TEMPLATE_STREAM_H_
#include <Stream.h>
#include <aJSON.h>
#include <streamlog.h>
//#define KEYLEN 8
extern aJsonObject * topics;
@@ -30,6 +32,7 @@ public:
{
str[pos+2+i]='\0';
val=resolveKey(str+pos+2);
valpos=0;
str[pos+2+i]='}';
pos+=3+i;
}
@@ -83,8 +86,9 @@ public:
if (valObj->type == aJson_String) return valObj->valuestring;
}
if (suffix && (suffix<=suffixNum) && !strcmp(key,"sfx"))
if (suffix && (suffix<suffixNum) && !strcmp(key,"sfx"))
{
//debugSerial<<F("Template: Suffix=")<<suffix<<endl;
buffer[0]='/';
strncpy_P(buffer+1,suffix_P[suffix],sizeof(buffer)-2);
return buffer;

View File

@@ -701,6 +701,11 @@ switch (cmdType)
// dict = aJson.createObject();
// aJson.addStringToObject(dict, "sfx", )
suffix=_itemCmd.getSuffix();
if (!suffix)
{
if (_itemCmd.isCommand()) suffix=S_CMD;
else if (_itemCmd.isValue()) suffix = S_SET;
}
}
//debugSerial << F("IN:") << (pin) << F(" : ") <<endl;
@@ -720,7 +725,7 @@ switch (cmdType)
char addrstr[MQTT_TOPIC_LENGTH];
//ts.setTimeout(0);
addrstr[ts.readBytesUntil('\0',addrstr,sizeof(addrstr))]='\0';
debugSerial << F("Emit: ")<<emit->valuestring<<" "<<addrstr<< F(" -> ")<<emitCommand<<endl;
debugSerial << F("Emit: <")<<emit->valuestring<<"> "<<addrstr<< F(" -> ")<<emitCommand<<endl;
/*
TODO implement
#ifdef WITH_DOMOTICZ
@@ -895,7 +900,7 @@ bool checkToken(char * token, char * data)
bool i2cReset(){
debugSerial.println("I2C Reset");
debugSerial.println(F("I2C Reset"));
Wire.endTransmission(true);
#if !defined(ARDUINO_ARCH_ESP8266)
@@ -911,19 +916,22 @@ pinMode(SDA,INPUT);
pulse=!pulse;
delay(10);//10us мкс
}
delay(20);
Wire.begin();
#ifdef DS2482_100_I2C_TO_1W_BRIDGE
if (oneWire && oneWire->checkPresence())
{
oneWire->deviceReset();
debugSerial.println(F("1WT: DS2482 present, reset"));
#ifndef APU_OFF
oneWire->setActivePullup();
#endif
if (oneWire->wireReset())
debugSerial.println(F("\tReset done"));
debugSerial.println(F("1WT: Bus Reset done"));
else
debugSerial.println(F("\tDS2482 reset error"));
debugSerial.println(F("1WT: Bus reset error"));
}
#endif