Linux 笔记本基于“敲打”的命令
们的用法和配置选项在本文后面部分会进行解释下面是其余的一些全局变量及其描述
清单 敲打模式参数
my @baseKnocks = (); # contains knock intervals currently entered my %knockHash = (); # contains knock patterns associated commands my $prevInterval = ; # previous interval of time my $knockCount = ; # current number of knocks detected my $restX = ; # `resting positiong of X axis accelerometer my $restY = ; # `resting positiong of Y axis accelerometer my $currX = ; # current position of X axis accelerometer my $currY = ; # current position of Y axis accelerometer my $lastX = ; # most recent position of X axis accelerometer my $lastY = ; # most recent position of Y axis accelerometer my $startTime = ; # to manage timeout intervals my $currTime = ; # to manage timeout intervals my $timeOut = ; # perpetual loop variable my $knockAge = ; # count of knocks to cycle time interval
子程序
在我们的子程序清单中首先是一个简单的逻辑块用来检查是否有加速器可读
清单 检查加速器的子程序
sub checkAccelerometer() { my $ret; $ret = readPosition (); if( $ret ){ print no accelerometer data available tis bork ed\n; exit(); } }#checkAccelerometer
Jeff Molofee 编写的 hdapsglc 代码为 knockAgepl 中的所有代码提供了一个很好的起点在下面的 readPosition 子程序中我们可以看到他的注释这个子程序将打开一个文件从中读取当前的加速器数据然后关闭文件并返回不包含 (逗号) 字符的数据
清单 readPosition subroutine
## comments from Jeff Molofee in hdapsglc #* read_position read the (xy) position pair from hdaps #* #* We open and close the file on every invocation which is lame but due to #* several features of sysfs files: #* #* (a) Sysfs files are seekable #* (b) Seeking to zero and then rereading does not seem to work ## sub readPosition() { my ($posX $posY) = ; my $fd = open(FH $hdapsFN); while( ){ s/\(//g; s/\)//g; ($posX $posY) = split ; }# while read close(FH); return( $posX $posY ); }#readPosition
getEpochSeconds 和 getEpochMicroSeconds 提供了有关敲打模式状态的详细而精确的信息
清单 时间分隔器
sub getEpochMicroSeconds { my $TIMEVAL_T = LL; # LL for microseconds my $timeVal = pack($TIMEVAL_T ()); syscall(SYS_gettimeofday $timeVal ) != or die micro seconds: $!; my @vals = unpack( $TIMEVAL_T $timeVal ); $timeVal = $vals[] $vals[]; $timeVal = substr( $timeVal ); my $padLen = length($timeVal); $timeVal = $timeVal x $padLen; return($timeVal); }#getEpochMicroSeconds sub getEpochSeconds { my $TIMEVAL_T = LL; # LL for microseconds my $start = pack($TIMEVAL_T ()); syscall(SYS_gettimeofday$start ) != or die seconds: $!; return( (unpack($TIMEVAL_T $start))[] ); }#getEpochSeconds
接下来是 knockListen 子程序前 行负责读取当前的加速器数据值并对基本的值读取进行调整如果加速器的数量在某一维度上大于更新上限值那么 checkKnock 变量就被设置为 为了调整这个程序使它只响应我们需要的敲打事件或类似的加速值我们需要扩大更新上限例如我们可以将 ThinkPad 放到自己的汽车中并让它在检测到硬加速(或减速)时更改 MP 播放列表
如果敲打笔记本的力度足够大并且大于了更新上限那么就会导致调用getEpochMicroSeconds 子程序然后 diffInterval 变量会在两次敲打事件之间被赋值这个值将很多击打力度大于更新上限的很多快速加速读取压缩到一个时间中如果没有间隔上限检查一次硬敲打就会被注册成很多事件就仿佛是加速器连续一段时间产生大量事件一样这种行为对于用户的视力和触觉来说都是无法感知到的但对于 HDAPS 来说显然并非如此如果已经达到了间隔上限那么敲打间隔会被记录在 baseKnocks 数组中然后将两次敲打之间的间隔重置
仔细修改这些变量可以帮助对程序进行优化从而识别出您特有的敲打风格缩小更新上限并扩大周期上限可以检测出更多间隔的轻微敲打机械敲打设备或特定的敲打方法可能会需要降低间隔上限从而识别出独特的敲打事件
清单 knockListen 子程序
sub knockListen() { my $c
- REDIce-Linux--灵活的实时Linux内核(11-12)
- linux文件系统基础(02-09)
- Linux标准趋向统一(11-12)
- linux基础技术(02-09)
- LINUX的目录树(02-09)
- 在Windows下启动Linux(02-09)