Skip to content

Instantly share code, notes, and snippets.

@kevinswiber
Last active August 29, 2015 14:24
Show Gist options
  • Select an option

  • Save kevinswiber/375d2e1429b683a45091 to your computer and use it in GitHub Desktop.

Select an option

Save kevinswiber/375d2e1429b683a45091 to your computer and use it in GitHub Desktop.
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);
}
}
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();
}
}
{
"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"
}
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