【问题标题】:BeagleBone boot to Qt app with touch screenBeagleBone 通过触摸屏启动到 Qt 应用程序
【发布时间】:2014-09-18 14:27:30
【问题描述】:

和其他许多人一样,我希望有一个在 BeagleBone Black 启动时直接运行的 Qt 应用程序。使用来自其他主题的答案,例如: Beaglebone Boot to Qt App ; Start QT Application on bootup on an Embedded Linux Device (Beaglebone Black)

我有一个带有 Angstrom 的 BeagleBone Black revC 2012-09-12。

我通过以下服务设置让我的应用程序在启动时启动:

"autoShow.service"
[Unit]
Description=Autorun Qt app
ConditionFileIsExecutable=/home/root/ShowcaseNice

[Service]
Type=simple
TimeoutStartSec=120
WorkingDirectory=/home/root
ExecStart=/bin/sh -c 'source /etc/profile ; /home/root/ShowcaseNice -qws'
Restart=always

[Install]
WantedBy=multi-user.target

但我的应用程序通过触摸屏 (4DCAPE-43T) 使用触摸界面,它根本不起作用。当 systemd 运行我的应用程序时,似乎没有加载 tslib 库。我推断这是因为当我将此行添加到服务 [Unit] 时:

ConditionPathExists=/dev/input/touchscreen0

然后服务不会加载应用程序并显示错误消息,因为路径不存在。

另外,如果我将类型从简单替换为空闲,那么它仅在 BeagleBone 处于空闲模式时加载应用程序,因此大多数时间在每次启动过程结束时,它有时会起作用。

所以我试图找到一种方法来确保在 tslib 完成加载后执行我的应用程序,但我找不到正在加载 tslib 的内容(不是服务?)。那么,如何确保文件“/dev/input/touchscreen0”在运行前已经存在?

谢谢!

PS:由于环境变量的定义,我的服务中提到了我的配置文件,这里是:

# /etc/profile: system-wide .profile file for the Bourne shell (sh(1))
# and Bourne compatible shells (bash(1), ksh(1), ash(1), ...).

PATH="/usr/local/bin:/usr/bin:/bin"
EDITOR="/bin/vi"            # needed for packages like cron
test -z "$TERM" && TERM="vt100" # Basic terminal capab. For screen etc.

if [ ! -e /etc/localtime ]; then
    TZ="UTC"        # Time Zone. Look at http://theory.uwinnipeg.ca/gnu/glibc/libc_303.html 
            # for an explanation of how to set this to your local timezone.
    export TZ
fi
if [ "$HOME" = "/home/root" ]; then
    PATH=$PATH:/usr/local/sbin:/usr/sbin:/sbin
fi
if [ "$PS1" ]; then
    # works for bash and ash (no other shells known to be in use here)
    PS1='\u@\h:\w\$ '
