Fri, 27 Nov 2015 22:56:00 +0100
Added simulator configuration.
438 | 1 | /***************************************************************************** |
2 | * Copyright (C) 2015 | |
3 | * | |
4 | * Michiel Broek <mbroek at mbse dot eu> | |
5 | * | |
6 | * This file is part of the mbsePi-apps | |
7 | * | |
8 | * This is free software; you can redistribute it and/or modify it | |
9 | * under the terms of the GNU General Public License as published by the | |
10 | * Free Software Foundation; either version 2, or (at your option) any | |
11 | * later version. | |
12 | * | |
13 | * mbsePi-apps is distributed in the hope that it will be useful, but | |
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 | * General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License | |
19 | * along with ThermFerm; see the file COPYING. If not, write to the Free | |
20 | * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. | |
21 | *****************************************************************************/ | |
22 | ||
23 | #include "brewco.h" | |
24 | #include "simulator.h" | |
25 | ||
26 | #ifdef USE_SIMULATOR | |
27 | ||
28 | extern int my_shutdown; | |
29 | extern int debug; | |
30 | extern sys_config Config; | |
31 | ||
32 | int SIM_hlt_value = 0; | |
33 | int SIM_mlt_value = 0; | |
34 | ||
35 | ||
36 | #ifdef HAVE_WIRINGPI_H | |
37 | PI_THREAD (my_simulator_loop) | |
38 | #else | |
39 | void *my_simulator_loop(void *threadid) | |
40 | #endif | |
41 | { | |
42 | time_t now, last = (time_t)0; | |
43 | int seconds = 0; | |
44 | // double hlt_heat_transfer, mlt_heat_transfer; | |
45 | // double vhc_air = 0.00121, vhc_water = 4.1796; | |
46 | ||
47 | syslog(LOG_NOTICE, "Thread my_simulator_loop started"); | |
48 | if (debug) | |
49 | fprintf(stdout, "Thread my_simulator_loop started\n"); | |
50 | ||
51 | /* | |
52 | * Heater and cooler have the air temperature | |
53 | */ | |
54 | Config.simulator->hlt_heater_temp = Config.simulator->mlt_heater_temp = Config.simulator->room_temperature; | |
55 | ||
56 | for (;;) { | |
57 | if (my_shutdown) | |
58 | break; | |
59 | ||
60 | now = time(NULL); | |
61 | if (now != last) { | |
62 | last = now; | |
63 | /* | |
64 | * Each second | |
65 | */ | |
66 | seconds++; | |
67 | ||
68 | /* | |
69 | * First calculate the heat loss for the HLT and MLT liquids. | |
70 | * Then decrease both liquid temperatures. | |
71 | */ | |
72 | ||
73 | /* | |
74 | * If heating, calculate the heating element temperature. | |
75 | * If not heating, shift towards the liquid temperature. | |
76 | */ | |
77 | ||
78 | /* | |
79 | * Shift the liquid temperature towards the heating elements temperature, | |
80 | * but never higher then 100 degrees celcius. | |
81 | */ | |
82 | ||
83 | /* | |
84 | * If heating, calculate temperature of the heating plate. If heating is off but | |
85 | * the plate is warmer then the air, calculate the cooling down temperature. | |
86 | * Finally, calculate the new air and plate temperature. | |
87 | */ | |
88 | ||
89 | // syslog(LOG_NOTICE, "air=%.3f beer=%.3f heater=%.3f cooler=%.3f", simulator->air_temperature, simulator->beer_temperature, | |
90 | // simulator->s_heat_temp, simulator->s_cool_temp); | |
91 | ||
92 | // if (debug) | |
93 | // 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", | |
94 | // sqm_room_air, simulator->air_temperature, air_heat_transfer, air_change, | |
95 | // sqm_beer_air, simulator->beer_temperature, beer_heat_transfer); | |
96 | } | |
97 | usleep(100000); | |
98 | } | |
99 | ||
100 | syslog(LOG_NOTICE, "Thread my_simulator_loop stopped"); | |
101 | if (debug) | |
102 | fprintf(stdout, "Thread my_simulator_loop stopped\n"); | |
103 | return 0; | |
104 | } | |
105 | ||
106 | ||
107 | #endif |