thermferm/thermferm.c

changeset 238
a0f1deb65889
parent 235
885ad8d52126
child 240
6bdda35b4a13
equal deleted inserted replaced
237:51a294d683cd 238:a0f1deb65889
39 extern int debug; 39 extern int debug;
40 extern sys_config Config; 40 extern sys_config Config;
41 #ifdef HAVE_WIRINGPI_H 41 #ifdef HAVE_WIRINGPI_H
42 extern int lcdHandle; 42 extern int lcdHandle;
43 int setupmenu = MENU_NONE; 43 int setupmenu = MENU_NONE;
44 units_list *current_unit = NULL; /* In panel editor this points to the current unit. */
44 45
45 #endif 46 #endif
46 int lcdupdate; 47 int lcdupdate;
47 #ifndef HAVE_WIRINGPI_H 48 #ifndef HAVE_WIRINGPI_H
48 pthread_t threads[4]; 49 pthread_t threads[4];
86 87
87 my_shutdown = TRUE; 88 my_shutdown = TRUE;
88 } 89 }
89 90
90 91
92
93 void show_mode(void)
94 {
95 char buf[21];
96
97 snprintf(buf, 20, "Old mode %s", UNITMODE[current_unit->mode]);
98 lcdPuts(lcdHandle, buf);
99 lcdPosition(lcdHandle, 0, 1);
100 }
101
102
103
91 #ifdef HAVE_WIRINGPI_H 104 #ifdef HAVE_WIRINGPI_H
92 void go_menu(int menu) 105 void go_menu(int menu)
93 { 106 {
107 char buf[21];
108
94 lcdClear(lcdHandle); 109 lcdClear(lcdHandle);
95 lcdPosition(lcdHandle, 0, 0); 110 lcdPosition(lcdHandle, 0, 0);
96 setupmenu = menu; 111 setupmenu = menu;
97 112
98 switch (menu) { 113 switch (menu) {
106 121
107 case MENU_TOP_UNITS: lcdPuts(lcdHandle, "Select units"); 122 case MENU_TOP_UNITS: lcdPuts(lcdHandle, "Select units");
108 break; 123 break;
109 124
110 case MENU_UNITS: lcdPuts(lcdHandle, "Choose unit:"); 125 case MENU_UNITS: lcdPuts(lcdHandle, "Choose unit:");
111 break; 126 if ((current_unit == NULL) && Config.units) {
112 127 /*
113 case MENU_MODE_OFF: lcdPuts(lcdHandle, "Set unit OFF"); 128 * First time in this menu, select the first unit.
114 break; 129 */
115 130 current_unit = Config.units;
116 case MENU_MODE_NONE: lcdPuts(lcdHandle, "Set unit NONE"); 131 lcdPosition(lcdHandle, 0, 1);
117 break; 132 lcdPuts(lcdHandle, Config.units->name);
118 133 }
119 case MENU_NONE_HEAT: lcdPuts(lcdHandle, "Switch heater"); 134 break;
120 break; 135
121 136 case MENU_MODE_OFF: show_mode();
122 case MENU_NONE_COOL: lcdPuts(lcdHandle, "Switch cooler"); 137 lcdPuts(lcdHandle, "New mode OFF");
123 break; 138 break;
124 139
125 case MENU_NONE_FAN: lcdPuts(lcdHandle, "Switch Fan"); 140 case MENU_MODE_NONE: show_mode();
126 break; 141 lcdPuts(lcdHandle, "New mode NONE");
127 142 break;
128 case MENU_MODE_BEER: lcdPuts(lcdHandle, "Set unit BEER"); 143
144 case MENU_NONE_HEAT: snprintf(buf, 20, "Set heater %s", current_unit->heater_state ? "OFF":"ON");
145 lcdPuts(lcdHandle, buf);
146 break;
147
148 case MENU_NONE_COOL: snprintf(buf, 20, "Set cooler %s", current_unit->cooler_state ? "OFF":"ON");
149 lcdPuts(lcdHandle, buf);
150 break;
151
152 case MENU_NONE_FAN: snprintf(buf, 20, "Set fan %s", current_unit->fan_state ? "OFF":"ON");
153 lcdPuts(lcdHandle, buf);
154 break;
155
156 case MENU_MODE_BEER: show_mode();
157 lcdPuts(lcdHandle, "New mode BEER");
129 break; 158 break;
130 159
131 case MENU_BEER_TEMP: lcdPuts(lcdHandle, "Set beer temp"); 160 case MENU_BEER_TEMP: lcdPuts(lcdHandle, "Set beer temp");
132 break; 161 break;
133 162
134 case MENU_MODE_FRIDGE: lcdPuts(lcdHandle, "Set unit FRIDGE"); 163 case MENU_MODE_FRIDGE: show_mode();
164 lcdPuts(lcdHandle, "New mode FRIDGE");
135 break; 165 break;
136 166
137 case MENU_FRIDGE_TEMP: lcdPuts(lcdHandle, "Set fridge temp"); 167 case MENU_FRIDGE_TEMP: lcdPuts(lcdHandle, "Set fridge temp");
138 break; 168 break;
139 169
140 case MENU_MODE_PROFILE: lcdPuts(lcdHandle, "Set unit PROFILE"); 170 case MENU_MODE_PROFILE: show_mode();
171 lcdPuts(lcdHandle, "New mode PROFILE");
141 break; 172 break;
142 173
143 case MENU_PROFILE_SELECT: lcdPuts(lcdHandle, "Select profile"); 174 case MENU_PROFILE_SELECT: lcdPuts(lcdHandle, "Select profile");
144 break; 175 break;
145 176
180 void stopLCD(void) 211 void stopLCD(void)
181 { 212 {
182 lcdClear(lcdHandle); 213 lcdClear(lcdHandle);
183 setBacklight(0); 214 setBacklight(0);
184 } 215 }
216
217
218
219 /*
220 * Change mode of current_unit
221 */
222 void change_mode(int mode)
223 {
224 if ((current_unit->mode == UNITMODE_OFF) && (mode != UNITMODE_OFF))
225 initlog(current_unit->name);
226 syslog(LOG_NOTICE, "Mode from %s to %s via panel interface", UNITMODE[current_unit->mode], UNITMODE[mode]);
227 current_unit->mode = mode;
228 /* Allways turn everything off after a mode change */
229 current_unit->PID_I_err = current_unit->PID_err_old = 0.0;
230 current_unit->heater_state = current_unit->cooler_state = current_unit->fan_state = 0;
231 device_out(current_unit->heater_address, current_unit->heater_state);
232 device_out(current_unit->cooler_address, current_unit->cooler_state);
233 device_out(current_unit->fan_address, current_unit->fan_state);
234 if (current_unit->mode == UNITMODE_PROFILE) {
235 /*
236 * Set a sane default until it will be overruled by the
237 * main processing loop.
238 */
239 current_unit->prof_target = 20.0;
240 }
241 }
242
243
185 #endif 244 #endif
186 245
187 246
188 247
189 int read_sensor(char *address, int *val) 248 int read_sensor(char *address, int *val)
415 } 474 }
416 } 475 }
417 476
418 477
419 #ifdef HAVE_WIRINGPI_H 478 #ifdef HAVE_WIRINGPI_H
420 lcd_buf_write(1, (char *)" ThermFerm "); 479 lcd_buf_write(1, (char *)" ThermFerm ");
421 lcd_buf_write(2, (char *)" Version %s ", VERSION); 480 lcd_buf_write(2, (char *)" Version %s ", VERSION);
422 #endif 481 #endif
423 482
424 for (unit = Config.units; unit; unit = unit->next) { 483 for (unit = Config.units; unit; unit = unit->next) {
425 if (unit->mode != UNITMODE_OFF) { 484 if (unit->mode != UNITMODE_OFF) {
863 go_menu(MENU_NONE); 922 go_menu(MENU_NONE);
864 if (key == KEY_DOWN) 923 if (key == KEY_DOWN)
865 go_menu(MENU_TOP_SYS); 924 go_menu(MENU_TOP_SYS);
866 if (key == KEY_UP) 925 if (key == KEY_UP)
867 go_menu(MENU_TOP_DEFAULT); 926 go_menu(MENU_TOP_DEFAULT);
927 if (key == KEY_ENTER)
928 go_menu(MENU_UNITS);
929 break;
930
931 case MENU_UNITS:
932 if (key == KEY_ESCAPE)
933 go_menu(MENU_TOP_UNITS);
934 if (key == KEY_DOWN) {
935 for (unit = Config.units; unit; unit = unit->next) {
936 if (strcmp(unit->uuid, current_unit->uuid) == 0) { /* Current unit */
937 if (unit->next) { /* Is there a next */
938 unit = unit->next; /* Select that */
939 lcdPosition(lcdHandle, 0, 1);
940 lcdPuts(lcdHandle, Config.units->name);
941 }
942 }
943 }
944 }
945 if (key == KEY_ENTER) {
946 for (unit = Config.units; unit; unit = unit->next) {
947 if (strcmp(unit->uuid, current_unit->uuid) == 0) {
948 if (unit->mode == UNITMODE_OFF)
949 go_menu(MENU_MODE_NONE);
950 else
951 go_menu(MENU_MODE_OFF);
952 }
953 }
954 }
955 break;
956
957 case MENU_MODE_OFF:
958 if (key == KEY_ESCAPE)
959 go_menu(MENU_UNITS);
960 if (key == KEY_DOWN)
961 go_menu(MENU_MODE_NONE);
962 if (key == KEY_UP)
963 go_menu(MENU_MODE_PROFILE);
964 if (key == KEY_ENTER) {
965 change_mode(UNITMODE_OFF);
966 go_menu(MENU_MODE_OFF);
967 }
968 break;
969
970 case MENU_MODE_NONE:
971 if (key == KEY_ESCAPE)
972 go_menu(MENU_UNITS);
973 if (key == KEY_DOWN)
974 go_menu(MENU_MODE_FRIDGE);
975 if (key == KEY_UP)
976 go_menu(MENU_MODE_OFF);
977 if (key == KEY_ENTER) {
978 if (current_unit->mode == UNITMODE_NONE)
979 go_menu(MENU_NONE_HEAT);
980 else {
981 change_mode(UNITMODE_NONE);
982 go_menu(MENU_MODE_NONE);
983 }
984 }
985 break;
986
987 case MENU_NONE_HEAT:
988 if (key == KEY_ESCAPE)
989 go_menu(MENU_MODE_NONE);
990 if (key == KEY_DOWN)
991 go_menu(MENU_NONE_COOL);
992 if (key == KEY_UP)
993 go_menu(MENU_NONE_FAN);
994 if (key == KEY_ENTER) {
995 if (current_unit->heater_state)
996 current_unit->heater_state = 0;
997 else
998 current_unit->heater_state = 100;
999 go_menu(MENU_NONE_HEAT);
1000 }
1001 break;
1002
1003 case MENU_NONE_COOL:
1004 if (key == KEY_ESCAPE)
1005 go_menu(MENU_MODE_NONE);
1006 if (key == KEY_DOWN)
1007 go_menu(MENU_NONE_FAN);
1008 if (key == KEY_UP)
1009 go_menu(MENU_NONE_HEAT);
1010 if (key == KEY_ENTER) {
1011 if (current_unit->cooler_state)
1012 current_unit->cooler_state = 0;
1013 else
1014 current_unit->cooler_state = 100;
1015 go_menu(MENU_NONE_COOL);
1016 }
1017 break;
1018
1019 case MENU_NONE_FAN:
1020 if (key == KEY_ESCAPE)
1021 go_menu(MENU_MODE_NONE);
1022 if (key == KEY_DOWN)
1023 go_menu(MENU_NONE_HEAT);
1024 if (key == KEY_UP)
1025 go_menu(MENU_NONE_COOL);
1026 if (key == KEY_ENTER) {
1027 if (current_unit->fan_state)
1028 current_unit->fan_state = 0;
1029 else
1030 current_unit->fan_state = 100;
1031 go_menu(MENU_NONE_FAN);
1032 }
1033 break;
1034
1035 case MENU_MODE_FRIDGE:
1036 if (key == KEY_ESCAPE)
1037 go_menu(MENU_UNITS);
1038 if (key == KEY_DOWN)
1039 go_menu(MENU_MODE_BEER);
1040 if (key == KEY_UP)
1041 go_menu(MENU_MODE_NONE);
1042 if (key == KEY_ENTER) {
1043 change_mode(UNITMODE_FRIDGE);
1044 go_menu(MENU_MODE_FRIDGE);
1045 }
1046 break;
1047
1048 case MENU_FRIDGE_TEMP:
1049 break;
1050
1051 case MENU_MODE_BEER:
1052 if (key == KEY_ESCAPE)
1053 go_menu(MENU_UNITS);
1054 if (key == KEY_DOWN)
1055 go_menu(MENU_MODE_PROFILE);
1056 if (key == KEY_UP)
1057 go_menu(MENU_MODE_FRIDGE);
1058 if (key == KEY_ENTER) {
1059 change_mode(UNITMODE_BEER);
1060 go_menu(MENU_MODE_BEER);
1061 }
1062 break;
1063
1064 case MENU_BEER_TEMP:
1065 break;
1066
1067 case MENU_MODE_PROFILE:
1068 if (key == KEY_ESCAPE)
1069 go_menu(MENU_UNITS);
1070 if (key == KEY_DOWN)
1071 go_menu(MENU_MODE_OFF);
1072 if (key == KEY_UP)
1073 go_menu(MENU_MODE_BEER);
1074 if (key == KEY_ENTER) {
1075 change_mode(UNITMODE_PROFILE);
1076 go_menu(MENU_MODE_PROFILE);
1077 }
1078 break;
1079
1080 case MENU_PROFILE_SELECT:
1081 break;
1082
1083 case MENU_PROFILE_START:
1084 break;
1085
1086 case MENU_PROFILE_PAUSE:
1087 break;
1088
1089 case MENU_PROFILE_ABORT:
1090 break;
1091
1092 case MENU_PROFILE_RESUME:
1093 break;
1094
1095 case MENU_PROFILE_GOOFF:
868 break; 1096 break;
869 1097
870 case MENU_TOP_SYS: 1098 case MENU_TOP_SYS:
871 if (key == KEY_ESCAPE) 1099 if (key == KEY_ESCAPE)
872 go_menu(MENU_NONE); 1100 go_menu(MENU_NONE);

mercurial