thermferm/thermferm.c

changeset 525
5855abe0e82c
parent 524
bd1ea64ae484
child 526
2f75f94d471b
equal deleted inserted replaced
524:bd1ea64ae484 525:5855abe0e82c
1063 */ 1063 */
1064 for (unit = Config.units; unit; unit = unit->next) { 1064 for (unit = Config.units; unit; unit = unit->next) {
1065 /* 1065 /*
1066 * Safety, turn everything off 1066 * Safety, turn everything off
1067 */ 1067 */
1068 unit->mqtt_flag = 0; 1068 unit->mqtt_flag = unit->alarm_flag = unit->alarm_last = 0;
1069 unit->heater_state = unit->cooler_state = unit->fan_state = unit->door_state = unit->light_state = 0; 1069 unit->heater_state = unit->cooler_state = unit->fan_state = unit->door_state = unit->light_state = 0;
1070 unit->heater_wait = unit->cooler_wait = unit->fan_wait = unit->light_wait = 0; 1070 unit->heater_wait = unit->cooler_wait = unit->fan_wait = unit->light_wait = 0;
1071 if (unit->mode == UNITMODE_PROFILE) { 1071 if (unit->mode == UNITMODE_PROFILE) {
1072 if (!unit->profile) 1072 if (!unit->profile)
1073 syslog(LOG_NOTICE, "Starting unit `%s' in profile mode, no profile defined.", unit->name); 1073 syslog(LOG_NOTICE, "Starting unit `%s' in profile mode, no profile defined.", unit->name);
1215 publishNData(false, 0); 1215 publishNData(false, 0);
1216 1216
1217 LCDunit = 0; 1217 LCDunit = 0;
1218 for (unit = Config.units; unit; unit = unit->next) { 1218 for (unit = Config.units; unit; unit = unit->next) {
1219 LCDunit++; 1219 LCDunit++;
1220 unit->mqtt_flag = 0; 1220 unit->mqtt_flag = unit->alarm_flag = 0;
1221 1221
1222 if (unit->air_address) { 1222 if (unit->air_address) {
1223 rc = device_in(unit->air_address, &temp); 1223 rc = device_in(unit->air_address, &temp);
1224 if (rc == DEVPRESENT_YES) { 1224 if (rc == DEVPRESENT_YES) {
1225 /* 1225 /*
1311 syslog(LOG_NOTICE, "Unit `%s' door opened", unit->name); 1311 syslog(LOG_NOTICE, "Unit `%s' door opened", unit->name);
1312 unit->door_state = 0; 1312 unit->door_state = 0;
1313 pub_domoticz_output(unit->door_idx, unit->door_state); 1313 pub_domoticz_output(unit->door_idx, unit->door_state);
1314 unit->mqtt_flag |= MQTT_FLAG_DATA; 1314 unit->mqtt_flag |= MQTT_FLAG_DATA;
1315 } 1315 }
1316 /*
1317 * If unit is active and the door is open
1318 */
1319 if (unit->mode != UNITMODE_NONE) {
1320 unit->alarm_flag |= ALARM_FLAG_DOOR;
1321 }
1316 } 1322 }
1317 } else { 1323 } else {
1318 unit->door_state = 1; 1324 unit->door_state = 1;
1319 } 1325 }
1320 } else { 1326 } else {
1339 syslog(LOG_NOTICE, "Unit `%s' PSU (12 volt) is off", unit->name); 1345 syslog(LOG_NOTICE, "Unit `%s' PSU (12 volt) is off", unit->name);
1340 unit->psu_state = 0; 1346 unit->psu_state = 0;
1341 pub_domoticz_output(unit->psu_idx, unit->psu_state); 1347 pub_domoticz_output(unit->psu_idx, unit->psu_state);
1342 unit->mqtt_flag |= MQTT_FLAG_DATA; 1348 unit->mqtt_flag |= MQTT_FLAG_DATA;
1343 } 1349 }
1350 unit->alarm_flag |= ALARM_FLAG_PSU;
1344 } 1351 }
1345 } else { 1352 } else {
1346 unit->psu_state = 1; 1353 unit->psu_state = 1;
1347 } 1354 }
1348 } else { 1355 } else {
1655 * Prevent cooling if we use a chiller and the chiller temperature is not low enough. 1662 * Prevent cooling if we use a chiller and the chiller temperature is not low enough.
1656 */ 1663 */
1657 if (unit->chiller_address && (unit->chiller_state == 0)) { 1664 if (unit->chiller_address && (unit->chiller_state == 0)) {
1658 if ((unit->chiller_temperature / 1000.0) > (unit->PID_cool->Input - 1)) { 1665 if ((unit->chiller_temperature / 1000.0) > (unit->PID_cool->Input - 1)) {
1659 unit->PID_cool->OutP = 0.0; 1666 unit->PID_cool->OutP = 0.0;
1667 unit->alarm_flag |= ALARM_FLAG_CHILLER;
1660 } 1668 }
1661 } 1669 }
1662 if (debug) 1670 if (debug)
1663 fprintf(stdout, "Cool: sp=%.2f Input=%.2f iState=%.2f Err=%.2f Out=%.2f\n", 1671 fprintf(stdout, "Cool: sp=%.2f Input=%.2f iState=%.2f Err=%.2f Out=%.2f\n",
1664 unit->PID_cool->SetP, unit->PID_cool->Input, unit->PID_cool->iState, unit->PID_cool->Err, unit->PID_cool->OutP); 1672 unit->PID_cool->SetP, unit->PID_cool->Input, unit->PID_cool->iState, unit->PID_cool->Err, unit->PID_cool->OutP);
1838 * Publish MQTT messages set in flag 1846 * Publish MQTT messages set in flag
1839 */ 1847 */
1840 if (unit->mqtt_flag) { 1848 if (unit->mqtt_flag) {
1841 publishDData(unit); 1849 publishDData(unit);
1842 } 1850 }
1851
1852 /*
1853 * Handle changed alarms
1854 */
1855 if (unit->alarm_flag != unit->alarm_last) {
1856 syslog(LOG_NOTICE, "Unit `%s' Alarm %d => %d", unit->name, unit->alarm_last, unit->alarm_flag);
1857 unit->alarm_last = unit->alarm_flag;
1858 }
1843 } /* for units */ 1859 } /* for units */
1844 1860
1845 #ifdef HAVE_WIRINGPI_H 1861 #ifdef HAVE_WIRINGPI_H
1846 piLock(LOCK_MENU); 1862 piLock(LOCK_MENU);
1847 #endif 1863 #endif

mercurial