Last active
August 29, 2015 14:24
-
-
Save kevinswiber/375d2e1429b683a45091 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| import Device from 'zetta-device'; | |
| export default class Heartbeat extends Device { | |
| constructor() { | |
| super(); | |
| this.pulse = null; | |
| } | |
| init(config) { | |
| config | |
| .type('heartbeat') | |
| .monitor('pulse') | |
| setInterval(() => { | |
| const min = 60; | |
| const max = 72; | |
| this.pulse = Math.round(Math.random() * (max - min) + min, 2); | |
| }, 1000); | |
| } | |
| } |
This file contains hidden or 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
| import Device from 'zetta-device' | |
| export default class LED extends Device { | |
| init(config) { | |
| config | |
| .type('led') | |
| .state('off') | |
| .when('off', { allow: ['turn-on'] }) | |
| .when('on', { allow: ['turn-off'] }) | |
| .map('turn-on', this.turnOn) | |
| .map('turn-off', this.turnOff); | |
| } | |
| turnOn(cb) { | |
| this.state = 'on'; | |
| cb(); | |
| } | |
| turnOff(cb) { | |
| this.state = 'off'; | |
| cb(); | |
| } | |
| } |
This file contains hidden or 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
| { | |
| "name": "asfasdfsfasd", | |
| "version": "1.0.0", | |
| "description": "", | |
| "main": "index.js", | |
| "dependencies": { | |
| "babel-runtime": "5.6.12", | |
| "zetta": "^0.30.0", | |
| "zetta-device": "^0.11.0" | |
| }, | |
| "devDependencies": { | |
| "babel": "5.6.12" | |
| }, | |
| "scripts": { | |
| "build": "rm -rf lib/* && babel src --ignore __tests__ --optional runtime --optional es7.classProperties --out-dir lib", | |
| "server": "npm run build && node lib/server.js" | |
| }, | |
| "author": "", | |
| "license": "ISC" | |
| } |
This file contains hidden or 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
| import zetta from 'zetta'; | |
| import LED from './led'; | |
| import Heartbeat from './heartbeat'; | |
| zetta() | |
| .use(LED) | |
| .use(Heartbeat) | |
| .listen(process.env.PORT || 1337); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment