diff --git a/test/hdmi-switch.js b/test/hdmi-switch.js new file mode 100644 index 0000000..4a66551 --- /dev/null +++ b/test/hdmi-switch.js @@ -0,0 +1,26 @@ +/* + Toggles between 3 available HDMI ports. + Port number can be set with 'hdmiPorts' option when creating new cec-controller object. + Desired port number can also be passed to 'changeSource()' function + (e.g. cec.dev0.changeSource(2) should switch to input 2). +*/ + +const cecInit = require('./shared/init'); +const writeLine = require('./shared/writeLine'); +cecInit().then(test); + +function test() +{ + writeLine(); + console.log('--- TV HDMI Switch Test ---'); + changeSource(); +} + +async function changeSource() +{ + writeLine(`Switching HDMI input...`); + await cec.dev0.changeSource(); + + writeLine(`Switching to next port in 5 sec...`); + setTimeout(changeSource, 5000); +} diff --git a/test/power.js b/test/power.js new file mode 100644 index 0000000..8bce82b --- /dev/null +++ b/test/power.js @@ -0,0 +1,22 @@ +/* + Turns ON and OFF TV. +*/ + +const cecInit = require('./shared/init'); +const writeLine = require('./shared/writeLine'); +cecInit().then(test); + +function test() +{ + writeLine(); + console.log('--- TV Power Test ---'); + writeLine(`Turning OFF in 10 sec...`); + setTimeout(powerOff, 10000); +} + +async function powerOff() +{ + writeLine('Turning OFF TV...'); + await cec.dev0.turnOff(); + writeLine('TV should be in standby'); +} diff --git a/test/remote.js b/test/remote.js new file mode 100644 index 0000000..b8c46a3 --- /dev/null +++ b/test/remote.js @@ -0,0 +1,17 @@ +/* + Prints pressed button name to stdout. + For use to determine which buttons can be used with CEC on a particular TV set. +*/ + +const cecInit = require('./shared/init'); +const writeLine = require('./shared/writeLine'); +cecInit().then(test); + +function test() +{ + writeLine(); + console.log('--- TV Remote Test ---'); + writeLine('Press any button on TV remote'); + + cec.on('keypress', (keyName) => writeLine(`User pressed: ${keyName}`)); +} diff --git a/test/shared/init.js b/test/shared/init.js new file mode 100644 index 0000000..e502e5b --- /dev/null +++ b/test/shared/init.js @@ -0,0 +1,28 @@ +const cecController = require('../../index'); +const writeLine = require('./writeLine'); +process.stdin.resume(); + +module.exports = () => +{ + return new Promise((resolve, reject) => + { + writeLine('CEC Controller initializing...'); + var cec = new cecController(); + + cec.on('ready', async() => + { + if(cec.dev0.powerStatus !== 'on') + { + writeLine('Turning ON TV...'); + await cec.dev0.turnOn(); + } + + writeLine('Setting this device as active source...'); + await cec.setActive(); + + resolve(); + }); + + cec.on('error', (err) => writeLine(err.message)); + }); +} diff --git a/test/shared/writeLine.js b/test/shared/writeLine.js new file mode 100644 index 0000000..25de14b --- /dev/null +++ b/test/shared/writeLine.js @@ -0,0 +1,6 @@ +module.exports = (text) => +{ + process.stdout.cursorTo(0); + process.stdout.clearLine(0); + process.stdout.write(text); +}