Created
May 3, 2013 21:34
-
-
Save JonathanMH/5514395 to your computer and use it in GitHub Desktop.
make node.js blink your keyboard backlight in morse code (tested with speedlink illuminator)
This file contains hidden or 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
var morse = require('morse'); | |
var childProcess = require('child_process'); | |
var async = require('async'); | |
var encoded = morse.encode('SOS'); | |
function onoff (duration, callback) { | |
childProcess.exec('xset led 3',function (error, stdout, stderr){ | |
}); | |
setTimeout(function(){ | |
childProcess.exec('xset -led 3',function (error, stdout, stderr){ | |
callback(); | |
}); | |
}, duration); | |
} | |
encoded = encoded.replace(/\s+/g, ''); | |
arr = encoded.split(''); | |
function ownlog(item, cb){ | |
if(item == '-'){ | |
duration = 2000; | |
} | |
else if(item == '.'){ | |
duration = 500; | |
} | |
else { | |
duration = 0; | |
cb(); | |
} | |
onoff(duration,function(){ | |
console.log(item + ' ' + duration); | |
}); | |
setTimeout(function(){ | |
cb(); | |
},300 + duration); | |
} | |
async.eachSeries(arr, ownlog, function(err){ | |
// if any of the saves produced an error, err would equal that error | |
if (err) throw err; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment