thermferm/thermferm.c

Sat, 30 Apr 2016 21:06:20 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Sat, 30 Apr 2016 21:06:20 +0200
changeset 497
18ace27338e5
parent 496
5cf6f099c897
child 498
4903b4da9d40
permissions
-rw-r--r--

Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4

26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1 /*****************************************************************************
326
ae34b47700bb Changed die() handler
Michiel Broek <mbroek@mbse.eu>
parents: 321
diff changeset
2 * Copyright (C) 2014-2015
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
3 *
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
4 * Michiel Broek <mbroek at mbse dot eu>
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
5 *
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
6 * This file is part of the mbsePi-apps
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
7 *
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
8 * This is free software; you can redistribute it and/or modify it
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
9 * under the terms of the GNU General Public License as published by the
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
10 * Free Software Foundation; either version 2, or (at your option) any
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
11 * later version.
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
12 *
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
13 * mbsePi-apps is distributed in the hope that it will be useful, but
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
16 * General Public License for more details.
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
17 *
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
213
2317b8d644fa Code cleanup, streamlined error messages.
Michiel Broek <mbroek@mbse.eu>
parents: 209
diff changeset
19 * along with ThermFerm; see the file COPYING. If not, write to the Free
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
20 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
21 *****************************************************************************/
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
22
106
1bd9a16f5061 Added .h files
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
23 #include "lock.h"
1bd9a16f5061 Added .h files
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
24 #include "logger.h"
1bd9a16f5061 Added .h files
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
25 #include "rdconfig.h"
160
87bfa951ffc2 Fixed wrong includes
Michiel Broek <mbroek@mbse.eu>
parents: 158
diff changeset
26 #include "devices.h"
106
1bd9a16f5061 Added .h files
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
27 #include "server.h"
41
f534ace74eea Code preparation for client/server communication
Michiel Broek <mbroek@mbse.eu>
parents: 40
diff changeset
28 #include "thermferm.h"
259
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 248
diff changeset
29 #include "simulator.h"
106
1bd9a16f5061 Added .h files
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
30 #include "lcd-pcf8574.h"
1bd9a16f5061 Added .h files
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
31 #include "lcd-buffer.h"
420
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents: 418
diff changeset
32 #include "slcd.h"
198
20716bcff2b0 Added dependencies for panel
Michiel Broek <mbroek@mbse.eu>
parents: 195
diff changeset
33 #include "panel.h"
106
1bd9a16f5061 Added .h files
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
34 #include "futil.h"
1bd9a16f5061 Added .h files
Michiel Broek <mbroek@mbse.eu>
parents: 105
diff changeset
35 #include "xutil.h"
316
73cd31dc6ce1 Moved pid function to separate files
Michiel Broek <mbroek@mbse.eu>
parents: 315
diff changeset
36 #include "pid.h"
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
37
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
38
75
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 74
diff changeset
39 int my_shutdown = FALSE;
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
40 static pid_t pgrp, mypid;
245
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
41 int run_pause = FALSE;
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
42 int run_hold = FALSE;
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
43
75
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 74
diff changeset
44 extern int debug;
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
45 extern sys_config Config;
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
46 extern int lcdHandle;
420
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents: 418
diff changeset
47 extern int slcdHandle;
205
ca18ff45deba Start initial menu setup
Michiel Broek <mbroek@mbse.eu>
parents: 204
diff changeset
48 int setupmenu = MENU_NONE;
238
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
49 units_list *current_unit = NULL; /* In panel editor this points to the current unit. */
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
50 profiles_list *current_profile = NULL;
246
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
51 float temp_temp = 20.0;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
52
74
879bd09e2b96 Reinstalled threads
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
53 #ifndef HAVE_WIRINGPI_H
259
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 248
diff changeset
54 pthread_t threads[5];
74
879bd09e2b96 Reinstalled threads
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
55 #endif
104
5e538c4e1ecb Added units logging
Michiel Broek <mbroek@mbse.eu>
parents: 93
diff changeset
56 extern const char UNITMODE[5][8];
195
b34a1b2421fb Reset output when a different profile is selected. Better startup logging about the unit state. Added Beer, Fridge and partial Profile settings from the liveview weeb screen.
Michiel Broek <mbroek@mbse.eu>
parents: 194
diff changeset
57 extern const char PROFSTATE[4][6];
104
5e538c4e1ecb Added units logging
Michiel Broek <mbroek@mbse.eu>
parents: 93
diff changeset
58
420
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents: 418
diff changeset
59 extern int sock;
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents: 418
diff changeset
60
40
dafbbd5e9922 Prepared unix socket communication
Michiel Broek <mbroek@mbse.eu>
parents: 34
diff changeset
61
484
7362ebd40f26 Use user defined characters for the LCD display just like in Arduino projects.
Michiel Broek <mbroek@mbse.eu>
parents: 481
diff changeset
62 unsigned char degC[8] = { 0b01000, 0b10100, 0b01000, 0b00111, 0b01000, 0b01000, 0b01000, 0b00111 }; // [1] degree c sybmol
7362ebd40f26 Use user defined characters for the LCD display just like in Arduino projects.
Michiel Broek <mbroek@mbse.eu>
parents: 481
diff changeset
63 unsigned char SP_Symbol[8] = { 0b11100, 0b10000, 0b11100, 0b00111, 0b11101, 0b00111, 0b00100, 0b00100 }; // [2] SP Symbol
7362ebd40f26 Use user defined characters for the LCD display just like in Arduino projects.
Michiel Broek <mbroek@mbse.eu>
parents: 481
diff changeset
64 unsigned char CoolONOFF[8] = { 0b00000, 0b01110, 0b01000, 0b01000, 0b01000, 0b01000, 0b01110, 0b00000 }; // [3] Cool Symbol
7362ebd40f26 Use user defined characters for the LCD display just like in Arduino projects.
Michiel Broek <mbroek@mbse.eu>
parents: 481
diff changeset
65 unsigned char RevCoolONOFF[8] = { 0b11111, 0b10001, 0b10111, 0b10111, 0b10111, 0b10111, 0b10001, 0b11111 }; // [4] Reverse Cool Symbol
7362ebd40f26 Use user defined characters for the LCD display just like in Arduino projects.
Michiel Broek <mbroek@mbse.eu>
parents: 481
diff changeset
66 unsigned char HeatONOFF[8] = { 0b00000, 0b01010, 0b01010, 0b01110, 0b01110, 0b01010, 0b01010, 0b00000 }; // [5] HEAT symbol
7362ebd40f26 Use user defined characters for the LCD display just like in Arduino projects.
Michiel Broek <mbroek@mbse.eu>
parents: 481
diff changeset
67 unsigned char RevHeatONOFF[8] = { 0b11111, 0b10101, 0b10101, 0b10001, 0b10001, 0b10101, 0b10101, 0b11111 }; // [6] reverse HEAT symbol
7362ebd40f26 Use user defined characters for the LCD display just like in Arduino projects.
Michiel Broek <mbroek@mbse.eu>
parents: 481
diff changeset
68
7362ebd40f26 Use user defined characters for the LCD display just like in Arduino projects.
Michiel Broek <mbroek@mbse.eu>
parents: 481
diff changeset
69
497
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
70 #ifdef HAVE_MOSQUITTO_H
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
71
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
72 #define STATUS_CONNECTING 0
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
73 #define STATUS_CONNACK_RECVD 1
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
74 #define STATUS_WAITING 2
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
75
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
76 /* Global variables for use in callbacks. */
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
77 static int mqtt_qos = 0;
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
78 static int mqtt_status = STATUS_CONNECTING;
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
79 static int mqtt_mid_sent = 0;
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
80 static int mqtt_last_mid = -1;
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
81 static int mqtt_last_mid_sent = -1;
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
82 static int mqtt_connected = TRUE;
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
83 static int mqtt_disconnect_sent = FALSE;
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
84 static int mqtt_connect_lost = FALSE;
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
85 static int mqtt_my_shutdown = FALSE;
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
86 static int mqtt_use = FALSE;
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
87
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
88 #endif
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
89
41
f534ace74eea Code preparation for client/server communication
Michiel Broek <mbroek@mbse.eu>
parents: 40
diff changeset
90 int server(void);
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
91 void help(void);
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
92 void die(int);
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
93 void stopLCD(void);
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 64
diff changeset
94 #ifdef HAVE_WIRINGPI_H
46
000399c64d3f More client/server communications
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
95 void sendRCswitch(char *, int);
000399c64d3f More client/server communications
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
96 void stopRCswitch(void);
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 64
diff changeset
97 #endif
46
000399c64d3f More client/server communications
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
98
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
99
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
100
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
101 void help(void)
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
102 {
41
f534ace74eea Code preparation for client/server communication
Michiel Broek <mbroek@mbse.eu>
parents: 40
diff changeset
103 fprintf(stdout, "mbsePi-apps thermferm v%s starting\n\n", VERSION);
f534ace74eea Code preparation for client/server communication
Michiel Broek <mbroek@mbse.eu>
parents: 40
diff changeset
104 fprintf(stdout, "Usage: thermferm [-d] [-h]\n");
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
105 fprintf(stdout, " -d --debug Debug and run in foreground\n");
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
106 fprintf(stdout, " -h --help Display this help\n");
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
107 }
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
108
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
109
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
110
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
111 void die(int onsig)
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
112 {
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
113 switch (onsig) {
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
114 case SIGHUP: syslog(LOG_NOTICE, "Got SIGHUP, shutting down");
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
115 break;
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
116 case SIGINT: syslog(LOG_NOTICE, "Keyboard interrupt, shutting down");
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
117 break;
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
118 case SIGTERM: syslog(LOG_NOTICE, "Got SIGTERM, shutting down");
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
119 break;
326
ae34b47700bb Changed die() handler
Michiel Broek <mbroek@mbse.eu>
parents: 321
diff changeset
120 case SIGSEGV: syslog(LOG_NOTICE, "Got SIGSEGV, shutting down");
ae34b47700bb Changed die() handler
Michiel Broek <mbroek@mbse.eu>
parents: 321
diff changeset
121 my_shutdown = TRUE;
ae34b47700bb Changed die() handler
Michiel Broek <mbroek@mbse.eu>
parents: 321
diff changeset
122 exit(SIGSEGV);
ae34b47700bb Changed die() handler
Michiel Broek <mbroek@mbse.eu>
parents: 321
diff changeset
123 break;
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
124 default: syslog(LOG_NOTICE, "die() on signal %d", onsig);
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
125 }
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
126
75
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 74
diff changeset
127 my_shutdown = TRUE;
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
128 }
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
129
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
130
238
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
131
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
132 void show_mode(void)
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
133 {
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
134 char buf[21];
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
135
328
1713dc0cd20f Fixed error
Michiel Broek <mbroek@mbse.eu>
parents: 326
diff changeset
136 snprintf(buf, 20, "Old mode %s", UNITMODE[current_unit->mode]);
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
137 #ifdef HAVE_WIRINGPI_H
238
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
138 lcdPuts(lcdHandle, buf);
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
139 lcdPosition(lcdHandle, 0, 1);
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
140 #endif
420
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents: 418
diff changeset
141 slcdPuts(slcdHandle, buf);
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents: 418
diff changeset
142 slcdPosition(slcdHandle, 0, 1);
238
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
143 }
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
144
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
145
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
146
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
147 void go_menu(int menu)
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
148 {
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
149 char buf[21];
238
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
150
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
151 #ifdef HAVE_WIRINGPI_H
241
4ba138737bf4 Added thread locks to all LCD access functions. This seems to have fixed the LCD corruption problems.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
152 piLock(LOCK_LCD);
244
2f868eaefec2 Selecting units in setup does now work. Menu select variables are protected with thread locking.
Michiel Broek <mbroek@mbse.eu>
parents: 241
diff changeset
153 piLock(LOCK_MENU);
223
14700edd2a67 Removed LCD shadow copy buffer.
Michiel Broek <mbroek@mbse.eu>
parents: 221
diff changeset
154 lcdClear(lcdHandle);
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
155 lcdPosition(lcdHandle, 0, 0);
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
156 #endif
420
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents: 418
diff changeset
157 slcdClear(slcdHandle);
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents: 418
diff changeset
158 slcdPosition(slcdHandle, 0, 0);
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents: 418
diff changeset
159
244
2f868eaefec2 Selecting units in setup does now work. Menu select variables are protected with thread locking.
Michiel Broek <mbroek@mbse.eu>
parents: 241
diff changeset
160 syslog(LOG_NOTICE, "from menu %d to menu %d", setupmenu, menu);
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
161 setupmenu = menu;
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
162
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
163 switch (menu) {
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
164 case MENU_NONE:
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
165 lcd_buf_show();
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
166 break;
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
167
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
168 case MENU_TOP_DEFAULT:
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
169 #ifdef HAVE_WIRINGPI_H
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
170 lcdPuts(lcdHandle, "Setup mode.");
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
171 lcdPosition(lcdHandle, 0, 1);
223
14700edd2a67 Removed LCD shadow copy buffer.
Michiel Broek <mbroek@mbse.eu>
parents: 221
diff changeset
172 lcdPuts(lcdHandle, "Up&Down = Escape");
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
173 #endif
420
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents: 418
diff changeset
174 slcdPuts(slcdHandle, "Setup mode.");
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents: 418
diff changeset
175 slcdPosition(slcdHandle, 0, 1);
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents: 418
diff changeset
176 slcdPuts(slcdHandle, "Up&Down = Escape");
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
177 break;
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
178
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
179 case MENU_TOP_UNITS:
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
180 #ifdef HAVE_WIRINGPI_H
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
181 lcdPuts(lcdHandle, "Select units");
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
182 #endif
420
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents: 418
diff changeset
183 slcdPuts(slcdHandle, "Select units");
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
184 break;
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
185
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
186 case MENU_UNITS:
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
187 #ifdef HAVE_WIRINGPI_H
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
188 lcdPuts(lcdHandle, "Choose unit:");
244
2f868eaefec2 Selecting units in setup does now work. Menu select variables are protected with thread locking.
Michiel Broek <mbroek@mbse.eu>
parents: 241
diff changeset
189 lcdPosition(lcdHandle, 0, 1);
2f868eaefec2 Selecting units in setup does now work. Menu select variables are protected with thread locking.
Michiel Broek <mbroek@mbse.eu>
parents: 241
diff changeset
190 lcdPuts(lcdHandle, current_unit->name);
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
191 #endif
420
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents: 418
diff changeset
192 slcdPuts(slcdHandle, "Choose unit:");
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents: 418
diff changeset
193 slcdPosition(slcdHandle, 0, 1);
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents: 418
diff changeset
194 slcdPuts(slcdHandle, current_unit->name);
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
195 break;
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
196
238
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
197 case MENU_MODE_OFF: show_mode();
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
198 #ifdef HAVE_WIRINGPI_H
238
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
199 lcdPuts(lcdHandle, "New mode OFF");
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
200 #endif
420
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents: 418
diff changeset
201 slcdPuts(slcdHandle, "New mode OFF");
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
202 break;
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
203
238
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
204 case MENU_MODE_NONE: show_mode();
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
205 #ifdef HAVE_WIRINGPI_H
238
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
206 lcdPuts(lcdHandle, "New mode NONE");
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
207 #endif
420
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents: 418
diff changeset
208 slcdPuts(slcdHandle, "New mode NONE");
238
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
209 break;
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
210
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
211 case MENU_NONE_HEAT: snprintf(buf, Config.lcd_cols, "Set heater %s", current_unit->heater_state ? "OFF":"ON");
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
212 #ifdef HAVE_WIRINGPI_H
238
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
213 lcdPuts(lcdHandle, buf);
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
214 #endif
420
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents: 418
diff changeset
215 slcdPuts(slcdHandle, buf);
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
216 break;
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
217
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
218 case MENU_NONE_COOL: snprintf(buf, Config.lcd_cols, "Set cooler %s", current_unit->cooler_state ? "OFF":"ON");
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
219 #ifdef HAVE_WIRINGPI_H
238
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
220 lcdPuts(lcdHandle, buf);
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
221 #endif
420
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents: 418
diff changeset
222 slcdPuts(slcdHandle, buf);
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
223 break;
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
224
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
225 case MENU_NONE_FAN: snprintf(buf, Config.lcd_cols, "Set fan %s", current_unit->fan_state ? "OFF":"ON");
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
226 #ifdef HAVE_WIRINGPI_H
238
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
227 lcdPuts(lcdHandle, buf);
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
228 #endif
420
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents: 418
diff changeset
229 slcdPuts(slcdHandle, buf);
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
230 break;
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
231
238
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
232 case MENU_MODE_BEER: show_mode();
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
233 #ifdef HAVE_WIRINGPI_H
238
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
234 lcdPuts(lcdHandle, "New mode BEER");
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
235 #endif
488
bee1f70fb42b Small brewpanel display error fix, did not affect real hardware.
Michiel Broek <mbroek@mbse.eu>
parents: 486
diff changeset
236 slcdPuts(slcdHandle, "New mode BEER");
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
237 break;
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
238
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
239 case MENU_BEER_TEMP:
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
240 #ifdef HAVE_WIRINGPI_H
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
241 lcdPuts(lcdHandle, "Set beer temp");
246
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
242 lcdPosition(lcdHandle, 0, 1);
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
243 #endif
420
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents: 418
diff changeset
244 slcdPuts(slcdHandle, "Set beer temp");
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents: 418
diff changeset
245 slcdPosition(slcdHandle, 0, 1);
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents: 418
diff changeset
246
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
247 snprintf(buf, Config.lcd_cols, "Set %.1f", temp_temp);
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
248 #ifdef HAVE_WIRINGPI_H
246
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
249 lcdPuts(lcdHandle, buf);
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
250 #endif
420
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents: 418
diff changeset
251 slcdPuts(slcdHandle, buf);
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
252 break;
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
253
238
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
254 case MENU_MODE_FRIDGE: show_mode();
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
255 #ifdef HAVE_WIRINGPI_H
238
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
256 lcdPuts(lcdHandle, "New mode FRIDGE");
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
257 #endif
420
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents: 418
diff changeset
258 slcdPuts(slcdHandle, "New mode FRIDGE");
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
259 break;
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
260
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
261 case MENU_FRIDGE_TEMP:
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
262 #ifdef HAVE_WIRINGPI_H
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
263 lcdPuts(lcdHandle, "Set fridge temp");
246
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
264 lcdPosition(lcdHandle, 0, 1);
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
265 #endif
420
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents: 418
diff changeset
266 slcdPuts(slcdHandle, "Set fridge temp");
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents: 418
diff changeset
267 slcdPosition(slcdHandle, 0, 1);
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
268 snprintf(buf, Config.lcd_cols, "Set %.1f", temp_temp);
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
269 #ifdef HAVE_WIRINGPI_H
246
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
270 lcdPuts(lcdHandle, buf);
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
271 #endif
420
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents: 418
diff changeset
272 slcdPuts(slcdHandle, buf);
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
273 break;
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
274
238
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
275 case MENU_MODE_PROFILE: show_mode();
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
276 #ifdef HAVE_WIRINGPI_H
238
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
277 lcdPuts(lcdHandle, "New mode PROFILE");
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
278 #endif
420
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents: 418
diff changeset
279 slcdPuts(slcdHandle, "New mode PROFILE");
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
280 break;
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
281
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
282 case MENU_PROFILE_SELECT: snprintf(buf, Config.lcd_cols, "%s", current_profile->name);
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
283 #ifdef HAVE_WIRINGPI_H
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
284 lcdPuts(lcdHandle, buf);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
285 lcdPosition(lcdHandle, 0, 1);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
286 lcdPuts(lcdHandle, "Select profile");
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
287 #endif
420
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents: 418
diff changeset
288 slcdPuts(slcdHandle, buf);
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents: 418
diff changeset
289 slcdPosition(slcdHandle, 0, 1);
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents: 418
diff changeset
290 slcdPuts(slcdHandle, "Select profile");
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
291 break;
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
292
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
293 case MENU_PROFILE_START: snprintf(buf, Config.lcd_cols, "%s", current_profile->name);
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
294 #ifdef HAVE_WIRINGPI_H
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
295 lcdPuts(lcdHandle, buf);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
296 lcdPosition(lcdHandle, 0, 1);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
297 lcdPuts(lcdHandle, "Start profile");
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
298 #endif
420
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents: 418
diff changeset
299 slcdPuts(slcdHandle, buf);
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents: 418
diff changeset
300 slcdPosition(slcdHandle, 0, 1);
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents: 418
diff changeset
301 slcdPuts(slcdHandle, "Start profile");
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
302 break;
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
303
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
304 case MENU_PROFILE_PAUSE: snprintf(buf, Config.lcd_cols, "%s", current_profile->name);
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
305 #ifdef HAVE_WIRINGPI_H
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
306 lcdPuts(lcdHandle, buf);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
307 lcdPosition(lcdHandle, 0, 1);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
308 lcdPuts(lcdHandle, "Pause profile");
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
309 #endif
420
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents: 418
diff changeset
310 slcdPuts(slcdHandle, buf);
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents: 418
diff changeset
311 slcdPosition(slcdHandle, 0, 1);
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents: 418
diff changeset
312 slcdPuts(slcdHandle, "Pause profile");
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
313 break;
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
314
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
315 case MENU_PROFILE_ABORT: snprintf(buf, Config.lcd_cols, "%s", current_profile->name);
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
316 #ifdef HAVE_WIRINGPI_H
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
317 lcdPuts(lcdHandle, buf);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
318 lcdPosition(lcdHandle, 0, 1);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
319 lcdPuts(lcdHandle, "Abort profile");
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
320 #endif
420
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents: 418
diff changeset
321 slcdPuts(slcdHandle, buf);
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents: 418
diff changeset
322 slcdPosition(slcdHandle, 0, 1);
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents: 418
diff changeset
323 slcdPuts(slcdHandle, "Abort profile");
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
324 break;
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
325
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
326 case MENU_PROFILE_RESUME: snprintf(buf, Config.lcd_cols, "%s", current_profile->name);
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
327 #ifdef HAVE_WIRINGPI_H
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
328 lcdPuts(lcdHandle, buf);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
329 lcdPosition(lcdHandle, 0, 1);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
330 lcdPuts(lcdHandle, "Resume profile");
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
331 #endif
420
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents: 418
diff changeset
332 slcdPuts(slcdHandle, buf);
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents: 418
diff changeset
333 slcdPosition(slcdHandle, 0, 1);
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents: 418
diff changeset
334 slcdPuts(slcdHandle, "Resume profile");
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
335 break;
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
336
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
337 case MENU_PROFILE_GOOFF: snprintf(buf, Config.lcd_cols, "%s", current_profile->name);
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
338 #ifdef HAVE_WIRINGPI_H
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
339 lcdPuts(lcdHandle, buf);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
340 lcdPosition(lcdHandle, 0, 1);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
341 lcdPuts(lcdHandle, "Set profile OFF");
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
342 #endif
420
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents: 418
diff changeset
343 slcdPuts(slcdHandle, buf);
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents: 418
diff changeset
344 slcdPosition(slcdHandle, 0, 1);
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents: 418
diff changeset
345 slcdPuts(slcdHandle, "Set profile OFF");
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
346 break;
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
347
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
348 case MENU_TOP_SYS:
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
349 #ifdef HAVE_WIRINGPI_H
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
350 lcdPuts(lcdHandle, "System menu");
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
351 #endif
420
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents: 418
diff changeset
352 slcdPuts(slcdHandle, "System menu");
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
353 break;
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
354
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
355 case MENU_SYS_HALT:
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
356 #ifdef HAVE_WIRINGPI_H
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
357 lcdPuts(lcdHandle, "Halt system");
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
358 #endif
420
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents: 418
diff changeset
359 slcdPuts(slcdHandle, "Halt system");
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
360 break;
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
361
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
362 case MENU_SYS_REBOOT:
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
363 #ifdef HAVE_WIRINGPI_H
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
364 lcdPuts(lcdHandle, "Reboot system");
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
365 #endif
420
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents: 418
diff changeset
366 slcdPuts(slcdHandle, "Reboot system");
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
367 break;
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
368 }
244
2f868eaefec2 Selecting units in setup does now work. Menu select variables are protected with thread locking.
Michiel Broek <mbroek@mbse.eu>
parents: 241
diff changeset
369
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
370 #ifdef HAVE_WIRINGPI_H
244
2f868eaefec2 Selecting units in setup does now work. Menu select variables are protected with thread locking.
Michiel Broek <mbroek@mbse.eu>
parents: 241
diff changeset
371 piUnlock(LOCK_MENU);
2f868eaefec2 Selecting units in setup does now work. Menu select variables are protected with thread locking.
Michiel Broek <mbroek@mbse.eu>
parents: 241
diff changeset
372 piUnlock(LOCK_LCD);
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
373 #endif
214
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
374 }
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
375
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
376
37d1eb0e1d66 Added a bunch of panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
377
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
378 void stopLCD(void)
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
379 {
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
380 #ifdef HAVE_WIRINGPI_H
241
4ba138737bf4 Added thread locks to all LCD access functions. This seems to have fixed the LCD corruption problems.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
381 piLock(LOCK_LCD);
223
14700edd2a67 Removed LCD shadow copy buffer.
Michiel Broek <mbroek@mbse.eu>
parents: 221
diff changeset
382 lcdClear(lcdHandle);
420
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents: 418
diff changeset
383 #endif
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents: 418
diff changeset
384 slcdClear(slcdHandle);
426
e54611453d29 Moved global bit defines to config.h
Michiel Broek <mbroek@mbse.eu>
parents: 423
diff changeset
385 setBacklight(0);
420
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents: 418
diff changeset
386 #ifdef HAVE_WIRINGPI_H
241
4ba138737bf4 Added thread locks to all LCD access functions. This seems to have fixed the LCD corruption problems.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
387 piUnlock(LOCK_LCD);
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
388 #endif
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
389 }
238
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
390
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
391
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
392
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
393 /*
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
394 * Change mode of current_unit
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
395 */
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
396 void change_mode(int mode)
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
397 {
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
398 if ((current_unit->mode == UNITMODE_OFF) && (mode != UNITMODE_OFF))
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
399 initlog(current_unit->name);
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
400 syslog(LOG_NOTICE, "Mode from %s to %s via panel interface", UNITMODE[current_unit->mode], UNITMODE[mode]);
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
401 current_unit->mode = mode;
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
402 /* Allways turn everything off after a mode change */
367
b9130db48c63 Fixed compiling on a real RPi
Michiel Broek <mbroek@mbse.eu>
parents: 364
diff changeset
403 current_unit->PID_cool->OutP = current_unit->PID_heat->OutP = 0.0;
b9130db48c63 Fixed compiling on a real RPi
Michiel Broek <mbroek@mbse.eu>
parents: 364
diff changeset
404 current_unit->PID_cool->Mode = current_unit->PID_heat->Mode = PID_MODE_NONE;
b9130db48c63 Fixed compiling on a real RPi
Michiel Broek <mbroek@mbse.eu>
parents: 364
diff changeset
405 current_unit->heater_state = current_unit->cooler_state = current_unit->fan_state = current_unit->light_state = 0;
b9130db48c63 Fixed compiling on a real RPi
Michiel Broek <mbroek@mbse.eu>
parents: 364
diff changeset
406 current_unit->heater_wait = current_unit->cooler_wait = current_unit->fan_wait = current_unit->light_wait = 0;
238
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
407 device_out(current_unit->heater_address, current_unit->heater_state);
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
408 device_out(current_unit->cooler_address, current_unit->cooler_state);
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
409 device_out(current_unit->fan_address, current_unit->fan_state);
367
b9130db48c63 Fixed compiling on a real RPi
Michiel Broek <mbroek@mbse.eu>
parents: 364
diff changeset
410 device_out(current_unit->light_address, current_unit->light_state);
238
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
411 if (current_unit->mode == UNITMODE_PROFILE) {
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
412 /*
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
413 * Set a sane default until it will be overruled by the
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
414 * main processing loop.
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
415 */
406
44566f986f76 Fixed compiling on a real RPi.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
416 current_unit->prof_target_lo = 19.8;
44566f986f76 Fixed compiling on a real RPi.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
417 current_unit->prof_target_hi = 20.2;
44566f986f76 Fixed compiling on a real RPi.
Michiel Broek <mbroek@mbse.eu>
parents: 405
diff changeset
418 current_unit->prof_fridge_mode = 0;
238
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
419 }
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
420 }
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
421
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
422
28
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 27
diff changeset
423
246
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
424 /*
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
425 * Handle panel key events
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
426 */
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
427 void panel_key_events(int key)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
428 {
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
429 units_list *unit;
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
430 profiles_list *profile;
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
431 int rc;
246
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
432
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
433 switch (setupmenu) {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
434 case MENU_NONE:
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
435 if ((key == KEY_DOWN) || (key == KEY_UP))
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
436 lcd_buf_step(key);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
437 if ((key == KEY_CONFIRM) && (setupmenu == MENU_NONE))
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
438 go_menu(MENU_TOP_DEFAULT);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
439 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
440
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
441 case MENU_TOP_DEFAULT:
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
442 if (key == KEY_ESCAPE)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
443 go_menu(MENU_NONE);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
444 if (key == KEY_DOWN)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
445 go_menu(MENU_TOP_UNITS);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
446 if (key == KEY_UP)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
447 go_menu(MENU_TOP_SYS);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
448 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
449
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
450 case MENU_TOP_UNITS:
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
451 if (key == KEY_ESCAPE)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
452 go_menu(MENU_NONE);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
453 if (key == KEY_DOWN)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
454 go_menu(MENU_TOP_SYS);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
455 if (key == KEY_UP)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
456 go_menu(MENU_TOP_DEFAULT);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
457 if ((key == KEY_ENTER) && Config.units) {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
458 /*
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
459 * Start with the first unit
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
460 */
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
461 current_unit = Config.units;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
462 go_menu(MENU_UNITS);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
463 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
464 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
465
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
466 case MENU_UNITS:
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
467 if (key == KEY_ESCAPE)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
468 go_menu(MENU_TOP_UNITS);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
469 if (key == KEY_DOWN) {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
470 if (current_unit->next) {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
471 current_unit = current_unit->next;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
472 go_menu(MENU_UNITS);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
473 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
474 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
475 if (key == KEY_UP) {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
476 for (unit = Config.units; unit; unit = unit->next) {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
477 if (unit->next && (unit->next == current_unit)) {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
478 current_unit = unit;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
479 go_menu(MENU_UNITS);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
480 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
481 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
482 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
483 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
484 if (key == KEY_ENTER) {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
485 /*
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
486 * Drop into the current mode
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
487 */
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
488 switch (current_unit->mode) {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
489 case UNITMODE_OFF: go_menu(MENU_MODE_OFF);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
490 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
491 case UNITMODE_NONE: go_menu(MENU_MODE_NONE);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
492 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
493 case UNITMODE_FRIDGE: go_menu(MENU_MODE_FRIDGE);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
494 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
495 case UNITMODE_BEER: go_menu(MENU_MODE_BEER);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
496 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
497 case UNITMODE_PROFILE: go_menu(MENU_MODE_PROFILE);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
498 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
499 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
500 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
501 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
502
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
503 case MENU_MODE_OFF:
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
504 if (key == KEY_ESCAPE)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
505 go_menu(MENU_UNITS);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
506 if (key == KEY_DOWN)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
507 go_menu(MENU_MODE_NONE);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
508 if (key == KEY_UP)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
509 go_menu(MENU_MODE_PROFILE);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
510 if (key == KEY_ENTER) {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
511 change_mode(UNITMODE_OFF);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
512 go_menu(MENU_MODE_OFF);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
513 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
514 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
515
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
516 case MENU_MODE_NONE:
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
517 if (key == KEY_ESCAPE)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
518 go_menu(MENU_UNITS);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
519 if (key == KEY_DOWN)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
520 go_menu(MENU_MODE_FRIDGE);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
521 if (key == KEY_UP)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
522 go_menu(MENU_MODE_OFF);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
523 if (key == KEY_ENTER) {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
524 if (current_unit->mode == UNITMODE_NONE)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
525 go_menu(MENU_NONE_HEAT);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
526 else {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
527 change_mode(UNITMODE_NONE);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
528 go_menu(MENU_MODE_NONE);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
529 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
530 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
531 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
532
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
533 case MENU_NONE_HEAT:
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
534 if (key == KEY_ESCAPE)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
535 go_menu(MENU_MODE_NONE);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
536 if (key == KEY_DOWN)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
537 go_menu(MENU_NONE_COOL);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
538 if (key == KEY_UP)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
539 go_menu(MENU_NONE_FAN);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
540 if (key == KEY_ENTER) {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
541 if (current_unit->heater_state)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
542 current_unit->heater_state = 0;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
543 else
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
544 current_unit->heater_state = 100;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
545 go_menu(MENU_NONE_HEAT);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
546 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
547 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
548
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
549 case MENU_NONE_COOL:
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
550 if (key == KEY_ESCAPE)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
551 go_menu(MENU_MODE_NONE);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
552 if (key == KEY_DOWN)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
553 go_menu(MENU_NONE_FAN);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
554 if (key == KEY_UP)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
555 go_menu(MENU_NONE_HEAT);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
556 if (key == KEY_ENTER) {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
557 if (current_unit->cooler_state)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
558 current_unit->cooler_state = 0;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
559 else
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
560 current_unit->cooler_state = 100;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
561 go_menu(MENU_NONE_COOL);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
562 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
563 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
564
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
565 case MENU_NONE_FAN:
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
566 if (key == KEY_ESCAPE)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
567 go_menu(MENU_MODE_NONE);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
568 if (key == KEY_DOWN)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
569 go_menu(MENU_NONE_HEAT);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
570 if (key == KEY_UP)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
571 go_menu(MENU_NONE_COOL);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
572 if (key == KEY_ENTER) {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
573 if (current_unit->fan_state)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
574 current_unit->fan_state = 0;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
575 else
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
576 current_unit->fan_state = 100;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
577 go_menu(MENU_NONE_FAN);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
578 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
579 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
580
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
581 case MENU_MODE_FRIDGE:
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
582 if (key == KEY_ESCAPE)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
583 go_menu(MENU_UNITS);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
584 if (key == KEY_DOWN)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
585 go_menu(MENU_MODE_BEER);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
586 if (key == KEY_UP)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
587 go_menu(MENU_MODE_NONE);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
588 if (key == KEY_ENTER) {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
589 if (current_unit->mode == UNITMODE_FRIDGE) {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
590 temp_temp = current_unit->fridge_set;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
591 go_menu(MENU_FRIDGE_TEMP);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
592 } else {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
593 change_mode(UNITMODE_FRIDGE);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
594 go_menu(MENU_MODE_FRIDGE);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
595 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
596 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
597 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
598
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
599 case MENU_FRIDGE_TEMP:
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
600 if (key == KEY_ESCAPE)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
601 go_menu(MENU_MODE_FRIDGE);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
602 if (key == KEY_DOWN) {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
603 if (temp_temp > current_unit->temp_set_min)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
604 temp_temp -= 0.1;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
605 go_menu(MENU_FRIDGE_TEMP);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
606 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
607 if (key == KEY_UP) {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
608 if (temp_temp < current_unit->temp_set_max)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
609 temp_temp += 0.1;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
610 go_menu(MENU_FRIDGE_TEMP);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
611 }
302
3d2bd47f35b4 Use confirm instead of enter key when stepping to a new beer or fridge temperature
Michiel Broek <mbroek@mbse.eu>
parents: 297
diff changeset
612 if (key == KEY_CONFIRM) {
246
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
613 if (temp_temp != current_unit->fridge_set) {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
614 syslog(LOG_NOTICE, "Fridge temperature changed from %.1f to %.1f degrees from the panel", current_unit->fridge_set, temp_temp);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
615 current_unit->fridge_set = temp_temp;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
616 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
617 go_menu(MENU_MODE_FRIDGE);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
618 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
619 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
620
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
621 case MENU_MODE_BEER:
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
622 if (key == KEY_ESCAPE)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
623 go_menu(MENU_UNITS);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
624 if (key == KEY_DOWN)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
625 go_menu(MENU_MODE_PROFILE);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
626 if (key == KEY_UP)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
627 go_menu(MENU_MODE_FRIDGE);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
628 if (key == KEY_ENTER) {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
629 if (current_unit->mode == UNITMODE_BEER) {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
630 temp_temp = current_unit->beer_set;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
631 go_menu(MENU_BEER_TEMP);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
632 } else {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
633 change_mode(UNITMODE_BEER);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
634 go_menu(MENU_MODE_BEER);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
635 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
636 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
637 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
638
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
639 case MENU_BEER_TEMP:
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
640 if (key == KEY_ESCAPE)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
641 go_menu(MENU_MODE_BEER);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
642 if (key == KEY_DOWN) {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
643 if (temp_temp > current_unit->temp_set_min)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
644 temp_temp -= 0.1;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
645 go_menu(MENU_BEER_TEMP);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
646 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
647 if (key == KEY_UP) {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
648 if (temp_temp < current_unit->temp_set_max)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
649 temp_temp += 0.1;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
650 go_menu(MENU_BEER_TEMP);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
651 }
302
3d2bd47f35b4 Use confirm instead of enter key when stepping to a new beer or fridge temperature
Michiel Broek <mbroek@mbse.eu>
parents: 297
diff changeset
652 if (key == KEY_CONFIRM) {
246
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
653 if (temp_temp != current_unit->beer_set) {
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
654 syslog(LOG_NOTICE, "Beer temperature changed from %.1f to %.1f degrees from the panel", current_unit->beer_set, temp_temp);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
655 current_unit->beer_set = temp_temp;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
656 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
657 go_menu(MENU_MODE_BEER);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
658 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
659 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
660
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
661 case MENU_MODE_PROFILE:
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
662 if (current_unit->profile) {
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
663 for (current_profile = Config.profiles; current_profile; current_profile = current_profile->next) {
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
664 if (strcmp(current_profile->uuid, current_unit->profile) == 0)
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
665 break;
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
666 }
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
667 } else {
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
668 current_profile = NULL;
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
669 }
246
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
670 if (key == KEY_ESCAPE)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
671 go_menu(MENU_UNITS);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
672 if (key == KEY_DOWN)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
673 go_menu(MENU_MODE_OFF);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
674 if (key == KEY_UP)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
675 go_menu(MENU_MODE_BEER);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
676 if (key == KEY_ENTER) {
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
677 if (current_unit->mode == UNITMODE_PROFILE) {
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
678 switch (current_unit->prof_state) {
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
679 case PROFILE_OFF: if (current_unit->profile)
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
680 go_menu(MENU_PROFILE_START);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
681 else
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
682 go_menu(MENU_PROFILE_SELECT);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
683 break;
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
684 case PROFILE_PAUSE: go_menu(MENU_PROFILE_RESUME);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
685 break;
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
686 case PROFILE_RUN: go_menu(MENU_PROFILE_PAUSE);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
687 break;
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
688 case PROFILE_DONE: go_menu(MENU_PROFILE_GOOFF);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
689 break;
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
690 }
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
691 } else {
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
692 change_mode(UNITMODE_PROFILE);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
693 go_menu(MENU_MODE_PROFILE);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
694 }
246
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
695 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
696 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
697
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
698 case MENU_PROFILE_SELECT:
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
699 if (key == KEY_ESCAPE)
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
700 go_menu(MENU_MODE_PROFILE);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
701 if (key == KEY_DOWN) {
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
702 if (current_profile->next) {
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
703 current_profile = current_profile->next;
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
704 go_menu(MENU_PROFILE_SELECT);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
705 } else {
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
706 go_menu(MENU_PROFILE_START);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
707 }
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
708 }
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
709 if (key == KEY_UP) {
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
710 for (profile = Config.profiles; profile; profile = profile->next) {
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
711 if (profile->next && profile->next == current_profile) {
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
712 current_profile = profile;
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
713 go_menu(MENU_PROFILE_SELECT);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
714 break;
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
715 }
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
716 }
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
717 go_menu(MENU_PROFILE_START);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
718 }
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
719 if (key == KEY_ENTER) {
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
720 current_unit->profile = current_profile->uuid;
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
721 syslog(LOG_NOTICE, "Profile %s selected from panel", current_profile->name);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
722 go_menu(MENU_PROFILE_START);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
723 }
246
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
724 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
725
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
726 case MENU_PROFILE_START:
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
727 if (key == KEY_ESCAPE)
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
728 go_menu(MENU_MODE_PROFILE);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
729 if ((key == KEY_DOWN) || (key == KEY_UP))
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
730 go_menu(MENU_PROFILE_SELECT);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
731 if (key == KEY_ENTER) {
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
732 current_unit->prof_state = PROFILE_RUN;
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
733 current_unit->prof_started = time(NULL);
289
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
734 current_unit->prof_paused = current_unit->prof_primary_done = 0;
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
735 current_unit->prof_peak_abs = current_unit->prof_peak_rel = 0.0;
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
736 syslog(LOG_NOTICE, "Profile started from the panel");
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
737 go_menu(MENU_MODE_PROFILE);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
738 }
246
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
739 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
740
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
741 case MENU_PROFILE_PAUSE:
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
742 if (key == KEY_ESCAPE)
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
743 go_menu(MENU_MODE_PROFILE);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
744 if ((key == KEY_DOWN) || (key == KEY_UP))
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
745 go_menu(MENU_PROFILE_ABORT);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
746 if (key == KEY_ENTER) {
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
747 current_unit->prof_state = PROFILE_PAUSE;
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
748 syslog(LOG_NOTICE, "Profile pause from the panel");
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
749 go_menu(MENU_MODE_PROFILE);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
750 }
246
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
751 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
752
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
753 case MENU_PROFILE_ABORT:
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
754 if (key == KEY_ESCAPE)
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
755 go_menu(MENU_MODE_PROFILE);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
756 if ((key == KEY_DOWN) || (key == KEY_UP)) {
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
757 if (current_unit->prof_state == PROFILE_PAUSE)
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
758 go_menu(MENU_PROFILE_RESUME);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
759 else if (current_unit->prof_state == PROFILE_RUN)
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
760 go_menu(MENU_PROFILE_PAUSE);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
761 }
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
762 if ((key == KEY_ENTER) && ((current_unit->prof_state == PROFILE_RUN) || (current_unit->prof_state == PROFILE_PAUSE))) {
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
763 current_unit->prof_state = PROFILE_OFF;
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
764 current_unit->prof_started = 0;
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
765 syslog(LOG_NOTICE, "Profile aborted from the panel");
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
766 go_menu(MENU_MODE_PROFILE);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
767 }
246
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
768 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
769
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
770 case MENU_PROFILE_RESUME:
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
771 if (key == KEY_ESCAPE)
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
772 go_menu(MENU_MODE_PROFILE);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
773 if ((key == KEY_DOWN) || (key == KEY_UP))
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
774 go_menu(MENU_PROFILE_ABORT);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
775 if (key == KEY_ENTER) {
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
776 current_unit->prof_state = PROFILE_RUN;
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
777 syslog(LOG_NOTICE, "Profile resume from the panel");
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
778 go_menu(MENU_MODE_PROFILE);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
779 }
246
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
780 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
781
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
782 case MENU_PROFILE_GOOFF:
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
783 if (key == KEY_ESCAPE)
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
784 go_menu(MENU_MODE_PROFILE);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
785 if (key == KEY_ENTER) {
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
786 if (current_unit->prof_state == PROFILE_DONE) {
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
787 current_unit->prof_state = PROFILE_OFF;
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
788 syslog(LOG_NOTICE, "Profile from done to off from the panel");
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
789 }
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
790 }
246
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
791 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
792
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
793 case MENU_TOP_SYS:
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
794 if (key == KEY_ESCAPE)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
795 go_menu(MENU_NONE);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
796 if (key == KEY_DOWN)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
797 go_menu(MENU_TOP_DEFAULT);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
798 if (key == KEY_UP)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
799 go_menu(MENU_TOP_UNITS);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
800 if (key == KEY_ENTER)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
801 go_menu(MENU_SYS_HALT);
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
802 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
803
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
804 case MENU_SYS_HALT:
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
805 if (key == KEY_ESCAPE)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
806 go_menu(MENU_TOP_SYS);
248
870d0be6880d Removed two system menus that would not work correctly. All panel menus are complete now.
Michiel Broek <mbroek@mbse.eu>
parents: 247
diff changeset
807 if ((key == KEY_DOWN) || (key == KEY_UP))
246
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
808 go_menu(MENU_SYS_REBOOT);
248
870d0be6880d Removed two system menus that would not work correctly. All panel menus are complete now.
Michiel Broek <mbroek@mbse.eu>
parents: 247
diff changeset
809 if (key == KEY_CONFIRM) {
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
810 rc = system("/sbin/halt");
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
811 syslog(LOG_NOTICE, "System halt from panel: /sbin/halt rc=%d", rc);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
812 go_menu(MENU_NONE);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
813 }
246
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
814 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
815
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
816 case MENU_SYS_REBOOT:
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
817 if (key == KEY_ESCAPE)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
818 go_menu(MENU_TOP_SYS);
248
870d0be6880d Removed two system menus that would not work correctly. All panel menus are complete now.
Michiel Broek <mbroek@mbse.eu>
parents: 247
diff changeset
819 if ((key == KEY_DOWN) || (key == KEY_UP))
246
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
820 go_menu(MENU_SYS_HALT);
248
870d0be6880d Removed two system menus that would not work correctly. All panel menus are complete now.
Michiel Broek <mbroek@mbse.eu>
parents: 247
diff changeset
821 if (key == KEY_CONFIRM) {
247
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
822 rc = system("/sbin/reboot");
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
823 syslog(LOG_NOTICE, "System reboot from panel: /sbin/reboot rc=%d", rc);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
824 go_menu(MENU_NONE);
f3d0e9445fcd Added profile panel menus and system panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 246
diff changeset
825 }
246
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
826 break;
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
827 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
828 }
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
829
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
830
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
831
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
832 int main(int argc, char *argv[])
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
833 {
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
834 int rc, c, i;
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
835 pid_t frk;
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
836
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
837 while (1) {
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
838 int option_index = 0;
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
839 static struct option long_options[] = {
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
840 {"debug", 0, 0, 'c'},
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
841 {"help", 0, 0, 'h'},
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
842 {0, 0, 0, 0}
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
843 };
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
844
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
845 c = getopt_long(argc, argv, "dh", long_options, &option_index);
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
846 if (c == -1)
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
847 break;
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
848
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
849 switch (c) {
75
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 74
diff changeset
850 case 'd': debug = TRUE;
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
851 break;
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
852 case 'h': help();
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
853 return 1;
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
854 }
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
855 }
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
856
41
f534ace74eea Code preparation for client/server communication
Michiel Broek <mbroek@mbse.eu>
parents: 40
diff changeset
857 openlog("thermferm", LOG_PID|LOG_CONS|LOG_NOWAIT, LOG_USER);
f534ace74eea Code preparation for client/server communication
Michiel Broek <mbroek@mbse.eu>
parents: 40
diff changeset
858 syslog(LOG_NOTICE, "mbsePi-apps thermferm v%s starting", VERSION);
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
859 if (debug)
41
f534ace74eea Code preparation for client/server communication
Michiel Broek <mbroek@mbse.eu>
parents: 40
diff changeset
860 fprintf(stdout, "mbsePi-apps thermferm v%s starting\n", VERSION);
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
861
86
3d7a241329e2 Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents: 83
diff changeset
862 if (rdconfig()) {
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
863 fprintf(stderr, "Error reading configuration\n");
268
dda91dfa4aa8 All syslog logging only to LOG_NOTICE
Michiel Broek <mbroek@mbse.eu>
parents: 267
diff changeset
864 syslog(LOG_NOTICE, "Error reading configuration: halted");
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
865 return 1;
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
866 }
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
867
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
868 /*
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
869 * Catch all the signals we can, and ignore the rest. Note that SIGKILL can't be ignored
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
870 * but that's live. This daemon should only be stopped by SIGTERM.
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
871 * Don't catch SIGCHLD.
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
872 */
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
873 for (i = 0; i < NSIG; i++) {
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
874 if ((i != SIGCHLD) && (i != SIGKILL) && (i != SIGSTOP))
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
875 signal(i, (void (*))die);
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
876 }
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
877
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 64
diff changeset
878 #ifdef HAVE_WIRINGPI_H
28
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 27
diff changeset
879 if (wiringPiSetup () )
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 27
diff changeset
880 return 1;
420
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents: 418
diff changeset
881 #endif
28
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 27
diff changeset
882
108
50d2187fdb74 New rotating LCD display
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
883 if ((rc = initLCD (Config.lcd_cols, Config.lcd_rows))) {
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
884 fprintf(stderr, "Cannot initialize LCD display, rc=%d\n", rc);
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
885 return 1;
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
886 }
28
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 27
diff changeset
887
484
7362ebd40f26 Use user defined characters for the LCD display just like in Arduino projects.
Michiel Broek <mbroek@mbse.eu>
parents: 481
diff changeset
888 #ifdef HAVE_WIRINGPI_H
7362ebd40f26 Use user defined characters for the LCD display just like in Arduino projects.
Michiel Broek <mbroek@mbse.eu>
parents: 481
diff changeset
889 lcdCharDef(lcdHandle, 1, degC);
7362ebd40f26 Use user defined characters for the LCD display just like in Arduino projects.
Michiel Broek <mbroek@mbse.eu>
parents: 481
diff changeset
890 lcdCharDef(lcdHandle, 2, SP_Symbol);
7362ebd40f26 Use user defined characters for the LCD display just like in Arduino projects.
Michiel Broek <mbroek@mbse.eu>
parents: 481
diff changeset
891 lcdCharDef(lcdHandle, 3, CoolONOFF);
7362ebd40f26 Use user defined characters for the LCD display just like in Arduino projects.
Michiel Broek <mbroek@mbse.eu>
parents: 481
diff changeset
892 lcdCharDef(lcdHandle, 4, RevCoolONOFF);
7362ebd40f26 Use user defined characters for the LCD display just like in Arduino projects.
Michiel Broek <mbroek@mbse.eu>
parents: 481
diff changeset
893 lcdCharDef(lcdHandle, 5, HeatONOFF);
7362ebd40f26 Use user defined characters for the LCD display just like in Arduino projects.
Michiel Broek <mbroek@mbse.eu>
parents: 481
diff changeset
894 lcdCharDef(lcdHandle, 6, RevHeatONOFF);
7362ebd40f26 Use user defined characters for the LCD display just like in Arduino projects.
Michiel Broek <mbroek@mbse.eu>
parents: 481
diff changeset
895 #endif
7362ebd40f26 Use user defined characters for the LCD display just like in Arduino projects.
Michiel Broek <mbroek@mbse.eu>
parents: 481
diff changeset
896 slcdCharDef(slcdHandle, 1, degC);
7362ebd40f26 Use user defined characters for the LCD display just like in Arduino projects.
Michiel Broek <mbroek@mbse.eu>
parents: 481
diff changeset
897 slcdCharDef(slcdHandle, 2, SP_Symbol);
7362ebd40f26 Use user defined characters for the LCD display just like in Arduino projects.
Michiel Broek <mbroek@mbse.eu>
parents: 481
diff changeset
898 slcdCharDef(slcdHandle, 3, CoolONOFF);
7362ebd40f26 Use user defined characters for the LCD display just like in Arduino projects.
Michiel Broek <mbroek@mbse.eu>
parents: 481
diff changeset
899 slcdCharDef(slcdHandle, 4, RevCoolONOFF);
7362ebd40f26 Use user defined characters for the LCD display just like in Arduino projects.
Michiel Broek <mbroek@mbse.eu>
parents: 481
diff changeset
900 slcdCharDef(slcdHandle, 5, HeatONOFF);
7362ebd40f26 Use user defined characters for the LCD display just like in Arduino projects.
Michiel Broek <mbroek@mbse.eu>
parents: 481
diff changeset
901 slcdCharDef(slcdHandle, 6, RevHeatONOFF);
7362ebd40f26 Use user defined characters for the LCD display just like in Arduino projects.
Michiel Broek <mbroek@mbse.eu>
parents: 481
diff changeset
902
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
903 if (debug) {
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
904 /*
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
905 * For debugging run in foreground.
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
906 */
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
907 rc = server();
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
908 } else {
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
909 /*
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
910 * Server initialization is complete. Now we can fork the
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
911 * daemon and return to the user. We need to do a setpgrp
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
912 * so that the daemon will no longer be assosiated with the
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
913 * users control terminal. This is done before the fork, so
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
914 * that the child will not be a process group leader. Otherwise,
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
915 * if the child were to open a terminal, it would become
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
916 * associated with that terminal as its control terminal.
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
917 */
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
918 if ((pgrp = setpgid(0, 0)) == -1) {
268
dda91dfa4aa8 All syslog logging only to LOG_NOTICE
Michiel Broek <mbroek@mbse.eu>
parents: 267
diff changeset
919 syslog(LOG_NOTICE, "setpgpid failed");
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
920 }
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
921
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
922 frk = fork();
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
923 switch (frk) {
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
924 case -1:
268
dda91dfa4aa8 All syslog logging only to LOG_NOTICE
Michiel Broek <mbroek@mbse.eu>
parents: 267
diff changeset
925 syslog(LOG_NOTICE, "Daemon fork failed: %s", strerror(errno));
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
926 stopLCD();
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
927 exit(1);
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
928 case 0: /*
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
929 * Run the daemon
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
930 */
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
931 fclose(stdin);
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
932 if (open("/dev/null", O_RDONLY) != 0) {
268
dda91dfa4aa8 All syslog logging only to LOG_NOTICE
Michiel Broek <mbroek@mbse.eu>
parents: 267
diff changeset
933 syslog(LOG_NOTICE, "Reopen of stdin to /dev/null failed");
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
934 _exit(2);
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
935 }
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
936 fclose(stdout);
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
937 if (open("/dev/null", O_WRONLY | O_APPEND | O_CREAT,0600) != 1) {
268
dda91dfa4aa8 All syslog logging only to LOG_NOTICE
Michiel Broek <mbroek@mbse.eu>
parents: 267
diff changeset
938 syslog(LOG_NOTICE, "Reopen of stdout to /dev/null failed");
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
939 _exit(2);
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
940 }
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
941 fclose(stderr);
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
942 if (open("/dev/null", O_WRONLY | O_APPEND | O_CREAT,0600) != 2) {
268
dda91dfa4aa8 All syslog logging only to LOG_NOTICE
Michiel Broek <mbroek@mbse.eu>
parents: 267
diff changeset
943 syslog(LOG_NOTICE, "Reopen of stderr to /dev/null failed");
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
944 _exit(2);
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
945 }
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
946 mypid = getpid();
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
947 rc = server();
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
948 break;
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
949 /* Not reached */
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
950 default:
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
951 /*
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
952 * Here we detach this process and let the child
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
953 * run the deamon process.
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
954 */
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
955 syslog(LOG_NOTICE, "Starting daemon with pid %d", frk);
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
956 exit(0);
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
957 }
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
958 }
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
959
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
960 syslog(LOG_NOTICE, "Finished, rc=%d", rc);
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
961 return rc;
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
962 }
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
963
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
964
497
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
965 #ifdef HAVE_MOSQUITTO_H
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
966
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
967 void my_connect_callback(struct mosquitto *mosq, void *obj, int result)
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
968 {
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
969 if (mqtt_connect_lost) {
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
970 mqtt_connect_lost = FALSE;
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
971 syslog(LOG_NOTICE, "Reconnect: %s", mosquitto_connack_string(result));
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
972 }
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
973
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
974 if (!result) {
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
975 mqtt_status = STATUS_CONNACK_RECVD;
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
976 } else {
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
977 syslog(LOG_NOTICE, "my_connect_callback: %s\n", mosquitto_connack_string(result));
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
978 }
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
979 }
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
980
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
981
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
982
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
983 void my_disconnect_callback(struct mosquitto *mosq, void *obj, int rc)
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
984 {
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
985 if (mqtt_my_shutdown) {
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
986 syslog(LOG_NOTICE, "Acknowledged DISCONNECT from %s", Config.mosq_host);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
987 mqtt_connected = FALSE;
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
988 } else {
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
989 /*
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
990 * The remote server was brought down. We must keep running
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
991 */
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
992 syslog(LOG_NOTICE, "Received DISCONNECT from %s, connection lost", Config.mosq_host);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
993 mqtt_connect_lost = TRUE;
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
994 }
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
995 }
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
996
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
997
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
998 void my_publish_callback(struct mosquitto *mosq, void *obj, int mid)
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
999 {
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1000 mqtt_last_mid_sent = mid;
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1001 }
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1002
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1003
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1004
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1005 void my_log_callback(struct mosquitto *mosq, void *obj, int level, const char *str)
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1006 {
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1007 syslog(LOG_NOTICE, "MQTT: %s", str);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1008 printf("MQTT: %s\n", str);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1009 mqtt_my_shutdown = TRUE;
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1010 }
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1011
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1012
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1013 #endif
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1014
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1015
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1016 int server(void)
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1017 {
397
00ca08f5a6f8 Fermentation profiles now have a low and high temperature setting so that you can use a temperture window. Each profile step can now set for beer or air temperature reference. The logfiles have an extra temperature field for this. Bumped to version 0.4.2.
Michiel Broek <mbroek@mbse.eu>
parents: 395
diff changeset
1018 char buf[1024], *filename, target_lo[40], target_hi[40], heater[40], cooler[40], fan[40], door[40];
355
8f946f9d125a Added logging of the room temperature.
Michiel Broek <mbroek@mbse.eu>
parents: 352
diff changeset
1019 char use_heater[40], use_cooler[40], use_fan[40], room_temp[40];
64
2431965e8a8c Write loglines only every 60 seconds
Michiel Broek <mbroek@mbse.eu>
parents: 63
diff changeset
1020 time_t now, last = (time_t)0;
104
5e538c4e1ecb Added units logging
Michiel Broek <mbroek@mbse.eu>
parents: 93
diff changeset
1021 units_list *unit;
194
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1022 profiles_list *profile;
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1023 prof_step *step;
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
1024 int row, rc, run = 1, seconds = 0, minutes = 0, temp, deviation;
422
13502d0dda65 The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents: 420
diff changeset
1025 int run_seconds, run_minutes, run_hours, tot_minutes, key;
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
1026 struct tm *tm;
422
13502d0dda65 The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents: 420
diff changeset
1027 #ifndef HAVE_WIRINGPI_H
74
879bd09e2b96 Reinstalled threads
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
1028 long t = 0;
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 64
diff changeset
1029 #endif
398
efdfef1677d1 Fixed crash after profile is finished. Fixed error in UNIT GET output.
Michiel Broek <mbroek@mbse.eu>
parents: 397
diff changeset
1030 int current_step, valid_step, time_until_now, previous_fridge_mode;
397
00ca08f5a6f8 Fermentation profiles now have a low and high temperature setting so that you can use a temperture window. Each profile step can now set for beer or air temperature reference. The logfiles have an extra temperature field for this. Bumped to version 0.4.2.
Michiel Broek <mbroek@mbse.eu>
parents: 395
diff changeset
1031 float previous_target_lo, previous_target_hi;
486
5a237a99a793 Compacted LCD display for units, allways 4 instead of 4 to 6 lines. But it's a bit more cryptic. We could write a short manual.
Michiel Broek <mbroek@mbse.eu>
parents: 484
diff changeset
1032 float LCDair, LCDbeer, LCDspL, LCDspH;
5a237a99a793 Compacted LCD display for units, allways 4 instead of 4 to 6 lines. But it's a bit more cryptic. We could write a short manual.
Michiel Broek <mbroek@mbse.eu>
parents: 484
diff changeset
1033 unsigned char LCDstatC, LCDstatH;
5a237a99a793 Compacted LCD display for units, allways 4 instead of 4 to 6 lines. But it's a bit more cryptic. We could write a short manual.
Michiel Broek <mbroek@mbse.eu>
parents: 484
diff changeset
1034 int LCDunit;
497
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1035 #ifdef HAVE_MOSQUITTO_H
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1036 char *id = NULL, *state = NULL, hostname[256], topic[1024], err[1024];
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1037 struct mosquitto *mosq = NULL;
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1038 int keepalive = 60;
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1039 unsigned int max_inflight = 20;
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1040 #endif
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1041
41
f534ace74eea Code preparation for client/server communication
Michiel Broek <mbroek@mbse.eu>
parents: 40
diff changeset
1042 if (lockprog((char *)"thermferm")) {
268
dda91dfa4aa8 All syslog logging only to LOG_NOTICE
Michiel Broek <mbroek@mbse.eu>
parents: 267
diff changeset
1043 syslog(LOG_NOTICE, "Can't lock");
34
38e3e3a49320 Added lock/pid file
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
1044 return 1;
38e3e3a49320 Added lock/pid file
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
1045 }
38e3e3a49320 Added lock/pid file
Michiel Broek <mbroek@mbse.eu>
parents: 33
diff changeset
1046
497
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1047
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1048 #ifdef HAVE_MOSQUITTO_H
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1049 /*
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1050 * Initialize mosquitto communication
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1051 */
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1052 gethostname(hostname, 255);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1053 mosquitto_lib_init();
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1054 id = xstrcpy((char *)"thermferm/");
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1055 id = xstrcat(id, hostname);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1056 if(strlen(id) > MOSQ_MQTT_ID_MAX_LENGTH) {
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1057 /*
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1058 * Enforce maximum client id length of 23 characters
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1059 */
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1060 id[MOSQ_MQTT_ID_MAX_LENGTH] = '\0';
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1061 }
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1062
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1063 mosq = mosquitto_new(id, true, NULL);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1064 if(!mosq) {
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1065 switch(errno) {
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1066 case ENOMEM:
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1067 syslog(LOG_NOTICE, "mosquitto_new: Out of memory");
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1068 break;
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1069 case EINVAL:
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1070 syslog(LOG_NOTICE, "mosquitto_new: Invalid id");
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1071 break;
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1072 }
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1073 mosquitto_lib_cleanup();
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1074 return 1;
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1075 }
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1076
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1077 if (debug) {
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1078 mosquitto_log_callback_set(mosq, my_log_callback);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1079 }
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1080
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1081 /*
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1082 * Set our will
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1083 */
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1084 state = xstrcpy((char *)"clients/");
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1085 state = xstrcat(state, hostname);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1086 state = xstrcat(state, (char *)"/thermferm/state");
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1087 sprintf(buf, "0");
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1088 if ((rc = mosquitto_will_set(mosq, state, strlen(buf), buf, mqtt_qos, TRUE))) {
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1089 if (rc == MOSQ_ERR_INVAL) {
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1090 syslog(LOG_NOTICE, "mosquitto_will_set: input parameters invalid");
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1091 } else if (rc == MOSQ_ERR_NOMEM) {
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1092 syslog(LOG_NOTICE, "mosquitto_will_set: Out of Memory");
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1093 } else if (rc == MOSQ_ERR_PAYLOAD_SIZE) {
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1094 syslog(LOG_NOTICE, "mosquitto_will_set: invalid payload size");
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1095 }
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1096 mosquitto_lib_cleanup();
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1097 return rc;
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1098 }
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1099
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1100 mosquitto_max_inflight_messages_set(mosq, max_inflight);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1101 mosquitto_connect_callback_set(mosq, my_connect_callback);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1102 mosquitto_disconnect_callback_set(mosq, my_disconnect_callback);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1103 mosquitto_publish_callback_set(mosq, my_publish_callback);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1104
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1105 if ((rc = mosquitto_connect(mosq, Config.mosq_host, Config.mosq_port, keepalive))) {
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1106 if (rc == MOSQ_ERR_ERRNO) {
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1107 strerror_r(errno, err, 1024);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1108 syslog(LOG_NOTICE, "mosquitto_connect: error: %s", err);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1109 } else {
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1110 syslog(LOG_NOTICE, "mosquitto_connect: unable to connect (%d)", rc);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1111 }
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1112 mosquitto_lib_cleanup();
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1113 } else {
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1114 mqtt_use = TRUE;
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1115 syslog(LOG_NOTICE, "MQTT connected with %s:%d", Config.mosq_host, Config.mosq_port);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1116
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1117 /*
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1118 * Initialise is complete, report our presence state
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1119 */
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1120 mosquitto_loop_start(mosq);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1121 sprintf(buf, "1");
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1122 rc = mosquitto_publish(mosq, &mqtt_mid_sent, state, strlen(buf), buf, mqtt_qos, 1);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1123 }
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1124 #endif
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1125
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1126
350
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1127 if ((rc = devices_detect())) {
158
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
1128 syslog(LOG_NOTICE, "Detected %d new devices", rc);
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
1129 wrconfig();
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
1130 }
f1b7e2ef90be Added device configuration
Michiel Broek <mbroek@mbse.eu>
parents: 156
diff changeset
1131
66
805f1d285acd Compiles with 1-wire bus on PC hardware
Michiel Broek <mbroek@mbse.eu>
parents: 64
diff changeset
1132 #ifdef HAVE_WIRINGPI_H
164
f16def8472ba Threads partly working via new devices interface
Michiel Broek <mbroek@mbse.eu>
parents: 160
diff changeset
1133 rc = piThreadCreate(my_devices_loop);
f16def8472ba Threads partly working via new devices interface
Michiel Broek <mbroek@mbse.eu>
parents: 160
diff changeset
1134 #else
f16def8472ba Threads partly working via new devices interface
Michiel Broek <mbroek@mbse.eu>
parents: 160
diff changeset
1135 rc = pthread_create(&threads[t], NULL, my_devices_loop, (void *)t );
f16def8472ba Threads partly working via new devices interface
Michiel Broek <mbroek@mbse.eu>
parents: 160
diff changeset
1136 #endif
f16def8472ba Threads partly working via new devices interface
Michiel Broek <mbroek@mbse.eu>
parents: 160
diff changeset
1137 if (rc) {
f16def8472ba Threads partly working via new devices interface
Michiel Broek <mbroek@mbse.eu>
parents: 160
diff changeset
1138 fprintf(stderr, "my_devices_loop thread didn't start rc=%d\n", rc);
268
dda91dfa4aa8 All syslog logging only to LOG_NOTICE
Michiel Broek <mbroek@mbse.eu>
parents: 267
diff changeset
1139 syslog(LOG_NOTICE, "my_devices_loop thread didn't start rc=%d", rc);
164
f16def8472ba Threads partly working via new devices interface
Michiel Broek <mbroek@mbse.eu>
parents: 160
diff changeset
1140 #ifndef HAVE_WIRINGPI_H
f16def8472ba Threads partly working via new devices interface
Michiel Broek <mbroek@mbse.eu>
parents: 160
diff changeset
1141 } else {
f16def8472ba Threads partly working via new devices interface
Michiel Broek <mbroek@mbse.eu>
parents: 160
diff changeset
1142 t++;
f16def8472ba Threads partly working via new devices interface
Michiel Broek <mbroek@mbse.eu>
parents: 160
diff changeset
1143 #endif
f16def8472ba Threads partly working via new devices interface
Michiel Broek <mbroek@mbse.eu>
parents: 160
diff changeset
1144 }
f16def8472ba Threads partly working via new devices interface
Michiel Broek <mbroek@mbse.eu>
parents: 160
diff changeset
1145
f16def8472ba Threads partly working via new devices interface
Michiel Broek <mbroek@mbse.eu>
parents: 160
diff changeset
1146 #ifdef HAVE_WIRINGPI_H
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 41
diff changeset
1147 rc = piThreadCreate(my_server_loop);
74
879bd09e2b96 Reinstalled threads
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
1148 #else
75
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 74
diff changeset
1149 rc = pthread_create(&threads[t], NULL, my_server_loop, (void *)t );
74
879bd09e2b96 Reinstalled threads
Michiel Broek <mbroek@mbse.eu>
parents: 72
diff changeset
1150 #endif
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 41
diff changeset
1151 if (rc) {
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 41
diff changeset
1152 fprintf(stderr, "my_server_loop thread didn't start rc=%d\n", rc);
268
dda91dfa4aa8 All syslog logging only to LOG_NOTICE
Michiel Broek <mbroek@mbse.eu>
parents: 267
diff changeset
1153 syslog(LOG_NOTICE, "my_server_loop thread didn't start rc=%d", rc);
75
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 74
diff changeset
1154 #ifndef HAVE_WIRINGPI_H
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 74
diff changeset
1155 } else {
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 74
diff changeset
1156 t++;
4b976601737d Writes a basic xml configuration next to the plain ascii config file
Michiel Broek <mbroek@mbse.eu>
parents: 74
diff changeset
1157 #endif
43
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 41
diff changeset
1158 }
24e731bb2e08 Initial server code added
Michiel Broek <mbroek@mbse.eu>
parents: 41
diff changeset
1159
199
3f5d277a69e3 Added panel thread
Michiel Broek <mbroek@mbse.eu>
parents: 198
diff changeset
1160 #ifdef HAVE_WIRINGPI_H
423
02653162b03b Fixed compiling for systems with wiringPi. Improved handling of udp sockets if there is no brewpanel running.
Michiel Broek <mbroek@mbse.eu>
parents: 422
diff changeset
1161 rc = piThreadCreate(my_panel_loop);
422
13502d0dda65 The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents: 420
diff changeset
1162 #else
13502d0dda65 The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents: 420
diff changeset
1163 rc = pthread_create(&threads[t], NULL, my_panel_loop, (void *)t );
13502d0dda65 The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents: 420
diff changeset
1164 #endif
13502d0dda65 The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents: 420
diff changeset
1165 if (rc) {
199
3f5d277a69e3 Added panel thread
Michiel Broek <mbroek@mbse.eu>
parents: 198
diff changeset
1166 fprintf(stderr, "my_panel_loop thread didn't start rc=%d\n", rc);
268
dda91dfa4aa8 All syslog logging only to LOG_NOTICE
Michiel Broek <mbroek@mbse.eu>
parents: 267
diff changeset
1167 syslog(LOG_NOTICE, "my_panel_loop thread didn't start rc=%d", rc);
422
13502d0dda65 The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents: 420
diff changeset
1168 #ifndef HAVE_WIRINGPI_H
13502d0dda65 The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents: 420
diff changeset
1169 } else {
13502d0dda65 The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents: 420
diff changeset
1170 t++;
199
3f5d277a69e3 Added panel thread
Michiel Broek <mbroek@mbse.eu>
parents: 198
diff changeset
1171 #endif
422
13502d0dda65 The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents: 420
diff changeset
1172 }
259
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 248
diff changeset
1173
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 248
diff changeset
1174 #ifdef USE_SIMULATOR
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 248
diff changeset
1175 #ifdef HAVE_WIRINGPI_H
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 248
diff changeset
1176 rc = piThreadCreate(my_simulator_loop);
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 248
diff changeset
1177 #else
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 248
diff changeset
1178 rc = pthread_create(&threads[t], NULL, my_simulator_loop, (void *)t );
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 248
diff changeset
1179 #endif
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 248
diff changeset
1180 if (rc) {
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 248
diff changeset
1181 fprintf(stderr, "my_simulator_loop thread didn't start rc=%d\n", rc);
268
dda91dfa4aa8 All syslog logging only to LOG_NOTICE
Michiel Broek <mbroek@mbse.eu>
parents: 267
diff changeset
1182 syslog(LOG_NOTICE, "my_simulator_loop thread didn't start rc=%d", rc);
259
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 248
diff changeset
1183 #ifndef HAVE_WIRINGPI_H
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 248
diff changeset
1184 } else {
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 248
diff changeset
1185 t++;
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 248
diff changeset
1186 #endif
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 248
diff changeset
1187 }
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 248
diff changeset
1188 #endif
b7c967359771 Added framework for a simulation of a fridge with heater to use as controlled fermentor
Michiel Broek <mbroek@mbse.eu>
parents: 248
diff changeset
1189
497
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1190
182
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1191 /*
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1192 * Initialize units for processing
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1193 */
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1194 for (unit = Config.units; unit; unit = unit->next) {
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1195 /*
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1196 * Safety, turn everything off
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1197 */
350
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1198 unit->heater_state = unit->cooler_state = unit->fan_state = unit->door_state = unit->light_state = 0;
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1199 unit->heater_wait = unit->cooler_wait = unit->fan_wait = unit->light_wait = 0;
497
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1200 #ifdef HAVE_MOSQUITTO_H
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1201 if (mqtt_use && (unit->mode != UNITMODE_OFF)) {
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1202 sprintf(buf, "1");
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1203 snprintf(topic, 1023, "fermenter/%s/%s/state", hostname, unit->uuid);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1204 mosquitto_publish(mosq, &mqtt_mid_sent, topic, strlen(buf), buf, mqtt_qos, 1);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1205 sprintf(buf, "%s", unit->name);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1206 snprintf(topic, 1023, "fermenter/%s/%s/name", hostname, unit->uuid);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1207 mosquitto_publish(mosq, &mqtt_mid_sent, topic, strlen(buf), buf, mqtt_qos, 1);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1208 sprintf(buf, "0");
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1209 if (unit->heater_address) {
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1210 snprintf(topic, 1023, "fermenter/%s/%s/heater", hostname, unit->uuid);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1211 mosquitto_publish(mosq, &mqtt_mid_sent, topic, strlen(buf), buf, mqtt_qos, 1);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1212 }
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1213 if (unit->cooler_address) {
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1214 snprintf(topic, 1023, "fermenter/%s/%s/cooler", hostname, unit->uuid);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1215 mosquitto_publish(mosq, &mqtt_mid_sent, topic, strlen(buf), buf, mqtt_qos, 1);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1216 }
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1217 if (unit->fan_address) {
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1218 snprintf(topic, 1023, "fermenter/%s/%s/fan", hostname, unit->uuid);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1219 mosquitto_publish(mosq, &mqtt_mid_sent, topic, strlen(buf), buf, mqtt_qos, 1);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1220 }
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1221 snprintf(topic, 1023, "fermenter/%s/%s/mode", hostname, unit->uuid);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1222 sprintf(buf, "%s", UNITMODE[unit->mode]);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1223 mosquitto_publish(mosq, &mqtt_mid_sent, topic, strlen(buf), buf, mqtt_qos, 1);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1224 }
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1225 #endif
195
b34a1b2421fb Reset output when a different profile is selected. Better startup logging about the unit state. Added Beer, Fridge and partial Profile settings from the liveview weeb screen.
Michiel Broek <mbroek@mbse.eu>
parents: 194
diff changeset
1226 if (unit->mode == UNITMODE_PROFILE) {
219
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1227 if (!unit->profile)
362
c92651a54969 Made the client-server protocol more robust. When a change to a unit is made using the web interface, the main process is stopped during the update. Splitted the PID in two PID's, one for heating and one for cooling. Adjusted the web edit scrreen for this, but there are still rough edges. Replaced the PID code, maybe this one works better for our purpose. The simulator air temperature changes on the simulator heater and cooler, but it is not realistic at all. This is a development version, do not use in production. The version is 0.3.0
Michiel Broek <mbroek@mbse.eu>
parents: 361
diff changeset
1228 syslog(LOG_NOTICE, "Starting unit `%s' in profile mode, no profile defined.", unit->name);
195
b34a1b2421fb Reset output when a different profile is selected. Better startup logging about the unit state. Added Beer, Fridge and partial Profile settings from the liveview weeb screen.
Michiel Broek <mbroek@mbse.eu>
parents: 194
diff changeset
1229 else
362
c92651a54969 Made the client-server protocol more robust. When a change to a unit is made using the web interface, the main process is stopped during the update. Splitted the PID in two PID's, one for heating and one for cooling. Adjusted the web edit scrreen for this, but there are still rough edges. Replaced the PID code, maybe this one works better for our purpose. The simulator air temperature changes on the simulator heater and cooler, but it is not realistic at all. This is a development version, do not use in production. The version is 0.3.0
Michiel Broek <mbroek@mbse.eu>
parents: 361
diff changeset
1230 syslog(LOG_NOTICE, "Starting unit `%s' in profile state %s.", unit->name, PROFSTATE[unit->prof_state]);
182
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1231 } else if (unit->mode == UNITMODE_BEER) {
362
c92651a54969 Made the client-server protocol more robust. When a change to a unit is made using the web interface, the main process is stopped during the update. Splitted the PID in two PID's, one for heating and one for cooling. Adjusted the web edit scrreen for this, but there are still rough edges. Replaced the PID code, maybe this one works better for our purpose. The simulator air temperature changes on the simulator heater and cooler, but it is not realistic at all. This is a development version, do not use in production. The version is 0.3.0
Michiel Broek <mbroek@mbse.eu>
parents: 361
diff changeset
1232 syslog(LOG_NOTICE, "Starting unit `%s' beer cooler at %.1f degrees", unit->name, unit->beer_set);
182
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1233 } else if (unit->mode == UNITMODE_FRIDGE) {
362
c92651a54969 Made the client-server protocol more robust. When a change to a unit is made using the web interface, the main process is stopped during the update. Splitted the PID in two PID's, one for heating and one for cooling. Adjusted the web edit scrreen for this, but there are still rough edges. Replaced the PID code, maybe this one works better for our purpose. The simulator air temperature changes on the simulator heater and cooler, but it is not realistic at all. This is a development version, do not use in production. The version is 0.3.0
Michiel Broek <mbroek@mbse.eu>
parents: 361
diff changeset
1234 syslog(LOG_NOTICE, "Starting unit `%s' as refridgerator at %.1f degrees", unit->name, unit->fridge_set);
182
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1235 } else if (unit->mode == UNITMODE_NONE) {
362
c92651a54969 Made the client-server protocol more robust. When a change to a unit is made using the web interface, the main process is stopped during the update. Splitted the PID in two PID's, one for heating and one for cooling. Adjusted the web edit scrreen for this, but there are still rough edges. Replaced the PID code, maybe this one works better for our purpose. The simulator air temperature changes on the simulator heater and cooler, but it is not realistic at all. This is a development version, do not use in production. The version is 0.3.0
Michiel Broek <mbroek@mbse.eu>
parents: 361
diff changeset
1236 syslog(LOG_NOTICE, "Starting unit `%s' in inactive state", unit->name);
182
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1237 } else {
362
c92651a54969 Made the client-server protocol more robust. When a change to a unit is made using the web interface, the main process is stopped during the update. Splitted the PID in two PID's, one for heating and one for cooling. Adjusted the web edit scrreen for this, but there are still rough edges. Replaced the PID code, maybe this one works better for our purpose. The simulator air temperature changes on the simulator heater and cooler, but it is not realistic at all. This is a development version, do not use in production. The version is 0.3.0
Michiel Broek <mbroek@mbse.eu>
parents: 361
diff changeset
1238 syslog(LOG_NOTICE, "Starting unit `%s' in off state", unit->name);
182
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1239 }
497
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1240
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1241 /*
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1242 * Initialize logfile
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1243 */
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1244 if (unit->mode != UNITMODE_OFF) {
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1245 initlog(unit->name);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1246 }
182
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1247 }
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1248
111
bdf3c5278a24 Added missing conditional
Michiel Broek <mbroek@mbse.eu>
parents: 108
diff changeset
1249 #ifdef HAVE_WIRINGPI_H
241
4ba138737bf4 Added thread locks to all LCD access functions. This seems to have fixed the LCD corruption problems.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
1250 piLock(LOCK_LCD);
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
1251 #endif
238
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 235
diff changeset
1252 lcd_buf_write(1, (char *)" ThermFerm ");
108
50d2187fdb74 New rotating LCD display
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
1253 lcd_buf_write(2, (char *)" Version %s ", VERSION);
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
1254 #ifdef HAVE_WIRINGPI_H
241
4ba138737bf4 Added thread locks to all LCD access functions. This seems to have fixed the LCD corruption problems.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
1255 piUnlock(LOCK_LCD);
111
bdf3c5278a24 Added missing conditional
Michiel Broek <mbroek@mbse.eu>
parents: 108
diff changeset
1256 #endif
108
50d2187fdb74 New rotating LCD display
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
1257
33
2357e8636a60 Added user log with temperatures and cooler state
Michiel Broek <mbroek@mbse.eu>
parents: 29
diff changeset
1258
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1259 do {
46
000399c64d3f More client/server communications
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
1260 if (my_shutdown)
000399c64d3f More client/server communications
Michiel Broek <mbroek@mbse.eu>
parents: 44
diff changeset
1261 run = 0;
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1262
245
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
1263 /*
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
1264 * Use to stop processing units. Should be used when a unit is
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
1265 * added or removed.
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
1266 */
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
1267 if (run_pause) {
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
1268 run_hold = TRUE;
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
1269 syslog(LOG_NOTICE, "run_pause: entering hold state");
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
1270 for (;;) {
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
1271 usleep(100000);
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
1272 if (! run_pause)
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
1273 break;
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
1274 }
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
1275 syslog(LOG_NOTICE, "run_pause: leaving hold state");
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
1276 run_hold = FALSE;
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
1277 #ifdef HAVE_WIRINGPI_H
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
1278 /*
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
1279 * In case the LCD buffers were cleared, setup the first page.
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
1280 */
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
1281 piLock(LOCK_LCD);
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
1282 #endif
245
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
1283 lcd_buf_write(1, (char *)" ThermFerm ");
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
1284 lcd_buf_write(2, (char *)" Version %s ", VERSION);
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
1285 #ifdef HAVE_WIRINGPI_H
245
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
1286 piUnlock(LOCK_LCD);
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
1287 #endif
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
1288 }
b01b6238eb67 You can now safely add and remove units on a running system.
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
1289
64
2431965e8a8c Write loglines only every 60 seconds
Michiel Broek <mbroek@mbse.eu>
parents: 63
diff changeset
1290 now = time(NULL);
104
5e538c4e1ecb Added units logging
Michiel Broek <mbroek@mbse.eu>
parents: 93
diff changeset
1291 if (now != last) {
189
cc2b04d4db99 Init logfile when a unit is turned on. Added comments for profile processing.
Michiel Broek <mbroek@mbse.eu>
parents: 188
diff changeset
1292 /*
cc2b04d4db99 Init logfile when a unit is turned on. Added comments for profile processing.
Michiel Broek <mbroek@mbse.eu>
parents: 188
diff changeset
1293 * Each second
cc2b04d4db99 Init logfile when a unit is turned on. Added comments for profile processing.
Michiel Broek <mbroek@mbse.eu>
parents: 188
diff changeset
1294 */
64
2431965e8a8c Write loglines only every 60 seconds
Michiel Broek <mbroek@mbse.eu>
parents: 63
diff changeset
1295 last = now;
104
5e538c4e1ecb Added units logging
Michiel Broek <mbroek@mbse.eu>
parents: 93
diff changeset
1296 seconds++;
5e538c4e1ecb Added units logging
Michiel Broek <mbroek@mbse.eu>
parents: 93
diff changeset
1297
108
50d2187fdb74 New rotating LCD display
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
1298 row = 3;
50d2187fdb74 New rotating LCD display
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
1299 tm = localtime(&now);
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
1300 #ifdef HAVE_WIRINGPI_H
241
4ba138737bf4 Added thread locks to all LCD access functions. This seems to have fixed the LCD corruption problems.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
1301 piLock(LOCK_LCD);
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
1302 #endif
108
50d2187fdb74 New rotating LCD display
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
1303 lcd_buf_write(row++, " %02d-%02d-%04d ", tm->tm_mday, tm->tm_mon + 1, tm->tm_year + 1900);
50d2187fdb74 New rotating LCD display
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
1304 lcd_buf_write(row++, " %02d:%02d:%02d ", tm->tm_hour, tm->tm_min, tm->tm_sec);
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
1305 #ifdef HAVE_WIRINGPI_H
241
4ba138737bf4 Added thread locks to all LCD access functions. This seems to have fixed the LCD corruption problems.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
1306 piUnlock(LOCK_LCD);
182
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1307 #endif
105
a5a964148e34 Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents: 104
diff changeset
1308
486
5a237a99a793 Compacted LCD display for units, allways 4 instead of 4 to 6 lines. But it's a bit more cryptic. We could write a short manual.
Michiel Broek <mbroek@mbse.eu>
parents: 484
diff changeset
1309 #ifdef HAVE_WIRINGPI_H
5a237a99a793 Compacted LCD display for units, allways 4 instead of 4 to 6 lines. But it's a bit more cryptic. We could write a short manual.
Michiel Broek <mbroek@mbse.eu>
parents: 484
diff changeset
1310 piLock(LOCK_LCD);
5a237a99a793 Compacted LCD display for units, allways 4 instead of 4 to 6 lines. But it's a bit more cryptic. We could write a short manual.
Michiel Broek <mbroek@mbse.eu>
parents: 484
diff changeset
1311 #endif
497
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1312 lcd_buf_write(row, "Room temp N/A ");
486
5a237a99a793 Compacted LCD display for units, allways 4 instead of 4 to 6 lines. But it's a bit more cryptic. We could write a short manual.
Michiel Broek <mbroek@mbse.eu>
parents: 484
diff changeset
1313 #ifdef HAVE_WIRINGPI_H
5a237a99a793 Compacted LCD display for units, allways 4 instead of 4 to 6 lines. But it's a bit more cryptic. We could write a short manual.
Michiel Broek <mbroek@mbse.eu>
parents: 484
diff changeset
1314 piUnlock(LOCK_LCD);
5a237a99a793 Compacted LCD display for units, allways 4 instead of 4 to 6 lines. But it's a bit more cryptic. We could write a short manual.
Michiel Broek <mbroek@mbse.eu>
parents: 484
diff changeset
1315 #endif
207
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1316 if (Config.temp_address) {
395
e32e83550963 Switched to new device read code. Removed the incomplete support for the DS2408 1-wire chip.
Michiel Broek <mbroek@mbse.eu>
parents: 367
diff changeset
1317 rc = device_in(Config.temp_address, &temp);
207
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1318 if (rc == DEVPRESENT_YES) {
497
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1319 #ifdef HAVE_MOSQUITTO_H
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1320 if (mqtt_use && (Config.temp_value != temp)) {
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1321 sprintf(buf, "%.1f", temp / 1000.0);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1322 snprintf(topic, 1023, "fermenter/%s/room/temperature", hostname);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1323 rc = mosquitto_publish(mosq, &mqtt_mid_sent, topic, strlen(buf), buf, mqtt_qos, 1);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1324 }
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1325 #endif
207
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1326 Config.temp_value = temp;
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1327 Config.temp_state = 0;
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1328 #ifdef HAVE_WIRINGPI_H
241
4ba138737bf4 Added thread locks to all LCD access functions. This seems to have fixed the LCD corruption problems.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
1329 piLock(LOCK_LCD);
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
1330 #endif
486
5a237a99a793 Compacted LCD display for units, allways 4 instead of 4 to 6 lines. But it's a bit more cryptic. We could write a short manual.
Michiel Broek <mbroek@mbse.eu>
parents: 484
diff changeset
1331 lcd_buf_write(row, "Room temp %.1f%c ", Config.temp_value / 1000.0, 0x01);
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
1332 #ifdef HAVE_WIRINGPI_H
241
4ba138737bf4 Added thread locks to all LCD access functions. This seems to have fixed the LCD corruption problems.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
1333 piUnlock(LOCK_LCD);
207
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1334 #endif
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1335 } else if (rc == DEVPRESENT_ERROR) {
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1336 Config.temp_state = 1;
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1337 } else {
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1338 Config.temp_state = 2;
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1339 }
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1340 }
486
5a237a99a793 Compacted LCD display for units, allways 4 instead of 4 to 6 lines. But it's a bit more cryptic. We could write a short manual.
Michiel Broek <mbroek@mbse.eu>
parents: 484
diff changeset
1341 row++;
5a237a99a793 Compacted LCD display for units, allways 4 instead of 4 to 6 lines. But it's a bit more cryptic. We could write a short manual.
Michiel Broek <mbroek@mbse.eu>
parents: 484
diff changeset
1342
5a237a99a793 Compacted LCD display for units, allways 4 instead of 4 to 6 lines. But it's a bit more cryptic. We could write a short manual.
Michiel Broek <mbroek@mbse.eu>
parents: 484
diff changeset
1343 #ifdef HAVE_WIRINGPI_H
5a237a99a793 Compacted LCD display for units, allways 4 instead of 4 to 6 lines. But it's a bit more cryptic. We could write a short manual.
Michiel Broek <mbroek@mbse.eu>
parents: 484
diff changeset
1344 piLock(LOCK_LCD);
5a237a99a793 Compacted LCD display for units, allways 4 instead of 4 to 6 lines. But it's a bit more cryptic. We could write a short manual.
Michiel Broek <mbroek@mbse.eu>
parents: 484
diff changeset
1345 #endif
497
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1346 lcd_buf_write(row, " Humidity N/A ");
486
5a237a99a793 Compacted LCD display for units, allways 4 instead of 4 to 6 lines. But it's a bit more cryptic. We could write a short manual.
Michiel Broek <mbroek@mbse.eu>
parents: 484
diff changeset
1347 #ifdef HAVE_WIRINGPI_H
5a237a99a793 Compacted LCD display for units, allways 4 instead of 4 to 6 lines. But it's a bit more cryptic. We could write a short manual.
Michiel Broek <mbroek@mbse.eu>
parents: 484
diff changeset
1348 piUnlock(LOCK_LCD);
5a237a99a793 Compacted LCD display for units, allways 4 instead of 4 to 6 lines. But it's a bit more cryptic. We could write a short manual.
Michiel Broek <mbroek@mbse.eu>
parents: 484
diff changeset
1349 #endif
207
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1350
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1351 if (Config.hum_address) {
395
e32e83550963 Switched to new device read code. Removed the incomplete support for the DS2408 1-wire chip.
Michiel Broek <mbroek@mbse.eu>
parents: 367
diff changeset
1352 rc = device_in(Config.hum_address, &temp);
207
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1353 if (rc == DEVPRESENT_YES) {
497
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1354 #ifdef HAVE_MOSQUITTO_H
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1355 if (mqtt_use && (Config.hum_value != temp)) {
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1356 sprintf(buf, "%.1f", temp / 1000.0);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1357 snprintf(topic, 1023, "fermenter/%s/room/humidity", hostname);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1358 mosquitto_publish(mosq, &mqtt_mid_sent, topic, strlen(buf), buf, mqtt_qos, 1);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1359 }
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1360 #endif
207
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1361 Config.hum_value = temp;
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1362 Config.hum_state = 0;
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1363 #ifdef HAVE_WIRINGPI_H
241
4ba138737bf4 Added thread locks to all LCD access functions. This seems to have fixed the LCD corruption problems.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
1364 piLock(LOCK_LCD);
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
1365 #endif
486
5a237a99a793 Compacted LCD display for units, allways 4 instead of 4 to 6 lines. But it's a bit more cryptic. We could write a short manual.
Michiel Broek <mbroek@mbse.eu>
parents: 484
diff changeset
1366 lcd_buf_write(row, " Humidity %.1f%% ", Config.hum_value / 1000.0);
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
1367 #ifdef HAVE_WIRINGPI_H
241
4ba138737bf4 Added thread locks to all LCD access functions. This seems to have fixed the LCD corruption problems.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
1368 piUnlock(LOCK_LCD);
207
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1369 #endif
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1370 } else if (rc == DEVPRESENT_ERROR) {
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1371 Config.hum_state = 1;
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1372 } else {
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1373 Config.hum_state = 2;
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1374 }
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1375 }
486
5a237a99a793 Compacted LCD display for units, allways 4 instead of 4 to 6 lines. But it's a bit more cryptic. We could write a short manual.
Michiel Broek <mbroek@mbse.eu>
parents: 484
diff changeset
1376 row++;
207
8d2ba4126519 Added global setup
Michiel Broek <mbroek@mbse.eu>
parents: 206
diff changeset
1377
486
5a237a99a793 Compacted LCD display for units, allways 4 instead of 4 to 6 lines. But it's a bit more cryptic. We could write a short manual.
Michiel Broek <mbroek@mbse.eu>
parents: 484
diff changeset
1378 LCDunit = 0;
108
50d2187fdb74 New rotating LCD display
Michiel Broek <mbroek@mbse.eu>
parents: 106
diff changeset
1379 for (unit = Config.units; unit; unit = unit->next) {
486
5a237a99a793 Compacted LCD display for units, allways 4 instead of 4 to 6 lines. But it's a bit more cryptic. We could write a short manual.
Michiel Broek <mbroek@mbse.eu>
parents: 484
diff changeset
1380 LCDunit++;
182
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1381 if (unit->air_address) {
395
e32e83550963 Switched to new device read code. Removed the incomplete support for the DS2408 1-wire chip.
Michiel Broek <mbroek@mbse.eu>
parents: 367
diff changeset
1382 rc = device_in(unit->air_address, &temp);
182
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1383 if (rc == DEVPRESENT_YES) {
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1384 /*
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1385 * It is possible to have read errors or extreme values.
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1386 * This can happen with bad connections so we compare the
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1387 * value with the previous one. If the difference is too
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1388 * much, we don't send that value. That also means that if
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1389 * the next value is ok again, it will be marked invalid too.
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1390 * Maximum error is 40 degrees for now.
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1391 */
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1392 deviation = 40000;
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1393 if ((unit->air_temperature == 0) ||
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1394 (unit->air_temperature && (temp > (int)unit->air_temperature - deviation) && (temp < ((int)unit->air_temperature + deviation)))) {
497
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1395 #ifdef HAVE_MOSQUITTO_H
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1396 if (mqtt_use && (unit->air_temperature != temp)) {
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1397 sprintf(buf, "%.3f", temp / 1000.0);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1398 snprintf(topic, 1023, "fermenter/%s/%s/air/temperature", hostname, unit->uuid);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1399 mosquitto_publish(mosq, &mqtt_mid_sent, topic, strlen(buf), buf, mqtt_qos, 1);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1400 }
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1401 #endif
182
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1402 unit->air_temperature = temp;
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1403 unit->air_state = 0;
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1404 } else {
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1405 syslog(LOG_NOTICE, "deviation error deviation=%d, old=%d new=%d", deviation, unit->air_temperature, temp);
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1406 if (debug) {
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1407 fprintf(stdout, "deviation error deviation=%d, old=%d new=%d\n", deviation, unit->air_temperature, temp);
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1408 }
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1409 }
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1410 } else if (rc == DEVPRESENT_ERROR) {
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1411 unit->air_state = 1;
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1412 } else {
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1413 unit->air_state = 2;
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1414 }
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1415 }
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1416
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1417 if (unit->beer_address) {
395
e32e83550963 Switched to new device read code. Removed the incomplete support for the DS2408 1-wire chip.
Michiel Broek <mbroek@mbse.eu>
parents: 367
diff changeset
1418 rc = device_in(unit->beer_address, &temp);
182
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1419 if (rc == DEVPRESENT_YES) {
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1420 deviation = 40000;
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1421 if ((unit->beer_temperature == 0) ||
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1422 (unit->beer_temperature && (temp > (int)unit->beer_temperature - deviation) && (temp < ((int)unit->beer_temperature + deviation)))) {
497
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1423 #ifdef HAVE_MOSQUITTO_H
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1424 if (mqtt_use && (unit->beer_temperature != temp)) {
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1425 sprintf(buf, "%.3f", temp / 1000.0);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1426 snprintf(topic, 1023, "fermenter/%s/%s/beer/temperature", hostname, unit->uuid);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1427 mosquitto_publish(mosq, &mqtt_mid_sent, topic, strlen(buf), buf, mqtt_qos, 1);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1428 }
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1429 #endif
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1430 unit->beer_temperature = temp;
182
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1431 unit->beer_state = 0;
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1432 } else {
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1433 syslog(LOG_NOTICE, "deviation error deviation=%d, old=%d new=%d", deviation, unit->beer_temperature, temp);
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1434 if (debug) {
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1435 fprintf(stdout, "deviation error deviation=%d, old=%d new=%d\n", deviation, unit->beer_temperature, temp);
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1436 }
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1437 }
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1438 } else if (rc == DEVPRESENT_ERROR) {
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1439 unit->beer_state = 1;
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1440 } else {
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1441 unit->beer_state = 2;
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1442 }
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
1443 }
184
db997a04fde3 Fixed switching problems
Michiel Broek <mbroek@mbse.eu>
parents: 182
diff changeset
1444
496
5cf6f099c897 The FAN always runs if the unit is active. Bumped tp version 0.5.3
Michiel Broek <mbroek@mbse.eu>
parents: 494
diff changeset
1445 /*
5cf6f099c897 The FAN always runs if the unit is active. Bumped tp version 0.5.3
Michiel Broek <mbroek@mbse.eu>
parents: 494
diff changeset
1446 * Unit door state, default is closed.
5cf6f099c897 The FAN always runs if the unit is active. Bumped tp version 0.5.3
Michiel Broek <mbroek@mbse.eu>
parents: 494
diff changeset
1447 */
5cf6f099c897 The FAN always runs if the unit is active. Bumped tp version 0.5.3
Michiel Broek <mbroek@mbse.eu>
parents: 494
diff changeset
1448 unit->door_state = 1;
350
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1449 if (unit->door_address) {
395
e32e83550963 Switched to new device read code. Removed the incomplete support for the DS2408 1-wire chip.
Michiel Broek <mbroek@mbse.eu>
parents: 367
diff changeset
1450 rc = device_in(unit->door_address, &temp);
350
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1451 if (rc == DEVPRESENT_YES) {
497
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1452 #ifdef HAVE_MOSQUITTO_H
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1453 snprintf(topic, 1023, "fermenter/%s/%s/door", hostname, unit->uuid);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1454 #endif
350
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1455 if (temp) {
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1456 if (unit->door_state == 0) {
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1457 syslog(LOG_NOTICE, "Unit `%s' door closed", unit->name);
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1458 unit->door_state = 1;
497
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1459 #ifdef HAVE_MOSQUITTO_H
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1460 if (mqtt_use) {
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1461 sprintf(buf, "closed");
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1462 mosquitto_publish(mosq, &mqtt_mid_sent, topic, strlen(buf), buf, mqtt_qos, 1);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1463 }
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1464 #endif
350
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1465 }
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1466 } else {
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1467 if (unit->door_state) {
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1468 syslog(LOG_NOTICE, "Unit `%s' door opened", unit->name);
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1469 unit->door_state = 0;
497
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1470 #ifdef HAVE_MOSQUITTO_H
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1471 if (mqtt_use) {
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1472 sprintf(buf, "open");
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1473 mosquitto_publish(mosq, &mqtt_mid_sent, topic, strlen(buf), buf, mqtt_qos, 1);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1474 }
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1475 #endif
350
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1476 }
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1477 }
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1478 }
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1479 }
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1480
496
5cf6f099c897 The FAN always runs if the unit is active. Bumped tp version 0.5.3
Michiel Broek <mbroek@mbse.eu>
parents: 494
diff changeset
1481 /*
5cf6f099c897 The FAN always runs if the unit is active. Bumped tp version 0.5.3
Michiel Broek <mbroek@mbse.eu>
parents: 494
diff changeset
1482 * Unit PSU state, default power is ok
5cf6f099c897 The FAN always runs if the unit is active. Bumped tp version 0.5.3
Michiel Broek <mbroek@mbse.eu>
parents: 494
diff changeset
1483 */
5cf6f099c897 The FAN always runs if the unit is active. Bumped tp version 0.5.3
Michiel Broek <mbroek@mbse.eu>
parents: 494
diff changeset
1484 unit->psu_state = 1;
350
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1485 if (unit->psu_address) {
395
e32e83550963 Switched to new device read code. Removed the incomplete support for the DS2408 1-wire chip.
Michiel Broek <mbroek@mbse.eu>
parents: 367
diff changeset
1486 rc = device_in(unit->psu_address, &temp);
350
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1487 if (rc == DEVPRESENT_YES) {
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1488 if (temp) {
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1489 if (unit->psu_state == 0) {
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1490 syslog(LOG_NOTICE, "Unit `%s' PSU (12 volt) is on", unit->name);
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1491 unit->psu_state = 1;
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1492 }
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1493 } else {
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1494 if (unit->psu_state) {
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1495 syslog(LOG_NOTICE, "Unit `%s' PSU (12 volt) is off", unit->name);
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1496 unit->psu_state = 0;
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1497 }
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1498 }
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1499 }
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1500 }
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1501
184
db997a04fde3 Fixed switching problems
Michiel Broek <mbroek@mbse.eu>
parents: 182
diff changeset
1502 /*
189
cc2b04d4db99 Init logfile when a unit is turned on. Added comments for profile processing.
Michiel Broek <mbroek@mbse.eu>
parents: 188
diff changeset
1503 * Handle profile
cc2b04d4db99 Init logfile when a unit is turned on. Added comments for profile processing.
Michiel Broek <mbroek@mbse.eu>
parents: 188
diff changeset
1504 */
cc2b04d4db99 Init logfile when a unit is turned on. Added comments for profile processing.
Michiel Broek <mbroek@mbse.eu>
parents: 188
diff changeset
1505 if ((unit->mode == UNITMODE_PROFILE) && (unit->profile)) {
cc2b04d4db99 Init logfile when a unit is turned on. Added comments for profile processing.
Michiel Broek <mbroek@mbse.eu>
parents: 188
diff changeset
1506 /*
cc2b04d4db99 Init logfile when a unit is turned on. Added comments for profile processing.
Michiel Broek <mbroek@mbse.eu>
parents: 188
diff changeset
1507 * unit->profile - uuid of the selected profile.
cc2b04d4db99 Init logfile when a unit is turned on. Added comments for profile processing.
Michiel Broek <mbroek@mbse.eu>
parents: 188
diff changeset
1508 * unit->prof_started - start time or 0 if not yet running.
cc2b04d4db99 Init logfile when a unit is turned on. Added comments for profile processing.
Michiel Broek <mbroek@mbse.eu>
parents: 188
diff changeset
1509 * unit->prof_state - PROFILE_OFF|PROFILE_PAUSE|PROFILE_RUN|PROFILE_DONE
cc2b04d4db99 Init logfile when a unit is turned on. Added comments for profile processing.
Michiel Broek <mbroek@mbse.eu>
parents: 188
diff changeset
1510 * unit->prof_target - Calculated target temperature.
194
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1511 * unit->prof_paused - Internal pause counter.
289
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1512 * unit->prof_peak_abs - Peak temperature of the beer.
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1513 * unit->prof_peak_rel - Peak temperature between beer and fridge.
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1514 * unit->prof_primary_done - time when primary fermentation was over the peak.
189
cc2b04d4db99 Init logfile when a unit is turned on. Added comments for profile processing.
Michiel Broek <mbroek@mbse.eu>
parents: 188
diff changeset
1515 */
194
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1516 for (profile = Config.profiles; profile; profile = profile->next) {
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1517 if (strcmp(unit->profile, profile->uuid) == 0) {
219
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1518
398
efdfef1677d1 Fixed crash after profile is finished. Fixed error in UNIT GET output.
Michiel Broek <mbroek@mbse.eu>
parents: 397
diff changeset
1519 /*
efdfef1677d1 Fixed crash after profile is finished. Fixed error in UNIT GET output.
Michiel Broek <mbroek@mbse.eu>
parents: 397
diff changeset
1520 * Safe defaults
efdfef1677d1 Fixed crash after profile is finished. Fixed error in UNIT GET output.
Michiel Broek <mbroek@mbse.eu>
parents: 397
diff changeset
1521 */
efdfef1677d1 Fixed crash after profile is finished. Fixed error in UNIT GET output.
Michiel Broek <mbroek@mbse.eu>
parents: 397
diff changeset
1522 unit->prof_target_lo = profile->inittemp_lo;
efdfef1677d1 Fixed crash after profile is finished. Fixed error in UNIT GET output.
Michiel Broek <mbroek@mbse.eu>
parents: 397
diff changeset
1523 unit->prof_target_hi = profile->inittemp_hi;
efdfef1677d1 Fixed crash after profile is finished. Fixed error in UNIT GET output.
Michiel Broek <mbroek@mbse.eu>
parents: 397
diff changeset
1524 unit->prof_fridge_mode = 0;
efdfef1677d1 Fixed crash after profile is finished. Fixed error in UNIT GET output.
Michiel Broek <mbroek@mbse.eu>
parents: 397
diff changeset
1525
194
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1526 switch (unit->prof_state) {
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1527 case PROFILE_OFF:
284
9e6fb5aed618 Profile progress is visible in the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 277
diff changeset
1528 unit->prof_percent = 0;
194
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1529 break;
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1530 case PROFILE_PAUSE:
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1531 /*
219
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1532 * Keep current temperature, measure pause time. For
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1533 * temperature fall thru.
194
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1534 */
219
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1535 unit->prof_paused++;
194
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1536 case PROFILE_RUN:
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1537 /*
288
8b99ab77262b Corrected comment
Michiel Broek <mbroek@mbse.eu>
parents: 284
diff changeset
1538 * Calculate current profile step and desired temperature.
8b99ab77262b Corrected comment
Michiel Broek <mbroek@mbse.eu>
parents: 284
diff changeset
1539 * When all steps are done, set state to PROFILE_DONE.
194
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1540 */
397
00ca08f5a6f8 Fermentation profiles now have a low and high temperature setting so that you can use a temperture window. Each profile step can now set for beer or air temperature reference. The logfiles have an extra temperature field for this. Bumped to version 0.4.2.
Michiel Broek <mbroek@mbse.eu>
parents: 395
diff changeset
1541 previous_target_lo = profile->inittemp_lo;
00ca08f5a6f8 Fermentation profiles now have a low and high temperature setting so that you can use a temperture window. Each profile step can now set for beer or air temperature reference. The logfiles have an extra temperature field for this. Bumped to version 0.4.2.
Michiel Broek <mbroek@mbse.eu>
parents: 395
diff changeset
1542 previous_target_hi = profile->inittemp_hi;
398
efdfef1677d1 Fixed crash after profile is finished. Fixed error in UNIT GET output.
Michiel Broek <mbroek@mbse.eu>
parents: 397
diff changeset
1543 previous_fridge_mode = profile->fridge_mode;
277
6f9a7cca8f19 Fixed profile progess percentage
Michiel Broek <mbroek@mbse.eu>
parents: 276
diff changeset
1544 time_until_now = current_step = 0;
194
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1545 run_seconds = (int)(now - unit->prof_started - unit->prof_paused);
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1546 run_minutes = run_seconds / 60;
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1547 run_hours = run_minutes / 60;
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1548 if (debug)
221
91a5e7281c35 Fixed end of profile steps, didn't go to the PROFILE_DONE state.
Michiel Broek <mbroek@mbse.eu>
parents: 219
diff changeset
1549 fprintf(stdout, "run_HMS=%d,%d,%d ", run_hours, run_minutes, run_seconds);
219
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1550
277
6f9a7cca8f19 Fixed profile progess percentage
Michiel Broek <mbroek@mbse.eu>
parents: 276
diff changeset
1551 /*
289
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1552 * Primary fermentation tests
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1553 */
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1554 if ((unit->beer_temperature / 1000.0) > unit->prof_peak_abs)
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1555 unit->prof_peak_abs = unit->beer_temperature / 1000.0;
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1556 if (((unit->beer_temperature - unit->air_temperature) / 1000.0) > unit->prof_peak_rel)
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1557 unit->prof_peak_rel = (unit->beer_temperature - unit->air_temperature) / 1000.0;
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1558 if (unit->prof_primary_done == 0) {
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1559 if (unit->cooler_address) {
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1560 /*
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1561 * There is a cooler. If the difference between the beer and air temperature
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1562 * drops we assume the primary fermentation is done.
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1563 */
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1564 if (((unit->beer_temperature - unit->air_temperature) / 1000.0) < (unit->prof_peak_rel - 0.5)) {
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1565 unit->prof_primary_done = time(NULL);
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1566 syslog(LOG_NOTICE, "Profile `%s' primary fermentation is ready (cooler mode)", profile->name);
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1567 }
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1568 } else {
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1569 /*
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1570 * This method works if the unit has no cooling or if the profile allowd the
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1571 * beer temperature to rise freely.
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1572 */
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1573 if ((unit->beer_temperature / 1000.0) < (unit->prof_peak_abs - 0.5)) {
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1574 unit->prof_primary_done = time(NULL);
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1575 syslog(LOG_NOTICE, "Profile `%s' primary fermentation is ready (free rise mode)", profile->name);
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1576 }
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1577 }
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1578 }
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1579
d810df0df36a Added code to detect primary fermentation
Michiel Broek <mbroek@mbse.eu>
parents: 288
diff changeset
1580 /*
277
6f9a7cca8f19 Fixed profile progess percentage
Michiel Broek <mbroek@mbse.eu>
parents: 276
diff changeset
1581 * See how long this profile will take
6f9a7cca8f19 Fixed profile progess percentage
Michiel Broek <mbroek@mbse.eu>
parents: 276
diff changeset
1582 */
6f9a7cca8f19 Fixed profile progess percentage
Michiel Broek <mbroek@mbse.eu>
parents: 276
diff changeset
1583 tot_minutes = 0;
6f9a7cca8f19 Fixed profile progess percentage
Michiel Broek <mbroek@mbse.eu>
parents: 276
diff changeset
1584 for (step = profile->steps; step; step = step->next) {
6f9a7cca8f19 Fixed profile progess percentage
Michiel Broek <mbroek@mbse.eu>
parents: 276
diff changeset
1585 tot_minutes += ((step->steptime + step->resttime) * 60);
6f9a7cca8f19 Fixed profile progess percentage
Michiel Broek <mbroek@mbse.eu>
parents: 276
diff changeset
1586 }
6f9a7cca8f19 Fixed profile progess percentage
Michiel Broek <mbroek@mbse.eu>
parents: 276
diff changeset
1587
221
91a5e7281c35 Fixed end of profile steps, didn't go to the PROFILE_DONE state.
Michiel Broek <mbroek@mbse.eu>
parents: 219
diff changeset
1588 valid_step = FALSE;
91a5e7281c35 Fixed end of profile steps, didn't go to the PROFILE_DONE state.
Michiel Broek <mbroek@mbse.eu>
parents: 219
diff changeset
1589 for (step = profile->steps; step; step = step->next) {
219
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1590 /*
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1591 * step->steptime
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1592 * step->resttime
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1593 * step->target
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1594 */
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1595 current_step++;
221
91a5e7281c35 Fixed end of profile steps, didn't go to the PROFILE_DONE state.
Michiel Broek <mbroek@mbse.eu>
parents: 219
diff changeset
1596 if ((run_hours >= time_until_now) && (run_hours < (time_until_now + step->steptime + step->resttime))) {
219
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1597 /*
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1598 * This is our current step
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1599 */
221
91a5e7281c35 Fixed end of profile steps, didn't go to the PROFILE_DONE state.
Michiel Broek <mbroek@mbse.eu>
parents: 219
diff changeset
1600 valid_step = TRUE;
219
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1601 if (debug)
397
00ca08f5a6f8 Fermentation profiles now have a low and high temperature setting so that you can use a temperture window. Each profile step can now set for beer or air temperature reference. The logfiles have an extra temperature field for this. Bumped to version 0.4.2.
Michiel Broek <mbroek@mbse.eu>
parents: 395
diff changeset
1602 fprintf(stdout, "step=%d step_pos=%d step=%d/%d target=%.1f..%.1f ",
221
91a5e7281c35 Fixed end of profile steps, didn't go to the PROFILE_DONE state.
Michiel Broek <mbroek@mbse.eu>
parents: 219
diff changeset
1603 current_step, run_hours - time_until_now,
397
00ca08f5a6f8 Fermentation profiles now have a low and high temperature setting so that you can use a temperture window. Each profile step can now set for beer or air temperature reference. The logfiles have an extra temperature field for this. Bumped to version 0.4.2.
Michiel Broek <mbroek@mbse.eu>
parents: 395
diff changeset
1604 step->steptime, step->resttime, step->target_lo, step->target_hi);
219
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1605 if ((run_hours - time_until_now) < step->steptime) {
397
00ca08f5a6f8 Fermentation profiles now have a low and high temperature setting so that you can use a temperture window. Each profile step can now set for beer or air temperature reference. The logfiles have an extra temperature field for this. Bumped to version 0.4.2.
Michiel Broek <mbroek@mbse.eu>
parents: 395
diff changeset
1606 unit->prof_target_lo = previous_target_lo + (((run_minutes - (time_until_now * 60.0)) / (step->steptime * 60.0)) * (step->target_lo - previous_target_lo));
00ca08f5a6f8 Fermentation profiles now have a low and high temperature setting so that you can use a temperture window. Each profile step can now set for beer or air temperature reference. The logfiles have an extra temperature field for this. Bumped to version 0.4.2.
Michiel Broek <mbroek@mbse.eu>
parents: 395
diff changeset
1607 unit->prof_target_hi = previous_target_hi + (((run_minutes - (time_until_now * 60.0)) / (step->steptime * 60.0)) * (step->target_hi - previous_target_hi));
401
0226d0f37bb7 More fixes for profiles temperature window. Added the sliding beer/air target switch.
Michiel Broek <mbroek@mbse.eu>
parents: 398
diff changeset
1608 if (step->fridge_mode > previous_fridge_mode) {
0226d0f37bb7 More fixes for profiles temperature window. Added the sliding beer/air target switch.
Michiel Broek <mbroek@mbse.eu>
parents: 398
diff changeset
1609 unit->prof_fridge_mode = (((run_minutes - (time_until_now * 60)) * 100) / (step->steptime * 60));
0226d0f37bb7 More fixes for profiles temperature window. Added the sliding beer/air target switch.
Michiel Broek <mbroek@mbse.eu>
parents: 398
diff changeset
1610 } else if (step->fridge_mode < previous_fridge_mode) {
0226d0f37bb7 More fixes for profiles temperature window. Added the sliding beer/air target switch.
Michiel Broek <mbroek@mbse.eu>
parents: 398
diff changeset
1611 unit->prof_fridge_mode = 100 - (((run_minutes - (time_until_now * 60)) * 100) / (step->steptime * 60));
0226d0f37bb7 More fixes for profiles temperature window. Added the sliding beer/air target switch.
Michiel Broek <mbroek@mbse.eu>
parents: 398
diff changeset
1612 } else {
0226d0f37bb7 More fixes for profiles temperature window. Added the sliding beer/air target switch.
Michiel Broek <mbroek@mbse.eu>
parents: 398
diff changeset
1613 unit->prof_fridge_mode = step->fridge_mode;
0226d0f37bb7 More fixes for profiles temperature window. Added the sliding beer/air target switch.
Michiel Broek <mbroek@mbse.eu>
parents: 398
diff changeset
1614 }
0226d0f37bb7 More fixes for profiles temperature window. Added the sliding beer/air target switch.
Michiel Broek <mbroek@mbse.eu>
parents: 398
diff changeset
1615 if (debug)
397
00ca08f5a6f8 Fermentation profiles now have a low and high temperature setting so that you can use a temperture window. Each profile step can now set for beer or air temperature reference. The logfiles have an extra temperature field for this. Bumped to version 0.4.2.
Michiel Broek <mbroek@mbse.eu>
parents: 395
diff changeset
1616 fprintf(stdout, "tempshift=%.1f..%.1f minutes=%d duration=%d temp_move=%.3f..%.3f ",
00ca08f5a6f8 Fermentation profiles now have a low and high temperature setting so that you can use a temperture window. Each profile step can now set for beer or air temperature reference. The logfiles have an extra temperature field for this. Bumped to version 0.4.2.
Michiel Broek <mbroek@mbse.eu>
parents: 395
diff changeset
1617 step->target_lo - previous_target_lo,
00ca08f5a6f8 Fermentation profiles now have a low and high temperature setting so that you can use a temperture window. Each profile step can now set for beer or air temperature reference. The logfiles have an extra temperature field for this. Bumped to version 0.4.2.
Michiel Broek <mbroek@mbse.eu>
parents: 395
diff changeset
1618 step->target_hi - previous_target_hi,
00ca08f5a6f8 Fermentation profiles now have a low and high temperature setting so that you can use a temperture window. Each profile step can now set for beer or air temperature reference. The logfiles have an extra temperature field for this. Bumped to version 0.4.2.
Michiel Broek <mbroek@mbse.eu>
parents: 395
diff changeset
1619 run_minutes - (time_until_now * 60),
00ca08f5a6f8 Fermentation profiles now have a low and high temperature setting so that you can use a temperture window. Each profile step can now set for beer or air temperature reference. The logfiles have an extra temperature field for this. Bumped to version 0.4.2.
Michiel Broek <mbroek@mbse.eu>
parents: 395
diff changeset
1620 step->steptime * 60, unit->prof_target_lo, unit->prof_target_hi);
219
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1621 } else {
397
00ca08f5a6f8 Fermentation profiles now have a low and high temperature setting so that you can use a temperture window. Each profile step can now set for beer or air temperature reference. The logfiles have an extra temperature field for this. Bumped to version 0.4.2.
Michiel Broek <mbroek@mbse.eu>
parents: 395
diff changeset
1622 unit->prof_target_lo = step->target_lo;
00ca08f5a6f8 Fermentation profiles now have a low and high temperature setting so that you can use a temperture window. Each profile step can now set for beer or air temperature reference. The logfiles have an extra temperature field for this. Bumped to version 0.4.2.
Michiel Broek <mbroek@mbse.eu>
parents: 395
diff changeset
1623 unit->prof_target_hi = step->target_hi;
398
efdfef1677d1 Fixed crash after profile is finished. Fixed error in UNIT GET output.
Michiel Broek <mbroek@mbse.eu>
parents: 397
diff changeset
1624 unit->prof_fridge_mode = step->fridge_mode;
397
00ca08f5a6f8 Fermentation profiles now have a low and high temperature setting so that you can use a temperture window. Each profile step can now set for beer or air temperature reference. The logfiles have an extra temperature field for this. Bumped to version 0.4.2.
Michiel Broek <mbroek@mbse.eu>
parents: 395
diff changeset
1625 if (debug)
00ca08f5a6f8 Fermentation profiles now have a low and high temperature setting so that you can use a temperture window. Each profile step can now set for beer or air temperature reference. The logfiles have an extra temperature field for this. Bumped to version 0.4.2.
Michiel Broek <mbroek@mbse.eu>
parents: 395
diff changeset
1626 fprintf(stdout, "resting target=%.1f..%.1f ", step->target_lo, step->target_hi);
219
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1627 }
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1628 break;
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1629 }
221
91a5e7281c35 Fixed end of profile steps, didn't go to the PROFILE_DONE state.
Michiel Broek <mbroek@mbse.eu>
parents: 219
diff changeset
1630 time_until_now += step->steptime + step->resttime;
397
00ca08f5a6f8 Fermentation profiles now have a low and high temperature setting so that you can use a temperture window. Each profile step can now set for beer or air temperature reference. The logfiles have an extra temperature field for this. Bumped to version 0.4.2.
Michiel Broek <mbroek@mbse.eu>
parents: 395
diff changeset
1631 previous_target_lo = step->target_lo;
00ca08f5a6f8 Fermentation profiles now have a low and high temperature setting so that you can use a temperture window. Each profile step can now set for beer or air temperature reference. The logfiles have an extra temperature field for this. Bumped to version 0.4.2.
Michiel Broek <mbroek@mbse.eu>
parents: 395
diff changeset
1632 previous_target_hi = step->target_hi;
398
efdfef1677d1 Fixed crash after profile is finished. Fixed error in UNIT GET output.
Michiel Broek <mbroek@mbse.eu>
parents: 397
diff changeset
1633 previous_fridge_mode = step->fridge_mode;
194
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1634 }
219
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1635 if (debug)
274
111b0e9663dc Added logging if profile state is changed via the web interface. Log profile progress each half hour in syslog. Profile resttime steps 0 hours is allowed, meaning resttime or steptime must be set for a valid step. Updated the helptext on the web page.
Michiel Broek <mbroek@mbse.eu>
parents: 273
diff changeset
1636 fprintf(stdout, " %s %02d:%02d\n", valid_step ? "TRUE":"FALSE", minutes, seconds);
221
91a5e7281c35 Fixed end of profile steps, didn't go to the PROFILE_DONE state.
Michiel Broek <mbroek@mbse.eu>
parents: 219
diff changeset
1637
274
111b0e9663dc Added logging if profile state is changed via the web interface. Log profile progress each half hour in syslog. Profile resttime steps 0 hours is allowed, meaning resttime or steptime must be set for a valid step. Updated the helptext on the web page.
Michiel Broek <mbroek@mbse.eu>
parents: 273
diff changeset
1638 if (valid_step == TRUE) {
284
9e6fb5aed618 Profile progress is visible in the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 277
diff changeset
1639 unit->prof_percent = (100 * run_minutes) / tot_minutes;
276
a19cc3770f09 Profile progress logging now also shows the percentage done. The DEVICE PUT command logs all changed values.
Michiel Broek <mbroek@mbse.eu>
parents: 275
diff changeset
1640 if (((minutes == 10) || (minutes == 40)) && (seconds == 1)) {
397
00ca08f5a6f8 Fermentation profiles now have a low and high temperature setting so that you can use a temperture window. Each profile step can now set for beer or air temperature reference. The logfiles have an extra temperature field for this. Bumped to version 0.4.2.
Michiel Broek <mbroek@mbse.eu>
parents: 395
diff changeset
1641 syslog(LOG_NOTICE, "Profile `%s' running %dd %02d:%02d in step %d, %d%% done, target %s %.3f..%.3f degrees",
276
a19cc3770f09 Profile progress logging now also shows the percentage done. The DEVICE PUT command logs all changed values.
Michiel Broek <mbroek@mbse.eu>
parents: 275
diff changeset
1642 profile->name, run_hours / 24, run_hours % 24, run_minutes % 60, current_step,
397
00ca08f5a6f8 Fermentation profiles now have a low and high temperature setting so that you can use a temperture window. Each profile step can now set for beer or air temperature reference. The logfiles have an extra temperature field for this. Bumped to version 0.4.2.
Michiel Broek <mbroek@mbse.eu>
parents: 395
diff changeset
1643 unit->prof_percent, unit->prof_fridge_mode ? (char *)"air":(char *)"beer",
00ca08f5a6f8 Fermentation profiles now have a low and high temperature setting so that you can use a temperture window. Each profile step can now set for beer or air temperature reference. The logfiles have an extra temperature field for this. Bumped to version 0.4.2.
Michiel Broek <mbroek@mbse.eu>
parents: 395
diff changeset
1644 unit->prof_target_lo, unit->prof_target_hi);
274
111b0e9663dc Added logging if profile state is changed via the web interface. Log profile progress each half hour in syslog. Profile resttime steps 0 hours is allowed, meaning resttime or steptime must be set for a valid step. Updated the helptext on the web page.
Michiel Broek <mbroek@mbse.eu>
parents: 273
diff changeset
1645 }
111b0e9663dc Added logging if profile state is changed via the web interface. Log profile progress each half hour in syslog. Profile resttime steps 0 hours is allowed, meaning resttime or steptime must be set for a valid step. Updated the helptext on the web page.
Michiel Broek <mbroek@mbse.eu>
parents: 273
diff changeset
1646 } else {
111b0e9663dc Added logging if profile state is changed via the web interface. Log profile progress each half hour in syslog. Profile resttime steps 0 hours is allowed, meaning resttime or steptime must be set for a valid step. Updated the helptext on the web page.
Michiel Broek <mbroek@mbse.eu>
parents: 273
diff changeset
1647 /*
111b0e9663dc Added logging if profile state is changed via the web interface. Log profile progress each half hour in syslog. Profile resttime steps 0 hours is allowed, meaning resttime or steptime must be set for a valid step. Updated the helptext on the web page.
Michiel Broek <mbroek@mbse.eu>
parents: 273
diff changeset
1648 * No more steps to do
111b0e9663dc Added logging if profile state is changed via the web interface. Log profile progress each half hour in syslog. Profile resttime steps 0 hours is allowed, meaning resttime or steptime must be set for a valid step. Updated the helptext on the web page.
Michiel Broek <mbroek@mbse.eu>
parents: 273
diff changeset
1649 */
221
91a5e7281c35 Fixed end of profile steps, didn't go to the PROFILE_DONE state.
Michiel Broek <mbroek@mbse.eu>
parents: 219
diff changeset
1650 unit->prof_state = PROFILE_DONE;
284
9e6fb5aed618 Profile progress is visible in the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 277
diff changeset
1651 unit->prof_percent = 100;
221
91a5e7281c35 Fixed end of profile steps, didn't go to the PROFILE_DONE state.
Michiel Broek <mbroek@mbse.eu>
parents: 219
diff changeset
1652 syslog(LOG_NOTICE, "Profile `%s' is done", profile->name);
91a5e7281c35 Fixed end of profile steps, didn't go to the PROFILE_DONE state.
Michiel Broek <mbroek@mbse.eu>
parents: 219
diff changeset
1653 }
194
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1654 break;
221
91a5e7281c35 Fixed end of profile steps, didn't go to the PROFILE_DONE state.
Michiel Broek <mbroek@mbse.eu>
parents: 219
diff changeset
1655
194
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1656 case PROFILE_DONE:
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1657 /*
219
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1658 * Keep this state, set target temperature to the last step.
194
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1659 */
397
00ca08f5a6f8 Fermentation profiles now have a low and high temperature setting so that you can use a temperture window. Each profile step can now set for beer or air temperature reference. The logfiles have an extra temperature field for this. Bumped to version 0.4.2.
Michiel Broek <mbroek@mbse.eu>
parents: 395
diff changeset
1660 previous_target_lo = profile->inittemp_lo;
00ca08f5a6f8 Fermentation profiles now have a low and high temperature setting so that you can use a temperture window. Each profile step can now set for beer or air temperature reference. The logfiles have an extra temperature field for this. Bumped to version 0.4.2.
Michiel Broek <mbroek@mbse.eu>
parents: 395
diff changeset
1661 previous_target_hi = profile->inittemp_hi;
398
efdfef1677d1 Fixed crash after profile is finished. Fixed error in UNIT GET output.
Michiel Broek <mbroek@mbse.eu>
parents: 397
diff changeset
1662 previous_fridge_mode = profile->fridge_mode;
219
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1663 for (step = profile->steps; step; step = step->next) {
398
efdfef1677d1 Fixed crash after profile is finished. Fixed error in UNIT GET output.
Michiel Broek <mbroek@mbse.eu>
parents: 397
diff changeset
1664 if ((step->steptime + step->resttime) == 0)
219
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1665 break;
397
00ca08f5a6f8 Fermentation profiles now have a low and high temperature setting so that you can use a temperture window. Each profile step can now set for beer or air temperature reference. The logfiles have an extra temperature field for this. Bumped to version 0.4.2.
Michiel Broek <mbroek@mbse.eu>
parents: 395
diff changeset
1666 previous_target_lo = step->target_lo;
00ca08f5a6f8 Fermentation profiles now have a low and high temperature setting so that you can use a temperture window. Each profile step can now set for beer or air temperature reference. The logfiles have an extra temperature field for this. Bumped to version 0.4.2.
Michiel Broek <mbroek@mbse.eu>
parents: 395
diff changeset
1667 previous_target_hi = step->target_hi;
398
efdfef1677d1 Fixed crash after profile is finished. Fixed error in UNIT GET output.
Michiel Broek <mbroek@mbse.eu>
parents: 397
diff changeset
1668 previous_fridge_mode = step->fridge_mode;
397
00ca08f5a6f8 Fermentation profiles now have a low and high temperature setting so that you can use a temperture window. Each profile step can now set for beer or air temperature reference. The logfiles have an extra temperature field for this. Bumped to version 0.4.2.
Michiel Broek <mbroek@mbse.eu>
parents: 395
diff changeset
1669
219
ae720212accc Added profile running and steps handling.
Michiel Broek <mbroek@mbse.eu>
parents: 215
diff changeset
1670 }
397
00ca08f5a6f8 Fermentation profiles now have a low and high temperature setting so that you can use a temperture window. Each profile step can now set for beer or air temperature reference. The logfiles have an extra temperature field for this. Bumped to version 0.4.2.
Michiel Broek <mbroek@mbse.eu>
parents: 395
diff changeset
1671 unit->prof_target_lo = previous_target_lo;
00ca08f5a6f8 Fermentation profiles now have a low and high temperature setting so that you can use a temperture window. Each profile step can now set for beer or air temperature reference. The logfiles have an extra temperature field for this. Bumped to version 0.4.2.
Michiel Broek <mbroek@mbse.eu>
parents: 395
diff changeset
1672 unit->prof_target_hi = previous_target_hi;
398
efdfef1677d1 Fixed crash after profile is finished. Fixed error in UNIT GET output.
Michiel Broek <mbroek@mbse.eu>
parents: 397
diff changeset
1673 unit->prof_fridge_mode = previous_fridge_mode;
284
9e6fb5aed618 Profile progress is visible in the web interface
Michiel Broek <mbroek@mbse.eu>
parents: 277
diff changeset
1674 unit->prof_percent = 100;
194
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1675 break;
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1676 } /* switch */
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1677 }
9eaaba49450f Added some ideas about profiles.
Michiel Broek <mbroek@mbse.eu>
parents: 189
diff changeset
1678 }
402
6b9f0c3c7f63 Set sane default profile values when not using a profile.
Michiel Broek <mbroek@mbse.eu>
parents: 401
diff changeset
1679 } else {
6b9f0c3c7f63 Set sane default profile values when not using a profile.
Michiel Broek <mbroek@mbse.eu>
parents: 401
diff changeset
1680 /*
6b9f0c3c7f63 Set sane default profile values when not using a profile.
Michiel Broek <mbroek@mbse.eu>
parents: 401
diff changeset
1681 * Set some sane values
6b9f0c3c7f63 Set sane default profile values when not using a profile.
Michiel Broek <mbroek@mbse.eu>
parents: 401
diff changeset
1682 */
6b9f0c3c7f63 Set sane default profile values when not using a profile.
Michiel Broek <mbroek@mbse.eu>
parents: 401
diff changeset
1683 unit->prof_target_lo = 19.8;
6b9f0c3c7f63 Set sane default profile values when not using a profile.
Michiel Broek <mbroek@mbse.eu>
parents: 401
diff changeset
1684 unit->prof_target_hi = 20.2;
6b9f0c3c7f63 Set sane default profile values when not using a profile.
Michiel Broek <mbroek@mbse.eu>
parents: 401
diff changeset
1685 unit->prof_fridge_mode = 0;
189
cc2b04d4db99 Init logfile when a unit is turned on. Added comments for profile processing.
Michiel Broek <mbroek@mbse.eu>
parents: 188
diff changeset
1686 }
cc2b04d4db99 Init logfile when a unit is turned on. Added comments for profile processing.
Michiel Broek <mbroek@mbse.eu>
parents: 188
diff changeset
1687
cc2b04d4db99 Init logfile when a unit is turned on. Added comments for profile processing.
Michiel Broek <mbroek@mbse.eu>
parents: 188
diff changeset
1688 /*
184
db997a04fde3 Fixed switching problems
Michiel Broek <mbroek@mbse.eu>
parents: 182
diff changeset
1689 * Manual switching
db997a04fde3 Fixed switching problems
Michiel Broek <mbroek@mbse.eu>
parents: 182
diff changeset
1690 */
db997a04fde3 Fixed switching problems
Michiel Broek <mbroek@mbse.eu>
parents: 182
diff changeset
1691 if (unit->mode == UNITMODE_NONE) {
db997a04fde3 Fixed switching problems
Michiel Broek <mbroek@mbse.eu>
parents: 182
diff changeset
1692 device_out(unit->heater_address, unit->heater_state);
db997a04fde3 Fixed switching problems
Michiel Broek <mbroek@mbse.eu>
parents: 182
diff changeset
1693 device_out(unit->cooler_address, unit->cooler_state);
db997a04fde3 Fixed switching problems
Michiel Broek <mbroek@mbse.eu>
parents: 182
diff changeset
1694 device_out(unit->fan_address, unit->fan_state);
db997a04fde3 Fixed switching problems
Michiel Broek <mbroek@mbse.eu>
parents: 182
diff changeset
1695 }
293
881b1ae75468 Added usage counters
Michiel Broek <mbroek@mbse.eu>
parents: 289
diff changeset
1696
881b1ae75468 Added usage counters
Michiel Broek <mbroek@mbse.eu>
parents: 289
diff changeset
1697 /*
881b1ae75468 Added usage counters
Michiel Broek <mbroek@mbse.eu>
parents: 289
diff changeset
1698 * Usage counters
881b1ae75468 Added usage counters
Michiel Broek <mbroek@mbse.eu>
parents: 289
diff changeset
1699 */
881b1ae75468 Added usage counters
Michiel Broek <mbroek@mbse.eu>
parents: 289
diff changeset
1700 if (unit->heater_address && unit->heater_state)
881b1ae75468 Added usage counters
Michiel Broek <mbroek@mbse.eu>
parents: 289
diff changeset
1701 unit->heater_usage++;
881b1ae75468 Added usage counters
Michiel Broek <mbroek@mbse.eu>
parents: 289
diff changeset
1702 if (unit->cooler_address && unit->cooler_state)
881b1ae75468 Added usage counters
Michiel Broek <mbroek@mbse.eu>
parents: 289
diff changeset
1703 unit->cooler_usage++;
881b1ae75468 Added usage counters
Michiel Broek <mbroek@mbse.eu>
parents: 289
diff changeset
1704 if (unit->fan_address && unit->fan_state)
881b1ae75468 Added usage counters
Michiel Broek <mbroek@mbse.eu>
parents: 289
diff changeset
1705 unit->fan_usage++;
350
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1706 if (unit->light_address && unit->light_state)
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1707 unit->light_usage++;
293
881b1ae75468 Added usage counters
Michiel Broek <mbroek@mbse.eu>
parents: 289
diff changeset
1708
350
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1709 /*
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1710 * Interior lights
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1711 */
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1712 if (unit->light_address) {
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1713 if (unit->door_state && unit->light_state) {
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1714 if (unit->light_wait > 0) {
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1715 unit->light_wait--;
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1716 } else {
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1717 unit->light_state = 0;
352
a8e106c95db4 Improved regular logging, disabled some debug logging.
Michiel Broek <mbroek@mbse.eu>
parents: 350
diff changeset
1718 syslog(LOG_NOTICE, "Unit `%s' lights On => Off", unit->name);
350
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1719 }
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1720 }
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1721 if (!unit->door_state && !unit->light_state) {
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1722 unit->light_wait = unit->light_delay; /* No delay to turn lights on */
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1723 unit->light_state = 1;
352
a8e106c95db4 Improved regular logging, disabled some debug logging.
Michiel Broek <mbroek@mbse.eu>
parents: 350
diff changeset
1724 syslog(LOG_NOTICE, "Unit `%s' lights Off => On", unit->name);
350
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1725 }
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1726 device_out(unit->light_address, unit->light_state);
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1727 }
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1728
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1729 /*
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1730 * Temperature control in this unit
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1731 */
312
7b0f819a3805 Added more precision to the unit low and high black window margins. Switched to PID routine from Pid without a PhD. The PID compute routine is now in the one second loop. The switch delay times are now in seconds, 0..720.
Michiel Broek <mbroek@mbse.eu>
parents: 311
diff changeset
1732 if ((unit->mode == UNITMODE_FRIDGE) || (unit->mode == UNITMODE_BEER) || (unit->mode == UNITMODE_PROFILE)) {
7b0f819a3805 Added more precision to the unit low and high black window margins. Switched to PID routine from Pid without a PhD. The PID compute routine is now in the one second loop. The switch delay times are now in seconds, 0..720.
Michiel Broek <mbroek@mbse.eu>
parents: 311
diff changeset
1733
362
c92651a54969 Made the client-server protocol more robust. When a change to a unit is made using the web interface, the main process is stopped during the update. Splitted the PID in two PID's, one for heating and one for cooling. Adjusted the web edit scrreen for this, but there are still rough edges. Replaced the PID code, maybe this one works better for our purpose. The simulator air temperature changes on the simulator heater and cooler, but it is not realistic at all. This is a development version, do not use in production. The version is 0.3.0
Michiel Broek <mbroek@mbse.eu>
parents: 361
diff changeset
1734 /*
c92651a54969 Made the client-server protocol more robust. When a change to a unit is made using the web interface, the main process is stopped during the update. Splitted the PID in two PID's, one for heating and one for cooling. Adjusted the web edit scrreen for this, but there are still rough edges. Replaced the PID code, maybe this one works better for our purpose. The simulator air temperature changes on the simulator heater and cooler, but it is not realistic at all. This is a development version, do not use in production. The version is 0.3.0
Michiel Broek <mbroek@mbse.eu>
parents: 361
diff changeset
1735 * Set both PID's to their input values.
c92651a54969 Made the client-server protocol more robust. When a change to a unit is made using the web interface, the main process is stopped during the update. Splitted the PID in two PID's, one for heating and one for cooling. Adjusted the web edit scrreen for this, but there are still rough edges. Replaced the PID code, maybe this one works better for our purpose. The simulator air temperature changes on the simulator heater and cooler, but it is not realistic at all. This is a development version, do not use in production. The version is 0.3.0
Michiel Broek <mbroek@mbse.eu>
parents: 361
diff changeset
1736 */
c92651a54969 Made the client-server protocol more robust. When a change to a unit is made using the web interface, the main process is stopped during the update. Splitted the PID in two PID's, one for heating and one for cooling. Adjusted the web edit scrreen for this, but there are still rough edges. Replaced the PID code, maybe this one works better for our purpose. The simulator air temperature changes on the simulator heater and cooler, but it is not realistic at all. This is a development version, do not use in production. The version is 0.3.0
Michiel Broek <mbroek@mbse.eu>
parents: 361
diff changeset
1737 unit->PID_cool->Mode = unit->PID_heat->Mode = PID_MODE_NONE;
312
7b0f819a3805 Added more precision to the unit low and high black window margins. Switched to PID routine from Pid without a PhD. The PID compute routine is now in the one second loop. The switch delay times are now in seconds, 0..720.
Michiel Broek <mbroek@mbse.eu>
parents: 311
diff changeset
1738 if (unit->mode == UNITMODE_FRIDGE) {
492
750f2468dec5 Changed PID code. PID parameters are now stored 3 digits instead of 2 behind the decimal point. Prevent extreme heating or cooling in Beer mode. Heat and Cool lockdown now allows the lagest value to win instead of zero them both. PID output treshold from 2% to 50%.
Michiel Broek <mbroek@mbse.eu>
parents: 491
diff changeset
1739 unit->PID_cool->SetP = unit->fridge_set + unit->PID_cool->idleRange;
750f2468dec5 Changed PID code. PID parameters are now stored 3 digits instead of 2 behind the decimal point. Prevent extreme heating or cooling in Beer mode. Heat and Cool lockdown now allows the lagest value to win instead of zero them both. PID output treshold from 2% to 50%.
Michiel Broek <mbroek@mbse.eu>
parents: 491
diff changeset
1740 unit->PID_heat->SetP = unit->fridge_set - unit->PID_heat->idleRange;
362
c92651a54969 Made the client-server protocol more robust. When a change to a unit is made using the web interface, the main process is stopped during the update. Splitted the PID in two PID's, one for heating and one for cooling. Adjusted the web edit scrreen for this, but there are still rough edges. Replaced the PID code, maybe this one works better for our purpose. The simulator air temperature changes on the simulator heater and cooler, but it is not realistic at all. This is a development version, do not use in production. The version is 0.3.0
Michiel Broek <mbroek@mbse.eu>
parents: 361
diff changeset
1741 unit->PID_cool->Input = unit->PID_heat->Input = unit->air_temperature / 1000.0;
c92651a54969 Made the client-server protocol more robust. When a change to a unit is made using the web interface, the main process is stopped during the update. Splitted the PID in two PID's, one for heating and one for cooling. Adjusted the web edit scrreen for this, but there are still rough edges. Replaced the PID code, maybe this one works better for our purpose. The simulator air temperature changes on the simulator heater and cooler, but it is not realistic at all. This is a development version, do not use in production. The version is 0.3.0
Michiel Broek <mbroek@mbse.eu>
parents: 361
diff changeset
1742 unit->PID_cool->Mode = unit->PID_heat->Mode = PID_MODE_BOO;
c92651a54969 Made the client-server protocol more robust. When a change to a unit is made using the web interface, the main process is stopped during the update. Splitted the PID in two PID's, one for heating and one for cooling. Adjusted the web edit scrreen for this, but there are still rough edges. Replaced the PID code, maybe this one works better for our purpose. The simulator air temperature changes on the simulator heater and cooler, but it is not realistic at all. This is a development version, do not use in production. The version is 0.3.0
Michiel Broek <mbroek@mbse.eu>
parents: 361
diff changeset
1743 } else if (unit->mode == UNITMODE_BEER) {
401
0226d0f37bb7 More fixes for profiles temperature window. Added the sliding beer/air target switch.
Michiel Broek <mbroek@mbse.eu>
parents: 398
diff changeset
1744 unit->PID_cool->SetP = unit->beer_set;
0226d0f37bb7 More fixes for profiles temperature window. Added the sliding beer/air target switch.
Michiel Broek <mbroek@mbse.eu>
parents: 398
diff changeset
1745 unit->PID_heat->SetP = unit->beer_set;
362
c92651a54969 Made the client-server protocol more robust. When a change to a unit is made using the web interface, the main process is stopped during the update. Splitted the PID in two PID's, one for heating and one for cooling. Adjusted the web edit scrreen for this, but there are still rough edges. Replaced the PID code, maybe this one works better for our purpose. The simulator air temperature changes on the simulator heater and cooler, but it is not realistic at all. This is a development version, do not use in production. The version is 0.3.0
Michiel Broek <mbroek@mbse.eu>
parents: 361
diff changeset
1746 unit->PID_cool->Input = unit->PID_heat->Input = unit->beer_temperature / 1000.0;
492
750f2468dec5 Changed PID code. PID parameters are now stored 3 digits instead of 2 behind the decimal point. Prevent extreme heating or cooling in Beer mode. Heat and Cool lockdown now allows the lagest value to win instead of zero them both. PID output treshold from 2% to 50%.
Michiel Broek <mbroek@mbse.eu>
parents: 491
diff changeset
1747 unit->PID_cool->Mode = unit->PID_heat->Mode = PID_MODE_AUTO;
312
7b0f819a3805 Added more precision to the unit low and high black window margins. Switched to PID routine from Pid without a PhD. The PID compute routine is now in the one second loop. The switch delay times are now in seconds, 0..720.
Michiel Broek <mbroek@mbse.eu>
parents: 311
diff changeset
1748 } else if (unit->mode == UNITMODE_PROFILE) {
401
0226d0f37bb7 More fixes for profiles temperature window. Added the sliding beer/air target switch.
Michiel Broek <mbroek@mbse.eu>
parents: 398
diff changeset
1749 double usetemp;
397
00ca08f5a6f8 Fermentation profiles now have a low and high temperature setting so that you can use a temperture window. Each profile step can now set for beer or air temperature reference. The logfiles have an extra temperature field for this. Bumped to version 0.4.2.
Michiel Broek <mbroek@mbse.eu>
parents: 395
diff changeset
1750 unit->PID_cool->SetP = unit->prof_target_hi;
00ca08f5a6f8 Fermentation profiles now have a low and high temperature setting so that you can use a temperture window. Each profile step can now set for beer or air temperature reference. The logfiles have an extra temperature field for this. Bumped to version 0.4.2.
Michiel Broek <mbroek@mbse.eu>
parents: 395
diff changeset
1751 unit->PID_heat->SetP = unit->prof_target_lo;
401
0226d0f37bb7 More fixes for profiles temperature window. Added the sliding beer/air target switch.
Michiel Broek <mbroek@mbse.eu>
parents: 398
diff changeset
1752 /*
0226d0f37bb7 More fixes for profiles temperature window. Added the sliding beer/air target switch.
Michiel Broek <mbroek@mbse.eu>
parents: 398
diff changeset
1753 * Get percentage to use from each thermometer. unit->prof_fridge_mode = 0..100
0226d0f37bb7 More fixes for profiles temperature window. Added the sliding beer/air target switch.
Michiel Broek <mbroek@mbse.eu>
parents: 398
diff changeset
1754 */
0226d0f37bb7 More fixes for profiles temperature window. Added the sliding beer/air target switch.
Michiel Broek <mbroek@mbse.eu>
parents: 398
diff changeset
1755 usetemp = ((unit->prof_fridge_mode * (unit->air_temperature / 1000.0)) +
0226d0f37bb7 More fixes for profiles temperature window. Added the sliding beer/air target switch.
Michiel Broek <mbroek@mbse.eu>
parents: 398
diff changeset
1756 ((100 - unit->prof_fridge_mode) * (unit->beer_temperature / 1000.0))) / 100.0;
0226d0f37bb7 More fixes for profiles temperature window. Added the sliding beer/air target switch.
Michiel Broek <mbroek@mbse.eu>
parents: 398
diff changeset
1757 if (debug)
0226d0f37bb7 More fixes for profiles temperature window. Added the sliding beer/air target switch.
Michiel Broek <mbroek@mbse.eu>
parents: 398
diff changeset
1758 fprintf(stdout, " fridge_mode=%d measured=%.3f %.3f => %.3f\n", unit->prof_fridge_mode,
0226d0f37bb7 More fixes for profiles temperature window. Added the sliding beer/air target switch.
Michiel Broek <mbroek@mbse.eu>
parents: 398
diff changeset
1759 unit->air_temperature / 1000.0, unit->beer_temperature / 1000.0, usetemp);
0226d0f37bb7 More fixes for profiles temperature window. Added the sliding beer/air target switch.
Michiel Broek <mbroek@mbse.eu>
parents: 398
diff changeset
1760 unit->PID_cool->Input = unit->PID_heat->Input = usetemp;
492
750f2468dec5 Changed PID code. PID parameters are now stored 3 digits instead of 2 behind the decimal point. Prevent extreme heating or cooling in Beer mode. Heat and Cool lockdown now allows the lagest value to win instead of zero them both. PID output treshold from 2% to 50%.
Michiel Broek <mbroek@mbse.eu>
parents: 491
diff changeset
1761 unit->PID_cool->Mode = unit->PID_heat->Mode = PID_MODE_AUTO;
314
a919c6dc2100 Restored blackout window
Michiel Broek <mbroek@mbse.eu>
parents: 313
diff changeset
1762 }
316
73cd31dc6ce1 Moved pid function to separate files
Michiel Broek <mbroek@mbse.eu>
parents: 315
diff changeset
1763
362
c92651a54969 Made the client-server protocol more robust. When a change to a unit is made using the web interface, the main process is stopped during the update. Splitted the PID in two PID's, one for heating and one for cooling. Adjusted the web edit scrreen for this, but there are still rough edges. Replaced the PID code, maybe this one works better for our purpose. The simulator air temperature changes on the simulator heater and cooler, but it is not realistic at all. This is a development version, do not use in production. The version is 0.3.0
Michiel Broek <mbroek@mbse.eu>
parents: 361
diff changeset
1764 /*
c92651a54969 Made the client-server protocol more robust. When a change to a unit is made using the web interface, the main process is stopped during the update. Splitted the PID in two PID's, one for heating and one for cooling. Adjusted the web edit scrreen for this, but there are still rough edges. Replaced the PID code, maybe this one works better for our purpose. The simulator air temperature changes on the simulator heater and cooler, but it is not realistic at all. This is a development version, do not use in production. The version is 0.3.0
Michiel Broek <mbroek@mbse.eu>
parents: 361
diff changeset
1765 * PID controller compute
c92651a54969 Made the client-server protocol more robust. When a change to a unit is made using the web interface, the main process is stopped during the update. Splitted the PID in two PID's, one for heating and one for cooling. Adjusted the web edit scrreen for this, but there are still rough edges. Replaced the PID code, maybe this one works better for our purpose. The simulator air temperature changes on the simulator heater and cooler, but it is not realistic at all. This is a development version, do not use in production. The version is 0.3.0
Michiel Broek <mbroek@mbse.eu>
parents: 361
diff changeset
1766 */
364
2f9bbbcd2407 Tuning PID code. Samll changes on the unit web page.
Michiel Broek <mbroek@mbse.eu>
parents: 363
diff changeset
1767 UpdatePID(unit->PID_heat);
2f9bbbcd2407 Tuning PID code. Samll changes on the unit web page.
Michiel Broek <mbroek@mbse.eu>
parents: 363
diff changeset
1768 UpdatePID(unit->PID_cool);
2f9bbbcd2407 Tuning PID code. Samll changes on the unit web page.
Michiel Broek <mbroek@mbse.eu>
parents: 363
diff changeset
1769
2f9bbbcd2407 Tuning PID code. Samll changes on the unit web page.
Michiel Broek <mbroek@mbse.eu>
parents: 363
diff changeset
1770 /*
2f9bbbcd2407 Tuning PID code. Samll changes on the unit web page.
Michiel Broek <mbroek@mbse.eu>
parents: 363
diff changeset
1771 * Logging
2f9bbbcd2407 Tuning PID code. Samll changes on the unit web page.
Michiel Broek <mbroek@mbse.eu>
parents: 363
diff changeset
1772 */
362
c92651a54969 Made the client-server protocol more robust. When a change to a unit is made using the web interface, the main process is stopped during the update. Splitted the PID in two PID's, one for heating and one for cooling. Adjusted the web edit scrreen for this, but there are still rough edges. Replaced the PID code, maybe this one works better for our purpose. The simulator air temperature changes on the simulator heater and cooler, but it is not realistic at all. This is a development version, do not use in production. The version is 0.3.0
Michiel Broek <mbroek@mbse.eu>
parents: 361
diff changeset
1773 if (unit->heater_address) {
492
750f2468dec5 Changed PID code. PID parameters are now stored 3 digits instead of 2 behind the decimal point. Prevent extreme heating or cooling in Beer mode. Heat and Cool lockdown now allows the lagest value to win instead of zero them both. PID output treshold from 2% to 50%.
Michiel Broek <mbroek@mbse.eu>
parents: 491
diff changeset
1774 /*
750f2468dec5 Changed PID code. PID parameters are now stored 3 digits instead of 2 behind the decimal point. Prevent extreme heating or cooling in Beer mode. Heat and Cool lockdown now allows the lagest value to win instead of zero them both. PID output treshold from 2% to 50%.
Michiel Broek <mbroek@mbse.eu>
parents: 491
diff changeset
1775 * Prevent extreme heating
750f2468dec5 Changed PID code. PID parameters are now stored 3 digits instead of 2 behind the decimal point. Prevent extreme heating or cooling in Beer mode. Heat and Cool lockdown now allows the lagest value to win instead of zero them both. PID output treshold from 2% to 50%.
Michiel Broek <mbroek@mbse.eu>
parents: 491
diff changeset
1776 */
750f2468dec5 Changed PID code. PID parameters are now stored 3 digits instead of 2 behind the decimal point. Prevent extreme heating or cooling in Beer mode. Heat and Cool lockdown now allows the lagest value to win instead of zero them both. PID output treshold from 2% to 50%.
Michiel Broek <mbroek@mbse.eu>
parents: 491
diff changeset
1777 if ((unit->mode == UNITMODE_BEER) && ((unit->air_temperature / 1000.0) > (unit->PID_heat->Input + 5.0))) {
750f2468dec5 Changed PID code. PID parameters are now stored 3 digits instead of 2 behind the decimal point. Prevent extreme heating or cooling in Beer mode. Heat and Cool lockdown now allows the lagest value to win instead of zero them both. PID output treshold from 2% to 50%.
Michiel Broek <mbroek@mbse.eu>
parents: 491
diff changeset
1778 unit->PID_heat->OutP = 0.0;
750f2468dec5 Changed PID code. PID parameters are now stored 3 digits instead of 2 behind the decimal point. Prevent extreme heating or cooling in Beer mode. Heat and Cool lockdown now allows the lagest value to win instead of zero them both. PID output treshold from 2% to 50%.
Michiel Broek <mbroek@mbse.eu>
parents: 491
diff changeset
1779 }
362
c92651a54969 Made the client-server protocol more robust. When a change to a unit is made using the web interface, the main process is stopped during the update. Splitted the PID in two PID's, one for heating and one for cooling. Adjusted the web edit scrreen for this, but there are still rough edges. Replaced the PID code, maybe this one works better for our purpose. The simulator air temperature changes on the simulator heater and cooler, but it is not realistic at all. This is a development version, do not use in production. The version is 0.3.0
Michiel Broek <mbroek@mbse.eu>
parents: 361
diff changeset
1780 if (debug)
363
468ec0d96cce Back to the old PID algorythm. Version 0.3.1.
Michiel Broek <mbroek@mbse.eu>
parents: 362
diff changeset
1781 fprintf(stdout, "Heat: sp=%.2f Input=%.2f iState=%.2f Err=%.2f Out=%.2f\n",
468ec0d96cce Back to the old PID algorythm. Version 0.3.1.
Michiel Broek <mbroek@mbse.eu>
parents: 362
diff changeset
1782 unit->PID_heat->SetP, unit->PID_heat->Input, unit->PID_heat->iState, unit->PID_heat->Err, unit->PID_heat->OutP);
492
750f2468dec5 Changed PID code. PID parameters are now stored 3 digits instead of 2 behind the decimal point. Prevent extreme heating or cooling in Beer mode. Heat and Cool lockdown now allows the lagest value to win instead of zero them both. PID output treshold from 2% to 50%.
Michiel Broek <mbroek@mbse.eu>
parents: 491
diff changeset
1783 if (seconds == 60) {
363
468ec0d96cce Back to the old PID algorythm. Version 0.3.1.
Michiel Broek <mbroek@mbse.eu>
parents: 362
diff changeset
1784 syslog(LOG_NOTICE, "Heat: sp=%.2f Input=%.2f iState=%.2f Err=%.2f Out=%.2f",
468ec0d96cce Back to the old PID algorythm. Version 0.3.1.
Michiel Broek <mbroek@mbse.eu>
parents: 362
diff changeset
1785 unit->PID_heat->SetP, unit->PID_heat->Input, unit->PID_heat->iState, unit->PID_heat->Err, unit->PID_heat->OutP);
362
c92651a54969 Made the client-server protocol more robust. When a change to a unit is made using the web interface, the main process is stopped during the update. Splitted the PID in two PID's, one for heating and one for cooling. Adjusted the web edit scrreen for this, but there are still rough edges. Replaced the PID code, maybe this one works better for our purpose. The simulator air temperature changes on the simulator heater and cooler, but it is not realistic at all. This is a development version, do not use in production. The version is 0.3.0
Michiel Broek <mbroek@mbse.eu>
parents: 361
diff changeset
1786 }
494
092b45686a75 Fix Deadlok problem when there is only a heater or a cooler.
Michiel Broek <mbroek@mbse.eu>
parents: 492
diff changeset
1787 } else {
092b45686a75 Fix Deadlok problem when there is only a heater or a cooler.
Michiel Broek <mbroek@mbse.eu>
parents: 492
diff changeset
1788 unit->PID_heat->OutP = 0.0;
362
c92651a54969 Made the client-server protocol more robust. When a change to a unit is made using the web interface, the main process is stopped during the update. Splitted the PID in two PID's, one for heating and one for cooling. Adjusted the web edit scrreen for this, but there are still rough edges. Replaced the PID code, maybe this one works better for our purpose. The simulator air temperature changes on the simulator heater and cooler, but it is not realistic at all. This is a development version, do not use in production. The version is 0.3.0
Michiel Broek <mbroek@mbse.eu>
parents: 361
diff changeset
1789 }
c92651a54969 Made the client-server protocol more robust. When a change to a unit is made using the web interface, the main process is stopped during the update. Splitted the PID in two PID's, one for heating and one for cooling. Adjusted the web edit scrreen for this, but there are still rough edges. Replaced the PID code, maybe this one works better for our purpose. The simulator air temperature changes on the simulator heater and cooler, but it is not realistic at all. This is a development version, do not use in production. The version is 0.3.0
Michiel Broek <mbroek@mbse.eu>
parents: 361
diff changeset
1790 if (unit->cooler_address) {
492
750f2468dec5 Changed PID code. PID parameters are now stored 3 digits instead of 2 behind the decimal point. Prevent extreme heating or cooling in Beer mode. Heat and Cool lockdown now allows the lagest value to win instead of zero them both. PID output treshold from 2% to 50%.
Michiel Broek <mbroek@mbse.eu>
parents: 491
diff changeset
1791 /*
750f2468dec5 Changed PID code. PID parameters are now stored 3 digits instead of 2 behind the decimal point. Prevent extreme heating or cooling in Beer mode. Heat and Cool lockdown now allows the lagest value to win instead of zero them both. PID output treshold from 2% to 50%.
Michiel Broek <mbroek@mbse.eu>
parents: 491
diff changeset
1792 * Prevent extreme cooling
750f2468dec5 Changed PID code. PID parameters are now stored 3 digits instead of 2 behind the decimal point. Prevent extreme heating or cooling in Beer mode. Heat and Cool lockdown now allows the lagest value to win instead of zero them both. PID output treshold from 2% to 50%.
Michiel Broek <mbroek@mbse.eu>
parents: 491
diff changeset
1793 */
750f2468dec5 Changed PID code. PID parameters are now stored 3 digits instead of 2 behind the decimal point. Prevent extreme heating or cooling in Beer mode. Heat and Cool lockdown now allows the lagest value to win instead of zero them both. PID output treshold from 2% to 50%.
Michiel Broek <mbroek@mbse.eu>
parents: 491
diff changeset
1794 if ((unit->mode == UNITMODE_BEER) && ((unit->air_temperature / 1000.0) < (unit->PID_cool->Input - 5.0))) {
750f2468dec5 Changed PID code. PID parameters are now stored 3 digits instead of 2 behind the decimal point. Prevent extreme heating or cooling in Beer mode. Heat and Cool lockdown now allows the lagest value to win instead of zero them both. PID output treshold from 2% to 50%.
Michiel Broek <mbroek@mbse.eu>
parents: 491
diff changeset
1795 unit->PID_cool->OutP = 0.0;
750f2468dec5 Changed PID code. PID parameters are now stored 3 digits instead of 2 behind the decimal point. Prevent extreme heating or cooling in Beer mode. Heat and Cool lockdown now allows the lagest value to win instead of zero them both. PID output treshold from 2% to 50%.
Michiel Broek <mbroek@mbse.eu>
parents: 491
diff changeset
1796 }
317
18dd6eadba31 Simple temperature control in fridge mode.
Michiel Broek <mbroek@mbse.eu>
parents: 316
diff changeset
1797 if (debug)
363
468ec0d96cce Back to the old PID algorythm. Version 0.3.1.
Michiel Broek <mbroek@mbse.eu>
parents: 362
diff changeset
1798 fprintf(stdout, "Cool: sp=%.2f Input=%.2f iState=%.2f Err=%.2f Out=%.2f\n",
468ec0d96cce Back to the old PID algorythm. Version 0.3.1.
Michiel Broek <mbroek@mbse.eu>
parents: 362
diff changeset
1799 unit->PID_cool->SetP, unit->PID_cool->Input, unit->PID_cool->iState, unit->PID_cool->Err, unit->PID_cool->OutP);
492
750f2468dec5 Changed PID code. PID parameters are now stored 3 digits instead of 2 behind the decimal point. Prevent extreme heating or cooling in Beer mode. Heat and Cool lockdown now allows the lagest value to win instead of zero them both. PID output treshold from 2% to 50%.
Michiel Broek <mbroek@mbse.eu>
parents: 491
diff changeset
1800 if (seconds == 60) {
363
468ec0d96cce Back to the old PID algorythm. Version 0.3.1.
Michiel Broek <mbroek@mbse.eu>
parents: 362
diff changeset
1801 syslog(LOG_NOTICE, "Cool: sp=%.2f Input=%.2f iState=%.2f Err=%.2f Out=%.2f",
468ec0d96cce Back to the old PID algorythm. Version 0.3.1.
Michiel Broek <mbroek@mbse.eu>
parents: 362
diff changeset
1802 unit->PID_cool->SetP, unit->PID_cool->Input, unit->PID_cool->iState, unit->PID_cool->Err, unit->PID_cool->OutP);
317
18dd6eadba31 Simple temperature control in fridge mode.
Michiel Broek <mbroek@mbse.eu>
parents: 316
diff changeset
1803 }
494
092b45686a75 Fix Deadlok problem when there is only a heater or a cooler.
Michiel Broek <mbroek@mbse.eu>
parents: 492
diff changeset
1804 } else {
092b45686a75 Fix Deadlok problem when there is only a heater or a cooler.
Michiel Broek <mbroek@mbse.eu>
parents: 492
diff changeset
1805 unit->PID_cool->OutP = 0.0;
362
c92651a54969 Made the client-server protocol more robust. When a change to a unit is made using the web interface, the main process is stopped during the update. Splitted the PID in two PID's, one for heating and one for cooling. Adjusted the web edit scrreen for this, but there are still rough edges. Replaced the PID code, maybe this one works better for our purpose. The simulator air temperature changes on the simulator heater and cooler, but it is not realistic at all. This is a development version, do not use in production. The version is 0.3.0
Michiel Broek <mbroek@mbse.eu>
parents: 361
diff changeset
1806 }
317
18dd6eadba31 Simple temperature control in fridge mode.
Michiel Broek <mbroek@mbse.eu>
parents: 316
diff changeset
1807
364
2f9bbbcd2407 Tuning PID code. Samll changes on the unit web page.
Michiel Broek <mbroek@mbse.eu>
parents: 363
diff changeset
1808 /*
494
092b45686a75 Fix Deadlok problem when there is only a heater or a cooler.
Michiel Broek <mbroek@mbse.eu>
parents: 492
diff changeset
1809 * Deadlock, kill lowest value.
364
2f9bbbcd2407 Tuning PID code. Samll changes on the unit web page.
Michiel Broek <mbroek@mbse.eu>
parents: 363
diff changeset
1810 */
362
c92651a54969 Made the client-server protocol more robust. When a change to a unit is made using the web interface, the main process is stopped during the update. Splitted the PID in two PID's, one for heating and one for cooling. Adjusted the web edit scrreen for this, but there are still rough edges. Replaced the PID code, maybe this one works better for our purpose. The simulator air temperature changes on the simulator heater and cooler, but it is not realistic at all. This is a development version, do not use in production. The version is 0.3.0
Michiel Broek <mbroek@mbse.eu>
parents: 361
diff changeset
1811 if (unit->PID_cool->OutP && unit->PID_heat->OutP) {
492
750f2468dec5 Changed PID code. PID parameters are now stored 3 digits instead of 2 behind the decimal point. Prevent extreme heating or cooling in Beer mode. Heat and Cool lockdown now allows the lagest value to win instead of zero them both. PID output treshold from 2% to 50%.
Michiel Broek <mbroek@mbse.eu>
parents: 491
diff changeset
1812 if (unit->PID_cool->OutP > unit->PID_heat->OutP)
750f2468dec5 Changed PID code. PID parameters are now stored 3 digits instead of 2 behind the decimal point. Prevent extreme heating or cooling in Beer mode. Heat and Cool lockdown now allows the lagest value to win instead of zero them both. PID output treshold from 2% to 50%.
Michiel Broek <mbroek@mbse.eu>
parents: 491
diff changeset
1813 unit->PID_heat->OutP = 0.0;
750f2468dec5 Changed PID code. PID parameters are now stored 3 digits instead of 2 behind the decimal point. Prevent extreme heating or cooling in Beer mode. Heat and Cool lockdown now allows the lagest value to win instead of zero them both. PID output treshold from 2% to 50%.
Michiel Broek <mbroek@mbse.eu>
parents: 491
diff changeset
1814 else
750f2468dec5 Changed PID code. PID parameters are now stored 3 digits instead of 2 behind the decimal point. Prevent extreme heating or cooling in Beer mode. Heat and Cool lockdown now allows the lagest value to win instead of zero them both. PID output treshold from 2% to 50%.
Michiel Broek <mbroek@mbse.eu>
parents: 491
diff changeset
1815 unit->PID_cool->OutP = 0.0;
316
73cd31dc6ce1 Moved pid function to separate files
Michiel Broek <mbroek@mbse.eu>
parents: 315
diff changeset
1816 }
73cd31dc6ce1 Moved pid function to separate files
Michiel Broek <mbroek@mbse.eu>
parents: 315
diff changeset
1817
318
aad7789a40f2 Better protection, fixed fridge mode.
Michiel Broek <mbroek@mbse.eu>
parents: 317
diff changeset
1818 if (unit->heater_address && ! unit->cooler_state) {
492
750f2468dec5 Changed PID code. PID parameters are now stored 3 digits instead of 2 behind the decimal point. Prevent extreme heating or cooling in Beer mode. Heat and Cool lockdown now allows the lagest value to win instead of zero them both. PID output treshold from 2% to 50%.
Michiel Broek <mbroek@mbse.eu>
parents: 491
diff changeset
1819 if (unit->PID_heat->OutP >= 50) {
313
8448fcf3d799 Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 312
diff changeset
1820 if (unit->heater_wait < unit->heater_delay) {
8448fcf3d799 Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 312
diff changeset
1821 unit->heater_wait++;
273
b863e0147296 Fixed unit edit heater/cooler delay values. Heater and Cooler start/stop now use a different algorithm.
Michiel Broek <mbroek@mbse.eu>
parents: 270
diff changeset
1822 } else {
362
c92651a54969 Made the client-server protocol more robust. When a change to a unit is made using the web interface, the main process is stopped during the update. Splitted the PID in two PID's, one for heating and one for cooling. Adjusted the web edit scrreen for this, but there are still rough edges. Replaced the PID code, maybe this one works better for our purpose. The simulator air temperature changes on the simulator heater and cooler, but it is not realistic at all. This is a development version, do not use in production. The version is 0.3.0
Michiel Broek <mbroek@mbse.eu>
parents: 361
diff changeset
1823 int power = round(unit->PID_heat->OutP);
319
8c454ec761a8 Actuators behind a PID now use power percentage instead of always 100%
Michiel Broek <mbroek@mbse.eu>
parents: 318
diff changeset
1824 if (unit->heater_state != power) {
352
a8e106c95db4 Improved regular logging, disabled some debug logging.
Michiel Broek <mbroek@mbse.eu>
parents: 350
diff changeset
1825 syslog(LOG_NOTICE, "Unit `%s' heater %d%% => %d%%", unit->name, unit->heater_state, power);
319
8c454ec761a8 Actuators behind a PID now use power percentage instead of always 100%
Michiel Broek <mbroek@mbse.eu>
parents: 318
diff changeset
1826 unit->heater_state = power;
497
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1827 #ifdef HAVE_MOSQUITTO_H
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1828 if (mqtt_use && unit->heater_address) {
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1829 sprintf(buf, "%d", unit->heater_state);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1830 snprintf(topic, 1023, "fermenter/%s/%s/heater", hostname, unit->uuid);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1831 mosquitto_publish(mosq, &mqtt_mid_sent, topic, strlen(buf), buf, mqtt_qos, 1);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1832 }
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1833 #endif
273
b863e0147296 Fixed unit edit heater/cooler delay values. Heater and Cooler start/stop now use a different algorithm.
Michiel Broek <mbroek@mbse.eu>
parents: 270
diff changeset
1834 }
234
b69438db19ec Added loggin when a device is switched on or off in beer/fridge/profile mode.
Michiel Broek <mbroek@mbse.eu>
parents: 233
diff changeset
1835 }
313
8448fcf3d799 Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 312
diff changeset
1836 } else {
8448fcf3d799 Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 312
diff changeset
1837 if (unit->heater_wait > 0) {
8448fcf3d799 Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 312
diff changeset
1838 unit->heater_wait--;
8448fcf3d799 Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 312
diff changeset
1839 } else {
8448fcf3d799 Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 312
diff changeset
1840 if (unit->heater_state) {
352
a8e106c95db4 Improved regular logging, disabled some debug logging.
Michiel Broek <mbroek@mbse.eu>
parents: 350
diff changeset
1841 syslog(LOG_NOTICE, "Unit `%s' heater On => Off", unit->name);
313
8448fcf3d799 Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 312
diff changeset
1842 unit->heater_state = 0;
497
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1843 #ifdef HAVE_MOSQUITTO_H
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1844 if (mqtt_use && unit->heater_address) {
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1845 sprintf(buf, "0");
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1846 snprintf(topic, 1023, "fermenter/%s/%s/heater", hostname, unit->uuid);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1847 mosquitto_publish(mosq, &mqtt_mid_sent, topic, strlen(buf), buf, mqtt_qos, 1);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1848 }
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1849 #endif
313
8448fcf3d799 Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 312
diff changeset
1850 }
8448fcf3d799 Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 312
diff changeset
1851 }
8448fcf3d799 Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 312
diff changeset
1852 }
350
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1853 if (unit->door_state)
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1854 device_out(unit->heater_address, unit->heater_state);
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1855 else
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1856 device_out(unit->heater_address, 0);
312
7b0f819a3805 Added more precision to the unit low and high black window margins. Switched to PID routine from Pid without a PhD. The PID compute routine is now in the one second loop. The switch delay times are now in seconds, 0..720.
Michiel Broek <mbroek@mbse.eu>
parents: 311
diff changeset
1857 }
350
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1858
318
aad7789a40f2 Better protection, fixed fridge mode.
Michiel Broek <mbroek@mbse.eu>
parents: 317
diff changeset
1859 if (unit->cooler_address && ! unit->heater_state) {
492
750f2468dec5 Changed PID code. PID parameters are now stored 3 digits instead of 2 behind the decimal point. Prevent extreme heating or cooling in Beer mode. Heat and Cool lockdown now allows the lagest value to win instead of zero them both. PID output treshold from 2% to 50%.
Michiel Broek <mbroek@mbse.eu>
parents: 491
diff changeset
1860 if (unit->PID_cool->OutP >= 50) {
313
8448fcf3d799 Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 312
diff changeset
1861 if (unit->cooler_wait < unit->cooler_delay) {
8448fcf3d799 Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 312
diff changeset
1862 unit->cooler_wait++;
273
b863e0147296 Fixed unit edit heater/cooler delay values. Heater and Cooler start/stop now use a different algorithm.
Michiel Broek <mbroek@mbse.eu>
parents: 270
diff changeset
1863 } else {
362
c92651a54969 Made the client-server protocol more robust. When a change to a unit is made using the web interface, the main process is stopped during the update. Splitted the PID in two PID's, one for heating and one for cooling. Adjusted the web edit scrreen for this, but there are still rough edges. Replaced the PID code, maybe this one works better for our purpose. The simulator air temperature changes on the simulator heater and cooler, but it is not realistic at all. This is a development version, do not use in production. The version is 0.3.0
Michiel Broek <mbroek@mbse.eu>
parents: 361
diff changeset
1864 int power = round(unit->PID_cool->OutP);
319
8c454ec761a8 Actuators behind a PID now use power percentage instead of always 100%
Michiel Broek <mbroek@mbse.eu>
parents: 318
diff changeset
1865 if (unit->cooler_state != power) {
352
a8e106c95db4 Improved regular logging, disabled some debug logging.
Michiel Broek <mbroek@mbse.eu>
parents: 350
diff changeset
1866 syslog(LOG_NOTICE, "Unit `%s' cooler %d%% => %d%%", unit->name, unit->cooler_state, power);
319
8c454ec761a8 Actuators behind a PID now use power percentage instead of always 100%
Michiel Broek <mbroek@mbse.eu>
parents: 318
diff changeset
1867 unit->cooler_state = power;
497
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1868 #ifdef HAVE_MOSQUITTO_H
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1869 if (mqtt_use && unit->cooler_address) {
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1870 sprintf(buf, "%d", unit->cooler_state);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1871 snprintf(topic, 1023, "fermenter/%s/%s/cooler", hostname, unit->uuid);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1872 mosquitto_publish(mosq, &mqtt_mid_sent, topic, strlen(buf), buf, mqtt_qos, 1);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1873 }
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1874 #endif
270
df81d583c2c3 The PID commands have an adjustable delay, default 5 minutes
Michiel Broek <mbroek@mbse.eu>
parents: 268
diff changeset
1875 }
234
b69438db19ec Added loggin when a device is switched on or off in beer/fridge/profile mode.
Michiel Broek <mbroek@mbse.eu>
parents: 233
diff changeset
1876 }
313
8448fcf3d799 Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 312
diff changeset
1877 } else {
8448fcf3d799 Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 312
diff changeset
1878 if (unit->cooler_wait > 0) {
8448fcf3d799 Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 312
diff changeset
1879 unit->cooler_wait--;
8448fcf3d799 Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 312
diff changeset
1880 } else {
8448fcf3d799 Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 312
diff changeset
1881 if (unit->cooler_state) {
352
a8e106c95db4 Improved regular logging, disabled some debug logging.
Michiel Broek <mbroek@mbse.eu>
parents: 350
diff changeset
1882 syslog(LOG_NOTICE, "Unit `%s' cooler On => Off", unit->name);
313
8448fcf3d799 Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 312
diff changeset
1883 unit->cooler_state = 0;
497
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1884 #ifdef HAVE_MOSQUITTO_H
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1885 if (mqtt_use && unit->cooler_address) {
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1886 sprintf(buf, "0");
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1887 snprintf(topic, 1023, "fermenter/%s/%s/cooler", hostname, unit->uuid);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1888 mosquitto_publish(mosq, &mqtt_mid_sent, topic, strlen(buf), buf, mqtt_qos, 1);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1889 }
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1890 #endif
313
8448fcf3d799 Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 312
diff changeset
1891 }
8448fcf3d799 Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 312
diff changeset
1892 }
8448fcf3d799 Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 312
diff changeset
1893 }
350
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1894 if (unit->door_state)
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1895 device_out(unit->cooler_address, unit->cooler_state);
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1896 else
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
1897 device_out(unit->cooler_address, 0);
312
7b0f819a3805 Added more precision to the unit low and high black window margins. Switched to PID routine from Pid without a PhD. The PID compute routine is now in the one second loop. The switch delay times are now in seconds, 0..720.
Michiel Broek <mbroek@mbse.eu>
parents: 311
diff changeset
1898 }
492
750f2468dec5 Changed PID code. PID parameters are now stored 3 digits instead of 2 behind the decimal point. Prevent extreme heating or cooling in Beer mode. Heat and Cool lockdown now allows the lagest value to win instead of zero them both. PID output treshold from 2% to 50%.
Michiel Broek <mbroek@mbse.eu>
parents: 491
diff changeset
1899 if (debug)
750f2468dec5 Changed PID code. PID parameters are now stored 3 digits instead of 2 behind the decimal point. Prevent extreme heating or cooling in Beer mode. Heat and Cool lockdown now allows the lagest value to win instead of zero them both. PID output treshold from 2% to 50%.
Michiel Broek <mbroek@mbse.eu>
parents: 491
diff changeset
1900 fprintf(stdout, "Final: PIDheat=%.2f PWRheat=%d PIDcool=%.2f PWRcool=%d\n",
750f2468dec5 Changed PID code. PID parameters are now stored 3 digits instead of 2 behind the decimal point. Prevent extreme heating or cooling in Beer mode. Heat and Cool lockdown now allows the lagest value to win instead of zero them both. PID output treshold from 2% to 50%.
Michiel Broek <mbroek@mbse.eu>
parents: 491
diff changeset
1901 unit->PID_heat->OutP, unit->heater_state, unit->PID_cool->OutP, unit->cooler_state);
348
ffc4b8aa824f Changed Fan switch logic.
Michiel Broek <mbroek@mbse.eu>
parents: 328
diff changeset
1902
496
5cf6f099c897 The FAN always runs if the unit is active. Bumped tp version 0.5.3
Michiel Broek <mbroek@mbse.eu>
parents: 494
diff changeset
1903 /*
5cf6f099c897 The FAN always runs if the unit is active. Bumped tp version 0.5.3
Michiel Broek <mbroek@mbse.eu>
parents: 494
diff changeset
1904 * If there is a fan, and the unit door is closed, and the unit should be doing
5cf6f099c897 The FAN always runs if the unit is active. Bumped tp version 0.5.3
Michiel Broek <mbroek@mbse.eu>
parents: 494
diff changeset
1905 * something, then turn on the global fan.
5cf6f099c897 The FAN always runs if the unit is active. Bumped tp version 0.5.3
Michiel Broek <mbroek@mbse.eu>
parents: 494
diff changeset
1906 */
5cf6f099c897 The FAN always runs if the unit is active. Bumped tp version 0.5.3
Michiel Broek <mbroek@mbse.eu>
parents: 494
diff changeset
1907 if (unit->fan_address) {
5cf6f099c897 The FAN always runs if the unit is active. Bumped tp version 0.5.3
Michiel Broek <mbroek@mbse.eu>
parents: 494
diff changeset
1908 if (unit->door_state) {
349
1f89da6511a9 Added Fan delay logic.
Michiel Broek <mbroek@mbse.eu>
parents: 348
diff changeset
1909 if (unit->fan_wait < unit->fan_delay) {
496
5cf6f099c897 The FAN always runs if the unit is active. Bumped tp version 0.5.3
Michiel Broek <mbroek@mbse.eu>
parents: 494
diff changeset
1910 unit->fan_wait++;
349
1f89da6511a9 Added Fan delay logic.
Michiel Broek <mbroek@mbse.eu>
parents: 348
diff changeset
1911 } else {
496
5cf6f099c897 The FAN always runs if the unit is active. Bumped tp version 0.5.3
Michiel Broek <mbroek@mbse.eu>
parents: 494
diff changeset
1912 if (! unit->fan_state) {
352
a8e106c95db4 Improved regular logging, disabled some debug logging.
Michiel Broek <mbroek@mbse.eu>
parents: 350
diff changeset
1913 syslog(LOG_NOTICE, "Unit `%s' Fan Off => On", unit->name);
496
5cf6f099c897 The FAN always runs if the unit is active. Bumped tp version 0.5.3
Michiel Broek <mbroek@mbse.eu>
parents: 494
diff changeset
1914 unit->fan_state = 100;
497
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1915 #ifdef HAVE_MOSQUITTO_H
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1916 if (mqtt_use && unit->fan_address) {
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1917 sprintf(buf, "100");
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1918 snprintf(topic, 1023, "fermenter/%s/%s/fan", hostname, unit->uuid);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1919 mosquitto_publish(mosq, &mqtt_mid_sent, topic, strlen(buf), buf, mqtt_qos, 1);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1920 }
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1921 #endif
496
5cf6f099c897 The FAN always runs if the unit is active. Bumped tp version 0.5.3
Michiel Broek <mbroek@mbse.eu>
parents: 494
diff changeset
1922 }
349
1f89da6511a9 Added Fan delay logic.
Michiel Broek <mbroek@mbse.eu>
parents: 348
diff changeset
1923 }
313
8448fcf3d799 Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 312
diff changeset
1924 } else {
349
1f89da6511a9 Added Fan delay logic.
Michiel Broek <mbroek@mbse.eu>
parents: 348
diff changeset
1925 if (unit->fan_wait > 0) {
1f89da6511a9 Added Fan delay logic.
Michiel Broek <mbroek@mbse.eu>
parents: 348
diff changeset
1926 unit->fan_wait--;
1f89da6511a9 Added Fan delay logic.
Michiel Broek <mbroek@mbse.eu>
parents: 348
diff changeset
1927 } else {
1f89da6511a9 Added Fan delay logic.
Michiel Broek <mbroek@mbse.eu>
parents: 348
diff changeset
1928 if (unit->fan_state) {
352
a8e106c95db4 Improved regular logging, disabled some debug logging.
Michiel Broek <mbroek@mbse.eu>
parents: 350
diff changeset
1929 syslog(LOG_NOTICE, "Unit `%s' Fan On => Off", unit->name);
349
1f89da6511a9 Added Fan delay logic.
Michiel Broek <mbroek@mbse.eu>
parents: 348
diff changeset
1930 unit->fan_state = 0;
497
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1931 #ifdef HAVE_MOSQUITTO_H
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1932 if (mqtt_use && unit->fan_address) {
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1933 sprintf(buf, "0");
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1934 snprintf(topic, 1023, "fermenter/%s/%s/fan", hostname, unit->uuid);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1935 mosquitto_publish(mosq, &mqtt_mid_sent, topic, strlen(buf), buf, mqtt_qos, 1);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1936 }
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1937 #endif
349
1f89da6511a9 Added Fan delay logic.
Michiel Broek <mbroek@mbse.eu>
parents: 348
diff changeset
1938 }
1f89da6511a9 Added Fan delay logic.
Michiel Broek <mbroek@mbse.eu>
parents: 348
diff changeset
1939 }
313
8448fcf3d799 Code cleanup
Michiel Broek <mbroek@mbse.eu>
parents: 312
diff changeset
1940 }
496
5cf6f099c897 The FAN always runs if the unit is active. Bumped tp version 0.5.3
Michiel Broek <mbroek@mbse.eu>
parents: 494
diff changeset
1941 device_out(unit->fan_address, unit->fan_state);
312
7b0f819a3805 Added more precision to the unit low and high black window margins. Switched to PID routine from Pid without a PhD. The PID compute routine is now in the one second loop. The switch delay times are now in seconds, 0..720.
Michiel Broek <mbroek@mbse.eu>
parents: 311
diff changeset
1942 }
496
5cf6f099c897 The FAN always runs if the unit is active. Bumped tp version 0.5.3
Michiel Broek <mbroek@mbse.eu>
parents: 494
diff changeset
1943
312
7b0f819a3805 Added more precision to the unit low and high black window margins. Switched to PID routine from Pid without a PhD. The PID compute routine is now in the one second loop. The switch delay times are now in seconds, 0..720.
Michiel Broek <mbroek@mbse.eu>
parents: 311
diff changeset
1944 } else {
362
c92651a54969 Made the client-server protocol more robust. When a change to a unit is made using the web interface, the main process is stopped during the update. Splitted the PID in two PID's, one for heating and one for cooling. Adjusted the web edit scrreen for this, but there are still rough edges. Replaced the PID code, maybe this one works better for our purpose. The simulator air temperature changes on the simulator heater and cooler, but it is not realistic at all. This is a development version, do not use in production. The version is 0.3.0
Michiel Broek <mbroek@mbse.eu>
parents: 361
diff changeset
1945 unit->PID_cool->Mode = unit->PID_heat->Mode = PID_MODE_NONE;
349
1f89da6511a9 Added Fan delay logic.
Michiel Broek <mbroek@mbse.eu>
parents: 348
diff changeset
1946 } /* fridge beer or profile mode */
486
5a237a99a793 Compacted LCD display for units, allways 4 instead of 4 to 6 lines. But it's a bit more cryptic. We could write a short manual.
Michiel Broek <mbroek@mbse.eu>
parents: 484
diff changeset
1947
5a237a99a793 Compacted LCD display for units, allways 4 instead of 4 to 6 lines. But it's a bit more cryptic. We could write a short manual.
Michiel Broek <mbroek@mbse.eu>
parents: 484
diff changeset
1948 /*
5a237a99a793 Compacted LCD display for units, allways 4 instead of 4 to 6 lines. But it's a bit more cryptic. We could write a short manual.
Michiel Broek <mbroek@mbse.eu>
parents: 484
diff changeset
1949 * Now everything is set and done, update the LCD display
5a237a99a793 Compacted LCD display for units, allways 4 instead of 4 to 6 lines. But it's a bit more cryptic. We could write a short manual.
Michiel Broek <mbroek@mbse.eu>
parents: 484
diff changeset
1950 */
5a237a99a793 Compacted LCD display for units, allways 4 instead of 4 to 6 lines. But it's a bit more cryptic. We could write a short manual.
Michiel Broek <mbroek@mbse.eu>
parents: 484
diff changeset
1951 LCDair = unit->air_temperature / 1000.0;
5a237a99a793 Compacted LCD display for units, allways 4 instead of 4 to 6 lines. But it's a bit more cryptic. We could write a short manual.
Michiel Broek <mbroek@mbse.eu>
parents: 484
diff changeset
1952 LCDbeer = unit->beer_temperature / 1000.0;
490
080c8ea4875e Remove temporary marker.
Michiel Broek <mbroek@mbse.eu>
parents: 489
diff changeset
1953 LCDstatC = LCDstatH = ' ';
486
5a237a99a793 Compacted LCD display for units, allways 4 instead of 4 to 6 lines. But it's a bit more cryptic. We could write a short manual.
Michiel Broek <mbroek@mbse.eu>
parents: 484
diff changeset
1954 if (unit->heater_address) {
5a237a99a793 Compacted LCD display for units, allways 4 instead of 4 to 6 lines. But it's a bit more cryptic. We could write a short manual.
Michiel Broek <mbroek@mbse.eu>
parents: 484
diff changeset
1955 if (unit->heater_state)
489
9cb274b7e027 Swapped heat/cool symbols.
Michiel Broek <mbroek@mbse.eu>
parents: 488
diff changeset
1956 LCDstatH = '\6';
486
5a237a99a793 Compacted LCD display for units, allways 4 instead of 4 to 6 lines. But it's a bit more cryptic. We could write a short manual.
Michiel Broek <mbroek@mbse.eu>
parents: 484
diff changeset
1957 else
489
9cb274b7e027 Swapped heat/cool symbols.
Michiel Broek <mbroek@mbse.eu>
parents: 488
diff changeset
1958 LCDstatH = '\5';
486
5a237a99a793 Compacted LCD display for units, allways 4 instead of 4 to 6 lines. But it's a bit more cryptic. We could write a short manual.
Michiel Broek <mbroek@mbse.eu>
parents: 484
diff changeset
1959 }
5a237a99a793 Compacted LCD display for units, allways 4 instead of 4 to 6 lines. But it's a bit more cryptic. We could write a short manual.
Michiel Broek <mbroek@mbse.eu>
parents: 484
diff changeset
1960 if (unit->cooler_address) {
5a237a99a793 Compacted LCD display for units, allways 4 instead of 4 to 6 lines. But it's a bit more cryptic. We could write a short manual.
Michiel Broek <mbroek@mbse.eu>
parents: 484
diff changeset
1961 if (unit->cooler_state)
489
9cb274b7e027 Swapped heat/cool symbols.
Michiel Broek <mbroek@mbse.eu>
parents: 488
diff changeset
1962 LCDstatC = '\4';
486
5a237a99a793 Compacted LCD display for units, allways 4 instead of 4 to 6 lines. But it's a bit more cryptic. We could write a short manual.
Michiel Broek <mbroek@mbse.eu>
parents: 484
diff changeset
1963 else
489
9cb274b7e027 Swapped heat/cool symbols.
Michiel Broek <mbroek@mbse.eu>
parents: 488
diff changeset
1964 LCDstatC = '\3';
486
5a237a99a793 Compacted LCD display for units, allways 4 instead of 4 to 6 lines. But it's a bit more cryptic. We could write a short manual.
Michiel Broek <mbroek@mbse.eu>
parents: 484
diff changeset
1965 }
5a237a99a793 Compacted LCD display for units, allways 4 instead of 4 to 6 lines. But it's a bit more cryptic. We could write a short manual.
Michiel Broek <mbroek@mbse.eu>
parents: 484
diff changeset
1966 LCDspH = LCDspL = 0.0;
5a237a99a793 Compacted LCD display for units, allways 4 instead of 4 to 6 lines. But it's a bit more cryptic. We could write a short manual.
Michiel Broek <mbroek@mbse.eu>
parents: 484
diff changeset
1967 if (unit->mode == UNITMODE_BEER)
5a237a99a793 Compacted LCD display for units, allways 4 instead of 4 to 6 lines. But it's a bit more cryptic. We could write a short manual.
Michiel Broek <mbroek@mbse.eu>
parents: 484
diff changeset
1968 LCDspH = LCDspL = unit->beer_set;
5a237a99a793 Compacted LCD display for units, allways 4 instead of 4 to 6 lines. But it's a bit more cryptic. We could write a short manual.
Michiel Broek <mbroek@mbse.eu>
parents: 484
diff changeset
1969 else if (unit->mode == UNITMODE_FRIDGE)
5a237a99a793 Compacted LCD display for units, allways 4 instead of 4 to 6 lines. But it's a bit more cryptic. We could write a short manual.
Michiel Broek <mbroek@mbse.eu>
parents: 484
diff changeset
1970 LCDspH = LCDspL = unit->fridge_set;
5a237a99a793 Compacted LCD display for units, allways 4 instead of 4 to 6 lines. But it's a bit more cryptic. We could write a short manual.
Michiel Broek <mbroek@mbse.eu>
parents: 484
diff changeset
1971 else if (unit->mode == UNITMODE_PROFILE) {
5a237a99a793 Compacted LCD display for units, allways 4 instead of 4 to 6 lines. But it's a bit more cryptic. We could write a short manual.
Michiel Broek <mbroek@mbse.eu>
parents: 484
diff changeset
1972 if (unit->prof_state != PROFILE_OFF) {
5a237a99a793 Compacted LCD display for units, allways 4 instead of 4 to 6 lines. But it's a bit more cryptic. We could write a short manual.
Michiel Broek <mbroek@mbse.eu>
parents: 484
diff changeset
1973 LCDspL = unit->prof_target_lo;
5a237a99a793 Compacted LCD display for units, allways 4 instead of 4 to 6 lines. But it's a bit more cryptic. We could write a short manual.
Michiel Broek <mbroek@mbse.eu>
parents: 484
diff changeset
1974 LCDspH = unit->prof_target_hi;
5a237a99a793 Compacted LCD display for units, allways 4 instead of 4 to 6 lines. But it's a bit more cryptic. We could write a short manual.
Michiel Broek <mbroek@mbse.eu>
parents: 484
diff changeset
1975 }
5a237a99a793 Compacted LCD display for units, allways 4 instead of 4 to 6 lines. But it's a bit more cryptic. We could write a short manual.
Michiel Broek <mbroek@mbse.eu>
parents: 484
diff changeset
1976 }
497
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1977 #ifdef HAVE_MOSQUITTO_H
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1978 if (mqtt_use && (seconds == 60)) {
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1979 sprintf(buf, "%.1f", LCDspH);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1980 snprintf(topic, 1023, "fermenter/%s/%s/setpoint/high", hostname, unit->uuid);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1981 mosquitto_publish(mosq, &mqtt_mid_sent, topic, strlen(buf), buf, mqtt_qos, 1);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1982 sprintf(buf, "%.1f", LCDspL);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1983 snprintf(topic, 1023, "fermenter/%s/%s/setpoint/low", hostname, unit->uuid);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1984 mosquitto_publish(mosq, &mqtt_mid_sent, topic, strlen(buf), buf, mqtt_qos, 1);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1985 }
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
1986 #endif
486
5a237a99a793 Compacted LCD display for units, allways 4 instead of 4 to 6 lines. But it's a bit more cryptic. We could write a short manual.
Michiel Broek <mbroek@mbse.eu>
parents: 484
diff changeset
1987 #ifdef HAVE_WIRINGPI_H
5a237a99a793 Compacted LCD display for units, allways 4 instead of 4 to 6 lines. But it's a bit more cryptic. We could write a short manual.
Michiel Broek <mbroek@mbse.eu>
parents: 484
diff changeset
1988 piLock(LOCK_LCD);
5a237a99a793 Compacted LCD display for units, allways 4 instead of 4 to 6 lines. But it's a bit more cryptic. We could write a short manual.
Michiel Broek <mbroek@mbse.eu>
parents: 484
diff changeset
1989 #endif
496
5cf6f099c897 The FAN always runs if the unit is active. Bumped tp version 0.5.3
Michiel Broek <mbroek@mbse.eu>
parents: 494
diff changeset
1990 /*
5cf6f099c897 The FAN always runs if the unit is active. Bumped tp version 0.5.3
Michiel Broek <mbroek@mbse.eu>
parents: 494
diff changeset
1991 * Write 4 rows to the LCD to display the unit state
5cf6f099c897 The FAN always runs if the unit is active. Bumped tp version 0.5.3
Michiel Broek <mbroek@mbse.eu>
parents: 494
diff changeset
1992 */
486
5a237a99a793 Compacted LCD display for units, allways 4 instead of 4 to 6 lines. But it's a bit more cryptic. We could write a short manual.
Michiel Broek <mbroek@mbse.eu>
parents: 484
diff changeset
1993 lcd_buf_write(row++, "Unit %d: %s ", LCDunit, UNITMODE[unit->mode]);
5a237a99a793 Compacted LCD display for units, allways 4 instead of 4 to 6 lines. But it's a bit more cryptic. We could write a short manual.
Michiel Broek <mbroek@mbse.eu>
parents: 484
diff changeset
1994 lcd_buf_write(row++, "%s ", unit->name);
5a237a99a793 Compacted LCD display for units, allways 4 instead of 4 to 6 lines. But it's a bit more cryptic. We could write a short manual.
Michiel Broek <mbroek@mbse.eu>
parents: 484
diff changeset
1995 lcd_buf_write(row++, "%c%5.1f\2 A%6.2f\1 ", LCDstatC, LCDspH, LCDair);
5a237a99a793 Compacted LCD display for units, allways 4 instead of 4 to 6 lines. But it's a bit more cryptic. We could write a short manual.
Michiel Broek <mbroek@mbse.eu>
parents: 484
diff changeset
1996 lcd_buf_write(row++, "%c%5.1f\2 B%6.2f\1 ", LCDstatH, LCDspL, LCDbeer);
5a237a99a793 Compacted LCD display for units, allways 4 instead of 4 to 6 lines. But it's a bit more cryptic. We could write a short manual.
Michiel Broek <mbroek@mbse.eu>
parents: 484
diff changeset
1997 #ifdef HAVE_WIRINGPI_H
5a237a99a793 Compacted LCD display for units, allways 4 instead of 4 to 6 lines. But it's a bit more cryptic. We could write a short manual.
Michiel Broek <mbroek@mbse.eu>
parents: 484
diff changeset
1998 piUnlock(LOCK_LCD);
5a237a99a793 Compacted LCD display for units, allways 4 instead of 4 to 6 lines. But it's a bit more cryptic. We could write a short manual.
Michiel Broek <mbroek@mbse.eu>
parents: 484
diff changeset
1999 #endif
349
1f89da6511a9 Added Fan delay logic.
Michiel Broek <mbroek@mbse.eu>
parents: 348
diff changeset
2000 } /* for units */
182
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
2001
204
9a14d6b2de7f Fixed LCD display updates. Better key routines.
Michiel Broek <mbroek@mbse.eu>
parents: 200
diff changeset
2002 #ifdef HAVE_WIRINGPI_H
244
2f868eaefec2 Selecting units in setup does now work. Menu select variables are protected with thread locking.
Michiel Broek <mbroek@mbse.eu>
parents: 241
diff changeset
2003 piLock(LOCK_MENU);
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
2004 #endif
241
4ba138737bf4 Added thread locks to all LCD access functions. This seems to have fixed the LCD corruption problems.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
2005 if (setupmenu == MENU_NONE) {
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
2006 #ifdef HAVE_WIRINGPI_H
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
2007 piLock(LOCK_LCD);
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
2008 #endif
205
ca18ff45deba Start initial menu setup
Michiel Broek <mbroek@mbse.eu>
parents: 204
diff changeset
2009 lcd_buf_show();
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
2010 #ifdef HAVE_WIRINGPI_H
241
4ba138737bf4 Added thread locks to all LCD access functions. This seems to have fixed the LCD corruption problems.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
2011 piUnlock(LOCK_LCD);
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
2012 #endif
241
4ba138737bf4 Added thread locks to all LCD access functions. This seems to have fixed the LCD corruption problems.
Michiel Broek <mbroek@mbse.eu>
parents: 240
diff changeset
2013 }
418
0bfe08c7ba6e Reenabled code round LCD driver.
Michiel Broek <mbroek@mbse.eu>
parents: 406
diff changeset
2014 #ifdef HAVE_WIRINGPI_H
244
2f868eaefec2 Selecting units in setup does now work. Menu select variables are protected with thread locking.
Michiel Broek <mbroek@mbse.eu>
parents: 241
diff changeset
2015 piUnlock(LOCK_MENU);
204
9a14d6b2de7f Fixed LCD display updates. Better key routines.
Michiel Broek <mbroek@mbse.eu>
parents: 200
diff changeset
2016 #endif
205
ca18ff45deba Start initial menu setup
Michiel Broek <mbroek@mbse.eu>
parents: 204
diff changeset
2017
182
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
2018 if (seconds == 60) {
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
2019 seconds = 0;
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
2020
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
2021 /*
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
2022 * Log temperature and status every minute if unit is active.
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
2023 */
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
2024 for (unit = Config.units; unit; unit = unit->next) {
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
2025 if (unit->mode != UNITMODE_OFF) {
176
8c7d87a2c094 Initial code for a simple PID controller.
Michiel Broek <mbroek@mbse.eu>
parents: 175
diff changeset
2026
397
00ca08f5a6f8 Fermentation profiles now have a low and high temperature setting so that you can use a temperture window. Each profile step can now set for beer or air temperature reference. The logfiles have an extra temperature field for this. Bumped to version 0.4.2.
Michiel Broek <mbroek@mbse.eu>
parents: 395
diff changeset
2027 snprintf(target_lo, 39, "NA");
00ca08f5a6f8 Fermentation profiles now have a low and high temperature setting so that you can use a temperture window. Each profile step can now set for beer or air temperature reference. The logfiles have an extra temperature field for this. Bumped to version 0.4.2.
Michiel Broek <mbroek@mbse.eu>
parents: 395
diff changeset
2028 snprintf(target_hi, 39, "NA");
105
a5a964148e34 Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents: 104
diff changeset
2029 snprintf(heater, 39, "NA");
a5a964148e34 Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents: 104
diff changeset
2030 snprintf(cooler, 39, "NA");
a5a964148e34 Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents: 104
diff changeset
2031 snprintf(fan, 39, "NA");
a5a964148e34 Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents: 104
diff changeset
2032 snprintf(door, 39, "NA");
297
a70527a4e56a Added usage counters to the beer logfiles. Bumped to version 0.2.4
Michiel Broek <mbroek@mbse.eu>
parents: 293
diff changeset
2033 snprintf(use_heater, 39, "NA");
a70527a4e56a Added usage counters to the beer logfiles. Bumped to version 0.2.4
Michiel Broek <mbroek@mbse.eu>
parents: 293
diff changeset
2034 snprintf(use_cooler, 39, "NA");
a70527a4e56a Added usage counters to the beer logfiles. Bumped to version 0.2.4
Michiel Broek <mbroek@mbse.eu>
parents: 293
diff changeset
2035 snprintf(use_fan, 39, "NA");
355
8f946f9d125a Added logging of the room temperature.
Michiel Broek <mbroek@mbse.eu>
parents: 352
diff changeset
2036 snprintf(room_temp, 39, "NA");
105
a5a964148e34 Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents: 104
diff changeset
2037
397
00ca08f5a6f8 Fermentation profiles now have a low and high temperature setting so that you can use a temperture window. Each profile step can now set for beer or air temperature reference. The logfiles have an extra temperature field for this. Bumped to version 0.4.2.
Michiel Broek <mbroek@mbse.eu>
parents: 395
diff changeset
2038 if (unit->mode == UNITMODE_BEER) {
00ca08f5a6f8 Fermentation profiles now have a low and high temperature setting so that you can use a temperture window. Each profile step can now set for beer or air temperature reference. The logfiles have an extra temperature field for this. Bumped to version 0.4.2.
Michiel Broek <mbroek@mbse.eu>
parents: 395
diff changeset
2039 snprintf(target_lo, 39, "%.1f", unit->beer_set);
00ca08f5a6f8 Fermentation profiles now have a low and high temperature setting so that you can use a temperture window. Each profile step can now set for beer or air temperature reference. The logfiles have an extra temperature field for this. Bumped to version 0.4.2.
Michiel Broek <mbroek@mbse.eu>
parents: 395
diff changeset
2040 snprintf(target_hi, 39, "%.1f", unit->beer_set);
00ca08f5a6f8 Fermentation profiles now have a low and high temperature setting so that you can use a temperture window. Each profile step can now set for beer or air temperature reference. The logfiles have an extra temperature field for this. Bumped to version 0.4.2.
Michiel Broek <mbroek@mbse.eu>
parents: 395
diff changeset
2041 } else if (unit->mode == UNITMODE_FRIDGE) {
00ca08f5a6f8 Fermentation profiles now have a low and high temperature setting so that you can use a temperture window. Each profile step can now set for beer or air temperature reference. The logfiles have an extra temperature field for this. Bumped to version 0.4.2.
Michiel Broek <mbroek@mbse.eu>
parents: 395
diff changeset
2042 snprintf(target_lo, 39, "%.1f", unit->fridge_set);
00ca08f5a6f8 Fermentation profiles now have a low and high temperature setting so that you can use a temperture window. Each profile step can now set for beer or air temperature reference. The logfiles have an extra temperature field for this. Bumped to version 0.4.2.
Michiel Broek <mbroek@mbse.eu>
parents: 395
diff changeset
2043 snprintf(target_hi, 39, "%.1f", unit->fridge_set);
00ca08f5a6f8 Fermentation profiles now have a low and high temperature setting so that you can use a temperture window. Each profile step can now set for beer or air temperature reference. The logfiles have an extra temperature field for this. Bumped to version 0.4.2.
Michiel Broek <mbroek@mbse.eu>
parents: 395
diff changeset
2044 } else if (unit->mode == UNITMODE_PROFILE) {
00ca08f5a6f8 Fermentation profiles now have a low and high temperature setting so that you can use a temperture window. Each profile step can now set for beer or air temperature reference. The logfiles have an extra temperature field for this. Bumped to version 0.4.2.
Michiel Broek <mbroek@mbse.eu>
parents: 395
diff changeset
2045 snprintf(target_lo, 39, "%.1f", unit->prof_target_lo);
00ca08f5a6f8 Fermentation profiles now have a low and high temperature setting so that you can use a temperture window. Each profile step can now set for beer or air temperature reference. The logfiles have an extra temperature field for this. Bumped to version 0.4.2.
Michiel Broek <mbroek@mbse.eu>
parents: 395
diff changeset
2046 snprintf(target_hi, 39, "%.1f", unit->prof_target_hi);
00ca08f5a6f8 Fermentation profiles now have a low and high temperature setting so that you can use a temperture window. Each profile step can now set for beer or air temperature reference. The logfiles have an extra temperature field for this. Bumped to version 0.4.2.
Michiel Broek <mbroek@mbse.eu>
parents: 395
diff changeset
2047 }
105
a5a964148e34 Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents: 104
diff changeset
2048
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
2049 if (unit->heater_address) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
2050 snprintf(heater, 39, "%d", unit->heater_state);
297
a70527a4e56a Added usage counters to the beer logfiles. Bumped to version 0.2.4
Michiel Broek <mbroek@mbse.eu>
parents: 293
diff changeset
2051 snprintf(use_heater, 39, "%d", unit->heater_usage);
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
2052 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
2053 if (unit->cooler_address) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
2054 snprintf(cooler, 39, "%d", unit->cooler_state);
297
a70527a4e56a Added usage counters to the beer logfiles. Bumped to version 0.2.4
Michiel Broek <mbroek@mbse.eu>
parents: 293
diff changeset
2055 snprintf(use_cooler, 39, "%d", unit->cooler_usage);
105
a5a964148e34 Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents: 104
diff changeset
2056 }
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
2057 if (unit->fan_address) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
2058 snprintf(fan, 39, "%d", unit->fan_state);
297
a70527a4e56a Added usage counters to the beer logfiles. Bumped to version 0.2.4
Michiel Broek <mbroek@mbse.eu>
parents: 293
diff changeset
2059 snprintf(use_fan, 39, "%d", unit->fan_usage);
175
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
2060 }
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
2061 if (unit->door_address) {
b73490398368 Units editing is more or less complete. Changed structures for heating, cooling, fan and door. Updated the web interface to confuigure all these things.
Michiel Broek <mbroek@mbse.eu>
parents: 174
diff changeset
2062 snprintf(door, 39, "%d", unit->door_state);
105
a5a964148e34 Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents: 104
diff changeset
2063 }
355
8f946f9d125a Added logging of the room temperature.
Michiel Broek <mbroek@mbse.eu>
parents: 352
diff changeset
2064 if (Config.temp_address) {
8f946f9d125a Added logging of the room temperature.
Michiel Broek <mbroek@mbse.eu>
parents: 352
diff changeset
2065 snprintf(room_temp, 39, "%.3f", Config.temp_value / 1000.0);
8f946f9d125a Added logging of the room temperature.
Michiel Broek <mbroek@mbse.eu>
parents: 352
diff changeset
2066 }
105
a5a964148e34 Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents: 104
diff changeset
2067
397
00ca08f5a6f8 Fermentation profiles now have a low and high temperature setting so that you can use a temperture window. Each profile step can now set for beer or air temperature reference. The logfiles have an extra temperature field for this. Bumped to version 0.4.2.
Michiel Broek <mbroek@mbse.eu>
parents: 395
diff changeset
2068 snprintf(buf, 1023, "%s,%.3f,%.3f,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s",
105
a5a964148e34 Started code of roulating lcd display
Michiel Broek <mbroek@mbse.eu>
parents: 104
diff changeset
2069 UNITMODE[unit->mode], unit->air_temperature / 1000.0,
397
00ca08f5a6f8 Fermentation profiles now have a low and high temperature setting so that you can use a temperture window. Each profile step can now set for beer or air temperature reference. The logfiles have an extra temperature field for this. Bumped to version 0.4.2.
Michiel Broek <mbroek@mbse.eu>
parents: 395
diff changeset
2070 unit->beer_temperature / 1000.0,
00ca08f5a6f8 Fermentation profiles now have a low and high temperature setting so that you can use a temperture window. Each profile step can now set for beer or air temperature reference. The logfiles have an extra temperature field for this. Bumped to version 0.4.2.
Michiel Broek <mbroek@mbse.eu>
parents: 395
diff changeset
2071 target_lo, heater, cooler, fan, door, use_heater, use_cooler, use_fan, room_temp, target_hi);
104
5e538c4e1ecb Added units logging
Michiel Broek <mbroek@mbse.eu>
parents: 93
diff changeset
2072 filename = xstrcpy(unit->name);
5e538c4e1ecb Added units logging
Michiel Broek <mbroek@mbse.eu>
parents: 93
diff changeset
2073 filename = xstrcat(filename, (char *)".log");
5e538c4e1ecb Added units logging
Michiel Broek <mbroek@mbse.eu>
parents: 93
diff changeset
2074 logger(filename, buf);
5e538c4e1ecb Added units logging
Michiel Broek <mbroek@mbse.eu>
parents: 93
diff changeset
2075 free(filename);
5e538c4e1ecb Added units logging
Michiel Broek <mbroek@mbse.eu>
parents: 93
diff changeset
2076 filename = NULL;
5e538c4e1ecb Added units logging
Michiel Broek <mbroek@mbse.eu>
parents: 93
diff changeset
2077 }
5e538c4e1ecb Added units logging
Michiel Broek <mbroek@mbse.eu>
parents: 93
diff changeset
2078 }
167
56b008563db8 Fixed GET AIR|BEER commands. Save configuration every 30 minutes.
Michiel Broek <mbroek@mbse.eu>
parents: 165
diff changeset
2079
56b008563db8 Fixed GET AIR|BEER commands. Save configuration every 30 minutes.
Michiel Broek <mbroek@mbse.eu>
parents: 165
diff changeset
2080 minutes++;
293
881b1ae75468 Added usage counters
Michiel Broek <mbroek@mbse.eu>
parents: 289
diff changeset
2081 if (minutes == 60) {
167
56b008563db8 Fixed GET AIR|BEER commands. Save configuration every 30 minutes.
Michiel Broek <mbroek@mbse.eu>
parents: 165
diff changeset
2082 minutes = 0;
293
881b1ae75468 Added usage counters
Michiel Broek <mbroek@mbse.eu>
parents: 289
diff changeset
2083 /*
881b1ae75468 Added usage counters
Michiel Broek <mbroek@mbse.eu>
parents: 289
diff changeset
2084 * Log usage counters every hour
881b1ae75468 Added usage counters
Michiel Broek <mbroek@mbse.eu>
parents: 289
diff changeset
2085 */
881b1ae75468 Added usage counters
Michiel Broek <mbroek@mbse.eu>
parents: 289
diff changeset
2086 for (unit = Config.units; unit; unit = unit->next) {
881b1ae75468 Added usage counters
Michiel Broek <mbroek@mbse.eu>
parents: 289
diff changeset
2087 syslog(LOG_NOTICE, "Unit `%s' usage heater=%d cooler=%d fan=%d", unit->name, unit->heater_usage, unit->cooler_usage, unit->fan_usage);
881b1ae75468 Added usage counters
Michiel Broek <mbroek@mbse.eu>
parents: 289
diff changeset
2088 }
881b1ae75468 Added usage counters
Michiel Broek <mbroek@mbse.eu>
parents: 289
diff changeset
2089 }
167
56b008563db8 Fixed GET AIR|BEER commands. Save configuration every 30 minutes.
Michiel Broek <mbroek@mbse.eu>
parents: 165
diff changeset
2090
227
1cb55ea51f76 Remove debug log information about regular configuration saving.
Michiel Broek <mbroek@mbse.eu>
parents: 223
diff changeset
2091 /*
1cb55ea51f76 Remove debug log information about regular configuration saving.
Michiel Broek <mbroek@mbse.eu>
parents: 223
diff changeset
2092 * Save the configuration each half hour.
1cb55ea51f76 Remove debug log information about regular configuration saving.
Michiel Broek <mbroek@mbse.eu>
parents: 223
diff changeset
2093 */
1cb55ea51f76 Remove debug log information about regular configuration saving.
Michiel Broek <mbroek@mbse.eu>
parents: 223
diff changeset
2094 if ((minutes == 15) || (minutes == 45))
167
56b008563db8 Fixed GET AIR|BEER commands. Save configuration every 30 minutes.
Michiel Broek <mbroek@mbse.eu>
parents: 165
diff changeset
2095 wrconfig();
64
2431965e8a8c Write loglines only every 60 seconds
Michiel Broek <mbroek@mbse.eu>
parents: 63
diff changeset
2096 }
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2097 }
200
a215ddaabbe2 Added first panel key routines. The LCD display steps manual only and has a 2 minutes backlight timeout.
Michiel Broek <mbroek@mbse.eu>
parents: 199
diff changeset
2098
422
13502d0dda65 The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents: 420
diff changeset
2099 slcdDummy(slcdHandle);
205
ca18ff45deba Start initial menu setup
Michiel Broek <mbroek@mbse.eu>
parents: 204
diff changeset
2100 key = keycheck();
246
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
2101 if (key != KEY_NONE)
6df404da3537 Setting fridge and beer temperature from the panel implemented
Michiel Broek <mbroek@mbse.eu>
parents: 245
diff changeset
2102 panel_key_events(key);
200
a215ddaabbe2 Added first panel key routines. The LCD display steps manual only and has a 2 minutes backlight timeout.
Michiel Broek <mbroek@mbse.eu>
parents: 199
diff changeset
2103
28
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 27
diff changeset
2104 usleep(100000);
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2105
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2106 } while (run);
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2107
182
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
2108 /*
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
2109 * Stop units processing in a neat way
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
2110 */
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
2111 for (unit = Config.units; unit; unit = unit->next) {
497
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
2112
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
2113 #ifdef HAVE_MOSQUITTO_H
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
2114 if (mqtt_use && (unit->mode != UNITMODE_OFF)) {
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
2115 sprintf(buf, "0");
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
2116 if (unit->heater_address) {
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
2117 snprintf(topic, 1023, "fermenter/%s/%s/heater", hostname, unit->uuid);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
2118 mosquitto_publish(mosq, &mqtt_mid_sent, topic, strlen(buf), buf, mqtt_qos, 1);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
2119 }
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
2120 if (unit->cooler_address) {
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
2121 snprintf(topic, 1023, "fermenter/%s/%s/cooler", hostname, unit->uuid);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
2122 mosquitto_publish(mosq, &mqtt_mid_sent, topic, strlen(buf), buf, mqtt_qos, 1);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
2123 }
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
2124 if (unit->fan_address) {
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
2125 snprintf(topic, 1023, "fermenter/%s/%s/fan", hostname, unit->uuid);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
2126 mosquitto_publish(mosq, &mqtt_mid_sent, topic, strlen(buf), buf, mqtt_qos, 1);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
2127 }
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
2128 snprintf(topic, 1023, "fermenter/%s/%s/state", hostname, unit->uuid);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
2129 mosquitto_publish(mosq, &mqtt_mid_sent, topic, strlen(buf), buf, mqtt_qos, 1);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
2130 }
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
2131 #endif
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
2132
182
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
2133 /*
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
2134 * Turn everything off
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
2135 */
350
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
2136 unit->heater_state = unit->cooler_state = unit->fan_state = unit->door_state = unit->light_state = 0;
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
2137 unit->heater_wait = unit->cooler_wait = unit->fan_wait = unit->light_wait = 0;
182
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
2138 device_out(unit->heater_address, unit->heater_state);
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
2139 device_out(unit->cooler_address, unit->cooler_state);
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
2140 device_out(unit->fan_address, unit->fan_state);
350
7283561977b1 Added door and PSU sensors. Added interior light logic and switching.
Michiel Broek <mbroek@mbse.eu>
parents: 349
diff changeset
2141 device_out(unit->light_address, unit->light_state);
352
a8e106c95db4 Improved regular logging, disabled some debug logging.
Michiel Broek <mbroek@mbse.eu>
parents: 350
diff changeset
2142 syslog(LOG_NOTICE, "Unit `%s' stopped in mode %s", unit->name, UNITMODE[unit->mode]);
182
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
2143 }
dd69ccba8fa8 Removing units thread
Michiel Broek <mbroek@mbse.eu>
parents: 179
diff changeset
2144
497
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
2145 #ifdef HAVE_MOSQUITTO_H
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
2146
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
2147 if (mqtt_use) {
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
2148 /*
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
2149 * Final publish 0 to clients/<hostname>/thermferm/state
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
2150 */
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
2151 syslog(LOG_NOTICE, "MQTT disconnecting");
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
2152 sprintf(buf, "0");
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
2153 mosquitto_publish(mosq, &mqtt_mid_sent, state, strlen(buf), buf, mqtt_qos, true);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
2154 mqtt_last_mid = mqtt_mid_sent;
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
2155 mqtt_status = STATUS_WAITING;
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
2156
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
2157 do {
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
2158 if (mqtt_status == STATUS_WAITING) {
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
2159 if (debug)
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
2160 fprintf(stdout, (char *)"Waiting\n");
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
2161 if (mqtt_last_mid_sent == mqtt_last_mid && mqtt_disconnect_sent == FALSE) {
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
2162 mosquitto_disconnect(mosq);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
2163 mqtt_disconnect_sent = TRUE;
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
2164 }
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
2165 usleep(100000);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
2166 }
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
2167 rc = MOSQ_ERR_SUCCESS;
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
2168 } while (rc == MOSQ_ERR_SUCCESS && mqtt_connected);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
2169
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
2170 mosquitto_loop_stop(mosq, FALSE);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
2171 mosquitto_destroy(mosq);
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
2172 mosquitto_lib_cleanup();
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
2173 }
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
2174 #endif
18ace27338e5 Compiles mosquitto code if library is found on the system. Bumped to version 0.5.4
Michiel Broek <mbroek@mbse.eu>
parents: 496
diff changeset
2175
420
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents: 418
diff changeset
2176 syslog(LOG_NOTICE, "Out of loop");
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2177 if (debug)
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2178 fprintf(stdout, (char *)"Out of loop\n");
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2179
28
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 27
diff changeset
2180 /*
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 27
diff changeset
2181 * Give threads time to cleanup
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 27
diff changeset
2182 */
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 27
diff changeset
2183 usleep(1500000);
32ed1ea4d0b6 Coolers working with a hardcode reference
Michiel Broek <mbroek@mbse.eu>
parents: 27
diff changeset
2184
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2185 stopLCD();
420
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents: 418
diff changeset
2186 if (sock != -1) {
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents: 418
diff changeset
2187 if (shutdown(sock, SHUT_RDWR)) {
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents: 418
diff changeset
2188 syslog(LOG_NOTICE, "Can't shutdown socket: %s", strerror(errno));
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents: 418
diff changeset
2189 }
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents: 418
diff changeset
2190 sock = -1;
644a6106d712 The first ideas of the brewpanel simulation are in place.
Michiel Broek <mbroek@mbse.eu>
parents: 418
diff changeset
2191 }
86
3d7a241329e2 Using final user paths for log, configuration and profiles
Michiel Broek <mbroek@mbse.eu>
parents: 83
diff changeset
2192 wrconfig();
41
f534ace74eea Code preparation for client/server communication
Michiel Broek <mbroek@mbse.eu>
parents: 40
diff changeset
2193 ulockprog((char *)"thermferm");
26
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2194 return 0;
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2195 }
9322c619c525 Added coolers program, first draft
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
2196

mercurial