2016-11-09 2 views
0

私は実際の生活の中でこのLuaスクリプトを撃退する物理的なボタンを持っています。しかし、ボタンを押し続けると、ボタンを離すまでスクリプトが何度も何度も送信されます。これを防ぐには何ができますか?このLuaスクリプトが何度も何度も送信されるのを防ぐには?

commandSent = 0 
enableDebug() 

while true do 

--if input turns on and command has not been sent, send command 
if io.input1 == 1 and commandSent == 0 then 
httpRequest("http://xxx.xxx.xx.xx/axis-cgi/virtualinput/activate.cgi?schemaversion=1&port=1",50) 
print("input turned on") 
sleep(50) 
httpRequest("http://xxx.xxx.xx.xx/axis-cgi/virtualinput/deactivate.cgi?schemaversion=1&port=1",50) 
commandSent = 1 
end 

--when input turns off, reset commandSent flag to 0 
if io.input1 == 0 then 
print("input turned off") 
commandSent = 0 
end 
end 
+0

ここではどのホスト環境で作業していますか?このスクリプトの読み込みと実行、および 'io.input1'の値の変更を容易にするものは何ですか? 'sleep'と' httpRequest'はどのように定義されていますか?合理的な答えを策定するためには、より多くの情報が必要です。 – Oka

+0

私はControlByWebからX600Mを使用しています。 Webインターフェースを通じてコン​​トロールを組み込んでいます。上記のスクリプトは、それらのプロパティにアクセスするだけです。 –

+0

私はあなたの立場にはないので、実装方法は不明ですが、基本的にデバウンスが必要です。彼らが押し下げられると、変数 "used"が真であるかどうかをチェックし、そうでなければtrueをセットしてコードを実行します。そうであれば、何もしないでください。ボタンから圧力を取り除いたときに使用するために設計された別の関数が用意されています。 – warspyking

答えて

1

固定しました。スクリプトに「ローカル」という単語を追加しました=)以下を参照してください:

local commandSent = 0 
enableDebug() 

while true do 

--if input turns on and command has not been sent, send command 
if io.input1 == 1 and commandSent == 0 then 
httpRequest("http://xxx.xxx.xx.xx/axis-cgi/virtualinput/activate.cgi?schemaversion=1&port=1",50) 
print("input turned on") 
sleep(50) 
httpRequest("http://xxx.xxx.xx.xx/axis-cgi/virtualinput/deactivate.cgi?schemaversion=1&port=1",50) 
commandSent = 1 
end 

--when input turns off, reset commandSent flag to 0 
if io.input1 == 0 then 
print("input turned off") 
commandSent = 0 
end 
end 
関連する問題