# HG changeset patch # User Michiel Broek # Date 1409396767 -7200 # Node ID df81d583c2c311131bdadec43a59d1929d7a46f9 # Parent dc88583a068d8e121f8b373fc7bc49b7dd560f5b The PID commands have an adjustable delay, default 5 minutes diff -r dc88583a068d -r df81d583c2c3 thermferm/rdconfig.c --- a/thermferm/rdconfig.c Tue Aug 26 14:45:03 2014 +0200 +++ b/thermferm/rdconfig.c Sat Aug 30 13:06:07 2014 +0200 @@ -350,6 +350,10 @@ syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); return 1; } + if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "HEATER_DELAY", "%d", tmp3->heater_delay)) < 0)) { + syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); + return 1; + } } if (tmp3->cooler_address) { if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "COOLER_ADDRESS", "%s", tmp3->cooler_address)) < 0)) { @@ -360,6 +364,10 @@ syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); return 1; } + if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "COOLER_DELAY", "%d", tmp3->cooler_delay)) < 0)) { + syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); + return 1; + } } if (tmp3->fan_address) { if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "FAN_ADDRESS", "%s", tmp3->fan_address)) < 0)) { @@ -370,6 +378,10 @@ syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); return 1; } + if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "FAN_DELAY", "%d", tmp3->fan_delay)) < 0)) { + syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement"); + return 1; + } } if (tmp3->door_address) { if (((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "DOOR_ADDRESS", "%s", tmp3->door_address)) < 0)) { @@ -837,6 +849,8 @@ unit->air_temperature = unit->beer_temperature = unit->beer_set = unit->fridge_set = 20.0; unit->air_state = unit->beer_state = 1; // missing unit->heater_state = unit->cooler_state = unit->fan_state = unit->door_state = unit->mode = unit->prof_state = 0; + unit->heater_delay = unit->cooler_delay = unit->fan_delay = 20; /* 5 minutes delay */ + unit->heater_wait = unit->cooler_wait = unit->fan_wait = 0; unit->temp_set_min = 1.0; unit->temp_set_max = 30.0; unit->idle_rangeH = 1.0; @@ -900,12 +914,30 @@ if ((!xmlStrcmp(cur->name, (const xmlChar *)"HEATER_ADDRESS"))) { unit->heater_address = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); } + if ((!xmlStrcmp(cur->name, (const xmlChar *)"HEATER_DELAY"))) { + key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); + if (sscanf((const char *)key, "%d", &ival) == 1) + unit->heater_delay = ival; + xmlFree(key); + } if ((!xmlStrcmp(cur->name, (const xmlChar *)"COOLER_ADDRESS"))) { unit->cooler_address = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); } + if ((!xmlStrcmp(cur->name, (const xmlChar *)"COOLER_DELAY"))) { + key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); + if (sscanf((const char *)key, "%d", &ival) == 1) + unit->cooler_delay = ival; + xmlFree(key); + } if ((!xmlStrcmp(cur->name, (const xmlChar *)"FAN_ADDRESS"))) { unit->fan_address = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); } + if ((!xmlStrcmp(cur->name, (const xmlChar *)"FAN_DELAY"))) { + key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); + if (sscanf((const char *)key, "%d", &ival) == 1) + unit->fan_delay = ival; + xmlFree(key); + } if ((!xmlStrcmp(cur->name, (const xmlChar *)"DOOR_ADDRESS"))) { unit->door_address = (char *)xmlNodeListGetString(doc, cur->xmlChildrenNode, 1); } diff -r dc88583a068d -r df81d583c2c3 thermferm/server.c --- a/thermferm/server.c Tue Aug 26 14:45:03 2014 +0200 +++ b/thermferm/server.c Sat Aug 30 13:06:07 2014 +0200 @@ -1350,6 +1350,8 @@ unit->air_temperature = unit->beer_temperature = 20000; unit->beer_set = unit->fridge_set = 20.0; unit->heater_state = unit->cooler_state = unit->fan_state = unit->door_state = unit->mode = unit->prof_state = 0; + unit->heater_delay = unit->cooler_delay = unit->fan_delay = 20; /* 5 minutes delay */ + unit->heater_wait = unit->cooler_wait = unit->fan_wait = 0; unit->temp_set_min = 1.0; unit->temp_set_max = 30.0; unit->idle_rangeH = 1.0; @@ -1429,10 +1431,13 @@ srv_send((char *)"BEER_TEMPERATURE,%.3f", unit->beer_temperature / 1000.0); srv_send((char *)"HEATER_ADDRESS,%s", unit->heater_address); srv_send((char *)"HEATER_STATE,%d", unit->heater_state); + srv_send((char *)"HEATER_DELAY,%d", unit->heater_delay); srv_send((char *)"COOLER_ADDRESS,%s", unit->cooler_address); srv_send((char *)"COOLER_STATE,%d", unit->cooler_state); + srv_send((char *)"COOLER_DELAY,%d", unit->cooler_delay); srv_send((char *)"FAN_ADDRESS,%s", unit->fan_address); srv_send((char *)"FAN_STATE,%d", unit->fan_state); + srv_send((char *)"FAN_DELAY,%d", unit->fan_delay); srv_send((char *)"DOOR_ADDRESS,%s", unit->door_address); srv_send((char *)"DOOR_STATE,%d", unit->door_state); srv_send((char *)"MODE,%s", UNITMODE[unit->mode]); @@ -1541,6 +1546,10 @@ if ((sscanf(val, "%d", &ival) == 1) && ((ival == 0) || (ival == 100))) unit->heater_state = ival; + } else if (val && (strcmp(kwd, (char *)"HEATER_DELAY") == 0)) { + if ((sscanf(val, "%d", &ival) == 1) && ((ival == 0) || (ival == 100))) + unit->heater_delay = ival; + } else if (strcmp(kwd, (char *)"COOLER_ADDRESS") == 0) { if (unit->cooler_address) { device_count(FALSE, unit->cooler_address); @@ -1556,6 +1565,10 @@ if ((sscanf(val, "%d", &ival) == 1) && ((ival == 0) || (ival == 100))) unit->cooler_state = ival; + } else if (val && (strcmp(kwd, (char *)"COOLER_DELAY") == 0)) { + if ((sscanf(val, "%d", &ival) == 1) && ((ival == 0) || (ival == 100))) + unit->cooler_delay = ival; + } else if (strcmp(kwd, (char *)"FAN_ADDRESS") == 0) { if (unit->fan_address) { device_count(FALSE, unit->fan_address); @@ -1571,6 +1584,10 @@ if ((sscanf(val, "%d", &ival) == 1) && ((ival == 0) || (ival == 100))) unit->fan_state = ival; + } else if (val && (strcmp(kwd, (char *)"FAN_DELAY") == 0)) { + if ((sscanf(val, "%d", &ival) == 1) && ((ival == 0) || (ival == 100))) + unit->fan_delay = ival; + } else if (strcmp(kwd, (char *)"DOOR_ADDRESS") == 0) { if (unit->door_address) { device_count(FALSE, unit->door_address); @@ -1593,6 +1610,7 @@ /* Allways turn everything off after a mode change */ unit->PID_I_err = unit->PID_err_old = 0.0; unit->heater_state = unit->cooler_state = unit->fan_state = 0; + unit->heater_wait = unit->cooler_wait = unit->fan_wait = 0; device_out(unit->heater_address, unit->heater_state); device_out(unit->cooler_address, unit->cooler_state); device_out(unit->fan_address, unit->fan_state); @@ -1635,6 +1653,7 @@ */ unit->PID_I_err = unit->PID_err_old = 0.0; unit->heater_state = unit->cooler_state = unit->fan_state = 0; + unit->heater_wait = unit->cooler_wait = unit->fan_wait = 0; device_out(unit->heater_address, unit->heater_state); device_out(unit->cooler_address, unit->cooler_state); device_out(unit->fan_address, unit->fan_state); diff -r dc88583a068d -r df81d583c2c3 thermferm/thermferm.c --- a/thermferm/thermferm.c Tue Aug 26 14:45:03 2014 +0200 +++ b/thermferm/thermferm.c Sat Aug 30 13:06:07 2014 +0200 @@ -252,6 +252,7 @@ /* Allways turn everything off after a mode change */ current_unit->PID_I_err = current_unit->PID_err_old = 0.0; current_unit->heater_state = current_unit->cooler_state = current_unit->fan_state = 0; + current_unit->heater_wait = current_unit->cooler_wait = current_unit->fan_wait = 0; device_out(current_unit->heater_address, current_unit->heater_state); device_out(current_unit->cooler_address, current_unit->cooler_state); device_out(current_unit->fan_address, current_unit->fan_state); @@ -915,6 +916,7 @@ * Safety, turn everything off */ unit->heater_state = unit->cooler_state = unit->fan_state = unit->door_state = 0; + unit->heater_wait = unit->cooler_wait = unit->fan_wait = 0; if (unit->mode == UNITMODE_PROFILE) { if (!unit->profile) syslog(LOG_NOTICE, "Starting unit %s in profile mode, no profile defined.", unit->name); @@ -1285,26 +1287,43 @@ sp, pv, unit->PID_err_old, err, P_err, unit->PID_I_err, D_err, Out); } if (unit->heater_address) { - if (Out >= 2) { - if (! unit->heater_state) - syslog(LOG_NOTICE, "Heater Off => On"); - unit->heater_state = 100; + 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) - syslog(LOG_NOTICE, "Heater On => Off"); - unit->heater_state = 0; + if (Out >= 2) { + if (! unit->heater_state && ! unit->cooler_state) { + syslog(LOG_NOTICE, "Heater Off => On"); + unit->heater_wait = 0; + unit->heater_state = 100; + } + } else { + if (unit->heater_state) { + syslog(LOG_NOTICE, "Heater On => Off"); + unit->heater_wait = 0; + unit->heater_state = 0; + } + } } device_out(unit->heater_address, unit->heater_state); } if (unit->cooler_address) { - if (Out <= -2) { - if (! unit->cooler_state) - syslog(LOG_NOTICE, "Cooler Off => On"); - unit->cooler_state = 100; + if (unit->cooler_wait < unit->cooler_delay) { + unit->cooler_wait++; } else { - if (unit->cooler_state) - syslog(LOG_NOTICE, "Cooler On => Off"); - unit->cooler_state = 0; + if (Out <= -2) { + 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_state) { + syslog(LOG_NOTICE, "Cooler On => Off"); + unit->cooler_wait = 0; + unit->cooler_state = 0; + } + } } device_out(unit->cooler_address, unit->cooler_state); } @@ -1422,6 +1441,7 @@ * Turn everything off */ unit->heater_state = unit->cooler_state = unit->fan_state = unit->door_state = 0; + unit->heater_wait = unit->cooler_wait = unit->fan_wait = 0; device_out(unit->heater_address, unit->heater_state); device_out(unit->cooler_address, unit->cooler_state); device_out(unit->fan_address, unit->fan_state); diff -r dc88583a068d -r df81d583c2c3 thermferm/thermferm.h --- a/thermferm/thermferm.h Tue Aug 26 14:45:03 2014 +0200 +++ b/thermferm/thermferm.h Sat Aug 30 13:06:07 2014 +0200 @@ -113,11 +113,17 @@ int beer_state; /* 0=ok, 1=missing, 2=error */ int beer_temperature; /* Beer temperature in C * 1000 */ char *heater_address; /* Heater relay or PWM */ - int heater_state; /* Heater status */ + int heater_state; /* Heater state 0..100 */ + int heater_delay; /* Heater delay time /15 sec */ + int heater_wait; /* Heater wait counter */ char *cooler_address; /* Cooler relay or PWM */ - int cooler_state; /* Cooler status */ + int cooler_state; /* Cooler state 0..100 */ + int cooler_delay; /* Cooler delay time /15 sec */ + int cooler_wait; /* Cooler wait counter */ char *fan_address; /* Fan relay or PWM */ - int fan_state; /* Fan status */ + int fan_state; /* Fan state 0..100 */ + int fan_delay; /* Fan delay time /15 sec */ + int fan_wait; /* Fan wait counter */ char *door_address; /* Door input address */ int door_state; /* Door and light status */ int mode; /* Unit mode */