-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
99 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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'); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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}`)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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)); | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = (text) => | ||
{ | ||
process.stdout.cursorTo(0); | ||
process.stdout.clearLine(0); | ||
process.stdout.write(text); | ||
} |