<meter id="pryje"><nav id="pryje"><delect id="pryje"></delect></nav></meter>
          <label id="pryje"></label>

          新聞中心

          EEPW首頁(yè) > 嵌入式系統(tǒng) > 設(shè)計(jì)應(yīng)用 > Linux 筆記本基于“敲打”的命令

          Linux 筆記本基于“敲打”的命令

          作者: 時(shí)間:2016-09-12 來(lái)源:網(wǎng)絡(luò) 收藏

          接下來(lái)是 knockListen 子程序前 行負(fù)責(zé)讀取當(dāng)前的加速器數(shù)據(jù)值并對(duì)基本的值讀取進(jìn)行調(diào)整如果加速器的數(shù)量在某一維度上大于更新上限值那么 checkKnock 變量就被設(shè)置為 為了調(diào)整這個(gè)程序使它只響應(yīng)我們需要的敲打事件或類似的加速值我們需要擴(kuò)大更新上限例如我們可以將 ThinkPad 放到自己的汽車(chē)中并讓它在檢測(cè)到硬加速(或減速)時(shí)更改 MP 播放列表

          如果敲打筆記本的力度足夠大并且大于了更新上限那么就會(huì)導(dǎo)致調(diào)用getEpochMicroSeconds 子程序然后 diffInterval 變量會(huì)在兩次敲打事件之間被賦值這個(gè)值將很多擊打力度大于更新上限的很多快速加速讀取壓縮到一個(gè)時(shí)間中如果沒(méi)有間隔上限檢查一次硬敲打就會(huì)被注冊(cè)成很多事件就仿佛是加速器連續(xù)一段時(shí)間產(chǎn)生大量事件一樣這種行為對(duì)于用戶的視力和觸覺(jué)來(lái)說(shuō)都是無(wú)法感知到的但對(duì)于 HDAPS 來(lái)說(shuō)顯然并非如此如果已經(jīng)達(dá)到了間隔上限那么敲打間隔會(huì)被記錄在 baseKnocks 數(shù)組中然后將兩次敲打之間的間隔重置

          仔細(xì)修改這些變量可以幫助對(duì)程序進(jìn)行優(yōu)化從而識(shí)別出您特有的敲打風(fēng)格縮小更新上限并擴(kuò)大周期上限可以檢測(cè)出更多間隔的輕微敲打機(jī)械敲打設(shè)備或特定的敲打方法可能會(huì)需要降低間隔上限從而識(shí)別出獨(dú)特的敲打事件

          清單 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)建敲打模式時(shí)該模式會(huì)被放入 ~/knockFile 文件中并使用下面的子程序進(jìn)行讀取

          清單 讀取敲打文件

          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

          當(dāng) knockListen 獲得敲打模式時(shí)它會(huì)將該模式與從 readKnockFile 中讀取的敲打模式進(jìn)行比較下面的 compareKnockSequences 子程序會(huì)對(duì)敲打之間的時(shí)間進(jìn)行簡(jiǎn)單的區(qū)別檢查注意敲打之間的差別并不是簡(jiǎn)單混合在一起的很多次敲打時(shí)的少量時(shí)間差別并不會(huì)累積成總體的匹配失效

          第一個(gè)要比較的是敲打的次數(shù)因?yàn)槲覀儧](méi)有必要將一個(gè)七次敲打的序列與一個(gè)兩次敲打的序列進(jìn)行比較如果敲打的次數(shù)與 ~/knockFile 中現(xiàn)有的敲打序列匹配每次敲打之間的差別也少于最大敲打偏差那么這次敲打就可以認(rèn)為是完全匹配的在允許敲打序列進(jìn)行不精確匹配時(shí)最大敲打偏差非常關(guān)鍵我們可以增大最大敲打偏差來(lái)使敲打節(jié)奏更加自由但是要注意這可能會(huì)導(dǎo)致敲打模式匹配不正確例如我們可以在所期望的時(shí)間之前或之后半秒鐘允許自己的敲打模式發(fā)生偏離但這仍然可以匹配這樣就可以有效地說(shuō)明刮臉和理發(fā) 可以與 Mary 姓 Little Lamb 匹配因此在修改這個(gè)參數(shù)時(shí)一定要小心

          如果完整的模式可以匹配就會(huì)運(yùn)行 ~/knockFile 中指定的如果啟用了冗余模式則會(huì)打印結(jié)果下一個(gè)步驟是如果沒(méi)有找到匹配項(xiàng)就退出這個(gè)子程序如果找到了匹配項(xiàng)就重置所記錄的敲打序列這個(gè)步驟會(huì)執(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



          關(guān)鍵詞: Linux 命令

          評(píng)論


          相關(guān)推薦

          技術(shù)專區(qū)

          關(guān)閉
          看屁屁www成人影院,亚洲人妻成人图片,亚洲精品成人午夜在线,日韩在线 欧美成人 (function(){ var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })();