@bugsounet/screen
I created this library if you want to manage for screen in your module.
This library is very simplified and ready for use in your node_helper.js
This library is used in MMM-Assistant2Display
single node routine for managing your screen
Installation
npm install @bugsounet/screen
Sample with screen contructor
const Screen = require("@bugsounet/screen")
this.config = {
delay: 10 * 1000,
turnOffDisplay: true,
ecoMode: true,
displayCounter: true,
detectorSleeping: true,
governorSleeping: true,
rpi4: false,
linux: false
}
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 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 sleeping
detectorSleeping - send a notification to manage detector when screen is off
governorSleeping - send a notification to manage governor when screen is off
rpi4 - rpi4 support (use dpms)
linux - linux support (use dpms)
callback (notification,value)
SCREEN_TIMER - Display the count down before sleeping mode (require displayCounter)
SCREEN_SHOWING - return notification for showing modules or other (require ecoMode)
SCREEN_HIDING - return notification for hiding modules or other (require ecoMode)
SCREEN_STATE - return object with actual screen state
object value:
running: return true if screen main script with count down is running
locked: return true if screen function is locked
power: return true if your display is On
{
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 detector
SNOWBOY_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 configuration
GOVERNOR_SLEEPING - return notification to change your governor to sleeping configuration
debug
if you want debuging information, just set to true
Functions
activate(): activate main screen script with count down (use it with first use)
it force turn on display when escape the script (ctl + c)
start(): start screen script with count down
stop(): stop screen script
reset(): reset count down
wakeup(): wake up the screen
lock(): lock the screen (start/stop/reset/wakeup will be ignored)
unlock(): unlock the screen
wantedPowerDisplay(wanted): comparate actual screen state and apply it if not set.
wanted value is boolean:
true: turn on screen
false: turn off screen
setPowerDisplay(set): like wantedPowerDisplay() but you force to apply it
set value is boolean:
true: force turn on screen
false: force turn off screen
state(): return state of screen in object
Notes
turnOffDisplay work only with activate() or start() function
you can use only wantedPowerDisplay() or setPowerDisplay() without main script !