Skip to content
This repository was archived by the owner on Aug 27, 2022. It is now read-only.

Commit 0ffc4ff

Browse files
jacques42andi34
authored andcommitted
hardwarebutton-rotary: updated FAQ, added robustness in validating GPIO configuration
1 parent 6fe94fd commit 0ffc4ff

File tree

2 files changed

+43
-27
lines changed

2 files changed

+43
-27
lines changed

faq/faq.md

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,27 @@ The Hardware Button functionality supports two separate modes of operation (sele
120120
- **Rotary Mode**: A rotary encoder connected to GPIOs will drive the input on the screen. This enables to use the rotary to scroll through the Photobooth UI buttons, and click to select actions.
121121
Modes can not be combined.
122122

123-
In any mode, Photobooth will watch GPIOs for a PIN_DOWN event - so the hardware button needs to pull the GPIO to ground, for to trigger.
123+
In any mode, Photobooth will watch GPIOs for a PIN_DOWN event - so the hardware button needs to pull the GPIO to ground, for to trigger. This requires the GPIOs to be configured in PULLUP mode - always.
124124

125125
Troubleshooting / Debugging:
126126

127127
- **Important: For WLAN connected screens you must make sure to set the IP address of the Photobooth web server in the admin settings - section "General"**. The loopback IP (127.0.0.1) does not work, it has to be the exact IP address of the Photobooth web server, to which the remote display connects to.
128-
- In "dev" mode the remote buzzer server logs to be written to the "tmp" directory of the photobooth installation (i.e. `data/tmp/remotebuzzer_server.log`). Clients will log server communication information to the browser console.
129-
- If hardware buttons do not trigger, GPIO interrupts might be disabled. Check file `/boot/config.txt` and remove / disable the following overlay `dtoverlay=gpio-no-irq` to enable interrupts for GPIOs.
128+
- In "Dev" mode the remote buzzer server logs are written to the "tmp" directory of the photobooth installation (i.e. `data/tmp/remotebuzzer_server.log`). Clients will log server communication information to the browser console. Activate "Dev" mode and check the logs for any error messages.
129+
- If hardware buttons do not trigger
130+
- GPIO interrupts might be disabled. Check file `/boot/config.txt` and remove / disable the following overlay `dtoverlay=gpio-no-irq` to enable interrupts for GPIOs.
131+
- GPIOs may not be configured as PULLUP. The configuration for this is done in fie `/boot/config.txt` by adding the GPIO numbers in use as follows - you **must reboot** the Raspberry Pi in order to activate changes in this setting.
132+
133+
```
134+
gpio=16,20,21=pu
135+
```
136+
137+
- For the Shutdown button to work, `www-data` needs to have the necessary sudo permissions. This is done by the `install-raspian.sh` script or can be manually added as
138+
139+
```
140+
cat >> /etc/sudoers.d/020_www-data-shutdown << EOF
141+
www-data ALL=NOPASSWD: /sbin/shutdown
142+
EOF
143+
```
130144

131145
As of Photobooth v3, hardware button support is fully integrated into Photobooth. Therefore the `button.py` script has been removed from the distribution. In case you are, for continued use of that script, for backward compatiblity please do not activate the Hardware Button feature in the admin GUI.
132146

@@ -173,13 +187,16 @@ After any button is triggered, all hardware button remain disabled until the act
173187
In rotary mode a rotary encoder (i.e. [KY-040](https://sensorkit.en.joy-it.net/index.php?title=KY-040_Rotary_encoder)) is connected to the GPIOs. Turning the rotary left / right will navigate through the currently visible set of buttons on the screen. Button press on the rotary will activate the currently highlighted button in Photobooth
174188

175189
The wiring layout is
190+
176191
```
177-
Raspberry Rotary Encoder
178-
GPIO 24 --- DT
179-
GPIO 20 --- CLK
180-
GPIO 16 --- SW
181-
3V3 --- +
182-
GND --- GND
192+
Button Rotary Encoder
193+
Mode Raspberry Mode
194+
195+
Picture --- GPIO 21 --- DT
196+
Collage --- GPIO 20 --- CLK
197+
Shutdown --- GPIO 16 --- SW
198+
3V3 --- +
199+
GND --- GND
183200
```
184201

185202
Known limitations:

src/js/remotebuzzer_server.js

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -151,19 +151,26 @@ log('socket.io server started');
151151

152152
/* SANITY CHECKS */
153153
function gpioSanity(gpioconfig) {
154-
return !(isNaN(gpioconfig) || gpioconfig < 0 || gpioconfig > 21);
155-
}
154+
if (isNaN(gpioconfig)) {
155+
throw new Error(gpioconfig + ' is not a valid number');
156+
}
156157

157-
if (!gpioSanity(config.remotebuzzer.picturegpio)) {
158-
log('GPIO configuration for Picture Button is invalid: ', config.remotebuzzer.picturegpio);
159-
}
160-
if (!gpioSanity(config.remotebuzzer.collagegpio)) {
161-
log('GPIO configuration for Collage Button is invalid: ', config.remotebuzzer.collagegpio);
162-
}
163-
if (!gpioSanity(config.remotebuzzer.shutdowngpio)) {
164-
log('GPIO configuration for Shutdown Button is invalid: ', config.remotebuzzer.shutdowngpio);
158+
if (gpioconfig < 1 || gpioconfig > 26) {
159+
throw new Error('GPIO' + gpioconfig + ' number is out of range (1-26)');
160+
}
161+
162+
cmd = 'sed -n "s/^gpio=\\(.*\\)=pu/\\1/p" /boot/config.txt';
163+
stdout = execSync(cmd).toString();
164+
165+
if (!stdout.split(',').find((el) => el == gpioconfig)) {
166+
throw new Error('GPIO' + gpioconfig + ' is not configured as PULLUP in /boot/config.txt - see FAQ for details');
167+
}
165168
}
166169

170+
gpioSanity(config.remotebuzzer.picturegpio);
171+
gpioSanity(config.remotebuzzer.collagegpio);
172+
gpioSanity(config.remotebuzzer.shutdowngpio);
173+
167174
/* BUTTON SEMAPHORE HELPER FUNCTION */
168175
function buttonActiveCheck(gpio, value) {
169176
/* init */
@@ -173,7 +180,6 @@ function buttonActiveCheck(gpio, value) {
173180

174181
/* clean state - no button pressed - activate lock */
175182
if (buttonActiveCheck.buttonIsPressed == 0 && !value) {
176-
// log('buttonActiveCheck: LOCK gpio ', gpio, ', value ', value);
177183
buttonActiveCheck.buttonIsPressed = gpio;
178184
buttonTimer(Date.now('millis'));
179185

@@ -182,7 +188,6 @@ function buttonActiveCheck(gpio, value) {
182188

183189
/* clean state - locked button release - release lock */
184190
if (buttonActiveCheck.buttonIsPressed == gpio && value) {
185-
// log('buttonActiveCheck: RELEASE gpio ', gpio, ', value ', value);
186191
buttonActiveCheck.buttonIsPressed = 0;
187192
buttonTimer(Date.now('millis'));
188193

@@ -191,7 +196,6 @@ function buttonActiveCheck(gpio, value) {
191196

192197
/* forced reset */
193198
if (gpio == -1 && value == -1) {
194-
// log('buttonActiveCheck - forced state reset');
195199
buttonActiveCheck.buttonIsPressed = 0;
196200
buttonTimer(0);
197201

@@ -227,7 +231,6 @@ function buttonTimer(millis) {
227231
/* start timer */
228232
if (buttonTimer.millis === 0) {
229233
buttonTimer.millis = millis;
230-
// log('buttonTimer started - value saved: ', millis);
231234

232235
return true;
233236
}
@@ -244,7 +247,6 @@ function buttonTimer(millis) {
244247
if (millis - buttonTimer.millis > 0) {
245248
buttonTimer.duration = millis - buttonTimer.millis;
246249
buttonTimer.millis = 0;
247-
// log('buttonTimer ended - ', buttonTimer.duration, ' ms');
248250

249251
return buttonTimer.duration;
250252
}
@@ -257,7 +259,6 @@ function buttonTimer(millis) {
257259

258260
/* WATCH FUNCTION PICTURE BUTTON WITH LONGPRESS FOR COLLAGE*/
259261
const watchPictureGPIOwithCollage = function watchPictureGPIOwithCollage(err, gpioValue) {
260-
//log('FUNCTION: watchPictureGPIOwithCollage()');
261262
if (err) {
262263
throw err;
263264
}
@@ -293,7 +294,6 @@ const watchPictureGPIOwithCollage = function watchPictureGPIOwithCollage(err, gp
293294

294295
/* WATCH FUNCTION PICTURE BUTTON */
295296
const watchPictureGPIO = function watchPictureGPIO(err, gpioValue) {
296-
//log('FUNCTION: watchPictureGPIO()');
297297
if (err) {
298298
throw err;
299299
}
@@ -327,7 +327,6 @@ const watchPictureGPIO = function watchPictureGPIO(err, gpioValue) {
327327

328328
/* WATCH FUNCTION COLLAGE BUTTON */
329329
const watchCollageGPIO = function watchCollageGPIO(err, gpioValue) {
330-
//log('FUNCTION: watchCollageGPIO()');
331330
if (err) {
332331
throw err;
333332
}

0 commit comments

Comments
 (0)