diff --git a/lighthub/item.cpp b/lighthub/item.cpp index 5a4c50b..66716a3 100644 --- a/lighthub/item.cpp +++ b/lighthub/item.cpp @@ -20,6 +20,7 @@ e-mail anklimov@gmail.com #include "options.h" #include "item.h" #include "aJSON.h" +#include "utils.h" #ifdef _dmxout @@ -197,21 +198,18 @@ boolean Item::getEnableCMD(int delta) { return ((millis() - lastctrl > (unsigned long) delta));// || ((void *)itemArr != (void *) lastobj)); } -int Item::Ctrl(short cmd, short n, int *Par, boolean send) { +#define MAXCTRLPAR 3 +int Item::Ctrl(short cmd, short n, int *Parameters, boolean send) { - Serial.print(F("Cmd=")); - Serial.println(cmd); - //va_list vl; + + Serial.print(F("Cmd="));Serial.print(cmd);Serial.print(F(" MEM="));Serial.println(freeRam()); - int _Par[3] = {0, 0, 0}; - if (Par == NULL) Par = _Par; + int Par[MAXCTRLPAR] = {0, 0, 0}; + if (Parameters) + for (short i=0;i 0) //Stored smthng @@ -311,25 +310,31 @@ int Item::Ctrl(short cmd, short n, int *Par, boolean send) { switch (itemType) { case CH_VCTEMP: - Par[0] = 20; - break; - default: + case CH_THERMO: + Par[0] = 20; //20 degrees celsium - safe temperature + params = 1; + SendStatus(0, params, Par); + break; + case CH_RGBW: + case CH_RGB: Par[0] = 100; Par[1] = 0; Par[2] = 100; + params = 3; + SendStatus(0, params, Par,true); + break; + default: + Par[0] = 100; + params = 1; + SendStatus(0, params, Par); } } - - for (short i = 0; i < params; i++) { Serial.print(F("Restored: ")); Serial.print(i); Serial.print(F("=")); Serial.println(Par[i]); } - - - if (send) setCmd(cmd); } else { //Double ON - apply special preset - clean white full power if (getEnableCMD(500)) switch (itemType) { case CH_RGBW: @@ -730,7 +735,7 @@ int Item::VacomSetHeat(int addr, int8_t val, int8_t cmd) { regval = round(((float) val - b) * 10 / a); } - Serial.println(regval); + //Serial.println(regval); node.writeSingleRegister(2004 - 1, regval); modbusBusy = 0; } @@ -913,7 +918,7 @@ int Item::checkFM() { int pwr = node.getResponseBuffer(3); if (pwr > 0) aJson.addNumberToObject(out, "pwr", pwr / 10.); else aJson.addNumberToObject(out, "pwr", 0); - if (ftemp>fset+FM_OVERHEAT_CELSIUS) + if (ftemp>fset+FM_OVERHEAT_CELSIUS && set) { mqttClient.publish("/alarm/ovrht", itemArr->name); Ctrl(CMD_OFF); //Shut down @@ -1025,12 +1030,15 @@ int Item::Poll() { break; case CH_VC: checkFM(); + sendDelayedStatus(); return INTERVAL_CHECK_MODBUS; break; case CH_RGB: //All channels with slider generate too many updates case CH_RGBW: case CH_DIMMER: - case CH_PWM: + case CH_PWM: + case CH_VCTEMP: + case CH_THERMO: sendDelayedStatus(); } return INTERVAL_POLLING; diff --git a/lighthub/item.h b/lighthub/item.h index bc5bbbe..72db496 100644 --- a/lighthub/item.h +++ b/lighthub/item.h @@ -87,7 +87,7 @@ class Item Item(char * name); Item(aJsonObject * obj); boolean isValid (); - virtual int Ctrl(short cmd, short n=0, int * Par=NULL, boolean send=true); + virtual int Ctrl(short cmd, short n=0, int * Parameters=NULL, boolean send=true); int getArg(short n=0); boolean getEnableCMD(int delta); //int getVal(short n); //From VAL array. Negative if no array diff --git a/lighthub/main.cpp b/lighthub/main.cpp index 676cc87..fdaa00e 100644 --- a/lighthub/main.cpp +++ b/lighthub/main.cpp @@ -1,4 +1,5 @@ -/* +/* Copyright © 2017-2018 Andrey Klimov. All rights reserved. + * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at @@ -33,27 +34,35 @@ e-mail anklimov@gmail.com * 1-w relay out * Termostat out -Todo +Todo (backlog) === -A/C control/Dimmer ? -rotary encoder local ctrl +rotary encoder local ctrl ? analog in local ctrl Smooth regulation/fading -PID Termostat out +PID Termostat out ? dmx relay out Relay array channel Relay DMX array channel -Config URL configuration +Config URL & MQTT password commandline configuration +1-wire Update refactoring (save memory) +Static IP +Topic configuration +Timer +Modbus response check +control/debug (Commandline) over MQTT +more Modbus dimmers todo DUE related: -HTTP PWM freq fix Config webserver +SSL todo ESP: -Ethernet - to wifi portation -DMX-OUT deploy on USART1 Config webserver +SSL + +ESP32 +PWM Out */ diff --git a/lighthub/options.h b/lighthub/options.h index a949e7b..b0aaf45 100644 --- a/lighthub/options.h +++ b/lighthub/options.h @@ -1,6 +1,6 @@ // Configuration of drivers enabled #ifndef PIO_SRC_REV -#define PIO_SRC_REV v0.993 +#define PIO_SRC_REV v0.994 #endif #define TXEnablePin 13