首页 > 解决方案 > 我在 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-pi3kiosk

解决方案


我一直在研究很多选项,现在有了一个工作脚本。我确信这可以改进,它在 Raspberry Pi Zero W 上进行了测试,它处理我的键非常慢,而 Raspberry Pi Model 3B+ 处理它很好。我首先创建了自己的页面,该页面使用 Javascript 处理键输入。

对于您的问题:

  1. 安装 xdotools。
  2. 创建一个可执行的 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)
  1. 如果你想要 F5,你可以使用xdotool key F5, 在 python 中是subprocess.call(["/usr/bin/xdotool", "key", "F5"]). 我尝试删除打印线,但随后它停止工作。这可能是一个时间问题,所以你应该在交互之前测试添加睡眠。
  2. 更改 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

让我知道说明是否完整!


推荐阅读