diff -r 9167ad4c2e77 -r fe8bf61cde06 brewco/simulator.c --- a/brewco/simulator.c Sun Dec 27 17:52:26 2015 +0100 +++ b/brewco/simulator.c Sun Dec 27 20:21:06 2015 +0100 @@ -68,9 +68,9 @@ * Then decrease both liquid temperatures and consider the volume. */ Config.simulator->hlt_temperature -= (Config.simulator->hlt_temperature - Config.simulator->room_temperature) / - (40000 * (Config.simulator->hlt_heater_volume / 2)); + (80000 * (Config.simulator->hlt_heater_volume / 2)); Config.simulator->mlt_temperature -= (Config.simulator->mlt_temperature - Config.simulator->room_temperature) / - (40000 * (Config.simulator->mlt_heater_volume / 2)); + (80000 * (Config.simulator->mlt_heater_volume / 2)); /* * If heating, calculate the heating element temperature but not higher then 250 degrees celcius. @@ -79,19 +79,20 @@ */ Config.simulator->hlt_heater_state = SIM_hlt_value; if (SIM_hlt_value) { - Config.simulator->hlt_heater_temp += (250 - Config.simulator->hlt_heater_temp) / 2000; + Config.simulator->hlt_heater_temp += (250 - Config.simulator->hlt_heater_temp) / 2000.0 * (Config.simulator->hlt_heater_power / 2000.0); } else { Config.simulator->hlt_heater_temp -= (Config.simulator->hlt_heater_temp - Config.simulator->hlt_temperature) / 250; } Config.simulator->mlt_heater_state = SIM_mlt_value; if (SIM_mlt_value) { - Config.simulator->mlt_heater_temp += (250 - Config.simulator->mlt_heater_temp) / 2000; + Config.simulator->mlt_heater_temp += (250 - Config.simulator->mlt_heater_temp) / 2000.0 * (Config.simulator->mlt_heater_power / 2000.0); } else { Config.simulator->mlt_heater_temp -= (Config.simulator->mlt_heater_temp - Config.simulator->mlt_temperature) / 250; } /* * If cooling, bring down the MLT temperature. Assume 14 degrees coolwater. + * The cooler is turned on or off by sending SIGUSR1 or SIGUSR2 to this program. */ if (SIM_cooler) { Config.simulator->mlt_temperature -= (Config.simulator->mlt_temperature - 14) / (175 * Config.simulator->hlt_heater_volume); @@ -101,10 +102,12 @@ * Shift the liquid temperature towards the heating elements temperature, * but never higher then 100 degrees celcius. */ - Config.simulator->hlt_temperature += (Config.simulator->hlt_heater_temp - Config.simulator->hlt_temperature) / (10000 * Config.simulator->hlt_heater_volume); + Config.simulator->hlt_temperature += (Config.simulator->hlt_heater_temp - Config.simulator->hlt_temperature) / + (10000.0 * Config.simulator->hlt_heater_volume * (2000.0 / Config.simulator->hlt_heater_power)); if (Config.simulator->hlt_temperature > 100.25) Config.simulator->hlt_temperature = 100.25; - Config.simulator->mlt_temperature += (Config.simulator->mlt_heater_temp - Config.simulator->mlt_temperature) / (10000 * Config.simulator->mlt_heater_volume); + Config.simulator->mlt_temperature += (Config.simulator->mlt_heater_temp - Config.simulator->mlt_temperature) / + (10000.0 * Config.simulator->mlt_heater_volume * (2000.0 / Config.simulator->mlt_heater_power)); if (Config.simulator->mlt_temperature > 100.25) Config.simulator->mlt_temperature = 100.25; @@ -115,11 +118,11 @@ /* * Each second */ -// if (debug) -// fprintf(stdout, "HLT temp=%f plate=%f val=%d MLT temp=%f plate=%f val=%d Room %.1f loops=%d cool=%s\n", -// Config.simulator->hlt_temperature, Config.simulator->hlt_heater_temp, Config.simulator->hlt_heater_state, -// Config.simulator->mlt_temperature, Config.simulator->mlt_heater_temp, Config.simulator->mlt_heater_state, -// Config.simulator->room_temperature, loops, SIM_cooler ? "Yes":"No"); + if (debug) + fprintf(stdout, "HLT temp=%f plate=%f val=%d MLT temp=%f plate=%f val=%d Room %.1f loops=%d cool=%s\n", + Config.simulator->hlt_temperature, Config.simulator->hlt_heater_temp, Config.simulator->hlt_heater_state, + Config.simulator->mlt_temperature, Config.simulator->mlt_heater_temp, Config.simulator->mlt_heater_state, + Config.simulator->room_temperature, loops, SIM_cooler ? "Yes":"No"); loops = 0; } usleep(50000);