Sun, 05 May 2024 17:24:54 +0200
Much faster shutdown of the websocket service.
197 | 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 | 3 | * |
4 | * Michiel Broek <mbroek at mbse dot eu> | |
5 | * | |
6 | * This file is part of the mbsePi-apps | |
7 | * | |
8 | * This is free software; you can redistribute it and/or modify it | |
9 | * under the terms of the GNU General Public License as published by the | |
10 | * Free Software Foundation; either version 2, or (at your option) any | |
11 | * later version. | |
12 | * | |
13 | * mbsePi-apps is distributed in the hope that it will be useful, but | |
14 | * WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
16 | * General Public License for more details. | |
17 | * | |
18 | * You should have received a copy of the GNU General Public License | |
19 | * along with ThermFerm; see the file COPYING. If not, write to the Free | |
20 | * Software Foundation, 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. | |
21 | *****************************************************************************/ | |
22 | ||
23 | #include "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 | 27 | #include "panel.h" |
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 | 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 | 49 | extern int debug; |
205 | 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 | 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 | 64 | int menutimer = 0; |
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 | 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 | 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 | 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; |
724
01e3936f62d4
Log pid of each started thread so we can see which uses the most cpu time.
Michiel Broek <mbroek@mbse.eu>
parents:
660
diff
changeset
|
110 | pid_t pid = gettid(); |
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
|
111 | |
646
e3edc783006b
Running threads and locking doesn't depend on wiringPi anymore.
Michiel Broek <mbroek@mbse.eu>
parents:
645
diff
changeset
|
112 | my_panel_state = 1; |
e3edc783006b
Running threads and locking doesn't depend on wiringPi anymore.
Michiel Broek <mbroek@mbse.eu>
parents:
645
diff
changeset
|
113 | |
422
13502d0dda65
The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents:
244
diff
changeset
|
114 | #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
|
115 | 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
|
116 | 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
|
117 | 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
|
118 | pinMode(PANEL_DOWN, INPUT); |
422
13502d0dda65
The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents:
244
diff
changeset
|
119 | #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
|
120 | |
724
01e3936f62d4
Log pid of each started thread so we can see which uses the most cpu time.
Michiel Broek <mbroek@mbse.eu>
parents:
660
diff
changeset
|
121 | syslog(LOG_NOTICE, "Thread my_panel_loop started, pid=%d", pid); |
199 | 122 | |
123 | /* | |
124 | * Loop forever until the external shutdown variable is set. | |
125 | */ | |
126 | 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
|
127 | if (my_panel_shutdown) |
199 | 128 | break; |
129 | ||
422
13502d0dda65
The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents:
244
diff
changeset
|
130 | #ifdef HAVE_WIRINGPI_H |
13502d0dda65
The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents:
244
diff
changeset
|
131 | 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
|
132 | #else |
13502d0dda65
The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents:
244
diff
changeset
|
133 | if ((keys & 0x0001) == 0) { |
13502d0dda65
The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents:
244
diff
changeset
|
134 | #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
|
135 | 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
|
136 | 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
|
137 | 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
|
138 | } 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
|
139 | 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
|
140 | 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
|
141 | 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
|
142 | 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
|
143 | Key_Enter_Long = TRUE; |
427
e8e548922e31
Initial part of LEDs and backlight implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
426
diff
changeset
|
144 | if (Enter == PRESS_LONG) { |
422
13502d0dda65
The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents:
244
diff
changeset
|
145 | #ifdef HAVE_WIRINGPI_H |
216
d734255e66a0
LED flash when panel enter key is pressed long.
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
146 | digitalWrite(PANEL_LED, 1); |
427
e8e548922e31
Initial part of LEDs and backlight implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
426
diff
changeset
|
147 | #endif |
e8e548922e31
Initial part of LEDs and backlight implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
426
diff
changeset
|
148 | leds |= SLED_TFLED; |
e8e548922e31
Initial part of LEDs and backlight implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
426
diff
changeset
|
149 | slcdLEDs(slcdHandle); |
e8e548922e31
Initial part of LEDs and backlight implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
426
diff
changeset
|
150 | } |
e8e548922e31
Initial part of LEDs and backlight implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
426
diff
changeset
|
151 | if (Enter == (PRESS_LONG + 10)) { |
e8e548922e31
Initial part of LEDs and backlight implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
426
diff
changeset
|
152 | #ifdef HAVE_WIRINGPI_H |
216
d734255e66a0
LED flash when panel enter key is pressed long.
Michiel Broek <mbroek@mbse.eu>
parents:
213
diff
changeset
|
153 | digitalWrite(PANEL_LED, 0); |
422
13502d0dda65
The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents:
244
diff
changeset
|
154 | #endif |
427
e8e548922e31
Initial part of LEDs and backlight implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
426
diff
changeset
|
155 | leds &= ~SLED_TFLED; |
e8e548922e31
Initial part of LEDs and backlight implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
426
diff
changeset
|
156 | slcdLEDs(slcdHandle); |
e8e548922e31
Initial part of LEDs and backlight implemented.
Michiel Broek <mbroek@mbse.eu>
parents:
426
diff
changeset
|
157 | } |
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
|
158 | } |
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
|
159 | |
422
13502d0dda65
The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents:
244
diff
changeset
|
160 | #ifdef HAVE_WIRINGPI_H |
13502d0dda65
The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents:
244
diff
changeset
|
161 | 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
|
162 | #else |
13502d0dda65
The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents:
244
diff
changeset
|
163 | if ((keys & 0x0008) == 0) { |
13502d0dda65
The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents:
244
diff
changeset
|
164 | #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
|
165 | 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
|
166 | 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
|
167 | } 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
|
168 | 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
|
169 | 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
|
170 | 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
|
171 | } |
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
|
172 | |
422
13502d0dda65
The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents:
244
diff
changeset
|
173 | #ifdef HAVE_WIRINGPI_H |
13502d0dda65
The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents:
244
diff
changeset
|
174 | 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
|
175 | #else |
13502d0dda65
The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents:
244
diff
changeset
|
176 | if ((keys & 0x0004) == 0) { |
13502d0dda65
The brewpanel works, but still needs a lot more
Michiel Broek <mbroek@mbse.eu>
parents:
244
diff
changeset
|
177 | #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
|
178 | 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
|
179 | 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
|
180 | } 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
|
181 | 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
|
182 | 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
|
183 | 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
|
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 | |
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 | 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
|
187 | 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
|
188 | /* |
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 | * 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
|
190 | */ |
728
da038d0bed04
Version 0.9.20a1. Analyse threads cpu usage. One-wire added a resolution flag to prevent continuous resolution checks, now only for new sensors and replugged known sensors. Added two 40 sSec delays in the state machine. In the panel thread moved a few locks so these expensive calls are called only when needed.
Michiel Broek <mbroek@mbse.eu>
parents:
724
diff
changeset
|
191 | if (Backlight == 0) { |
da038d0bed04
Version 0.9.20a1. Analyse threads cpu usage. One-wire added a resolution flag to prevent continuous resolution checks, now only for new sensors and replugged known sensors. Added two 40 sSec delays in the state machine. In the panel thread moved a few locks so these expensive calls are called only when needed.
Michiel Broek <mbroek@mbse.eu>
parents:
724
diff
changeset
|
192 | pthread_mutex_lock(&mutexes[LOCK_LCD]); |
da038d0bed04
Version 0.9.20a1. Analyse threads cpu usage. One-wire added a resolution flag to prevent continuous resolution checks, now only for new sensors and replugged known sensors. Added two 40 sSec delays in the state machine. In the panel thread moved a few locks so these expensive calls are called only when needed.
Michiel Broek <mbroek@mbse.eu>
parents:
724
diff
changeset
|
193 | setBacklight(1); |
da038d0bed04
Version 0.9.20a1. Analyse threads cpu usage. One-wire added a resolution flag to prevent continuous resolution checks, now only for new sensors and replugged known sensors. Added two 40 sSec delays in the state machine. In the panel thread moved a few locks so these expensive calls are called only when needed.
Michiel Broek <mbroek@mbse.eu>
parents:
724
diff
changeset
|
194 | pthread_mutex_unlock(&mutexes[LOCK_LCD]); |
da038d0bed04
Version 0.9.20a1. Analyse threads cpu usage. One-wire added a resolution flag to prevent continuous resolution checks, now only for new sensors and replugged known sensors. Added two 40 sSec delays in the state machine. In the panel thread moved a few locks so these expensive calls are called only when needed.
Michiel Broek <mbroek@mbse.eu>
parents:
724
diff
changeset
|
195 | } |
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
|
196 | Backlight = LCD_SLEEP; |
205 | 197 | 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
|
198 | } 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
|
199 | /* |
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 | * 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
|
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 | 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
|
203 | } |
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 | |
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 | 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
|
206 | 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
|
207 | 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
|
208 | |
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 | 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
|
210 | if (Backlight == 1) { |
645
49eb753a958b
All thread locks from wiringPi to standard pthreads.
Michiel Broek <mbroek@mbse.eu>
parents:
427
diff
changeset
|
211 | 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
|
212 | setBacklight(0); |
645
49eb753a958b
All thread locks from wiringPi to standard pthreads.
Michiel Broek <mbroek@mbse.eu>
parents:
427
diff
changeset
|
213 | 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
|
214 | } |
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
|
215 | 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
|
216 | 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
|
217 | } |
205 | 218 | |
219 | if (setupmenu != MENU_NONE) { | |
728
da038d0bed04
Version 0.9.20a1. Analyse threads cpu usage. One-wire added a resolution flag to prevent continuous resolution checks, now only for new sensors and replugged known sensors. Added two 40 sSec delays in the state machine. In the panel thread moved a few locks so these expensive calls are called only when needed.
Michiel Broek <mbroek@mbse.eu>
parents:
724
diff
changeset
|
220 | pthread_mutex_lock(&mutexes[LOCK_MENU]); |
205 | 221 | if (menutimer < MENU_TIMEOUT) |
222 | menutimer++; | |
238 | 223 | else { |
205 | 224 | setupmenu = MENU_NONE; |
238 | 225 | } |
728
da038d0bed04
Version 0.9.20a1. Analyse threads cpu usage. One-wire added a resolution flag to prevent continuous resolution checks, now only for new sensors and replugged known sensors. Added two 40 sSec delays in the state machine. In the panel thread moved a few locks so these expensive calls are called only when needed.
Michiel Broek <mbroek@mbse.eu>
parents:
724
diff
changeset
|
226 | pthread_mutex_unlock(&mutexes[LOCK_MENU]); |
205 | 227 | } |
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
|
228 | } |
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
|
229 | } |
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
|
230 | |
199 | 231 | /* |
232 | * Loop 10 milliseconds | |
233 | */ | |
652
16d3d4b58b5b
Moved all delay functions into a new general file.
Michiel Broek <mbroek@mbse.eu>
parents:
646
diff
changeset
|
234 | mDelay(10); |
199 | 235 | } |
236 | ||
237 | 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
|
238 | my_panel_state = 0; |
199 | 239 | return 0; |
240 | } | |
197 | 241 | |
242 |