微波EDA网,见证研发工程师的成长!
首页 > 硬件设计 > 嵌入式设计 > Linux 笔记本基于“敲打”的命令

Linux 笔记本基于“敲打”的命令

时间:09-12 来源:互联网 点击:

heckKnock = ; ($currX $currY) = readPosition(); $currX = $restX; # adjust for rest data state $currY = $restY; # adjust for rest data state # require a high threshold of acceleration to ignore nonevents like # bashing the enter key or hitting the side with the mouse if( abs ($currX) > $UPDATE_THRESHOLD) { $checkKnock = ; } if( abs ($currY) > $UPDATE_THRESHOLD) { $checkKnock = ; } if( $checkKnock == ){ my $currVal = getEpochMicroSeconds(); my $diffInterval = abs($prevInterval $currVal); # hard knock events can create continuous acceleration across a large time # threshold requiring an elapsed time between knock events effectively # reduces what appear as multiple events according to sleep_interval and # update_threshold into a singular event if( $diffInterval > $INTERVAL_THRESHOLD ){ if( $knockCount == ){ $diffInterval = } if( $option ){ print Knock: $knockCount ## last: [$currVal] curr: [$prevInterval] ; print difference is: $diffInterval\n; } push @baseKnocks $diffInterval; $knockCount++; }# if the difference interval is greater than the threshold $prevInterval = $currVal; }#if checkknock passed }#knockListen

在创建敲打模式时该模式会被放入 ~/knockFile 文件中并使用下面的子程序进行读取

清单 读取敲打文件

sub readKnockFile { open(KNCKFILE$ENV{HOME}/knockFile) or die no knock file: $!; while(){ if( !/^#/ ){ my @arrLine = split _#_; $knockHash{ $arrLine[] }{ cmd } = $arrLine[]; $knockHash{ $arrLine[] }{ comment } = $arrLine[]; }#if not a comment line }#for each line in file close(KNCKFILE); }#readKnockFile

当 knockListen 获得敲打模式时它会将该模式与从 readKnockFile 中读取的敲打模式进行比较下面的 compareKnockSequences 子程序会对敲打之间的时间进行简单的区别检查注意敲打之间的差别并不是简单混合在一起的很多次敲打时的少量时间差别并不会累积成总体的匹配失效

第一个要比较的是敲打的次数因为我们没有必要将一个七次敲打的序列与一个两次敲打的序列进行比较如果敲打的次数与 ~/knockFile 中现有的敲打序列匹配每次敲打之间的差别也少于最大敲打偏差那么这次敲打就可以认为是完全匹配的在允许敲打序列进行不精确匹配时最大敲打偏差非常关键我们可以增大最大敲打偏差来使敲打节奏更加自由但是要注意这可能会导致敲打模式匹配不正确例如我们可以在所期望的时间之前或之后半秒钟允许自己的敲打模式发生偏离但这仍然可以匹配这样就可以有效地说明刮脸和理发 可以与 Mary 姓 Little Lamb 匹配因此在修改这个参数时一定要小心

如果完整的模式可以匹配就会运行 ~/knockFile 中指定的命令如果启用了冗余模式则会打印结果下一个步骤是如果没有找到匹配项就退出这个子程序如果找到了匹配项就重置所记录的敲打序列这个步骤会执行 compareKnockSequences 子程序

清单 比较敲打序列

sub compareKnockSequences { my $countMatch = ; # record how many knocks matched # for each knock sequence in the config file for( keys %knockHash ){ # get the timings between knocks my @confKnocks = split; # if the count of knocks match if( $knockCount eq @confKnocks ){ my $knockDiff = ; my $counter = ; for( $counter=; $counter$knockCount; $counter++ ){ $knockDiff = abs($confKnocks[$counter] $baseKnocks[$counter]); my $knkStr = k $counter b $baseKnocks[$counter] c $confKnocks[$counter] d $knockDiff\n; # if its an exact match increment the matching counter if( $knockDiff $MAX_KNOCK_DEV ){ if( $option ){ print MATCH $knkStr } $countMatch++; # if the knocks dont match move on to the next pattern in the list }else{ if( $option ){ print DISSONANCE $knkStr } last; }# deviation check }#for each knock }#if number of knocks matches # if the count of knocks is an exact match run the command if( $countMatch eq @confKno

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top