# HG changeset patch # User Michiel Broek # Date 1409502332 -7200 # Node ID b863e01472963f4b0aaf7b5cd2363e2195cb1644 # Parent f436d826de4b09e7dad1d198c29fdf18d602bf76 Fixed unit edit heater/cooler delay values. Heater and Cooler start/stop now use a different algorithm. diff -r f436d826de4b -r b863e0147296 thermferm/server.c --- a/thermferm/server.c Sun Aug 31 17:51:04 2014 +0200 +++ b/thermferm/server.c Sun Aug 31 18:25:32 2014 +0200 @@ -1547,7 +1547,7 @@ unit->heater_state = ival; } else if (val && (strcmp(kwd, (char *)"HEATER_DELAY") == 0)) { - if ((sscanf(val, "%d", &ival) == 1) && ((ival == 0) || (ival == 100))) + if (sscanf(val, "%d", &ival) == 1) unit->heater_delay = ival; } else if (strcmp(kwd, (char *)"COOLER_ADDRESS") == 0) { @@ -1566,7 +1566,7 @@ unit->cooler_state = ival; } else if (val && (strcmp(kwd, (char *)"COOLER_DELAY") == 0)) { - if ((sscanf(val, "%d", &ival) == 1) && ((ival == 0) || (ival == 100))) + if (sscanf(val, "%d", &ival) == 1) unit->cooler_delay = ival; } else if (strcmp(kwd, (char *)"FAN_ADDRESS") == 0) { @@ -1585,7 +1585,7 @@ unit->fan_state = ival; } else if (val && (strcmp(kwd, (char *)"FAN_DELAY") == 0)) { - if ((sscanf(val, "%d", &ival) == 1) && ((ival == 0) || (ival == 100))) + if (sscanf(val, "%d", &ival) == 1) unit->fan_delay = ival; } else if (strcmp(kwd, (char *)"DOOR_ADDRESS") == 0) { diff -r f436d826de4b -r b863e0147296 thermferm/thermferm.c --- a/thermferm/thermferm.c Sun Aug 31 17:51:04 2014 +0200 +++ b/thermferm/thermferm.c Sun Aug 31 18:25:32 2014 +0200 @@ -1287,40 +1287,47 @@ sp, pv, unit->PID_err_old, err, P_err, unit->PID_I_err, D_err, Out); } if (unit->heater_address) { - if (unit->heater_wait < unit->heater_delay) { - unit->heater_wait++; - syslog(LOG_NOTICE, "heater_wait %d/%d", unit->heater_wait, unit->heater_delay); - } else { - if (Out >= 2) { + if (Out >= 2) { + if (unit->heater_wait < unit->heater_delay) { + unit->heater_wait++; + syslog(LOG_NOTICE, "heater_wait + %d/%d", unit->heater_wait, unit->heater_delay); + } else { if (! unit->heater_state && ! unit->cooler_state) { - syslog(LOG_NOTICE, "Heater Off => On"); - unit->heater_wait = 0; - unit->heater_state = 100; + syslog(LOG_NOTICE, "Heater Off => On"); + unit->heater_state = 100; } - } else { + } + } else { + if (unit->heater_wait > 0) { + unit->heater_wait--; + syslog(LOG_NOTICE, "heater_wait - %d/%d", unit->heater_wait, unit->heater_delay); + } else { if (unit->heater_state) { - syslog(LOG_NOTICE, "Heater On => Off"); - unit->heater_wait = 0; - unit->heater_state = 0; + syslog(LOG_NOTICE, "Heater On => Off"); + unit->heater_state = 0; } - } + } } device_out(unit->heater_address, unit->heater_state); } if (unit->cooler_address) { - if (unit->cooler_wait < unit->cooler_delay) { - unit->cooler_wait++; - } else { - if (Out <= -2) { + if (Out <= -2) { + if (unit->cooler_wait < unit->cooler_delay) { + unit->cooler_wait++; + syslog(LOG_NOTICE, "cooler_wait + %d/%d", unit->cooler_wait, unit->cooler_delay); + } else { if (! unit->cooler_state && ! unit->heater_state) { syslog(LOG_NOTICE, "Cooler Off => On"); - unit->cooler_wait = 0; unit->cooler_state = 100; } + } + } else { + if (unit->cooler_wait > 0) { + unit->cooler_wait--; + syslog(LOG_NOTICE, "cooler_wait - %d/%d", unit->cooler_wait, unit->cooler_delay); } else { if (unit->cooler_state) { syslog(LOG_NOTICE, "Cooler On => Off"); - unit->cooler_wait = 0; unit->cooler_state = 0; } }