raspberry-pi3 - 我在 Raspberry Pi 上使用 Dakboard 信息亭,有没有办法将 GPIO 按钮编码为“F5”键盘输入以进行刷新?
问题描述
我使用旧显示器、Raspberry Pi 和 Dakboard 制作了一个挂历,就像一个信息亭。有时我需要刷新网页并使用键盘F5按钮来执行此操作,但我想知道有没有办法使用 GPIO 中的F5按钮作为刷新网页的按钮?我使用此代码使其自动运行:
sudo nano /etc/xdg/lxsession/LXDE-pi/autostart
@xset s off
@xset -dpms
@xest s noblank
@chromium-browser --noerrdialogs --incognito --kiosk http://dakboard.com
解决方案
我一直在研究很多选项,现在有了一个工作脚本。我确信这可以改进,它在 Raspberry Pi Zero W 上进行了测试,它处理我的键非常慢,而 Raspberry Pi Model 3B+ 处理它很好。我首先创建了自己的页面,该页面使用 Javascript 处理键输入。
对于您的问题:
- 安装 xdotools。
- 创建一个可执行的 python3 脚本(当然还要安装 python3)。我的脚本处理来自端口 17、27 和 22 的三个按钮。
#!/bin/bash
import subprocess
import RPi.GPIO as GPIO
import time
GPIO.setmode(GPIO.BCM)
GPIO.setup(17, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(27, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
GPIO.setup(22, GPIO.IN, pull_up_down=GPIO.PUD_DOWN)
print("\n\nscript started\n")
while (True):
if GPIO.input(17) > 0:
print("rode knop ingedrukt")
subprocess.call(["/usr/bin/xdotool", "key", "Right"])
time.sleep(0.3)
if GPIO.input(27) > 0:
print("gele knop ingedrukt")
subprocess.call(["/usr/bin/xdotool", "key", "0xff0d"])
time.sleep(0.3)
if GPIO.input(22) > 0:
print("groene knop ingedrukt")
subprocess.call(["/usr/bin/xdotool", "key", "Left"])
time.sleep(0.3)
- 如果你想要 F5,你可以使用
xdotool key F5
, 在 python 中是subprocess.call(["/usr/bin/xdotool", "key", "F5"])
. 我尝试删除打印线,但随后它停止工作。这可能是一个时间问题,所以你应该在交互之前测试添加睡眠。 - 更改 xserver 的自动启动脚本。添加 python-script
sudo python3 GpioPython.py
,更改显示export DISPLAY=:0
,不要忘记&
chromium-browser 行后面的 & 符号!
xset s off
xset s noblank
xset -dpms
setxkbmap -option terminate:ctrl_alt_bksp
sed -i 's/"exited_cleanly":false/"exited_cleanly":true/' ~/.config/chromium/Default/Preferences
sed -i 's/"exit_type":"Crashed"/"exit_type":"Normal"/' ~/.config/chromium/Default/Preferences
export DISPLAY=:0
chromium-browser --disable-infobars --kiosk 'http:.......' &
sudo python3 GpioPython.py
让我知道说明是否完整!
推荐阅读
- oracle - 如何避免 OR 扩展?
- vue.js - 在 b-form 中使用 Vue Validate 滚动到第一个错误
- react-native - 初始化 react-native-twitter-signin 时出现异常
- r - ggplot2散点图添加自定义置信区间带线;类似于 abline() 方法
- python - 有一个特殊的网页找不到任何元素
- java - 尊重非@Primary @Bean 上的@Lazy 注释
- flutter - 如何在 dart/flutter 中监听流值
- react-native - 在 React Native 中使用离线存储图像的最佳方式
- xpath - Xpath 在每 li 之后插入 ","
- python - 如何在 django rest 框架中获得评分计数