thermferm/panel.c

Mon, 15 Apr 2024 17:04:57 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Mon, 15 Apr 2024 17:04:57 +0200
changeset 678
cc49115e769e
parent 660
a28ef4d9afa4
child 724
01e3936f62d4
permissions
-rw-r--r--

Better websocket broadcast messages. Added GLOBAL JSON command to the server. Better logic to trigger websocket and mqtt data updates for the fermenter units. Websocket receive added fermenter mode, stage, setpoints, switches. Added more css styles for the fermenter screen. Added the fermenter screen php and javascript.

197
531725a09012 Added panel sourcecode files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
1 /*****************************************************************************
645
49eb753a958b All thread locks from wiringPi to standard pthreads.
Michiel Broek <mbroek@mbse.eu>
parents: 427
diff changeset
2 * Copyright (C) 2014-2024
197
531725a09012 Added panel sourcecode files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
3 *
531725a09012 Added panel sourcecode files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
4 * Michiel Broek <mbroek at mbse dot eu>
531725a09012 Added panel sourcecode files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
5 *
531725a09012 Added panel sourcecode files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
6 * This file is part of the mbsePi-apps
531725a09012 Added panel sourcecode files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
7 *
531725a09012 Added panel sourcecode files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
8 * This is free software; you can redistribute it and/or modify it
531725a09012 Added panel sourcecode files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
9 * under the terms of the GNU General Public License as published by the
531725a09012 Added panel sourcecode files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
10 * Free Software Foundation; either version 2, or (at your option) any
531725a09012 Added panel sourcecode files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
11 * later version.
531725a09012 Added panel sourcecode files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
12 *
531725a09012 Added panel sourcecode files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
13 * mbsePi-apps is distributed in the hope that it will be useful, but
531725a09012 Added panel sourcecode files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
531725a09012 Added panel sourcecode files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
531725a09012 Added panel sourcecode files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
16 * General Public License for more details.
531725a09012 Added panel sourcecode files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
17 *
531725a09012 Added panel sourcecode files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
18 * You should have received a copy of the GNU General Public License
531725a09012 Added panel sourcecode files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
19 * along with ThermFerm; see the file COPYING. If not, write to the Free
531725a09012 Added panel sourcecode files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
20 * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
531725a09012 Added panel sourcecode files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
21 *****************************************************************************/
531725a09012 Added panel sourcecode files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
22
531725a09012 Added panel sourcecode files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
23 #include "thermferm.h"
652
16d3d4b58b5b Moved all delay functions into a new general file.
Michiel Broek <mbroek@mbse.eu>
parents: 646
diff changeset
24 #include "delay.h"
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
25 #include "lcd-pcf8574.h"
422
13502d0dda65 The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
26 #include "slcd.h"
197
531725a09012 Added panel sourcecode files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
27 #include "panel.h"
531725a09012 Added panel sourcecode files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
28
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
29
197
531725a09012 Added panel sourcecode files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
30
229
5f93b61adb34 Move some public functions to private functions
Michiel Broek <mbroek@mbse.eu>
parents: 228
diff changeset
31 /*
5f93b61adb34 Move some public functions to private functions
Michiel Broek <mbroek@mbse.eu>
parents: 228
diff changeset
32 * 10 Milliseconds counts for a key to be short or long pressed.
5f93b61adb34 Move some public functions to private functions
Michiel Broek <mbroek@mbse.eu>
parents: 228
diff changeset
33 */
5f93b61adb34 Move some public functions to private functions
Michiel Broek <mbroek@mbse.eu>
parents: 228
diff changeset
34 #define PRESS_NORMAL 5
5f93b61adb34 Move some public functions to private functions
Michiel Broek <mbroek@mbse.eu>
parents: 228
diff changeset
35 #define PRESS_LONG 200
5f93b61adb34 Move some public functions to private functions
Michiel Broek <mbroek@mbse.eu>
parents: 228
diff changeset
36
5f93b61adb34 Move some public functions to private functions
Michiel Broek <mbroek@mbse.eu>
parents: 228
diff changeset
37 /*
5f93b61adb34 Move some public functions to private functions
Michiel Broek <mbroek@mbse.eu>
parents: 228
diff changeset
38 * LCD timeout in seconds
5f93b61adb34 Move some public functions to private functions
Michiel Broek <mbroek@mbse.eu>
parents: 228
diff changeset
39 */
5f93b61adb34 Move some public functions to private functions
Michiel Broek <mbroek@mbse.eu>
parents: 228
diff changeset
40 #define LCD_SLEEP 120
5f93b61adb34 Move some public functions to private functions
Michiel Broek <mbroek@mbse.eu>
parents: 228
diff changeset
41
5f93b61adb34 Move some public functions to private functions
Michiel Broek <mbroek@mbse.eu>
parents: 228
diff changeset
42 /*
5f93b61adb34 Move some public functions to private functions
Michiel Broek <mbroek@mbse.eu>
parents: 228
diff changeset
43 * Menu timeout in seconds
5f93b61adb34 Move some public functions to private functions
Michiel Broek <mbroek@mbse.eu>
parents: 228
diff changeset
44 */
5f93b61adb34 Move some public functions to private functions
Michiel Broek <mbroek@mbse.eu>
parents: 228
diff changeset
45 #define MENU_TIMEOUT 60
5f93b61adb34 Move some public functions to private functions
Michiel Broek <mbroek@mbse.eu>
parents: 228
diff changeset
46
5f93b61adb34 Move some public functions to private functions
Michiel Broek <mbroek@mbse.eu>
parents: 228
diff changeset
47
5f93b61adb34 Move some public functions to private functions
Michiel Broek <mbroek@mbse.eu>
parents: 228
diff changeset
48
199
3f5d277a69e3 Added panel thread
Michiel Broek <mbroek@mbse.eu>
parents: 197
diff changeset
49 extern int debug;
205
ca18ff45deba Start initial menu setup
Michiel Broek <mbroek@mbse.eu>
parents: 204
diff changeset
50 extern int setupmenu;
422
13502d0dda65 The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
51 extern uint16_t keys;
427
e8e548922e31 Initial part of LEDs and backlight implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 426
diff changeset
52 extern uint16_t leds;
e8e548922e31 Initial part of LEDs and backlight implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 426
diff changeset
53 extern int slcdHandle;
645
49eb753a958b All thread locks from wiringPi to standard pthreads.
Michiel Broek <mbroek@mbse.eu>
parents: 427
diff changeset
54 extern pthread_mutex_t mutexes[5];
199
3f5d277a69e3 Added panel thread
Michiel Broek <mbroek@mbse.eu>
parents: 197
diff changeset
55
646
e3edc783006b Running threads and locking doesn't depend on wiringPi anymore.
Michiel Broek <mbroek@mbse.eu>
parents: 645
diff changeset
56 int my_panel_state = 0;
660
a28ef4d9afa4 Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents: 652
diff changeset
57 int my_panel_shutdown = 0;
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
58 int Key_Enter = FALSE;
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
59 int Key_Enter_Long = FALSE;
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
60 int Key_Up = FALSE;
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
61 int Key_Down = FALSE;
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
62
204
9a14d6b2de7f Fixed LCD display updates. Better key routines.
Michiel Broek <mbroek@mbse.eu>
parents: 200
diff changeset
63 int previous_key = KEY_NONE;
205
ca18ff45deba Start initial menu setup
Michiel Broek <mbroek@mbse.eu>
parents: 204
diff changeset
64 int menutimer = 0;
ca18ff45deba Start initial menu setup
Michiel Broek <mbroek@mbse.eu>
parents: 204
diff changeset
65
204
9a14d6b2de7f Fixed LCD display updates. Better key routines.
Michiel Broek <mbroek@mbse.eu>
parents: 200
diff changeset
66
229
5f93b61adb34 Move some public functions to private functions
Michiel Broek <mbroek@mbse.eu>
parents: 228
diff changeset
67 int keypressed(void);
5f93b61adb34 Move some public functions to private functions
Michiel Broek <mbroek@mbse.eu>
parents: 228
diff changeset
68
204
9a14d6b2de7f Fixed LCD display updates. Better key routines.
Michiel Broek <mbroek@mbse.eu>
parents: 200
diff changeset
69
9a14d6b2de7f Fixed LCD display updates. Better key routines.
Michiel Broek <mbroek@mbse.eu>
parents: 200
diff changeset
70 /*
9a14d6b2de7f Fixed LCD display updates. Better key routines.
Michiel Broek <mbroek@mbse.eu>
parents: 200
diff changeset
71 * Check for a key. Return last pressed key or none.
9a14d6b2de7f Fixed LCD display updates. Better key routines.
Michiel Broek <mbroek@mbse.eu>
parents: 200
diff changeset
72 */
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
73 int keycheck(void)
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
74 {
204
9a14d6b2de7f Fixed LCD display updates. Better key routines.
Michiel Broek <mbroek@mbse.eu>
parents: 200
diff changeset
75 int key, retkey = KEY_NONE;
9a14d6b2de7f Fixed LCD display updates. Better key routines.
Michiel Broek <mbroek@mbse.eu>
parents: 200
diff changeset
76
9a14d6b2de7f Fixed LCD display updates. Better key routines.
Michiel Broek <mbroek@mbse.eu>
parents: 200
diff changeset
77 key = keypressed();
9a14d6b2de7f Fixed LCD display updates. Better key routines.
Michiel Broek <mbroek@mbse.eu>
parents: 200
diff changeset
78 if ((key == KEY_NONE) && (previous_key != KEY_NONE)) {
9a14d6b2de7f Fixed LCD display updates. Better key routines.
Michiel Broek <mbroek@mbse.eu>
parents: 200
diff changeset
79 retkey = previous_key;
9a14d6b2de7f Fixed LCD display updates. Better key routines.
Michiel Broek <mbroek@mbse.eu>
parents: 200
diff changeset
80 }
9a14d6b2de7f Fixed LCD display updates. Better key routines.
Michiel Broek <mbroek@mbse.eu>
parents: 200
diff changeset
81
9a14d6b2de7f Fixed LCD display updates. Better key routines.
Michiel Broek <mbroek@mbse.eu>
parents: 200
diff changeset
82 previous_key = key;
9a14d6b2de7f Fixed LCD display updates. Better key routines.
Michiel Broek <mbroek@mbse.eu>
parents: 200
diff changeset
83 return retkey;
9a14d6b2de7f Fixed LCD display updates. Better key routines.
Michiel Broek <mbroek@mbse.eu>
parents: 200
diff changeset
84 }
9a14d6b2de7f Fixed LCD display updates. Better key routines.
Michiel Broek <mbroek@mbse.eu>
parents: 200
diff changeset
85
9a14d6b2de7f Fixed LCD display updates. Better key routines.
Michiel Broek <mbroek@mbse.eu>
parents: 200
diff changeset
86
9a14d6b2de7f Fixed LCD display updates. Better key routines.
Michiel Broek <mbroek@mbse.eu>
parents: 200
diff changeset
87
9a14d6b2de7f Fixed LCD display updates. Better key routines.
Michiel Broek <mbroek@mbse.eu>
parents: 200
diff changeset
88 int keypressed(void)
9a14d6b2de7f Fixed LCD display updates. Better key routines.
Michiel Broek <mbroek@mbse.eu>
parents: 200
diff changeset
89 {
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
90 if (Key_Enter && Key_Up && Key_Down)
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
91 return KEY_ALL;
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
92 if (Key_Up && Key_Down)
205
ca18ff45deba Start initial menu setup
Michiel Broek <mbroek@mbse.eu>
parents: 204
diff changeset
93 return KEY_ESCAPE;
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
94 if (Key_Up)
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
95 return KEY_UP;
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
96 if (Key_Down)
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
97 return KEY_DOWN;
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
98 if (Key_Enter_Long)
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
99 return KEY_CONFIRM;
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
100 if (Key_Enter)
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
101 return KEY_ENTER;
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
102 return KEY_NONE;
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
103 }
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
104
199
3f5d277a69e3 Added panel thread
Michiel Broek <mbroek@mbse.eu>
parents: 197
diff changeset
105
422
13502d0dda65 The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
106 void *my_panel_loop(void *threadid)
199
3f5d277a69e3 Added panel thread
Michiel Broek <mbroek@mbse.eu>
parents: 197
diff changeset
107 {
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
108 int Enter = 0, Up = 0, Down = 0, Backlight = LCD_SLEEP, AnyKey = FALSE;
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
109 time_t Last = (time_t)0, Now;
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
110
646
e3edc783006b Running threads and locking doesn't depend on wiringPi anymore.
Michiel Broek <mbroek@mbse.eu>
parents: 645
diff changeset
111 my_panel_state = 1;
e3edc783006b Running threads and locking doesn't depend on wiringPi anymore.
Michiel Broek <mbroek@mbse.eu>
parents: 645
diff changeset
112
422
13502d0dda65 The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
113 #ifdef HAVE_WIRINGPI_H
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
114 pinMode(PANEL_LED, OUTPUT);
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
115 pinMode(PANEL_ENTER, INPUT);
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
116 pinMode(PANEL_UP, INPUT);
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
117 pinMode(PANEL_DOWN, INPUT);
422
13502d0dda65 The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
118 #endif
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
119
199
3f5d277a69e3 Added panel thread
Michiel Broek <mbroek@mbse.eu>
parents: 197
diff changeset
120 syslog(LOG_NOTICE, "Thread my_panel_loop started");
3f5d277a69e3 Added panel thread
Michiel Broek <mbroek@mbse.eu>
parents: 197
diff changeset
121
3f5d277a69e3 Added panel thread
Michiel Broek <mbroek@mbse.eu>
parents: 197
diff changeset
122 /*
3f5d277a69e3 Added panel thread
Michiel Broek <mbroek@mbse.eu>
parents: 197
diff changeset
123 * Loop forever until the external shutdown variable is set.
3f5d277a69e3 Added panel thread
Michiel Broek <mbroek@mbse.eu>
parents: 197
diff changeset
124 */
3f5d277a69e3 Added panel thread
Michiel Broek <mbroek@mbse.eu>
parents: 197
diff changeset
125 for (;;) {
660
a28ef4d9afa4 Version 0.9.17a1. Revised starting and stopping the threads. Fixed stopping the command server thread. Moved one-wire tempeature sensors resolution correction to the one-wire thread. The devices thread fetches temperatures from the one-wire thread. The one-wire thread does everything for the temperature sensors. The command server uses private sockets. Still, only one session at the same time is handled.
Michiel Broek <mbroek@mbse.eu>
parents: 652
diff changeset
126 if (my_panel_shutdown)
199
3f5d277a69e3 Added panel thread
Michiel Broek <mbroek@mbse.eu>
parents: 197
diff changeset
127 break;
3f5d277a69e3 Added panel thread
Michiel Broek <mbroek@mbse.eu>
parents: 197
diff changeset
128
422
13502d0dda65 The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
129 #ifdef HAVE_WIRINGPI_H
13502d0dda65 The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
130 if (digitalRead(PANEL_ENTER) && ((keys & 0x0001) == 0)) {
13502d0dda65 The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
131 #else
13502d0dda65 The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
132 if ((keys & 0x0001) == 0) {
13502d0dda65 The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
133 #endif
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
134 Enter = 0;
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
135 Key_Enter = FALSE;
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
136 Key_Enter_Long = FALSE;
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
137 } else {
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
138 Enter++;
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
139 if (Enter > PRESS_NORMAL)
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
140 Key_Enter = TRUE;
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
141 if (Enter > PRESS_LONG)
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
142 Key_Enter_Long = TRUE;
427
e8e548922e31 Initial part of LEDs and backlight implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 426
diff changeset
143 if (Enter == PRESS_LONG) {
422
13502d0dda65 The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
144 #ifdef HAVE_WIRINGPI_H
216
d734255e66a0 LED flash when panel enter key is pressed long.
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
145 digitalWrite(PANEL_LED, 1);
427
e8e548922e31 Initial part of LEDs and backlight implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 426
diff changeset
146 #endif
e8e548922e31 Initial part of LEDs and backlight implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 426
diff changeset
147 leds |= SLED_TFLED;
e8e548922e31 Initial part of LEDs and backlight implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 426
diff changeset
148 slcdLEDs(slcdHandle);
e8e548922e31 Initial part of LEDs and backlight implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 426
diff changeset
149 }
e8e548922e31 Initial part of LEDs and backlight implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 426
diff changeset
150 if (Enter == (PRESS_LONG + 10)) {
e8e548922e31 Initial part of LEDs and backlight implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 426
diff changeset
151 #ifdef HAVE_WIRINGPI_H
216
d734255e66a0 LED flash when panel enter key is pressed long.
Michiel Broek <mbroek@mbse.eu>
parents: 213
diff changeset
152 digitalWrite(PANEL_LED, 0);
422
13502d0dda65 The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
153 #endif
427
e8e548922e31 Initial part of LEDs and backlight implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 426
diff changeset
154 leds &= ~SLED_TFLED;
e8e548922e31 Initial part of LEDs and backlight implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 426
diff changeset
155 slcdLEDs(slcdHandle);
e8e548922e31 Initial part of LEDs and backlight implemented.
Michiel Broek <mbroek@mbse.eu>
parents: 426
diff changeset
156 }
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
157 }
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
158
422
13502d0dda65 The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
159 #ifdef HAVE_WIRINGPI_H
13502d0dda65 The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
160 if (digitalRead(PANEL_UP) && ((keys & 0x0008) == 0)) {
13502d0dda65 The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
161 #else
13502d0dda65 The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
162 if ((keys & 0x0008) == 0) {
13502d0dda65 The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
163 #endif
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
164 Up = 0;
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
165 Key_Up = FALSE;
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
166 } else {
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
167 Up++;
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
168 if (Up > PRESS_NORMAL)
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
169 Key_Up = TRUE;
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
170 }
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
171
422
13502d0dda65 The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
172 #ifdef HAVE_WIRINGPI_H
13502d0dda65 The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
173 if (digitalRead(PANEL_DOWN) && ((keys & 0x0004) == 0)) {
13502d0dda65 The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
174 #else
13502d0dda65 The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
175 if ((keys & 0x0004) == 0) {
13502d0dda65 The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents: 244
diff changeset
176 #endif
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
177 Down = 0;
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
178 Key_Down = FALSE;
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
179 } else {
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
180 Down++;
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
181 if (Down > PRESS_NORMAL)
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
182 Key_Down = TRUE;
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
183 }
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
184
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
185 if (Key_Enter || Key_Up || Key_Down) {
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
186 AnyKey = TRUE;
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
187 /*
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
188 * Any key is pressed.
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
189 */
645
49eb753a958b All thread locks from wiringPi to standard pthreads.
Michiel Broek <mbroek@mbse.eu>
parents: 427
diff changeset
190 pthread_mutex_lock(&mutexes[LOCK_LCD]);
228
11655e7124c5 Fixed stepping down in LCD screens.
Michiel Broek <mbroek@mbse.eu>
parents: 219
diff changeset
191 setBacklight(1);
645
49eb753a958b All thread locks from wiringPi to standard pthreads.
Michiel Broek <mbroek@mbse.eu>
parents: 427
diff changeset
192 pthread_mutex_unlock(&mutexes[LOCK_LCD]);
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
193 Backlight = LCD_SLEEP;
205
ca18ff45deba Start initial menu setup
Michiel Broek <mbroek@mbse.eu>
parents: 204
diff changeset
194 menutimer = 0;
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
195 } else {
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
196 /*
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
197 * No key pressed.
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
198 */
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
199 AnyKey = FALSE;
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
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
201
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
202 Now = time(NULL);
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
203 if (Now != Last) {
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
204 Last = Now;
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
205
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
206 if (AnyKey == FALSE) {
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: 238
diff changeset
207 if (Backlight == 1) {
645
49eb753a958b All thread locks from wiringPi to standard pthreads.
Michiel Broek <mbroek@mbse.eu>
parents: 427
diff changeset
208 pthread_mutex_lock(&mutexes[LOCK_LCD]);
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
209 setBacklight(0);
645
49eb753a958b All thread locks from wiringPi to standard pthreads.
Michiel Broek <mbroek@mbse.eu>
parents: 427
diff changeset
210 pthread_mutex_unlock(&mutexes[LOCK_LCD]);
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: 238
diff changeset
211 }
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
212 if (Backlight > 0) {
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
213 Backlight--;
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
214 }
205
ca18ff45deba Start initial menu setup
Michiel Broek <mbroek@mbse.eu>
parents: 204
diff changeset
215
645
49eb753a958b All thread locks from wiringPi to standard pthreads.
Michiel Broek <mbroek@mbse.eu>
parents: 427
diff changeset
216 pthread_mutex_lock(&mutexes[LOCK_MENU]);
205
ca18ff45deba Start initial menu setup
Michiel Broek <mbroek@mbse.eu>
parents: 204
diff changeset
217 if (setupmenu != MENU_NONE) {
ca18ff45deba Start initial menu setup
Michiel Broek <mbroek@mbse.eu>
parents: 204
diff changeset
218 if (menutimer < MENU_TIMEOUT)
ca18ff45deba Start initial menu setup
Michiel Broek <mbroek@mbse.eu>
parents: 204
diff changeset
219 menutimer++;
238
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 229
diff changeset
220 else {
205
ca18ff45deba Start initial menu setup
Michiel Broek <mbroek@mbse.eu>
parents: 204
diff changeset
221 setupmenu = MENU_NONE;
238
a0f1deb65889 Added more panel menus
Michiel Broek <mbroek@mbse.eu>
parents: 229
diff changeset
222 }
205
ca18ff45deba Start initial menu setup
Michiel Broek <mbroek@mbse.eu>
parents: 204
diff changeset
223 }
645
49eb753a958b All thread locks from wiringPi to standard pthreads.
Michiel Broek <mbroek@mbse.eu>
parents: 427
diff changeset
224 pthread_mutex_unlock(&mutexes[LOCK_MENU]);
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
225 }
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
226 }
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
227
199
3f5d277a69e3 Added panel thread
Michiel Broek <mbroek@mbse.eu>
parents: 197
diff changeset
228 /*
3f5d277a69e3 Added panel thread
Michiel Broek <mbroek@mbse.eu>
parents: 197
diff changeset
229 * Loop 10 milliseconds
3f5d277a69e3 Added panel thread
Michiel Broek <mbroek@mbse.eu>
parents: 197
diff changeset
230 */
652
16d3d4b58b5b Moved all delay functions into a new general file.
Michiel Broek <mbroek@mbse.eu>
parents: 646
diff changeset
231 mDelay(10);
199
3f5d277a69e3 Added panel thread
Michiel Broek <mbroek@mbse.eu>
parents: 197
diff changeset
232 }
3f5d277a69e3 Added panel thread
Michiel Broek <mbroek@mbse.eu>
parents: 197
diff changeset
233
3f5d277a69e3 Added panel thread
Michiel Broek <mbroek@mbse.eu>
parents: 197
diff changeset
234 syslog(LOG_NOTICE, "Thread my_panel_loop stopped");
646
e3edc783006b Running threads and locking doesn't depend on wiringPi anymore.
Michiel Broek <mbroek@mbse.eu>
parents: 645
diff changeset
235 my_panel_state = 0;
199
3f5d277a69e3 Added panel thread
Michiel Broek <mbroek@mbse.eu>
parents: 197
diff changeset
236 return 0;
3f5d277a69e3 Added panel thread
Michiel Broek <mbroek@mbse.eu>
parents: 197
diff changeset
237 }
197
531725a09012 Added panel sourcecode files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
238
531725a09012 Added panel sourcecode files
Michiel Broek <mbroek@mbse.eu>
parents:
diff changeset
239

mercurial