免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1845 | 回复: 4
打印 上一主题 下一主题

如何监测电源键的状态 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2010-05-31 13:18 |只看该作者 |倒序浏览
电源键在linux中被模拟成一个设备,如果想知道电源键的状态需要读取设备文件的值,但总不能一直循环着读取吧,有没有什么好的办法。我们还有不少设备的值也是靠读取设备文件的值,现在流行的做法是什么,请大家指点一下。

论坛徽章:
0
2 [报告]
发表于 2010-05-31 14:12 |只看该作者
acpid

论坛徽章:
0
3 [报告]
发表于 2010-05-31 16:09 |只看该作者
那它的原理是什么,我不仅仅是管理电源按纽

论坛徽章:
0
4 [报告]
发表于 2010-06-01 05:10 |只看该作者
acpid  is designed to notify user-space programs of ACPI events.  acpid should be started during the system boot,
       and will run as a background process, by default.  It will open an events file (/proc/acpi/event by default)  and
       attempt to read whole lines.  When a line is received (an event), acpid will examine a list of rules, and execute
       the rules that match the event.

       Rules are defined by simple configuration files.  acpid will look in a configuration directory  (/etc/acpi/events
       by  default),  and  parse  all files that do not begin with a period (’.’).  Each file must define two things: an
       event and an action.  Any blank lines, or lines where the first character is a  pound  sign  (’#’)  are  ignored.
       Extraneous  lines  are  flagged  as  warnings, but are not fatal.  Each line has three tokens: the key, a literal
       equal sign, and the value.  The key can be up to 63 characters, and is case-insensitive (but whitespace matters).
       The value can be up to 511 characters, and is case and whitespace sensitive.

这些事件不一定是电源管理按钮,比如我的系统中在/etc/acpid/events下面就有:
[root@localhost ~]# ls /etc/acpi/events/
ac                     asus-media-prev   ibm-hibernatebtn           panasonic-hibernatebtn  sony-mute             tosh-media
asus-a6j-touchpad      asus-media-stop   ibm-lockbtn                panasonic-lockbtn       sony-sleep            tosh-mute
asus-internet          asus-touchpad     ibm-sleepbtn               panasonic-sleepbtn      sony-volume-down      tosh-next
asus-lock              asus-volume-down  ibm-videobtn               powerbtn                sony-volume-up        tosh-play
asus-mail              asus-volume-mute  ibm-wireless               sleepbtn                tosh-brightness-down  tosh-prev
asus-media-eject       asus-volume-up    lidbtn                     sony-brightness-down    tosh-brightness-up    tosh-sleep
asus-media-next        asus-wireless     panasonic-brightness-down  sony-brightness-up      tosh-hibernate        tosh-stop
asus-media-play-pause  battery           panasonic-brightness-up    sony-hibernate          tosh-lock             tosh-wireless
这么多按钮的事件处理。不过你应该是要kernel module的配合的

论坛徽章:
0
5 [报告]
发表于 2010-06-01 11:23 |只看该作者
看到DPM(动态电源管理)是IBM等专门为嵌入式linux开发的电源管理系统,但是并没有加入主线内核,而且现在支持的平台比较少,仅有i386、pxa27x和OMAP。据我所知,还有几个电源管理标准,比如APM,ACPI,由于APM需要BIOS支持,先不去看它
  问几个个问题:
1.是不是ACPI也可以用在嵌入式linux中
2.如果可以,哪个更适用于嵌入式linux呢
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP