Sat, 28 Nov 2015 21:00:29 +0100
Split some sources
442 | 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 "slcd.h" | |
25 | #include "setup.h" | |
26 | #include "prompt.h" | |
27 | #include "xutil.h" | |
28 | #include "keyboard.h" | |
29 | ||
30 | ||
31 | extern int my_shutdown; | |
32 | extern int debug; | |
33 | extern sys_config Config; | |
34 | extern int lcdHandle; | |
35 | extern int slcdHandle; | |
36 | ||
37 | ||
38 | ||
39 | void editUnit(units_list *unit) | |
40 | { | |
41 | if (debug) | |
42 | fprintf(stdout, "Start edit brewsystem %d %s\n", unit->number, unit->uuid); | |
43 | ||
44 | if (debug) | |
45 | fprintf(stdout, "End edit brewsystem %d %s\n", unit->number, unit->uuid); | |
46 | } | |
47 | ||
48 | ||
49 | ||
50 | void addUnit(int number) | |
51 | { | |
52 | units_list *tmpu, *unit = (units_list *)malloc(sizeof(units_list)); | |
53 | char name[81]; | |
54 | uuid_t uu; | |
55 | ||
56 | if (debug) | |
57 | fprintf(stdout, "Adding new brewsystem %d\n", number); | |
58 | unit->next = NULL; | |
59 | unit->version = 1; | |
60 | unit->uuid = malloc(37); | |
61 | uuid_generate(uu); | |
62 | uuid_unparse(uu, unit->uuid); | |
63 | snprintf(name, 20, "System %d", number); | |
64 | unit->name = xstrcpy(name); | |
65 | unit->number = number; | |
66 | if (number == 1) | |
67 | unit->active = 1; | |
68 | else | |
69 | unit->active = 0; | |
70 | unit->hlt_sensor = unit->mlt_sensor = NULL; | |
71 | unit->hlt_heater = unit->mlt_heater = unit->mlt_pump = NULL; | |
72 | unit->hlt_heater_mltfirst = 1; | |
73 | unit->pump_cycle = 7; | |
74 | unit->pump_rest = 2; | |
75 | unit->pump_premash = 1; | |
76 | unit->pump_onmash = 1; | |
77 | unit->pump_mashout = 0; | |
78 | unit->pump_onboil = 0; | |
79 | unit->pump_stop = 90; | |
80 | unit->skip_add = 0; | |
81 | unit->skip_remove = 0; | |
82 | unit->skip_iodine = 0; | |
83 | unit->iodine_time = 90; | |
84 | unit->whirlpool = 1; | |
85 | unit->PID_hlt = (pid_var *)malloc(sizeof(pid_var)); | |
86 | unit->PID_mlt = (pid_var *)malloc(sizeof(pid_var)); | |
87 | InitPID(unit->PID_hlt); | |
88 | InitPID(unit->PID_mlt); | |
89 | ||
90 | editUnit(unit); | |
91 | ||
92 | if (Config.units == NULL) { | |
93 | Config.units = unit; | |
94 | } else { | |
95 | for (tmpu = Config.units; tmpu; tmpu = tmpu->next) { | |
96 | if (tmpu->next == NULL) { | |
97 | tmpu->next = unit; | |
98 | break; | |
99 | } | |
100 | } | |
101 | } | |
102 | syslog(LOG_NOTICE, "Brewsystem %d added to the configuration", number); | |
103 | if (debug) | |
104 | fprintf(stdout, "Brewsystem %d added to the configuration\n", number); | |
105 | } | |
106 | ||
107 | ||
108 | ||
109 | void setup(void) | |
110 | { | |
111 | int key, option = 202; | |
112 | ||
113 | for (;;) { | |
114 | if (debug) | |
115 | fprintf(stdout, "setup() option=%d\n", option); | |
116 | prompt(0); | |
117 | prompt(102); | |
118 | prompt(option); | |
119 | if (option == 202) | |
120 | prompt(402); | |
121 | #ifdef USE_SIMULATOR | |
122 | else if (option == 205) | |
123 | #else | |
124 | else if (option == 204) | |
125 | #endif | |
126 | prompt(404); | |
127 | else | |
128 | prompt(403); | |
129 | ||
130 | key = keywait(); | |
131 | ||
132 | if ((key == KEY_RETURN) || my_shutdown) | |
133 | return; | |
134 | if ((key == KEY_UP) && (option > 202)) { | |
135 | option--; | |
136 | } | |
137 | #ifdef USE_SIMULATOR | |
138 | if ((key == KEY_DOWN) && (option < 205)) { | |
139 | #else | |
140 | if ((key == KEY_DOWN) && (option < 204)) { | |
141 | #endif | |
142 | option++; | |
143 | } | |
144 | ||
145 | } | |
146 | } | |
147 | ||
148 |