Created
August 11, 2014 12:43
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
globalDefine = { | |
modeFlag: false, | |
irkit: "https://api.getirkit.com/1/messages", | |
clientkey: "", | |
deviceid: "" | |
} | |
remoteCommand = { | |
tv :'{"format":"raw","freq":38,"data":[]}', | |
air_off :'{"format":"raw","freq":38,"data":[]}', | |
air_on :'{"format":"raw","freq":38,"data":[]}', | |
catv :'{"format":"raw","freq":38,"data":[]}' | |
} | |
simply.on('singleClick', function(e) { | |
simply.title(e.button); | |
switch(e.button){ | |
case "up": | |
globalDefine.modeFlag = true; | |
simply.body("all controll is on."); | |
break; | |
case "down": | |
globalDefine.modeFlag = false; | |
simply.body("all controll is off."); | |
break; | |
} | |
}); | |
simply.on('accelTap', function(e) { | |
if(globalDefine.modeFlag){ | |
var commandList = [remoteCommand.tv,remoteCommand.air_on,remoteCommand.catv] | |
}else{ | |
var commandList = [remoteCommand.tv,remoteCommand.air_off,remoteCommand.catv] | |
} | |
for (var i = 0; i < commandList.length; i++) { | |
sendHttpRequest(commandList[i],i,commandList) | |
}; | |
}); | |
function sendHttpRequest(message,num,commandList){ | |
(function(thisNum,thisCount){ | |
setTimeout(function(){ | |
ajax({ | |
url: globalDefine.irkit, | |
method: 'post', | |
data: { | |
clientkey: globalDefine.clientkey, | |
deviceid: globalDefine.deviceid, | |
message: message | |
} | |
},function(){ | |
simply.body(num + " is excuted!") | |
if(commandList.length==(num+1)) simply.vibe("dobble"); | |
}); | |
},500*num); | |
}(num,commandList)); | |
} | |
simply.setText({ | |
title: 'IRKit is running!', | |
body: 'all controll is off.' | |
}, true); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment