forked from philip1986/pimatic-led-light
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from philip1986/master
Update to latest master version
- Loading branch information
Showing
28 changed files
with
1,204 additions
and
2,421 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,10 @@ | ||
language: node_js | ||
|
||
before_install: | ||
- export NODE_ENV=travis-test | ||
- sudo apt-get update | ||
# - sudo apt-get install libusb-1.0-0-dev | ||
- sudo apt-get install libudev-dev | ||
|
||
node_js: | ||
- 0.10 |
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
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
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
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,73 @@ | ||
module.exports = (env) -> | ||
Promise = env.require 'bluebird' | ||
_ = require 'lodash' | ||
Color = require 'color' | ||
BaseLedLight = require('./base')(env) | ||
|
||
|
||
class Blinkstick extends BaseLedLight | ||
|
||
constructor: (@config, lastState) -> | ||
nodeBlinkstick = require 'blinkstick' | ||
if @config.serial | ||
@device = new nodeBlinkstick.findBySerial(@config.serial) | ||
else | ||
@device = new nodeBlinkstick.findFirst() | ||
|
||
initState = _.clone lastState | ||
for key, value of lastState | ||
initState[key] = value.value | ||
super(initState) | ||
if @power then @turnOn() else @turnOff() | ||
|
||
_updateState: (attr) -> | ||
state = _.assign @getState(), attr | ||
super null, state | ||
|
||
setMaxValue = (color, brightness) -> | ||
return (color / 255) * (brightness * 2.5) | ||
|
||
turnOn: -> | ||
@_updateState power: true | ||
if @mode | ||
color = Color(@color).rgb() | ||
else | ||
color = | ||
r: 255 | ||
g: 255 | ||
b: 255 | ||
|
||
@device.setColor(setMaxValue(color.r, @brightness), setMaxValue(color.g, @brightness), setMaxValue(color.b, @brightness)) | ||
Promise.resolve() | ||
|
||
turnOff: -> | ||
@_updateState power: false | ||
@device.turnOff() | ||
Promise.resolve() | ||
|
||
setColor: (newColor) -> | ||
color = Color(newColor).rgb() | ||
@_updateState | ||
mode: @COLOR_MODE | ||
color: color | ||
@device.setColor(setMaxValue(color.r, @brightness), setMaxValue(color.g, @brightness), setMaxValue(color.b, @brightness)) if @power | ||
Promise.resolve() | ||
|
||
setWhite: () -> | ||
@_updateState mode: @WHITE_MODE | ||
@device.setColor(setMaxValue(255, @brightness), setMaxValue(255, @brightness), setMaxValue(255, @brightness)) if @power | ||
Promise.resolve() | ||
|
||
setBrightness: (newBrightness) -> | ||
@_updateState brightness: newBrightness | ||
if @mode | ||
color = Color(@color).rgb() | ||
else | ||
color = | ||
r: 255 | ||
g: 255 | ||
b: 255 | ||
@device.setColor(setMaxValue(color.r, newBrightness), setMaxValue(color.g, newBrightness), setMaxValue(color.b, newBrightness)) if @power | ||
Promise.resolve() | ||
|
||
return Blinkstick |
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,49 @@ | ||
module.exports = (env) -> | ||
Promise = env.require 'bluebird' | ||
_ = require 'lodash' | ||
Color = require 'color' | ||
BaseLedLight = require('./base')(env) | ||
|
||
class DummyLedLight extends BaseLedLight | ||
|
||
constructor: (@config, lastState) -> | ||
@device = @ | ||
@name = config.name | ||
@id = config.id | ||
@_dimlevel = lastState?.dimlevel?.value or 0 | ||
|
||
initState = _.clone lastState | ||
for key, value of lastState | ||
initState[key] = value.value | ||
super(initState) | ||
if @power then @turnOn() else @turnOff() | ||
|
||
_updateState: (attr) -> | ||
state = _.assign @getState(), attr | ||
super null, state | ||
|
||
turnOn: -> | ||
@_updateState power: true | ||
Promise.resolve() | ||
|
||
turnOff: -> | ||
@_updateState power: false | ||
Promise.resolve() | ||
|
||
setColor: (newColor) -> | ||
color = Color(newColor).rgb() | ||
@_updateState | ||
mode: @COLOR_MODE | ||
color: color | ||
Promise.resolve() | ||
|
||
setWhite: -> | ||
@_updateState mode: @WHITE_MODE | ||
Promise.resolve() | ||
|
||
setBrightness: (newBrightness) -> | ||
@_updateState brightness: newBrightness | ||
Promise.resolve() | ||
|
||
return DummyLedLight | ||
|
Oops, something went wrong.