Skip to content

Instantly share code, notes, and snippets.

@kogai
Created August 11, 2014 12:43
Show Gist options
  • Save kogai/4ab760b8f7fd2da66423 to your computer and use it in GitHub Desktop.
Save kogai/4ab760b8f7fd2da66423 to your computer and use it in GitHub Desktop.
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