I have made a plugin to send the WD Live to sleep after 15, 30, 45, ... 120 minutes. Just press the search button to select the time. You can increase the value at any time by pressing the search button again.
Only one problem remains: You only see the time in movie, music or picture mode. The onPageCreated method is not called in any other mode. Maybe somebody can help with that?
major update 3:
- * new feature: now you can select sleep on idle and your devide will fall asleep after 10 mintues of no activity. So after playing your music or movie the device will go to standby mode automatically.
* some code cleanup & optimization
Update 2:
- * Plugin is now futur proof and doesn't rely on Content lib anymore
Update:
- * added option to turn sleep timer off
* found a solution for the display problem if more than on plugin adds content to the same view. more info can be found here (http://forum.wdlxtv.com/viewtopic.php?f=48&t=619#p4159)
Setup:
1) enable EIRI by uncommenting the following line in your /boot/S00custon_options
- Code: Select all
config_tool -c EIRI=ON
2) add this plugin and reboot your device
SleepTimer.plugin.js
- Code: Select all
traceln("SleepTimerPlugin: Start loading VolumeControl plugin");
function SleepTimerPlugin(path) {
this.debugLogEnable = true
this.rootPath = path;
traceln("SleepTimerPlugin: base path: " + this.rootPath);
this.timerRun = false
this.cmd = '';
this.showOSD = 4
this.sleepTime = 0
this.sleepTimeMax = 120
this.sleepTimeInterval = 15
this.keyCode = 53 //search button
this.counter = 0
}
SleepTimerPlugin.prototype = new Plugin();
SleepTimerPlugin.prototype.constructor = SleepTimerPlugin;
SleepTimerPlugin.prototype.debugLog = function (text) {
if (this.debugLogEnable == true) {
if (text && text != "") {
traceln("SleepTimerPlugin: " + text)
}
}
}
SleepTimerPlugin.prototype.onPageCreated = function(page) {
this.debugLog("[ onPageCreated ]")
var extraContent = <wrapper><text text="@@vc_sleeptime" x="40" y="30" w="300" h="30" fontsize="26" textcolor="0xffffff" align="left"/></wrapper>;
addExtraContent(page, extraContent);
}
SleepTimerPlugin.prototype.onPageTimer = function(page) {
if (this.timerRun == true) {
if (this.counter < this.showOSD) {
this.counter++
} else {
this.counter = 0;
this.timerRun = false;
this.debugLog("[ onPageTimer ] clearing OSD display")
this.debugLog("[ onPageTimer ] ### RUN COMMAND ###");
this.debugLog(" cmd: " + this.cmd)
system(this.cmd)
Page.Top.setParam("vc_sleeptime", "")
Page.redraw(true)
}
}
}
SleepTimerPlugin.prototype.setTime = function(time) {
this.debugLog("[ setTime ] time: " + time)
var timestring = "";
if (time > (this.sleepTimeMax + this.sleepTimeInterval)) //turn it off
{
this.debugLog("[ setTime ] ---> : turn it off");
this.sleepTime = 0;
this.cmd = "echo 'if [ -f $0.pid ]; then p=$(cat $0.pid); rm $0.pid; kill -9 $p; fi && killall -9 sleep &' > /tmp/sleeptimer.sh && sh /tmp/sleeptimer.sh &"
timestring = "Sleep: off";
}
else if (time == (this.sleepTimeMax + this.sleepTimeInterval)) //idle mode
{
//this.sleepTime = 0;
this.debugLog("[ setTime ] ---> : idle mode");
this.cmd = "echo \"if [ -f \\$0.pid ]; then p=\\$(cat \\$0.pid); rm \\$0.pid; kill -9 \\$p; fi; echo \\$\\$ > \\$0.pid; killall -9 sleep; sleeptime=60; idle=0; loop=0; while [ \\$loop -le 10 ]; do t=\\$(top -b -n 1 > /tmp/topdump.txt; cat /tmp/topdump.txt | grep idle | perl -wlne 'print \\$1 if /([0-9]+)\\.[0-9]% idle/'); if [ \\$t == 0 ]; then sleep \\$sleeptime; continue; fi; if [ \\$t -le 75 ]; then loop=0; idle=\\$t; else loop=\\`expr \\$loop + 1\\`; idle=\\`expr \\$idle + \\$t\\`; fi; echo \\$loop; echo \\$idle; sleep \\$sleeptime; done; rm \\$0.pid; \\$(/usr/bin/irsend POWER)\" > /tmp/sleeptimer.sh && sh /tmp/sleeptimer.sh &";
timestring = "Sleep: on idle";
}
else
{
var sleepTime = time * 60; //time in seconds
this.cmd = "echo 'if [ -f $0.pid ]; then p=$(cat $0.pid); rm $0.pid; kill -9 $p; fi && echo $$ > $0.pid && killall -9 sleep && sleep "+sleepTime+" && rm $0.pid && /usr/bin/irsend POWER' > /tmp/sleeptimer.sh && sh /tmp/sleeptimer.sh &"
timestring = "Sleep: "+time;
}
Page.Top.setParam("vc_sleeptime", timestring)
Page.redraw(true)
this.counter = 0
this.timerRun = true
}
SleepTimerPlugin.prototype.onPageKey = function(page, key)
{
this.debugLog("[ onPageKey ]")
this.debugLog(" page: " + page.markupFileName + " key: " + key)
if (key == this.keyCode)
{
this.sleepTime += this.sleepTimeInterval;
this.debugLog(" setting sleep time: " + this.sleepTime)
this.setTime(this.sleepTime)
return true
}
}
SleepTimerPlugin.instance = new SleepTimerPlugin(scriptPath);
Plugin.registerPlugin(SleepTimerPlugin.instance);
function addExtraContent(page, add) {
if (!page || !add) { return }
if(!page.extraContent) {
page.extraContent = ""
}
var oldContent = page.extraContent;
var addContent = add;
var newContent = <wrapper></wrapper>;
if (oldContent) {
if (oldContent.length() > 0) {
if (oldContent.wrapper.length() > 0) {
newContent.wrapper += oldContent.wrapper
} else {
newContent.wrapper += oldContent
}
}
}
if (addContent) {
if (addContent.length() > 0) {
if (addContent.wrapper.length() > 0) {
newContent.wrapper += addContent.wrapper
} else {
newContent.wrapper += addContent
}
}
}
page.extraContent = newContent;
return
}
traceln("SleepTimerPlugin: End loading SleepTimerPlugin plugin");



