Skip to content

Instantly share code, notes, and snippets.

@MobliMic
Created March 23, 2017 10:31
Show Gist options
  • Save MobliMic/c9759177493c3776e16d71657332df87 to your computer and use it in GitHub Desktop.
Save MobliMic/c9759177493c3776e16d71657332df87 to your computer and use it in GitHub Desktop.
led.js
// Importing packages
var fs = require('fs');
var util = require('util');
exec = require('child_process').exec;
// Set the Omega LED trigger to the specified mode
function setLed (triggerPath, triggerMode) {
fs.open(triggerPath, 'w', (err, fd) => {
fs.write(fd, triggerMode, () =>{
fs.close(fd);
});
});
}
var child = exec('uci get system.@led[0].sysfs',
function (error, stdout, stderr) {
// set the Omega LED to blink
var triggerPath = '/sys/class/leds/' + stdout.replace('\n','') + '/trigger'
setLed(triggerPath, 'timer');
// Print a greeting based on the time of day
currentTime = new Date(); // get the current time
if (currentTime.getHours() < 12) {
console.log('Good morning.');
}
else if (currentTime.getHours() < 18 && currentTime.getHours() >= 12) {
console.log('Good afternoon.');
}
else {
console.log('Good evening.');
}
// set the Omega LED to solid after 5 seconds
setTimeout(() => {
setLed(triggerPath, 'default-on');
}, 5000);
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment