diff -r c92651a54969 -r 468ec0d96cce thermferm/simulator.c --- a/thermferm/simulator.c Sat May 16 17:39:30 2015 +0200 +++ b/thermferm/simulator.c Sun May 17 19:34:55 2015 +0200 @@ -49,6 +49,13 @@ if (debug) fprintf(stdout, "Thread my_simulator_loop started\n"); + for (simulator = Config.simulators; simulator; simulator = simulator->next) { + /* + * Heater and cooler have the air temperature + */ + simulator->s_heat_temp = simulator->s_cool_temp = simulator->room_temperature; + } + for (;;) { for (simulator = Config.simulators; simulator; simulator = simulator->next) { if (my_shutdown) @@ -81,7 +88,11 @@ * Finally, calculate the new air and plate temperature. */ if (SIMheating) { - simulator->air_temperature += 0.01; + if (simulator->s_heat_temp < simulator->heater_temp) + simulator->s_heat_temp += 0.05; + } else { + if (simulator->s_heat_temp > simulator->room_temperature) + simulator->s_heat_temp -= 0.05; } /* @@ -90,9 +101,16 @@ * Finsally, calculate the new air and plate temperature. */ if (SIMcooling) { - simulator->air_temperature -= 0.01; + if (simulator->s_cool_temp > simulator->cooler_temp) + simulator->s_cool_temp -= 0.05; + } else { + if (simulator->s_cool_temp < simulator->room_temperature) + simulator->s_cool_temp += 0.05; } + simulator->air_temperature += ((simulator->s_heat_temp - simulator->air_temperature) / 50.0); + simulator->air_temperature -= ((simulator->air_temperature - simulator->s_cool_temp) / 50.0); + /* * Calculate the extra beer temperatur rise to simulate the heat produced by the * fermentation process. Peak about one day after start and slowly decrease after @@ -107,6 +125,12 @@ /* * Calculate final temperature of the beer and the air. */ + // Cheap trick, just follow slowly the air temp. + simulator->beer_temperature += ((simulator->air_temperature - simulator->beer_temperature) / 200.0); + + syslog(LOG_NOTICE, "air=%.3f beer=%.3f heater=%.3f cooler=%.3f", simulator->air_temperature, simulator->beer_temperature, + simulator->s_heat_temp, simulator->s_cool_temp); + if (debug) fprintf(stdout, "sqm_room_air=%f air=%f air_heat_transfer=%f air_change=%f sqm_beer_air=%f beer=%f beer_heat_transfer=%f\n", sqm_room_air, simulator->air_temperature, air_heat_transfer, air_change,