thermferm/thermferm.c

changeset 270
df81d583c2c3
parent 268
dda91dfa4aa8
child 273
b863e0147296
equal deleted inserted replaced
269:dc88583a068d 270:df81d583c2c3
250 syslog(LOG_NOTICE, "Mode from %s to %s via panel interface", UNITMODE[current_unit->mode], UNITMODE[mode]); 250 syslog(LOG_NOTICE, "Mode from %s to %s via panel interface", UNITMODE[current_unit->mode], UNITMODE[mode]);
251 current_unit->mode = mode; 251 current_unit->mode = mode;
252 /* Allways turn everything off after a mode change */ 252 /* Allways turn everything off after a mode change */
253 current_unit->PID_I_err = current_unit->PID_err_old = 0.0; 253 current_unit->PID_I_err = current_unit->PID_err_old = 0.0;
254 current_unit->heater_state = current_unit->cooler_state = current_unit->fan_state = 0; 254 current_unit->heater_state = current_unit->cooler_state = current_unit->fan_state = 0;
255 current_unit->heater_wait = current_unit->cooler_wait = current_unit->fan_wait = 0;
255 device_out(current_unit->heater_address, current_unit->heater_state); 256 device_out(current_unit->heater_address, current_unit->heater_state);
256 device_out(current_unit->cooler_address, current_unit->cooler_state); 257 device_out(current_unit->cooler_address, current_unit->cooler_state);
257 device_out(current_unit->fan_address, current_unit->fan_state); 258 device_out(current_unit->fan_address, current_unit->fan_state);
258 if (current_unit->mode == UNITMODE_PROFILE) { 259 if (current_unit->mode == UNITMODE_PROFILE) {
259 /* 260 /*
913 for (unit = Config.units; unit; unit = unit->next) { 914 for (unit = Config.units; unit; unit = unit->next) {
914 /* 915 /*
915 * Safety, turn everything off 916 * Safety, turn everything off
916 */ 917 */
917 unit->heater_state = unit->cooler_state = unit->fan_state = unit->door_state = 0; 918 unit->heater_state = unit->cooler_state = unit->fan_state = unit->door_state = 0;
919 unit->heater_wait = unit->cooler_wait = unit->fan_wait = 0;
918 if (unit->mode == UNITMODE_PROFILE) { 920 if (unit->mode == UNITMODE_PROFILE) {
919 if (!unit->profile) 921 if (!unit->profile)
920 syslog(LOG_NOTICE, "Starting unit %s in profile mode, no profile defined.", unit->name); 922 syslog(LOG_NOTICE, "Starting unit %s in profile mode, no profile defined.", unit->name);
921 else 923 else
922 syslog(LOG_NOTICE, "Starting unit %s in profile state %s.", unit->name, PROFSTATE[unit->prof_state]); 924 syslog(LOG_NOTICE, "Starting unit %s in profile state %s.", unit->name, PROFSTATE[unit->prof_state]);
1283 sp, pv, unit->PID_err_old, err, P_err, unit->PID_I_err, D_err, Out); 1285 sp, pv, unit->PID_err_old, err, P_err, unit->PID_I_err, D_err, Out);
1284 syslog(LOG_NOTICE, "sp=%.2f pv=%.2f err_old=%.2f err=%.2f P_err=%.2f I_err=%.2f D_err=%.2f Out=%.2f", 1286 syslog(LOG_NOTICE, "sp=%.2f pv=%.2f err_old=%.2f err=%.2f P_err=%.2f I_err=%.2f D_err=%.2f Out=%.2f",
1285 sp, pv, unit->PID_err_old, err, P_err, unit->PID_I_err, D_err, Out); 1287 sp, pv, unit->PID_err_old, err, P_err, unit->PID_I_err, D_err, Out);
1286 } 1288 }
1287 if (unit->heater_address) { 1289 if (unit->heater_address) {
1288 if (Out >= 2) { 1290 if (unit->heater_wait < unit->heater_delay) {
1289 if (! unit->heater_state) 1291 unit->heater_wait++;
1290 syslog(LOG_NOTICE, "Heater Off => On"); 1292 syslog(LOG_NOTICE, "heater_wait %d/%d", unit->heater_wait, unit->heater_delay);
1291 unit->heater_state = 100;
1292 } else { 1293 } else {
1293 if (unit->heater_state) 1294 if (Out >= 2) {
1294 syslog(LOG_NOTICE, "Heater On => Off"); 1295 if (! unit->heater_state && ! unit->cooler_state) {
1295 unit->heater_state = 0; 1296 syslog(LOG_NOTICE, "Heater Off => On");
1297 unit->heater_wait = 0;
1298 unit->heater_state = 100;
1299 }
1300 } else {
1301 if (unit->heater_state) {
1302 syslog(LOG_NOTICE, "Heater On => Off");
1303 unit->heater_wait = 0;
1304 unit->heater_state = 0;
1305 }
1306 }
1296 } 1307 }
1297 device_out(unit->heater_address, unit->heater_state); 1308 device_out(unit->heater_address, unit->heater_state);
1298 } 1309 }
1299 if (unit->cooler_address) { 1310 if (unit->cooler_address) {
1300 if (Out <= -2) { 1311 if (unit->cooler_wait < unit->cooler_delay) {
1301 if (! unit->cooler_state) 1312 unit->cooler_wait++;
1302 syslog(LOG_NOTICE, "Cooler Off => On");
1303 unit->cooler_state = 100;
1304 } else { 1313 } else {
1305 if (unit->cooler_state) 1314 if (Out <= -2) {
1306 syslog(LOG_NOTICE, "Cooler On => Off"); 1315 if (! unit->cooler_state && ! unit->heater_state) {
1307 unit->cooler_state = 0; 1316 syslog(LOG_NOTICE, "Cooler Off => On");
1317 unit->cooler_wait = 0;
1318 unit->cooler_state = 100;
1319 }
1320 } else {
1321 if (unit->cooler_state) {
1322 syslog(LOG_NOTICE, "Cooler On => Off");
1323 unit->cooler_wait = 0;
1324 unit->cooler_state = 0;
1325 }
1326 }
1308 } 1327 }
1309 device_out(unit->cooler_address, unit->cooler_state); 1328 device_out(unit->cooler_address, unit->cooler_state);
1310 } 1329 }
1311 if (unit->heater_address && unit->cooler_address && unit->fan_address) { 1330 if (unit->heater_address && unit->cooler_address && unit->fan_address) {
1312 /* 1331 /*
1420 for (unit = Config.units; unit; unit = unit->next) { 1439 for (unit = Config.units; unit; unit = unit->next) {
1421 /* 1440 /*
1422 * Turn everything off 1441 * Turn everything off
1423 */ 1442 */
1424 unit->heater_state = unit->cooler_state = unit->fan_state = unit->door_state = 0; 1443 unit->heater_state = unit->cooler_state = unit->fan_state = unit->door_state = 0;
1444 unit->heater_wait = unit->cooler_wait = unit->fan_wait = 0;
1425 device_out(unit->heater_address, unit->heater_state); 1445 device_out(unit->heater_address, unit->heater_state);
1426 device_out(unit->cooler_address, unit->cooler_state); 1446 device_out(unit->cooler_address, unit->cooler_state);
1427 device_out(unit->fan_address, unit->fan_state); 1447 device_out(unit->fan_address, unit->fan_state);
1428 syslog(LOG_NOTICE, "Stopped unit %s mode %s", unit->name, UNITMODE[unit->mode]); 1448 syslog(LOG_NOTICE, "Stopped unit %s mode %s", unit->name, UNITMODE[unit->mode]);
1429 } 1449 }

mercurial