mirror of
https://github.com/anklimov/lighthub
synced 2025-12-06 11:49:51 +03:00
Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 90298cd5a3 | |||
| 5719ba209a | |||
| 2e21362fd8 | |||
| fe054c3c4e | |||
| e3d84a1a02 | |||
| ca457a2a05 | |||
| 6d4f76c642 |
@@ -13,7 +13,7 @@
|
||||
-DAC_DISABLE
|
||||
-DSYSLOG_ENABLE
|
||||
-DPID_DISABLE
|
||||
-DWiz5100
|
||||
#-DWiz5100
|
||||
-DMOTOR_DISABLE
|
||||
-DOTA
|
||||
-DARDUINO_OTA_MDNS_DISABLE
|
||||
@@ -27,4 +27,4 @@
|
||||
-DPID_DISABLE
|
||||
-DPWM_DISABLE
|
||||
-DSPILED_DISABLE
|
||||
-DOW_DEVICES_LIMIT=17
|
||||
#-DOW_DEVICES_LIMIT=17
|
||||
Binary file not shown.
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Binary file not shown.
File diff suppressed because it is too large
Load Diff
BIN
compiled/mega2560slim/firmware.bin
Executable file
BIN
compiled/mega2560slim/firmware.bin
Executable file
Binary file not shown.
7074
compiled/mega2560slim/firmware.hex
Normal file
7074
compiled/mega2560slim/firmware.hex
Normal file
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
Binary file not shown.
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
0
compiled/tools/arduinoOTA
Normal file → Executable file
0
compiled/tools/arduinoOTA
Normal file → Executable file
@@ -1,8 +1,8 @@
|
||||
copy ..\.pio\build\due\firmware.bin due
|
||||
copy ..\.pio\build\controllino\firmware.hex controllino
|
||||
copy ..\.pio\build\m5stack\firmware.bin m5stack
|
||||
copy ..\.pio\build\mega2560slim-5100\firmware.hex mega2560slim-5100
|
||||
copy ..\.pio\build\mega2560slim-5100\firmware.bin mega2560slim-5100
|
||||
copy ..\.pio\build\mega2560slim\firmware.hex mega2560slim
|
||||
copy ..\.pio\build\mega2560slim\firmware.bin mega2560slim
|
||||
copy ..\.pio\build\mega2560slim2\firmware.hex mega2560slim2
|
||||
copy ..\.pio\build\mega2560slim2\firmware.bin mega2560slim2
|
||||
copy ..\.pio\build\due-5100\firmware.bin due-5100
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
cp ../.pio/build/due/firmware.bin due
|
||||
cp ../.pio/build/controllino/firmware.hex controllino
|
||||
cp ../.pio/build/m5stack/firmware.bin m5stack
|
||||
cp ../.pio/build/mega2560slim-5100/firmware.hex mega2560slim-5100
|
||||
cp ../.pio/build/mega2560slim-5100/firmware.bin mega2560slim-5100
|
||||
cp ../.pio/build/mega2560slim/firmware.hex mega2560slim
|
||||
cp ../.pio/build/mega2560slim/firmware.bin mega2560slim
|
||||
cp ../.pio/build/mega2560-optiboot/firmware.hex mega2560-optiboot
|
||||
cp ../.pio/build/mega2560-optiboot/firmware.bin mega2560-optiboot
|
||||
cp ../.pio/build/mega2560-5100/firmware.hex mega2560-5100
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
#include "Arduino.h"
|
||||
|
||||
#define CST_UNKNOWN 0
|
||||
#define CST_INITIALIZED 1
|
||||
#define CST_FAILED -1
|
||||
#define CST_FAILED 1
|
||||
#define CST_INITIALIZED 2
|
||||
|
||||
class abstractCh {
|
||||
public:
|
||||
@@ -14,6 +14,7 @@ public:
|
||||
virtual int Anounce () {return 0;};
|
||||
virtual int Stop() {return 0;}; //Should free resources
|
||||
virtual int Status() {return CST_UNKNOWN;}
|
||||
virtual void setStatus(uint8_t status) {}
|
||||
|
||||
|
||||
protected:
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
|
||||
|
||||
#include "item.h"
|
||||
#include "abstractout.h"
|
||||
#include "itemCmd.h"
|
||||
@@ -25,3 +26,15 @@ int abstractOut::Setup()
|
||||
if (item && (item->getCmd()==-1)) item->setCmd(CMD_OFF);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int abstractOut::Status()
|
||||
{
|
||||
if (item && item->itemArr)
|
||||
return item->itemArr->subtype;
|
||||
return CST_UNKNOWN;
|
||||
}
|
||||
|
||||
void abstractOut::setStatus(uint8_t status)
|
||||
{
|
||||
if (item && item->itemArr) item->itemArr->subtype = status & 0xF;
|
||||
}
|
||||
@@ -14,6 +14,8 @@ public:
|
||||
virtual itemCmd getDefaultOnVal(){return itemCmd().Percents255(255);};
|
||||
virtual int getChanType(){return 0;}
|
||||
virtual int getDefaultStorageType(){return 0;} /// Remove?? Now getChanType used instead
|
||||
virtual int Status() override;
|
||||
virtual void setStatus(uint8_t status) override;
|
||||
int Setup() override;
|
||||
protected:
|
||||
Item * item;
|
||||
|
||||
@@ -1936,7 +1936,7 @@ return itemType;
|
||||
|
||||
// Setup FLAG_SEND_RETRY flag to repeat unsucsessfull modbus tranzaction after release line
|
||||
void Item::mb_fail(int result) {
|
||||
debugSerial<<F("Modbus op failed:")<<_HEX(result)<<endl;
|
||||
debugSerial<<F("Modbus op ")<<itemArr->name<<F(" failed:")<<_HEX(result)<<endl;
|
||||
setFlag(FLAG_SEND_RETRY);
|
||||
// isPendedModbusWrites=true;
|
||||
}
|
||||
@@ -2132,7 +2132,7 @@ int Item::VacomSetFan(itemCmd st) {
|
||||
}
|
||||
uint8_t result;
|
||||
int addr = getArg();
|
||||
debugSerial<<F("VC#")<<addr<<F("=")<<val<<endl;
|
||||
debugSerial<<F("MB: VC#")<<addr<<F("=")<<val<<endl;
|
||||
if (modbusBusy) {
|
||||
// setCmd(cmd);
|
||||
// setVal(val);
|
||||
@@ -2152,7 +2152,7 @@ int Item::VacomSetFan(itemCmd st) {
|
||||
//node.writeSingleRegister(2001-1,1);
|
||||
} else result=node.writeSingleRegister(2001 - 1, 0);
|
||||
delay(100);
|
||||
if (result == node.ku8MBSuccess) debugSerial << F("MB ok")<<endl;
|
||||
if (result == node.ku8MBSuccess) debugSerial << F("MB: ok")<<endl;
|
||||
result = node.writeSingleRegister(2003 - 1, val * 100);
|
||||
modbusBusy = 0;
|
||||
//resumeModbus();
|
||||
@@ -2165,7 +2165,7 @@ int Item::VacomSetFan(itemCmd st) {
|
||||
#define a 0.1842f
|
||||
#define b -36.68f
|
||||
|
||||
///move to float todo
|
||||
|
||||
int Item::VacomSetHeat(itemCmd st)
|
||||
{
|
||||
float val=st.getFloat();
|
||||
@@ -2176,10 +2176,13 @@ int addr;
|
||||
if (itemArg->type != aJson_String) return 0;
|
||||
|
||||
Item it(itemArg->valuestring);
|
||||
if (it.isValid() && it.itemType == CH_VC) addr=it.getArg();
|
||||
if (it.isValid() && it.itemType == CH_VC)
|
||||
{
|
||||
addr=it.getArg();
|
||||
}
|
||||
else return 0;
|
||||
|
||||
debugSerial<<F("VC_heat#")<<addr<<F("=")<<val<<F(" cmd=")<<cmd<<endl;
|
||||
debugSerial<<F("MB: VC_heat#")<<addr<<F("=")<<val<<F(" cmd=")<<cmd<<endl;
|
||||
if (modbusBusy) {
|
||||
//setCmd(cmd);
|
||||
//setVal(val);
|
||||
@@ -2197,17 +2200,18 @@ int addr;
|
||||
switch (cmd) {
|
||||
case CMD_OFF:
|
||||
case CMD_HALT:
|
||||
case CMD_FAN:
|
||||
regval = 0;
|
||||
it.itemArr->subtype = 0;
|
||||
break;
|
||||
|
||||
default:
|
||||
it.itemArr->subtype = 1;
|
||||
regval = round(( val - b) * 10 / a);
|
||||
}
|
||||
|
||||
//debugSerial<<regval);
|
||||
result=node.writeSingleRegister(2004 - 1, regval);
|
||||
modbusBusy = 0;
|
||||
//resumeModbus();
|
||||
if (result == node.ku8MBSuccess) return 1;
|
||||
mb_fail(result);
|
||||
return 0;
|
||||
@@ -2219,7 +2223,7 @@ int Item::modbusDimmerSet(int addr, uint16_t _reg, int _regType, int _mask, uint
|
||||
if (_regType != MODBUS_COIL_REG_TYPE || _regType != MODBUS_HOLDING_REG_TYPE) {
|
||||
|
||||
}
|
||||
|
||||
debugSerial<<F("MB: Addr:")<<addr<<F(" Reg:0x")<<_HEX(_reg)<<F(" T:")<<_regType<<F(" Val:0x")<<_HEX(value)<<endl;
|
||||
if (modbusBusy) {
|
||||
mb_fail();
|
||||
return 0;
|
||||
@@ -2251,7 +2255,7 @@ int Item::modbusDimmerSet(int addr, uint16_t _reg, int _regType, int _mask, uint
|
||||
|
||||
|
||||
}
|
||||
debugSerial<<F("Addr:")<<addr<<F(" Reg:0x")<<_HEX(_reg)<<F(" T:")<<_regType<<F(" Val:0x")<<_HEX(value)<<endl;
|
||||
|
||||
switch (_regType) {
|
||||
case MODBUS_HOLDING_REG_TYPE:
|
||||
result = node.writeSingleRegister(_reg, value);
|
||||
@@ -2260,7 +2264,7 @@ int Item::modbusDimmerSet(int addr, uint16_t _reg, int _regType, int _mask, uint
|
||||
result = node.writeSingleCoil(_reg, value);
|
||||
break;
|
||||
default:
|
||||
debugSerial<<F("Not supported reg type\n");
|
||||
debugSerial<<F("MB: Not supported reg type\n");
|
||||
}
|
||||
modbusBusy = 0;
|
||||
//resumeModbus();
|
||||
@@ -2297,12 +2301,13 @@ int Item::checkFM() {
|
||||
modbusSerial.begin(MODBUS_FM_BAUD, MODBUS_FM_PARAM);
|
||||
node.begin(getArg(), modbusSerial);
|
||||
|
||||
|
||||
debugSerial << F("MB: polling FM ") << itemArr->name<< endl;
|
||||
delay(50);
|
||||
result = node.readHoldingRegisters(2101 - 1, 10);
|
||||
|
||||
// do something with data if read is successful
|
||||
if (result == node.ku8MBSuccess) {
|
||||
debugSerial<<F(" FM Val :");
|
||||
debugSerial<<F("MB: FM Val :");
|
||||
for (j = 0; j < 10; j++) {
|
||||
data = node.getResponseBuffer(j);
|
||||
debugSerial<<_HEX(data)<<F("-");
|
||||
@@ -2330,10 +2335,12 @@ int Item::checkFM() {
|
||||
}
|
||||
}
|
||||
} else
|
||||
debugSerial << F("Modbus polling error=") << _HEX(result) << endl;
|
||||
debugSerial << F("MB: polling ") << itemArr->name<< F(" error=") << _HEX(result) << endl;
|
||||
|
||||
if (node.getResponseBuffer(0) & 8) //Active fault
|
||||
{
|
||||
debugSerial << F("MB: polling FM fault ") << itemArr->name<< endl;
|
||||
delay(50);
|
||||
result = node.readHoldingRegisters(2111 - 1, 1);
|
||||
if (result == node.ku8MBSuccess) aJson.addNumberToObject(out, "flt", (long int) node.getResponseBuffer(0));
|
||||
modbusBusy=0;
|
||||
@@ -2343,12 +2350,13 @@ int Item::checkFM() {
|
||||
modbusBusy=1;
|
||||
} else aJson.addNumberToObject(out, "flt", (long int)0);
|
||||
|
||||
debugSerial << F("MB: polling PI ") << itemArr->name<< endl;
|
||||
delay(50);
|
||||
result = node.readHoldingRegisters(20 - 1, 4);
|
||||
|
||||
// do something with data if read is successful
|
||||
if (result == node.ku8MBSuccess) {
|
||||
debugSerial << F(" PI Val :");
|
||||
debugSerial << F("MB: PI Val :");
|
||||
for (j = 0; j < 4; j++) {
|
||||
data = node.getResponseBuffer(j);
|
||||
debugSerial << data << F("-");
|
||||
@@ -2371,7 +2379,8 @@ int Item::checkFM() {
|
||||
Off(); //Shut down
|
||||
}
|
||||
} else
|
||||
debugSerial << F("Modbus polling error=") << _HEX(result);
|
||||
debugSerial << F("MB: polling PI ") << itemArr->name<< F(" error=") << _HEX(result) << endl;
|
||||
|
||||
outch = aJson.print(out);
|
||||
if (mqttClient.connected() && !ethernetIdleCount)
|
||||
mqttClient.publish(addrstr, outch);
|
||||
@@ -2388,7 +2397,7 @@ int Item::checkModbusDimmer() {
|
||||
|
||||
short numpar = 0;
|
||||
if ((itemArg->type != aJson_Array) || ((numpar = aJson.getArraySize(itemArg)) < 2)) {
|
||||
debugSerial<<F("Illegal arguments\n");
|
||||
debugSerial<<F("MB: Illegal arguments\n");
|
||||
return -4;
|
||||
}
|
||||
|
||||
@@ -2415,7 +2424,7 @@ int Item::checkModbusDimmer() {
|
||||
|
||||
modbusSerial.begin(MODBUS_SERIAL_BAUD, MODBUS_SERIAL_PARAM);
|
||||
node.begin(addr, modbusSerial);
|
||||
|
||||
debugSerial << F("MB: polling dimmer ") << itemArr->name<< endl;
|
||||
switch (_regType) {
|
||||
case MODBUS_HOLDING_REG_TYPE:
|
||||
result = node.readHoldingRegisters(reg, 1);
|
||||
@@ -2430,7 +2439,7 @@ int Item::checkModbusDimmer() {
|
||||
result = node.readInputRegisters(reg, 1);
|
||||
break;
|
||||
default:
|
||||
debugSerial<<F("Not supported reg type\n");
|
||||
debugSerial<<F("MB: Not supported reg type\n");
|
||||
}
|
||||
|
||||
if (result == node.ku8MBSuccess) {
|
||||
@@ -2448,7 +2457,8 @@ int Item::checkModbusDimmer() {
|
||||
pollingItem = items->child;
|
||||
}
|
||||
} else
|
||||
debugSerial << F("Modbus polling error=") << _HEX(result) << endl;
|
||||
debugSerial << F("MB: polling ") << itemArr->name<< F(" error=") << _HEX(result) << endl;
|
||||
|
||||
modbusBusy = 0;
|
||||
//resumeModbus();
|
||||
|
||||
@@ -2457,6 +2467,8 @@ return 1;
|
||||
|
||||
|
||||
int Item::checkModbusDimmer(int data) {
|
||||
if (getFlag(FLAG_SEND_RETRY)) return 0; //Active send transaction
|
||||
|
||||
short mask = getArg(2);
|
||||
itemCmd st;
|
||||
|
||||
|
||||
@@ -140,6 +140,7 @@ volatile unsigned long timerCount=0;
|
||||
volatile int16_t timerNumber=-1;
|
||||
volatile int8_t timerHandlerBusy=0;
|
||||
volatile uint32_t cryptoSalt=0;
|
||||
//uint32_t timerCtr=0;
|
||||
|
||||
aJsonObject *pollingItem = NULL;
|
||||
|
||||
@@ -1358,7 +1359,7 @@ setupSyslog();
|
||||
#ifdef _owire
|
||||
owArr = aJson.getObjectItem(root, "ow");
|
||||
if (owArr && !owReady) {
|
||||
aJsonObject *item = owArr->child;
|
||||
//aJsonObject *item = owArr->child;
|
||||
owReady = owSetup();
|
||||
if (owReady) infoSerial<<F("One wire Ready\n");
|
||||
}
|
||||
@@ -1978,18 +1979,19 @@ void postTransmission() {
|
||||
|
||||
void TimerHandler(void)
|
||||
{
|
||||
timerHandlerBusy++;
|
||||
interrupts();
|
||||
timerCount=micros();
|
||||
if (configLoaded && !timerHandlerBusy)
|
||||
{
|
||||
timerHandlerBusy++;
|
||||
interrupts();
|
||||
|
||||
inputLoop(CHECK_INTERRUPT);
|
||||
#ifdef DMX_SMOOTH
|
||||
DMXOUT_propagate();
|
||||
#endif
|
||||
timerHandlerBusy--;
|
||||
}
|
||||
timerCount=micros()-timerCount;
|
||||
timerHandlerBusy--;
|
||||
}
|
||||
|
||||
#if defined(__SAM3X8E__) && defined (TIMER_INT)
|
||||
@@ -2273,9 +2275,7 @@ while ((digitalRead(CONFIG_CLEAN_PIN)==LOW) && !needClean)
|
||||
delay(20);
|
||||
//owReady = 0;
|
||||
|
||||
#ifdef _owire
|
||||
setupOwIdle(&owIdle);
|
||||
#endif
|
||||
|
||||
|
||||
mqttClient.setCallback(mqttCallback);
|
||||
|
||||
@@ -2661,6 +2661,8 @@ void loop_main() {
|
||||
yield();
|
||||
inputLoop(CHECK_INPUT);
|
||||
|
||||
yield();
|
||||
inputSensorsLoop();
|
||||
#if defined (_espdmx)
|
||||
yield();
|
||||
dmxout.update();
|
||||
@@ -2672,13 +2674,32 @@ if (initializedListeners) ipmodbusLoop();
|
||||
|
||||
}
|
||||
|
||||
//static uint32_t tm=0;
|
||||
|
||||
void owIdle(void) {
|
||||
// timerCtr++;
|
||||
#ifdef _artnet
|
||||
if (artnet && (lanStatus>=HAVE_IP_ADDRESS)) artnet->read();
|
||||
#endif
|
||||
|
||||
wdt_res();
|
||||
inputLoop(CHECK_INTERRUPT);
|
||||
inputLoop(CHECK_INPUT);
|
||||
//inputLoop(CHECK_INTERRUPT);
|
||||
/*
|
||||
if (isTimeOver(tm,millis(),100))
|
||||
{
|
||||
tm=millis();
|
||||
debugSerial<<F("1WT: Tick")<<endl;
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#if defined (_espdmx)
|
||||
yield();
|
||||
dmxout.update();
|
||||
#endif
|
||||
|
||||
return; //?????
|
||||
|
||||
#ifdef _dmxin
|
||||
@@ -2686,10 +2707,7 @@ inputLoop(CHECK_INTERRUPT);
|
||||
DMXCheck();
|
||||
#endif
|
||||
|
||||
#if defined (_espdmx)
|
||||
yield();
|
||||
dmxout.update();
|
||||
#endif
|
||||
|
||||
|
||||
#ifdef IPMODBUS
|
||||
if (initializedListeners) ipmodbusLoop();
|
||||
@@ -2705,7 +2723,9 @@ ethernetIdleCount++;
|
||||
ethernetIdleCount--;
|
||||
};
|
||||
|
||||
|
||||
void modbusIdle(void) {
|
||||
|
||||
wdt_res();
|
||||
statusLED.poll();
|
||||
yield();
|
||||
@@ -2782,9 +2802,16 @@ configLocked++;
|
||||
if (cause != CHECK_INTERRUPT) timerInputCheck = millis();// + INTERVAL_CHECK_INPUT;
|
||||
inCache.invalidateInputCache();
|
||||
}
|
||||
configLocked--;
|
||||
inputLoopBusy--;
|
||||
}
|
||||
|
||||
//if (millis() > timerSensorCheck)
|
||||
if (cause != CHECK_INTERRUPT && isTimeOver(timerSensorCheck,millis(),INTERVAL_CHECK_SENSOR))
|
||||
|
||||
void inputSensorsLoop() {
|
||||
if (!inputs || inputLoopBusy) return;
|
||||
//inputLoopBusy++;
|
||||
configLocked++;
|
||||
if (isTimeOver(timerSensorCheck,millis(),INTERVAL_CHECK_SENSOR))
|
||||
{
|
||||
aJsonObject *input = inputs->child;
|
||||
while (input) {
|
||||
@@ -2793,15 +2820,17 @@ configLocked++;
|
||||
in.Poll(CHECK_SENSOR);
|
||||
}
|
||||
yield();
|
||||
inputLoop(CHECK_INPUT);
|
||||
input = input->next;
|
||||
}
|
||||
timerSensorCheck = millis();// + INTERVAL_CHECK_SENSOR;
|
||||
timerSensorCheck = millis();
|
||||
}
|
||||
configLocked--;
|
||||
inputLoopBusy--;
|
||||
//inputLoopBusy--;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void inputSetup(void) {
|
||||
if (!inputs) return;
|
||||
configLocked++;
|
||||
|
||||
@@ -287,6 +287,8 @@ void modbusIdle(void);
|
||||
|
||||
void inputLoop(short);
|
||||
|
||||
void inputSensorsLoop();
|
||||
|
||||
void inputSetup(void);
|
||||
|
||||
void pollingLoop(void);
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
#include "Streaming.h"
|
||||
#include "item.h"
|
||||
#include "main.h"
|
||||
#include "Wire.h"
|
||||
|
||||
#if defined(M5STACK)
|
||||
#include <M5Stack.h>
|
||||
@@ -63,8 +64,10 @@ delay(2000); */
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
int in_hdc1080::Setup()
|
||||
{
|
||||
//i2cReset();
|
||||
if (HDC1080ready) {debugSerial<<F("hdc1080 is already initialized")<<endl; return 0;}
|
||||
debugSerial.println("HDC1080 Init ");
|
||||
Wire.begin(); //Inialize I2C Harware
|
||||
@@ -81,14 +84,7 @@ HDC1080ready = true;
|
||||
return 1;
|
||||
}
|
||||
|
||||
void i2cReset(){
|
||||
Wire.endTransmission(true);
|
||||
#if defined (SCL_RESET)
|
||||
SCL_LOW();
|
||||
delay(300);
|
||||
SCL_HIGH();
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
int in_hdc1080::Poll(short cause)
|
||||
{
|
||||
@@ -130,7 +126,6 @@ if (reg!=0xff)
|
||||
}
|
||||
else //ESP I2C glitch
|
||||
{
|
||||
debugSerial.println("I2C Reset");
|
||||
i2cReset();
|
||||
}
|
||||
return INTERVAL_SLOW_POLLING;
|
||||
|
||||
@@ -19,10 +19,10 @@ extern bool disableCMD;
|
||||
|
||||
#define INTERVAL_AC_POLLING 5000L
|
||||
|
||||
#define AC_FAILED 15
|
||||
#define AC_FAILED CST_FAILED
|
||||
#define AC_UNKNOWN CST_UNKNOWN
|
||||
#define AC_IDLE CST_INITIALIZED
|
||||
#define AC_SENDING 2
|
||||
#define AC_SENDING 3
|
||||
|
||||
//byte inCheck = 0;
|
||||
byte qstn[] = {255,255,10,0,0,0,0,0,1,1,77,1,90}; // Команда опроса
|
||||
@@ -273,7 +273,7 @@ byte getCRC(byte req[], size_t size){
|
||||
|
||||
void out_AC::SendData(byte req[], size_t size){
|
||||
if (!store || !item) return;
|
||||
if (item->itemArr->subtype == AC_SENDING)
|
||||
if (Status() == AC_SENDING)
|
||||
{
|
||||
while (store->timestamp && !isTimeOver(store->timestamp,millis(),150)) yield();
|
||||
}
|
||||
@@ -299,7 +299,7 @@ if (item->itemArr->subtype == AC_SENDING)
|
||||
}
|
||||
}
|
||||
debugSerial.println();
|
||||
item->itemArr->subtype = AC_SENDING;
|
||||
setStatus(AC_SENDING);
|
||||
// #if defined (__SAM3X8E__)
|
||||
// if (item->getArg(0)==2) postTransmission();
|
||||
// #endif
|
||||
@@ -340,9 +340,9 @@ if (!portNum)// && (g_APinDescription[0].ulPinType == PIO_PA8A_URXD))
|
||||
#endif
|
||||
}
|
||||
ACSerial->begin(9600);
|
||||
item->itemArr->subtype = AC_IDLE;
|
||||
setStatus (AC_IDLE);
|
||||
|
||||
|
||||
//driverStatus = CST_INITIALIZED;
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -353,10 +353,11 @@ debugSerial<<F("AC: De-Init: ")<<portNum<<endl;
|
||||
delete store;
|
||||
item->setPersistent(NULL);
|
||||
store = NULL;
|
||||
item->itemArr->subtype = CST_UNKNOWN;
|
||||
setStatus (CST_UNKNOWN);
|
||||
return 1;
|
||||
}
|
||||
|
||||
/*
|
||||
int out_AC::Status()
|
||||
{
|
||||
if (!item) return 0;
|
||||
@@ -368,7 +369,8 @@ default:
|
||||
return CST_INITIALIZED;
|
||||
//return item->itemArr->subtype;
|
||||
}
|
||||
}
|
||||
}*/
|
||||
|
||||
int out_AC::isActive()
|
||||
{
|
||||
if (!store) return 0;
|
||||
@@ -379,7 +381,7 @@ int out_AC::Poll(short cause)
|
||||
{
|
||||
if (!store) return -1;
|
||||
|
||||
switch (item->itemArr->subtype)
|
||||
switch (Status())
|
||||
{
|
||||
case AC_FAILED: return -1;
|
||||
case AC_UNKNOWN: return -1;
|
||||
@@ -387,7 +389,7 @@ case AC_SENDING:
|
||||
{
|
||||
if (store->timestamp && isTimeOver(store->timestamp,millis(),150))
|
||||
{
|
||||
item->itemArr->subtype = AC_IDLE;
|
||||
setStatus(AC_IDLE);
|
||||
store->timestamp=millisNZ();
|
||||
}
|
||||
}
|
||||
@@ -395,7 +397,7 @@ case AC_SENDING:
|
||||
|
||||
if (cause!=POLLING_SLOW) return false;
|
||||
|
||||
if ((item->itemArr->subtype == AC_IDLE) && isTimeOver(store->timestamp,millis(),INTERVAL_AC_POLLING))
|
||||
if ((Status() == AC_IDLE) && isTimeOver(store->timestamp,millis(),INTERVAL_AC_POLLING))
|
||||
{
|
||||
debugSerial.println(F("AC: Polling"));
|
||||
SendData(qstn, sizeof(qstn)/sizeof(byte)); //Опрос кондиционера
|
||||
|
||||
@@ -40,7 +40,6 @@ public:
|
||||
int Setup() override;
|
||||
int Poll(short cause) override;
|
||||
int Stop() override;
|
||||
int Status() override;
|
||||
int isActive() override;
|
||||
int getChanType() override;
|
||||
int getDefaultStorageType(){return ST_FLOAT_CELSIUS;};
|
||||
|
||||
@@ -8,25 +8,20 @@
|
||||
#include "main.h"
|
||||
|
||||
|
||||
static int driverStatus = CST_UNKNOWN;
|
||||
|
||||
int out_counter::Setup()
|
||||
{
|
||||
abstractOut::Setup();
|
||||
driverStatus = CST_INITIALIZED;
|
||||
setStatus(CST_INITIALIZED);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int out_counter::Stop()
|
||||
{
|
||||
driverStatus = CST_UNKNOWN;
|
||||
setStatus(CST_UNKNOWN);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int out_counter::Status()
|
||||
{
|
||||
return driverStatus;
|
||||
}
|
||||
|
||||
|
||||
int out_counter::Poll(short cause)
|
||||
|
||||
@@ -13,7 +13,6 @@ public:
|
||||
int Setup() override;
|
||||
int Poll(short cause) override;
|
||||
int Stop() override;
|
||||
int Status() override;
|
||||
int getChanType() override;
|
||||
int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true, bool authorized = false) override;
|
||||
};
|
||||
|
||||
@@ -9,28 +9,22 @@
|
||||
#include "main.h"
|
||||
#include "dmx.h"
|
||||
|
||||
static int driverStatus = CST_UNKNOWN;
|
||||
|
||||
int out_dmx::Setup()
|
||||
{
|
||||
abstractOut::Setup();
|
||||
debugSerial<<F("DMX-Out Init: ")<< item->itemArr->name <<endl;
|
||||
driverStatus = CST_INITIALIZED;
|
||||
setStatus(CST_INITIALIZED);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int out_dmx::Stop()
|
||||
{
|
||||
debugSerial<<F("DMX-Out stop: ")<< item->itemArr->name << endl;
|
||||
driverStatus = CST_UNKNOWN;
|
||||
setStatus(CST_UNKNOWN);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int out_dmx::Status()
|
||||
{
|
||||
return driverStatus;
|
||||
}
|
||||
|
||||
int out_dmx::getChanType()
|
||||
{
|
||||
if (item)
|
||||
|
||||
@@ -13,7 +13,6 @@ public:
|
||||
out_dmx(Item * _item):colorChannel(_item){};
|
||||
int Setup() override;
|
||||
int Stop() override;
|
||||
int Status() override;
|
||||
|
||||
int getChanType() override;
|
||||
// int Ctrl(itemCmd cmd, char* subItem=NULL) override;
|
||||
|
||||
@@ -78,14 +78,14 @@ store->timestamp=millisNZ();
|
||||
if (getConfig())
|
||||
{
|
||||
infoSerial<<F("Mercury: config loaded ")<< item->itemArr->name<<endl;
|
||||
store->driverStatus = CST_INITIALIZED;
|
||||
setStatus(CST_INITIALIZED);
|
||||
store->lastSuccessTS = 0;
|
||||
initLine(true);
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{ errorSerial<<F("Mercury: config error")<<endl;
|
||||
store->driverStatus = CST_FAILED;
|
||||
setStatus(CST_FAILED);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -101,18 +101,6 @@ store = NULL;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int out_Mercury::Status()
|
||||
{
|
||||
if (store)
|
||||
return store->driverStatus;
|
||||
return CST_UNKNOWN;
|
||||
}
|
||||
|
||||
|
||||
void out_Mercury::setStatus(short status)
|
||||
{
|
||||
if (store) store->driverStatus=status;
|
||||
}
|
||||
|
||||
short out_Mercury::connectMercury()
|
||||
{
|
||||
@@ -337,7 +325,7 @@ int out_Mercury::Poll(short cause)
|
||||
//bool lineInitialized = false;
|
||||
if (cause==POLLING_SLOW) return 0;
|
||||
if (modbusBusy || ( mbusSlenceTimer && !isTimeOver(mbusSlenceTimer,millis(),100))) return 0;
|
||||
if (store->driverStatus == CST_FAILED) return 0;
|
||||
if (Status() == CST_FAILED) return 0;
|
||||
if (!getConfig()) return 0;
|
||||
|
||||
switch (Status())
|
||||
|
||||
@@ -12,7 +12,6 @@
|
||||
class mercuryPersistent : public chPersistent {
|
||||
|
||||
public:
|
||||
int8_t driverStatus;
|
||||
uint32_t timestamp;
|
||||
uint32_t lastSuccessTS;
|
||||
};
|
||||
@@ -47,7 +46,6 @@ public:
|
||||
int Setup() override;
|
||||
int Poll(short cause) override;
|
||||
int Stop() override;
|
||||
int Status() override;
|
||||
int getChanType() override;
|
||||
int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true, bool authorized = false) override;
|
||||
int getDefaultStorageType(){return ST_INT32;};
|
||||
@@ -58,7 +56,6 @@ protected:
|
||||
uint16_t pollingInterval;
|
||||
bool getConfig();
|
||||
void initLine(bool full = false);
|
||||
void setStatus(short);
|
||||
short connectMercury();
|
||||
short disconnectMercury();
|
||||
short getCurrentVal12(byte param, String topic,int divisor=1);
|
||||
|
||||
@@ -180,12 +180,12 @@ store->timestamp=millisNZ();
|
||||
if (getConfig())
|
||||
{
|
||||
infoSerial<<F("MBUS: config loaded ")<< item->itemArr->name<<endl;
|
||||
store->driverStatus = CST_INITIALIZED;
|
||||
setStatus(CST_INITIALIZED);
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{ errorSerial<<F("MBUS: config error")<<endl;
|
||||
store->driverStatus = CST_FAILED;
|
||||
setStatus(CST_FAILED);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -202,12 +202,6 @@ store = NULL;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int out_Modbus::Status()
|
||||
{
|
||||
if (store)
|
||||
return store->driverStatus;
|
||||
return CST_UNKNOWN;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -11,8 +11,7 @@
|
||||
class mbPersistent : public chPersistent {
|
||||
|
||||
public:
|
||||
// int addr
|
||||
int8_t driverStatus;
|
||||
|
||||
int baud;
|
||||
serialParamType serialParam;
|
||||
uint16_t pollingInterval;
|
||||
@@ -37,7 +36,6 @@ public:
|
||||
int Setup() override;
|
||||
int Poll(short cause) override;
|
||||
int Stop() override;
|
||||
int Status() override;
|
||||
int getChanType() override;
|
||||
int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true, bool authorized = false) override;
|
||||
int getDefaultStorageType(){return ST_INT32;};
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
#include "item.h"
|
||||
#include "main.h"
|
||||
|
||||
static int driverStatus = CST_UNKNOWN;
|
||||
|
||||
void out_Motor::getConfig()
|
||||
{
|
||||
@@ -64,7 +63,7 @@ pinMode(pinFeedback, INPUT);
|
||||
item->setExt(0);
|
||||
item->clearFlag(FLAG_ACTION_NEEDED);
|
||||
item->clearFlag(FLAG_ACTION_IN_PROCESS);
|
||||
driverStatus = CST_INITIALIZED;
|
||||
setStatus(CST_INITIALIZED);
|
||||
motorQuote = MOTOR_QUOTE;
|
||||
return 1;
|
||||
}
|
||||
@@ -73,7 +72,7 @@ int out_Motor::Stop()
|
||||
{
|
||||
debugSerial.println("Motor: De-Init");
|
||||
item->setExt(0);
|
||||
driverStatus = CST_UNKNOWN;
|
||||
setStatus(CST_UNKNOWN);
|
||||
|
||||
if (isProtectedPin(pinUp)||isProtectedPin(pinDown)) {errorSerial<<F("pin disabled")<<endl;return 0;}
|
||||
digitalWrite(pinUp,INACTIVE);
|
||||
@@ -82,26 +81,6 @@ digitalWrite(pinDown,INACTIVE);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int out_Motor::Status()
|
||||
{
|
||||
return driverStatus;
|
||||
}
|
||||
/*
|
||||
int out_Motor::isActive()
|
||||
{
|
||||
itemCmd st;
|
||||
switch (item->getCmd())
|
||||
{
|
||||
case CMD_OFF:
|
||||
case CMD_HALT:
|
||||
return 0;
|
||||
break;
|
||||
default:
|
||||
st.loadItem(item);
|
||||
return st.getPercents255();
|
||||
}
|
||||
}
|
||||
*/
|
||||
int out_Motor::Poll(short cause)
|
||||
{
|
||||
if (cause==POLLING_SLOW) return 0;
|
||||
|
||||
@@ -24,7 +24,6 @@ public:
|
||||
int Setup() override;
|
||||
int Poll(short cause) override;
|
||||
int Stop() override;
|
||||
int Status() override;
|
||||
//int isActive() override;
|
||||
int getChanType() override;
|
||||
int getDefaultStorageType(){return ST_PERCENTS255;};
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
#include "item.h"
|
||||
#include "main.h"
|
||||
|
||||
static int driverStatus = CST_UNKNOWN;
|
||||
|
||||
void out_Multivent::getConfig()
|
||||
{
|
||||
@@ -46,7 +45,7 @@ if (gatesObj /*&& aJson.getArraySize(item->itemArg)>=2*/)
|
||||
i=i->next;
|
||||
}
|
||||
debugSerial << F ("MultiVent init")<< endl;
|
||||
driverStatus = CST_INITIALIZED;
|
||||
setStatus(CST_INITIALIZED);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -58,30 +57,10 @@ return 0;
|
||||
int out_Multivent::Stop()
|
||||
{
|
||||
debugSerial << F ("Multivent De-Init") << endl;
|
||||
driverStatus = CST_UNKNOWN;
|
||||
setStatus(CST_UNKNOWN);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int out_Multivent::Status()
|
||||
{
|
||||
return driverStatus;
|
||||
}
|
||||
/*
|
||||
int out_Multivent::isActive()
|
||||
{
|
||||
itemCmd st;
|
||||
switch (item->getCmd())
|
||||
{
|
||||
case CMD_OFF:
|
||||
case CMD_HALT:
|
||||
return 0;
|
||||
break;
|
||||
default:
|
||||
st.loadItem(item);
|
||||
return st.getPercents255();
|
||||
}
|
||||
}
|
||||
*/
|
||||
int out_Multivent::Poll(short cause)
|
||||
{
|
||||
return 0;
|
||||
@@ -93,7 +72,6 @@ int out_Multivent::getChanType()
|
||||
}
|
||||
|
||||
|
||||
|
||||
int out_Multivent::Ctrl(itemCmd cmd, char* subItem , bool toExecute, bool authorized)
|
||||
{
|
||||
|
||||
|
||||
@@ -15,7 +15,6 @@ public:
|
||||
int Setup() override;
|
||||
int Poll(short cause) override;
|
||||
int Stop() override;
|
||||
int Status() override;
|
||||
//int isActive() override;
|
||||
int getChanType() override;
|
||||
int getDefaultStorageType(){return ST_PERCENTS255;};
|
||||
|
||||
@@ -125,12 +125,12 @@ if (getConfig())
|
||||
// if (item->getCmd()) item->setFlag(FLAG_COMMAND);
|
||||
// if (item->itemVal) item->setFlag(FLAG_PARAMETERS);
|
||||
store->prevOut = -2.0;
|
||||
store->driverStatus = CST_INITIALIZED;
|
||||
setStatus(CST_INITIALIZED);
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{ errorSerial<<F("PID: config error")<<endl;
|
||||
store->driverStatus = CST_FAILED;
|
||||
setStatus(CST_FAILED);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -147,12 +147,6 @@ store = NULL;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int out_pid::Status()
|
||||
{
|
||||
if (store)
|
||||
return store->driverStatus;
|
||||
return CST_UNKNOWN;
|
||||
}
|
||||
|
||||
int out_pid::isActive()
|
||||
{
|
||||
|
||||
@@ -15,7 +15,6 @@ public:
|
||||
double input;
|
||||
double setpoint;
|
||||
float prevOut;
|
||||
int driverStatus;
|
||||
uint32_t alarmTimer;
|
||||
bool alarmArmed;
|
||||
uint16_t alarmTimeout; //in sec
|
||||
@@ -30,7 +29,6 @@ public:
|
||||
int Setup() override;
|
||||
int Poll(short cause) override;
|
||||
int Stop() override;
|
||||
int Status() override;
|
||||
int isActive() override;
|
||||
int getChanType() override;
|
||||
int getDefaultStorageType(){return ST_FLOAT;};
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
#include "main.h"
|
||||
#include "dmx.h"
|
||||
|
||||
static int driverStatus = CST_UNKNOWN;
|
||||
|
||||
#if defined(ARDUINO_ARCH_ESP32)
|
||||
void analogWrite(int pin, int val)
|
||||
@@ -55,7 +54,7 @@ switch (getChanType())
|
||||
TCCR3B |= tval;
|
||||
#endif
|
||||
|
||||
driverStatus = CST_INITIALIZED;
|
||||
setStatus(CST_INITIALIZED);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -75,15 +74,10 @@ switch (getChanType())
|
||||
default:
|
||||
pinMode(iaddr, INPUT);
|
||||
}
|
||||
driverStatus = CST_UNKNOWN;
|
||||
setStatus(CST_UNKNOWN);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int out_pwm::Status()
|
||||
{
|
||||
return driverStatus;
|
||||
}
|
||||
|
||||
|
||||
int out_pwm::getChanType()
|
||||
{
|
||||
|
||||
@@ -13,7 +13,7 @@ public:
|
||||
out_pwm(Item * _item):colorChannel(_item){numChannels=0;};
|
||||
int Setup() override;
|
||||
int Stop() override;
|
||||
int Status() override;
|
||||
|
||||
|
||||
int getChanType() override;
|
||||
//int Ctrl(itemCmd cmd, char* subItem=NULL) override;
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
#include "main.h"
|
||||
#include "dmx.h"
|
||||
#include "utils.h"
|
||||
static int driverStatus = CST_UNKNOWN;
|
||||
|
||||
void out_relay::getConfig()
|
||||
{
|
||||
@@ -43,7 +42,7 @@ digitalWrite(pin,INACTIVE);
|
||||
if (item) item->setExt(0);
|
||||
//if (item->getCmd()) item->setFlag(FLAG_COMMAND);
|
||||
//if (item->itemVal) item->setFlag(FLAG_PARAMETERS);
|
||||
driverStatus = CST_INITIALIZED;
|
||||
setStatus(CST_INITIALIZED);
|
||||
if (item->isActive()>0) ///????
|
||||
{
|
||||
item->setExt(millisNZ());
|
||||
@@ -55,24 +54,10 @@ int out_relay::Stop()
|
||||
{
|
||||
debugSerial<<F("Relay-Out #")<<pin<<F(" stop")<<endl;
|
||||
pinMode(pin, INPUT);
|
||||
driverStatus = CST_UNKNOWN;
|
||||
setStatus(CST_UNKNOWN);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int out_relay::Status()
|
||||
{
|
||||
return driverStatus;
|
||||
}
|
||||
/*
|
||||
const char action_P[] PROGMEM = "action";
|
||||
const char cooling_P[] PROGMEM = "cooling";
|
||||
const char heating_P[] PROGMEM = "heating";
|
||||
const char drying_P[] PROGMEM = "drying";
|
||||
const char idle_P[] PROGMEM = "idle";
|
||||
const char fan_P[] PROGMEM = "fan";
|
||||
const char off_P[] PROGMEM = "off";
|
||||
*/
|
||||
|
||||
void out_relay::relay(bool state)
|
||||
{
|
||||
char subtopic[10]="/";
|
||||
|
||||
@@ -15,7 +15,6 @@ public:
|
||||
int Setup() override;
|
||||
int Poll(short cause) override;
|
||||
int Stop() override;
|
||||
int Status() override;
|
||||
|
||||
int getChanType() override;
|
||||
int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true, bool authorized = false) override;
|
||||
|
||||
@@ -24,7 +24,6 @@ static CRGB *leds = NULL;
|
||||
|
||||
#define NUM_LEDS 43
|
||||
|
||||
static int driverStatus = CST_UNKNOWN;
|
||||
|
||||
void out_SPILed::getConfig()
|
||||
{
|
||||
@@ -63,7 +62,7 @@ FastLED.addLeds<CONTROLLER, DATA_PIN, ORDER>(leds, numLeds);
|
||||
#endif
|
||||
}
|
||||
|
||||
driverStatus = CST_INITIALIZED;
|
||||
setStatus(CST_INITIALIZED);
|
||||
return 1;
|
||||
}
|
||||
|
||||
@@ -78,15 +77,11 @@ delete leds;
|
||||
FastLED.clear(true);
|
||||
delete [] leds;
|
||||
#endif
|
||||
driverStatus = CST_UNKNOWN;
|
||||
setStatus(CST_UNKNOWN);
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int out_SPILed::Status()
|
||||
{
|
||||
return driverStatus;
|
||||
}
|
||||
|
||||
|
||||
int out_SPILed::getChanType()
|
||||
|
||||
@@ -18,7 +18,6 @@ public:
|
||||
out_SPILed(Item * _item):colorChannel(_item){getConfig();};
|
||||
int Setup() override;
|
||||
int Stop() override;
|
||||
int Status() override;
|
||||
int getChanType() override;
|
||||
//int Ctrl(short cmd, short n=0, int * Parameters=NULL, int suffixCode=0, char* subItem=NULL) override;
|
||||
//int Ctrl(itemCmd cmd, char* subItem=NULL) override;
|
||||
|
||||
@@ -121,12 +121,12 @@ if (!store)
|
||||
if (getConfig())
|
||||
{
|
||||
infoSerial<<F("UARTbridge config loaded ")<< item->itemArr->name<<endl;
|
||||
store->driverStatus = CST_INITIALIZED;
|
||||
setStatus(CST_INITIALIZED)
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{ errorSerial<<F("UARTbridge config error")<<endl;
|
||||
store->driverStatus = CST_FAILED;
|
||||
setStatus(CST_FAILED);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@@ -146,12 +146,6 @@ store = NULL;
|
||||
return 1;
|
||||
}
|
||||
|
||||
int out_UARTbridge::Status()
|
||||
{
|
||||
if (store)
|
||||
return store->driverStatus;
|
||||
return CST_UNKNOWN;
|
||||
}
|
||||
|
||||
String _RR_A;
|
||||
String _WR_A;
|
||||
|
||||
@@ -43,8 +43,7 @@
|
||||
class ubPersistent : public chPersistent {
|
||||
|
||||
public:
|
||||
// int addr
|
||||
int8_t driverStatus;
|
||||
|
||||
int baud;
|
||||
serialParamType serialParam;
|
||||
//uint16_t pollingInterval;
|
||||
@@ -63,7 +62,6 @@ public:
|
||||
int Setup() override;
|
||||
int Poll(short cause) override;
|
||||
int Stop() override;
|
||||
int Status() override;
|
||||
int getChanType() override;
|
||||
int Ctrl(itemCmd cmd, char* subItem=NULL, bool toExecute=true, bool authorized = false) override;
|
||||
int getDefaultStorageType(){return ST_INT32;};
|
||||
|
||||
@@ -26,8 +26,10 @@ e-mail anklimov@gmail.com
|
||||
#include "options.h"
|
||||
#include "main.h"
|
||||
#include "aJSON.h"
|
||||
//#include "twi.h"
|
||||
|
||||
extern aJsonObject *owArr;
|
||||
extern uint32_t timerCtr;
|
||||
aJsonObject *dev2Check = NULL;
|
||||
|
||||
OneWire *oneWire = NULL;
|
||||
@@ -96,6 +98,7 @@ int owUpdate() {
|
||||
while (oneWire->wireSearch(dev) > 0)
|
||||
{
|
||||
wdt_res();
|
||||
// owIdle();
|
||||
char addrstr[17];
|
||||
SetBytes(dev, 8, addrstr);
|
||||
addrstr[16] = 0;
|
||||
@@ -112,45 +115,7 @@ int owUpdate() {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
if (oneWire) oneWire->reset_search();
|
||||
for (short i = 0; i < t_count; i++) wstat[i] &= ~SW_FIND; //absent
|
||||
|
||||
while (oneWire && oneWire->wireSearch(term[t_count]) > 0 && (t_count < t_max) && !isTimeOver(finish,millis(), OW_UPDATE_INTERVAL))//&& finish > millis())
|
||||
{
|
||||
short ifind = -1;
|
||||
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;
|
||||
wstat[i] |= SW_FIND;
|
||||
debugSerial.print(F(" Node:"));
|
||||
PrintBytes(term[t_count], 8,0);
|
||||
processTemp(-1, term[t_count], 0.0); //print note
|
||||
debugSerial.println(F(" alive"));
|
||||
break;
|
||||
}; //alive
|
||||
if (ifind < 0 && sensors && !zero(term[t_count],8))
|
||||
{
|
||||
wstat[t_count] = SW_FIND; //Newly detected
|
||||
debugSerial<<F("dev#")<<t_count<<F(" Addr:");
|
||||
PrintBytes(term[t_count], 8,0);
|
||||
if processTemp(-1, term[t_count], 0.0); //print note
|
||||
debugSerial.println();
|
||||
if (term[t_count][0] == 0x28) {
|
||||
sensors->setResolution(term[t_count], TEMPERATURE_PRECISION);
|
||||
#ifdef DS2482_100_I2C_TO_1W_BRIDGE
|
||||
oneWire->setStrongPullup();
|
||||
#endif
|
||||
// sensors.requestTemperaturesByAddress(term[t_count]);
|
||||
}
|
||||
t_count++;
|
||||
}
|
||||
}//if
|
||||
} //while
|
||||
|
||||
debugSerial<<F("1-wire count: ")<<t_count<<endl;
|
||||
*/
|
||||
#endif
|
||||
return true;
|
||||
}
|
||||
@@ -161,6 +126,7 @@ int owSetup() {
|
||||
//// todo - move memory allocation to here
|
||||
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;
|
||||
oneWire = new OneWire;
|
||||
@@ -176,24 +142,11 @@ if (!oneWire)
|
||||
return false;
|
||||
}
|
||||
|
||||
/*
|
||||
term = new DeviceAddress[t_max];
|
||||
debugSerial<<F("Term. Free:")<<freeRam()<<endl;
|
||||
//regs = new int [t_max];
|
||||
wstat = new uint16_t[t_max];
|
||||
debugSerial<<F("wstat. Free:")<<freeRam()<<endl;
|
||||
if (!term || ! wstat)
|
||||
{
|
||||
errorSerial<<F("Error 1-w init #2 Free:")<<freeRam()<<endl;
|
||||
return false;
|
||||
}
|
||||
owChanged = owCh;
|
||||
*/
|
||||
|
||||
#ifdef DS2482_100_I2C_TO_1W_BRIDGE
|
||||
Wire.begin();
|
||||
if (oneWire->checkPresence()) {
|
||||
debugSerial.println(F("DS2482-100 present"));
|
||||
infoSerial.println(F("1WT: DS2482-100 present"));
|
||||
oneWire->deviceReset();
|
||||
#ifdef APU_OFF
|
||||
debugSerial.println(F("APU off"));
|
||||
@@ -204,19 +157,58 @@ if (!term || ! wstat)
|
||||
debugSerial.println(F("\tChecking for 1-Wire devices..."));
|
||||
if (oneWire->wireReset())
|
||||
debugSerial.println(F("\tReset done"));
|
||||
return true;
|
||||
}
|
||||
else
|
||||
debugSerial.println(F("\tDS2482 reset error"));
|
||||
return true;
|
||||
//return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
i2cReset();
|
||||
if (oneWire->checkPresence())
|
||||
infoSerial<<F("1WT: DS2482-100 I2C restored")<<endl;
|
||||
else
|
||||
{
|
||||
errorSerial.println(F("1WT: DS2482-100 not present"));
|
||||
return false;
|
||||
}
|
||||
}
|
||||
#else
|
||||
// software driver
|
||||
oneWire->reset();
|
||||
delay(500);
|
||||
return true;
|
||||
// return true;
|
||||
#endif //DS2482-100
|
||||
|
||||
#endif //1w is not disabled
|
||||
if (!owArr) return false;
|
||||
|
||||
if (!sensors)
|
||||
{
|
||||
// Setup sensors library and resolution
|
||||
sensors = new DallasTemperature(oneWire);
|
||||
sensors->begin();
|
||||
// IC Default 9 bit. If you have troubles consider upping it 12. Ups the delay giving the IC more time to process the temperature measurement
|
||||
|
||||
//for (short i = 0; i < t_count; i++) sensors->setResolution(term[i],TEMPERATURE_PRECISION);
|
||||
sensors->setWaitForConversion(false);
|
||||
}
|
||||
|
||||
aJsonObject *item = owArr->child;
|
||||
DeviceAddress curDev;
|
||||
while (owArr && item && SetAddr(item->name,curDev) )
|
||||
{
|
||||
debugSerial<<F("1WT: setup resolution ")<<item->name<<endl;
|
||||
sensors->setResolution(curDev,TEMPERATURE_PRECISION);
|
||||
item=item->next;
|
||||
}
|
||||
|
||||
//owUpdate();
|
||||
|
||||
return true;
|
||||
|
||||
#else //1w is not disabled
|
||||
|
||||
return false;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
@@ -247,20 +239,19 @@ int sensors_loop(void) {
|
||||
oneWire->wireReset();
|
||||
return INTERVAL_1W;
|
||||
}
|
||||
if (!oneWire->checkPresence())
|
||||
{
|
||||
infoSerial.println(F("1WT: lost DS2482-100"));
|
||||
i2cReset();
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
if (!sensors)
|
||||
if (!sensors || !owArr)
|
||||
{
|
||||
// Setup sensors library and resolution
|
||||
sensors = new DallasTemperature(oneWire);
|
||||
sensors->begin();
|
||||
// IC Default 9 bit. If you have troubles consider upping it 12. Ups the delay giving the IC more time to process the temperature measurement
|
||||
|
||||
//for (short i = 0; i < t_count; i++) sensors->setResolution(term[i],TEMPERATURE_PRECISION);
|
||||
sensors->setWaitForConversion(false);
|
||||
errorSerial<<F("1WT: not init")<<endl;
|
||||
return INTERVAL_1W;
|
||||
}
|
||||
|
||||
if (!dev2Check && owArr)
|
||||
@@ -269,13 +260,8 @@ if (!sensors)
|
||||
///owUpdate(); //every check circle - scan for new devices
|
||||
}
|
||||
|
||||
/*
|
||||
if (si >= t_count) {
|
||||
owUpdate(); //every check circle - scan for new devices
|
||||
si = 0;
|
||||
return 8000;
|
||||
}
|
||||
*/
|
||||
|
||||
setupOwIdle(&owIdle);
|
||||
DeviceAddress curDev;
|
||||
|
||||
if (dev2Check && SetAddr(dev2Check->name,curDev))
|
||||
@@ -284,12 +270,17 @@ if (!sensors)
|
||||
switch (curDev[0]) {
|
||||
|
||||
case 0x28: // Thermomerer
|
||||
sensors->setResolution(curDev,TEMPERATURE_PRECISION);
|
||||
//debugSerial<<millis()<<" "<<timerCtr<<endl;
|
||||
|
||||
t = sensors->getTempC(curDev);//*10.0;
|
||||
//owIdle();
|
||||
//debugSerial<<millis()<<" "<<timerCtr<<endl;
|
||||
processTemp(dev2Check, t);
|
||||
sensors->requestTemperaturesByAddress(curDev);
|
||||
//owIdle();
|
||||
|
||||
sensors->requestTemperaturesByAddress(curDev);
|
||||
//owIdle();
|
||||
//debugSerial<<millis()<<" "<<timerCtr<<endl;
|
||||
} //switch
|
||||
}
|
||||
|
||||
@@ -308,34 +299,7 @@ void owLoop() {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
int owFind(DeviceAddress addr) {
|
||||
for (short i = 0; i < t_count; i++) if (!memcmp(term[i], addr, 8)) return i;//find
|
||||
return -1;
|
||||
}
|
||||
|
||||
void owAdd(DeviceAddress addr) {
|
||||
#ifndef OWIRE_DISABLE
|
||||
infoSerial<<F("dev#")<<t_count<<F(" Addr:");
|
||||
PrintBytes(term[t_count], 8,0);
|
||||
infoSerial<<endl;
|
||||
|
||||
if (t_count>=t_max) return;
|
||||
if (zero(term[t_count],8)) return;
|
||||
|
||||
wstat[t_count] = SW_FIND; //Newly detected
|
||||
memcpy(term[t_count], addr, 8);
|
||||
|
||||
|
||||
#ifdef DS2482_100_I2C_TO_1W_BRIDGE
|
||||
if (term[t_count][0] == 0x28)
|
||||
oneWire->setStrongPullup();
|
||||
#endif
|
||||
t_count++;
|
||||
#endif
|
||||
}
|
||||
|
||||
*/
|
||||
#endif
|
||||
|
||||
void setupOwIdle (void (*ptr)())
|
||||
|
||||
@@ -876,5 +876,45 @@ bool checkToken(char * token, char * data)
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
bool i2cReset(){
|
||||
debugSerial.println("I2C Reset");
|
||||
|
||||
Wire.endTransmission(true);
|
||||
#if !defined(ARDUINO_ARCH_ESP8266)
|
||||
Wire.end();
|
||||
#endif
|
||||
pinMode(SCL,OUTPUT);
|
||||
pinMode(SDA,INPUT);
|
||||
//10 сигналов клок
|
||||
bool pulse=false;
|
||||
for (int i=0; i<20;i++) {
|
||||
//i2c_scl_toggle(i2c);
|
||||
digitalWrite(SCL,pulse?HIGH:LOW);
|
||||
pulse=!pulse;
|
||||
delay(10);//10us мкс
|
||||
}
|
||||
Wire.begin();
|
||||
|
||||
#ifdef DS2482_100_I2C_TO_1W_BRIDGE
|
||||
if (oneWire && oneWire->checkPresence())
|
||||
{
|
||||
oneWire->deviceReset();
|
||||
#ifndef APU_OFF
|
||||
oneWire->setActivePullup();
|
||||
#endif
|
||||
if (oneWire->wireReset())
|
||||
debugSerial.println(F("\tReset done"));
|
||||
else
|
||||
debugSerial.println(F("\tDS2482 reset error"));
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
#pragma message(VAR_NAME_VALUE(debugSerial))
|
||||
#pragma message(VAR_NAME_VALUE(SERIAL_BAUD))
|
||||
|
||||
@@ -79,3 +79,5 @@ bool getPinVal(uint8_t pin);
|
||||
int str2regSize(char * str);
|
||||
bool checkToken(char * token, char * data);
|
||||
bool isProtectedPin(short pin);
|
||||
bool i2cReset();
|
||||
|
||||
|
||||
@@ -13,9 +13,9 @@ src_dir = lighthub
|
||||
default_envs =
|
||||
; ****** UNCOMMENT single environment name for target platform below *******
|
||||
|
||||
; Arduino Mega compact build + Ethernet shield Wiznet 5100, 1-wire, thermostates.
|
||||
; Without DMX, Wiznet 5100 network driver
|
||||
; mega2560slim-5100
|
||||
; Arduino Mega compact build + Ethernet shield Wiznet 5X00, 1-wire, thermostates.
|
||||
; Without DMX, Wiznet network driver
|
||||
; mega2560slim
|
||||
|
||||
; Another Arduino Mega compact build without 1-wire, DMX, but with OTA
|
||||
; OPTIBOOT bootloader required! https://github.com/MCUdude/MegaCore
|
||||
@@ -328,13 +328,13 @@ lib_deps =
|
||||
rweather/Crypto
|
||||
monitor_speed = 115200
|
||||
|
||||
[env:mega2560slim-5100]
|
||||
[env:mega2560slim]
|
||||
platform = atmelavr
|
||||
board = megaatmega2560
|
||||
upload_port = net:192.168.88.2:23000
|
||||
_upload_command = custom-build-flags/upload_mega2560slim-5100 $SOURCE
|
||||
_upload_command = custom-build-flags/upload_mega2560slim $SOURCE
|
||||
framework = arduino
|
||||
build_flags = !python get_build_flags.py mega2560slim-5100
|
||||
build_flags = !python get_build_flags.py mega2560slim
|
||||
extra_scripts = post:toBin.py
|
||||
lib_ignore =
|
||||
;DS2482_OneWire //UNCOMMENT for software 1-wire driver
|
||||
@@ -369,8 +369,9 @@ lib_deps =
|
||||
https://github.com/anklimov/CmdArduino
|
||||
;https://github.com/anklimov/ModbusMaster
|
||||
;https://github.com/anklimov/DMXSerial
|
||||
https://github.com/anklimov/Ethernet5100
|
||||
;https://github.com/anklimov/Ethernet5100
|
||||
;5100 lib have ~90 bytes less footprint of RAM
|
||||
https://github.com/anklimov/Ethernet.git
|
||||
https://github.com/anklimov/pubsubclient.git
|
||||
;https://github.com/anklimov/Artnet.git
|
||||
;FastLED@3.3.2
|
||||
|
||||
Reference in New Issue
Block a user