Linux 筆記本基于“敲打”的命令
接下來是 knockListen 子程序前 行負責讀取當前的加速器數(shù)據(jù)值并對基本的值讀取進行調(diào)整如果加速器的數(shù)量在某一維度上大于更新上限值那么 checkKnock 變量就被設置為 為了調(diào)整這個程序使它只響應我們需要的敲打事件或類似的加速值我們需要擴大更新上限例如我們可以將 ThinkPad 放到自己的汽車中并讓它在檢測到硬加速(或減速)時更改 MP 播放列表
如果敲打筆記本的力度足夠大并且大于了更新上限那么就會導致調(diào)用getEpochMicroSeconds 子程序然后 diffInterval 變量會在兩次敲打事件之間被賦值這個值將很多擊打力度大于更新上限的很多快速加速讀取壓縮到一個時間中如果沒有間隔上限檢查一次硬敲打就會被注冊成很多事件就仿佛是加速器連續(xù)一段時間產(chǎn)生大量事件一樣這種行為對于用戶的視力和觸覺來說都是無法感知到的但對于 HDAPS 來說顯然并非如此如果已經(jīng)達到了間隔上限那么敲打間隔會被記錄在 baseKnocks 數(shù)組中然后將兩次敲打之間的間隔重置
仔細修改這些變量可以幫助對程序進行優(yōu)化從而識別出您特有的敲打風格縮小更新上限并擴大周期上限可以檢測出更多間隔的輕微敲打機械敲打設備或特定的敲打方法可能會需要降低間隔上限從而識別出獨特的敲打事件
清單 knockListen 子程序
sub knockListen() { my $checkKnock = ; ($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: $diffIntervaln; } push @baseKnocks $diffInterval; $knockCount++; }# if the difference interval is greater than the threshold $prevInterval = $currVal; }#if checkknock passed }#knockListen
在創(chuàng)建敲打模式時該模式會被放入 ~/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 子程序會對敲打之間的時間進行簡單的區(qū)別檢查注意敲打之間的差別并不是簡單混合在一起的很多次敲打時的少量時間差別并不會累積成總體的匹配失效
第一個要比較的是敲打的次數(shù)因為我們沒有必要將一個七次敲打的序列與一個兩次敲打的序列進行比較如果敲打的次數(shù)與 ~/knockFile 中現(xiàn)有的敲打序列匹配每次敲打之間的差別也少于最大敲打偏差那么這次敲打就可以認為是完全匹配的在允許敲打序列進行不精確匹配時最大敲打偏差非常關(guān)鍵我們可以增大最大敲打偏差來使敲打節(jié)奏更加自由但是要注意這可能會導致敲打模式匹配不正確例如我們可以在所期望的時間之前或之后半秒鐘允許自己的敲打模式發(fā)生偏離但這仍然可以匹配這樣就可以有效地說明刮臉和理發(fā) 可以與 Mary 姓 Little Lamb 匹配因此在修改這個參數(shù)時一定要小心
如果完整的模式可以匹配就會運行 ~/knockFile 中指定的命令如果啟用了冗余模式則會打印結(jié)果下一個步驟是如果沒有找到匹配項就退出這個子程序如果找到了匹配項就重置所記錄的敲打序列這個步驟會執(zhí)行 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 $knockDiffn; # 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 @confKnocks ){ my $cmd = system( $knockHash{@confKnocks }{ cmd } ); if( $option ){ print $cmdn } last; # otherwise make the count of matches zero in order to not reset }else{ $countMatch = ; } }#for keys # if the match count is zero exit and dont reset variables so a longer # knock sequence can be entered and checked if( $countMatch == ){ return() } # if a match occurred reset the variables so it wont match another pattern $knockCount = ; @baseKnocks = (); }#compareKnockSequences
評論