这些变量及其注释都非常简单。它们的用法和配置选项在本文后面部分会进行解释。下面是其余的一些全局变量及其描述。
清单 2. 敲打模式参数
my @baseKnocks = (); # contains knock intervals currently entered
my %knockHash = (); # contains knock patterns, associated commands
my $prevInterval = 0; # previous interval of time
my $knockCount = 0; # current number of knocks detected
my $restX = 0; # `resting' positiong of X axis accelerometer
my $restY = 0; # `resting' positiong of Y axis accelerometer
my $currX = 0; # current position of X axis accelerometer
my $currY = 0; # current position of Y axis accelerometer
my $lastX = 0; # most recent position of X axis accelerometer
my $lastY = 0; # most recent position of Y axis accelerometer
my $startTime = 0; # to manage timeout intervals
my $currTime = 0; # to manage timeout intervals
my $timeOut = 0; # perpetual loop variable
my $knockAge = 0; # count of knocks to cycle time interval
|
子程序
在我们的子程序清单中首先是一个简单的逻辑块,用来检查是否有加速器可读:
清单 3. 检查加速器的子程序
sub checkAccelerometer() {
my $ret;
$ret = readPosition ();
if( $ret ){
print "no accelerometer data available - tis bork ed\n";
exit(1);
}
}#checkAccelerometer
|
Jeff Molofee 编写的 hdaps-gl.c 代码为 knockAge.pl 中的所有代码提供了一个很好的起点。在下面的 readPosition
子程序中,我们可以看到他的注释。这个子程序将打开一个文件,从中读取当前的加速器数据,然后关闭文件,并返回不包含 “,
(逗号)” 字符的数据。
清单 4. readPosition subroutine
## comments from Jeff Molofee in hdaps-gl.c
#* read_position - read the (x,y) 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( <FH> ){
s/\(//g;
s/\)//g;
($posX, $posY) = split ",";
}# while read
close(FH);
return( $posX, $posY );
}#readPosition
|
getEpochSeconds
和 getEpochMicroSeconds
提供了有关敲打模式状态的详细而精确的信息。
本新闻共
6页,当前在第
3页
1 2 3 4 5 6