Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

expand example #65

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions example/interactive-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@ console.log('Press 6 to turn the lights a bright bluish white');
console.log('Press 7 to turn the lights a bright reddish white');
console.log('Press 8 to show debug messages including network traffic');
console.log('Press 9 to hide debug messages including network traffic');
console.log('Press a to increase brightness by 10');
console.log('Press z to decrease brightness by 10');
console.log('Press q to increase hue by 10');
console.log('Press s to decrease hue by 10');
console.log('Press w to increase saturation by 10');
console.log('Press x to decrease saturation by 10');

console.log('Press 0 to exit\n');

process.stdin.setEncoding('utf8');
Expand Down Expand Up @@ -128,6 +135,72 @@ process.stdin.on('data', function(key) {
} else if (key === '9') {
client.setDebug(false);
console.log('Debug messages are hidden');
} else if (key === 'a') {
client.lights().forEach(function(light) {
light.getState(function(err, info) {
if (err) {
console.log(err);
}
let b = info.color.brightness;
b = Math.min(b+10, 100);
light.color(info.color.hue, info.color.saturation, b, info.kelvin);
});
});
} else if (key === 'z') {
client.lights().forEach(function(light) {
light.getState(function(err, info) {
if (err) {
console.log(err);
}
let b = info.color.brightness;
b = Math.max(b - 10, 0);
light.color(info.color.hue, info.color.saturation, b, info.kelvin);
});
});
} else if (key === 'q') {
client.lights().forEach(function(light) {
light.getState(function(err, info) {
if (err) {
console.log(err);
}
let h = info.color.hue;
h = Math.min(h + 10, 360);
light.color(h, info.color.saturation, info.color.brightness, info.kelvin);
});
});
} else if (key === 's') {
client.lights().forEach(function(light) {
light.getState(function(err, info) {
if (err) {
console.log(err);
}
let h = info.color.hue;
h = Math.max(h - 10, 0);
light.color(h, info.color.saturation, info.color.brightness, info.kelvin);
});
});
} else if (key === 'w') {
client.lights().forEach(function(light) {
light.getState(function(err, info) {
if (err) {
console.log(err);
}
let s = info.color.saturation;
s = Math.min(s + 10, 100);
light.color(info.color.hue, s, info.color.brightness, info.kelvin);
});
});
} else if (key === 'x') {
client.lights().forEach(function(light) {
light.getState(function(err, info) {
if (err) {
console.log(err);
}
let s = info.color.saturation;
s = Math.max(s - 10, 0);
light.color(info.color.hue, s, info.color.brightness, info.kelvin);
});
});
} else if (key === '\u0003' || key === '0') { // Ctrl + C
client.destroy();
process.exit(); // eslint-disable-line no-process-exit
Expand Down