mirror of
https://github.com/anklimov/lighthub
synced 2025-12-07 20:29:50 +03:00
MASSIVE refactoring. /set scale changed 100 -> 255
This commit is contained in:
@@ -2177,129 +2177,3 @@ publishStat();
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
|
||||
|
||||
bool isThermostatWithMinArraySize(aJsonObject *item, int minimalArraySize) {
|
||||
return (item->type == aJson_Array) && (aJson.getArrayItem(item, I_TYPE)->valueint == CH_THERMO) &&
|
||||
(aJson.getArraySize(item) >= minimalArraySize);
|
||||
}
|
||||
|
||||
bool thermoDisabledOrDisconnected(aJsonObject *thermoExtensionArray, int thermoStateCommand) {
|
||||
if (aJson.getArrayItem(thermoExtensionArray, IET_ATTEMPTS)->valueint == 0) return true;
|
||||
switch (thermoStateCommand) {
|
||||
case CMD_ON:
|
||||
case CMD_XON:
|
||||
case CMD_AUTO:
|
||||
case CMD_HEAT:
|
||||
return false;
|
||||
default: return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
//TODO: refactoring
|
||||
void thermoLoop(void) {
|
||||
// if (millis() < timerThermostatCheck)
|
||||
if (!isTimeOver(timerThermostatCheck,millis(),THERMOSTAT_CHECK_PERIOD))
|
||||
return;
|
||||
if (!items) return;
|
||||
bool thermostatCheckPrinted = false;
|
||||
configLocked++;
|
||||
for (aJsonObject *thermoItem = items->child; thermoItem; thermoItem = thermoItem->next) {
|
||||
if (isThermostatWithMinArraySize(thermoItem, 5)) {
|
||||
aJsonObject *thermoExtensionArray = aJson.getArrayItem(thermoItem, I_EXT);
|
||||
if (thermoExtensionArray && (aJson.getArraySize(thermoExtensionArray) > 1)) {
|
||||
|
||||
Item thermostat(thermoItem);
|
||||
if (!thermostat.isValid()) continue;
|
||||
|
||||
itemCmd thermostatCmd(&thermostat);
|
||||
|
||||
|
||||
//int thermoPin = aJson.getArrayItem(thermoItem, I_ARG)->valueint;
|
||||
int thermoPin = thermostat.getArg(0);
|
||||
|
||||
//float thermoSetting = aJson.getArrayItem(thermoItem, I_VAL)->valueint; ///
|
||||
float thermoSetting = thermostatCmd.getFloat();
|
||||
|
||||
int thermoStateCommand = aJson.getArrayItem(thermoItem, I_CMD)->valueint;
|
||||
|
||||
float curTemp = aJson.getArrayItem(thermoExtensionArray, IET_TEMP)->valuefloat;
|
||||
|
||||
if (!aJson.getArrayItem(thermoExtensionArray, IET_ATTEMPTS)->valueint) {
|
||||
errorSerial<<thermoItem->name<<F(" Expired\n");
|
||||
|
||||
} else {
|
||||
if (!(--aJson.getArrayItem(thermoExtensionArray, IET_ATTEMPTS)->valueint))
|
||||
mqttClient.publish("/alarm/snsr", thermoItem->name);
|
||||
|
||||
}
|
||||
if (curTemp > THERMO_OVERHEAT_CELSIUS) mqttClient.publish("/alarm/ovrht", thermoItem->name);
|
||||
|
||||
|
||||
debugSerial << endl << thermoItem->name << F(" Set:") << thermoSetting << F(" Cur:") << curTemp
|
||||
<< F(" cmd:") << thermoStateCommand;
|
||||
if (thermoPin<0) pinMode(-thermoPin, OUTPUT); else pinMode(thermoPin, OUTPUT);
|
||||
if (thermoDisabledOrDisconnected(thermoExtensionArray, thermoStateCommand)) {
|
||||
if (thermoPin<0) digitalWrite(-thermoPin, LOW); else digitalWrite(thermoPin, LOW);
|
||||
// Caution - for water heaters (negative pin#) if some comes wrong (or no connection with termometers output is LOW - valve OPEN)
|
||||
// OFF - also VALVE is OPEN (no teat control)
|
||||
debugSerial<<F(" OFF");
|
||||
} else {
|
||||
if (curTemp < thermoSetting - THERMO_GIST_CELSIUS) {
|
||||
if (thermoPin<0) digitalWrite(-thermoPin, LOW); else digitalWrite(thermoPin, HIGH);
|
||||
debugSerial<<F(" ON");
|
||||
} //too cold
|
||||
else if (curTemp >= thermoSetting) {
|
||||
if (thermoPin<0) digitalWrite(-thermoPin, HIGH); else digitalWrite(thermoPin, LOW);
|
||||
debugSerial<<F(" OFF");
|
||||
} //Reached settings
|
||||
else debugSerial<<F(" -target zone-"); // Nothing to do
|
||||
}
|
||||
thermostatCheckPrinted = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
configLocked--;
|
||||
timerThermostatCheck = millis();// + THERMOSTAT_CHECK_PERIOD;
|
||||
publishStat();
|
||||
#ifndef DISABLE_FREERAM_PRINT
|
||||
(thermostatCheckPrinted) ? debugSerial<<F("\nRAM=")<<freeRam()<<" " : debugSerial<<F(" ")<<freeRam()<<F(" ");
|
||||
#endif
|
||||
|
||||
|
||||
}
|
||||
|
||||
short thermoSetCurTemp(char *name, float t) {
|
||||
if (!name || !strlen(name)) return 0;
|
||||
if (items) {
|
||||
aJsonObject *thermoItem = aJson.getObjectItem(items, name);
|
||||
if (!thermoItem) return 0;
|
||||
if (isThermostatWithMinArraySize(thermoItem, 4)) {
|
||||
aJsonObject *extArray = NULL;
|
||||
|
||||
if (aJson.getArraySize(thermoItem) == 4) //No thermo extension yet
|
||||
{
|
||||
extArray = aJson.createArray(); //Create Ext Array
|
||||
|
||||
aJsonObject *ocurt = aJson.createItem(t); //Create float
|
||||
aJsonObject *oattempts = aJson.createItem((long int) T_ATTEMPTS); //Create int
|
||||
aJson.addItemToArray(extArray, ocurt);
|
||||
aJson.addItemToArray(extArray, oattempts);
|
||||
aJson.addItemToArray(thermoItem, extArray); //Adding to thermoItem
|
||||
}
|
||||
else if (extArray = aJson.getArrayItem(thermoItem, I_EXT)) {
|
||||
aJsonObject *att = aJson.getArrayItem(extArray, IET_ATTEMPTS);
|
||||
aJson.getArrayItem(extArray, IET_TEMP)->valuefloat = t;
|
||||
if (att->valueint == 0) mqttClient.publish("/alarmoff/snsr", thermoItem->name);
|
||||
att->valueint = (int) T_ATTEMPTS;
|
||||
}
|
||||
}
|
||||
return 1;}
|
||||
return 0;}
|
||||
*/
|
||||
Reference in New Issue
Block a user