1.1.9 • Published 4 years ago
@bugsounet/screen v1.1.9
screen
single node routine for managing your screen
Installation
npm install @bugsounet/screen
sudo apt-get install cec-utils -ySample with screen contructor
const Screen = require("@bugsounet/screen")
this.config = {
delay: 10 * 1000,
turnOffDisplay: true,
ecoMode: true,
displayCounter: true,
displayBar: true,
detectorSleeping: true,
governorSleeping: true,
mode: 1,
delayed: 0
}
var debug = true
this.screen = new Screen(this.config, callback, debug, detectorControl, governorControl)
this.screen.start()
setTimeout(() => { this.screen.state() } , 5 * 1000)
setTimeout(() => { this.screen.stop() } , 15 * 1000)
function callback(noti, value) {
if (noti == "SCREEN_TIMER") console.log ("Turn off in", value)
else if (noti == "SCREEN_BAR") console.log("Bar value", value)
else if (noti == "SCREEN_STATE") console.log ("Status:", value)
else console.log("Screen Notification:", noti)
}
function detectorControl(noti) {
console.log("detectorControl Notification:", noti)
}
function governorControl(noti) {
console.log("governorControl Notification:", noti)
}constructor of screen
Screen(screenConfig, callback, debug, detectorControl, governorControl)
screenConfig {}
delay- Time before turns off the display. (in ms).turnOffDisplay- Should the display turn off after timeout?ecoMode- send a notification to hide all module after timeout?displayCounter- send a notification with count-down before sleepingdisplayBar- send a notification with actual count since start (for progress bar)detectorSleeping- send a notification to manage detector when screen is offgovernorSleeping- send a notification to manage governor when screen is offmode- mode for turn on/off screendelayed- delayed time for turn on the screen if your screen is off (in ms)
5 modes are available:
mode: 1- use vgencmd (RPI only)mode: 2- use dpms (version RPI)mode: 3- use tvservice (RPI only)mode: 4- use HDMI CECmode: 5- use dpms (linux version for debian, ubuntu, ...)
note: the mode 0 disable turnOffDisplay too
callback (notification,value)
SCREEN_TIMER- Display the count down before sleeping mode (requiredisplayCounter)SCREEN_BAR- Display the counter since start to sleeping mode (requiredisplayBar)SCREEN_SHOWING- return notification for showing modules or other (requireecoMode)SCREEN_HIDING- return notification for hiding modules or other (requireecoMode)SCREEN_PRESENCE- return notification for USER_PRESENCE true/falseSCREEN_STATE- return object with actual screen state object value:mode: return the configuration of moderunning: returntrueifscreenmain script with count down is runninglocked: returntrueifscreenfunction is lockedpower: returntrueif your display is On
{
mode: 1,
running: true,
locked: false,
power: true
}detectorControl optional
require @bugsounet/snowboy or compatible
require detectorSleeping and only work with activate() or start() function
SNOWBOY_START- return notification for start your detectorSNOWBOY_STOP- return notification for stop your detector
governorControl optional
require @bugsounet/governor
require governorSleeping and only work with activate() or start() function
GOVERNOR_WORKING- return notification to change your governor to working configurationGOVERNOR_SLEEPING- return notification to change your governor to sleeping configuration
debug
if you want debuging information, just set to true
Functions
activate(): activate mainscreenscript with count down (use it with first use) it force turn on display when escape the script (ctl + c)start(): startscreenscript with count downstop(): stopscreenscriptreset(): reset count downwakeup(): wake up the screenlock(): lock the screen (start/stop/reset/wakeup will be ignored)unlock(): unlock the screenwantedPowerDisplay(wanted): comparate actual screen state and apply it if not set.wantedvalue is boolean:true: turn on screenfalse: turn off screen
setPowerDisplay(set): likewantedPowerDisplay()but you force to apply itsetvalue is boolean:true: force turn on screenfalse: force turn off screen
state(): return state ofscreenin object
Notes
turnOffDisplaywork only withactivate()orstart()function- you can use only
wantedPowerDisplay()orsetPowerDisplay()without main script !