Yoga 900 有一个加速度计,可以实现自动旋转行为。
安装时 https://github.com/hadess/iio-sensor-proxy(Linux*、LightDM)可以运行监视传感器。
➜ ~ monitor-sensor
Waiting for iio-sensor-proxy to appear
+++ iio-sensor-proxy appeared
=== Has accelerometer (orientation: undefined)
=== Has ambient light sensor (value: 0.000000, unit: lux)
Accelerometer orientation changed: normal
Light changed: 49.999999 (lux)
Light changed: 79.999998 (lux)
Accelerometer orientation changed: left-up
Accelerometer orientation changed: normal
Accelerometer orientation changed: left-up
Accelerometer orientation changed: bottom-up
数据在iio-sensor-proxy
dbus 上可用。其形式为:
signal time=1479631365.562013 sender=:1.15 -> destination=(null destination) serial=449861 path=/com/ubuntu/Upstart; interface=com.ubuntu.Upstart0_6; member=EventEmitted
string "dbus"
array [
string "SIGNAL=PropertiesChanged"
string "BUS=system"
string "INTERFACE=org.freedesktop.DBus.Properties"
string "OBJPATH=/net/hadess/SensorProxy"
string "SENDER=:1.4"
string "ARG0=net.hadess.SensorProxy"
]
是否可以运行一个脚本只醒来在某些 dbus 事件上?我最好在已经存在的守护进程中重新使用事件循环,而不是构建自己的 Python 脚本或 C 程序。添加文件之类的操作
/etc/dbus.d/handlers/net/hadess/SensorProxy
真的很酷。如果我不运行,
monitor-sensor
即使iio-sensor-proxy
实际运行,dbus 上似乎也不会出现消息。这些消息是否仅在有人监听时才发送?
[*] Linux V 4.8.1-040801-generic #201610071031 SMP 2016 年 10 月 7 日星期五 14:34:10 UTC x86_64 x86_64 x86_64 GNU/Linux
PS:使用时根据powertop monitor-sensor
:
14.7 mW 1.5 ms/s 8.8 Process dbus-monitor
答案应该描述在 Linux 上处理此问题的规范方法,并且从电池使用角度来看是最友好的解决方案。
答案1
我不是 Linux 专家,但它看起来dbus-monitor
确实是可用工具。
对帖子的回复 如何创建一个守护进程来监听 dbus 并在收到消息时触发脚本说:
基于 https://askubuntu.com/questions/150790/how-do-i-run-a-script-on-a-dbus-signal
#!/bin/bash interface=org.gnome.ScreenSaver member=ActiveChanged dbus-monitor --profile "interface='$interface',member='$member'" | while read -r line; do echo $line | grep ActiveChanged && your_script_goes_here done
只需将其插入/etc/init.d/监控-for-解锁,使其可执行,然后在 rc2.d 中创建软链接
chmod +x /etc/init.d/monitor-for-unlock cd /etc/rc2.d ln -s /etc/init.d/monitor-for-unlock .
文章监控 D-Bus添加:
dbus-monitor 最强大的功能可能在于您不仅限于一次使用一个监视表达式。以下示例同时监视所有 3 个 Tomboy 信号,并使用 awk 解析 dbus-monitor 的输出并显示一条有意义的消息。
#!/bin/bash OJECT="'org.gnome.Tomboy'" IFACE="'org.gnome.Tomboy.RemoteControl'" DPATH="'/org/gnome/Tomboy/RemoteControl'" WATCH1="type='signal', sender=${OJECT}, interface=${IFACE}, path=${DPATH}, member='NoteAdded'" WATCH2="type='signal', sender=${OJECT}, interface=${IFACE}, path=${DPATH}, member='NoteSaved'" WATCH3="type='signal', sender=${OJECT}, interface=${IFACE}, path=${DPATH}, member='NoteDeleted'" dbus-monitor "${WATCH1}" "${WATCH2}" "${WATCH3}" | \ awk ' /member=NoteAdded/ { getline; print "Created note " substr($2,7) } /member=NoteSaved/ { getline; print "Added note " substr($2,7) } /member=NoteDeleted/ { getline; print "Deleted note " substr($2,7) } '
这是我单击 Tomboy 图标创建新注释、等待自动保存然后选择删除选项删除注释时生成的输出。
$ ./test Created note //tomboy/3da026dc-f6ee-4637-8a94-bec6e2844824" Added note //tomboy/3da026dc-f6ee-4637-8a94-bec6e2844824" Deleted note //tomboy/3da026dc-f6ee-4637-8a94-bec6e2844824"