问题描述
我有一个带有Raspbian Buster Lite的Raspberry Pi,我以自动登录的KIOSK模式启动。目的是在连接的7英寸触摸屏(带有Chromium)上显示单个网页。如果系统空闲,我的python脚本应检测到该页面并自动使屏幕变暗。当用户再次与屏幕交互时,它应点亮再次起来
这是我的脚本:
#!/usr/bin/env python3 import subprocess import time import sys from rpi_backlight import Backlight backlight = Backlight() # read arguments from the run command: # idle time before dim (in seconds) idleTimeBeforeDimMS = int( sys.argv[1] )*1000 # brightness when dimmed (between 0 and 100) brightnessDimmed = int( sys.argv[2] ) brightnessFull = 100 def get(cmd): # just a helper function return subprocess.check_output(cmd).decode("utf-8").strip() isIdle0 = False stateChanged = False timeIntervalToWatchChangesS = 100 / 1000 while True: time.sleep( timeIntervalToWatchChangesS ) currentIdleTimeMS = int( get("xprintidle") ) isIdle = currentIdleTimeMS > idleTimeBeforeDimMS stateChanged = isIdle0 != isIdle if isIdle and stateChanged: # idling backlight.brightness = brightnessDimmed elif not isIdle and stateChanged: # active backlight.brightness = brightnessFull # set current state as initial one for the next loop cycle isIdle0 = isIdle
我的脚本从SSH启动时可以按预期工作(可以通过在Windows 10计算机上从Putty连接到我的Pi进行测试):
pi@raspberrypi:~$ /usr/bin/python3 /home/pi/startup_scripts/dim_screen.py 10 25
不幸的是,当我尝试从systemd(或通过systemctl start dim_screen.service
)引导时将脚本作为服务运行时,情况并非如此。我无法正常工作。
这是我的dim_screen.service文件:
[Unit] Description=Ensures that the 7" raspberry pi screen automatically will dim to 10% brightness after 25 minutes of user not interacting with it After=multi-user.target [Service] ExecStart=/usr/bin/python3 /home/pi/startup_scripts/dim_screen.py 10 25 [Install] WantedBy=multi-user.target
如果我重新启动并运行sudo systemctl status dim_screen.service
,则会得到以下提示:
我认为最重要的调试信息是以下行:Command 'xprintidle' returned non-zero exit status 1.
我觉得这很奇怪吗?如果在终端中运行xprintidle
,会发生以下情况:
pi@raspberrypi:~$ xprintidle 11399922
换句话说,我收到xprintidle
的有效回复。我相信还有其他我不明白的地方吗?
将python脚本(dim_screen.py
)作为服务启动的正确方法是什么?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)