fi
if [ -d /etc/profile.d ]; then
    for i in /etc/profile.d/* ; do
      . $i
    done
    unset i
fi

PATH=$PATH:/opt/qt/lib
QWS_MOUSE_PROTO="LinuxInput:/dev/input/touchscreen0 MouseMan:/dev/input/mouse2"
SLOTS=/sys/devices/bone_capemgr.8/slots
PINS=/sys/kernel/debug/pinctrl/44e10800.pinmux/pins
export PATH PS1 OPIEDIR QPEDIR QTDIR EDITOR TERM QWS_MOUSE_PROTO SLOTS PINS
echo DM-GPIO-Test > $SLOTS
umask 022

编辑1: 服务文件修改为:

"autoShow.service"
[Unit]
Description=Autorun Qt app
ConditionFileIsExecutable=/home/root/ShowcaseNice
After=systemd-modules-load.service

[Service]
Type=oneshot
WorkingDirectory=/home/root
ExecStart=/bin/sh -c 'source /etc/profile ; /home/root/ShowcaseNice -qws'
Restart=always
RemainAfterExit=1;

[Install]
WantedBy=multi-user.target

在应用程序运行时检查状态后,我得到以下输出(触摸功能不工作):

root@beaglebone:~# systemctl status systemd-modules-load.service
systemd-modules-load.service - Load Kernel Modules
      Loaded: loaded (/lib/systemd/system/systemd-modules-load.service; static)
      Active: active (exited) since Sat 2000-01-01 01:16:39 CET; 29s ago
        Docs: man:systemd-modules-load.service(8)
              man:modules-load.d(5)
     Process: 89 ExecStart=/lib/systemd/systemd-modules-load (code=exited, status=0/SUCCESS)
      CGroup: name=systemd:/system/systemd-modules-load.service
Warning: Journal has been rotated since unit was started. Log output is incomplete or unavailable.

root@beaglebone:~# systemctl status autoShow.service
autoShow.service - Autorun Qt app
      Loaded: loaded (/lib/systemd/system/autoShow.service; enabled)
      Active: activating (start) since Sat 2000-01-01 01:16:39 CET; 32s ago
    Main PID: 140 (sh)
      CGroup: name=systemd:/system/autoShow.service
          |-140 /bin/sh -c source /etc/profile ; /home/root/ShowcaseNice -qws
          `-195 /home/root/ShowcaseNice -qws
Jan 01 01:16:39 beaglebone systemd[1]: Starting Autorun Qt app...
Jan 01 01:16:45 beaglebone sh[140]: Cannot open mouse input device '/dev/input/touchscreen0': No such file or directory

root@beaglebone:~# systemctl status rc-local.service
rc-local.service
      Loaded: error (Reason: No such file or directory)
      Active: inactive (dead)

编辑2: 在结合命题进行了几次测试后,我找到了一个似乎在大多数情况下都有效的中间解决方案。但有时触摸功能仍然不起作用。由于我在 systemd (see this post) 上遇到了其他问题,所以我把它放在一边。

这是我几乎可以工作的服务文件:

"autoShow.service"
[Unit]
Description=Autorun Qt app
ConditionFileIsExecutable=/home/root/ShowcaseNice

[Service]
After=getty@.service or getty.target
Requires=systemd-modules-load.service
WorkingDirectory=/home/root
ExecStart=/bin/sh -c 'source /etc/profile ; /home/root/ShowcaseNice -qws'
Restart=always
sysVStartPriority=99
Type=idle

[Install]
WantedBy=multi-user.target

【问题讨论】:

  • 你试过After=getty@.service还是getty.target
  • 是的,我之前已经试过了,我又试了一次(即使 Erik 给出了低优先级的技巧)但它不起作用。

标签: qt touch beagleboneblack angstrom-linux systemd


【解决方案1】:

实际上没有加载 tslib。那是一个用户土地库。如果 systemd 尝试启动程序时设备不存在,那很可能是因为尚未加载硬件的内核模块。

After=systemd-modules-load.service

将它添加到您的服务应该会使 systemd 在所有静态定义的内核模块都加载后启动您的程序。

如果这还不够晚,请考虑从 /etc/rc.local 启动程序或设置“After=rc-local.service”(执行 /etc/rc.local)。 /etc/rc.local 应该是 systemd 默认启动的最后一件事。

rc-local.service:

#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either version 2 of the License, or
#  (at your option) any later version.

[Unit]
Description=Local customization

[Service]
ExecStart=/etc/rc.local start
TimeoutSec=0
StandardOutput=tty
RemainAfterExit=yes
SysVStartPriority=99

rc.local 需要是可执行的:

#!/bin/sh
#
# This script will be executed *after* all the other init scripts.
# You can put your own initialization stuff in here if you don't
# want to do the full Sys V style init stuff.

我什至没有想到这一点,但是您可以将 SysVStartPriority=[1-99] 添加到您的服务中。这不是推荐的属性(systemd.service 建议在之后或之前),但它比在 systemd 中找出启动过程中的位置更容易。他们确实需要更好的工具来显示启动顺序。

【讨论】:

  • 谢谢!我尝试添加After=systemd-modules-load.service 行但没有完全成功,因为当我尝试将类型更改为空闲时,它有时但并非总是有效。我想尝试使用 rc-local.service 或 /etc/rc.local 但内核 3.8.13 上不存在服务或文件......你知道这个版本的等价物吗? (详见 EDIT1)
  • 查看我的编辑。我希望 rc.local 回来,因为它是我放置所有自定义项的地方,但您也可以使用它的 SysVStartPriority 技巧来推动您的服务稍后启动。
  • 我尝试了 SysVStartPriority 技巧,但仍然无法正常工作。只有 Type=idle 似乎有点作用。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-08-03
  • 1970-01-01
  • 1970-01-01
  • 2018-11-29
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多