-
-
Save mdobson/5268d0a73b065b33b4f8 to your computer and use it in GitHub Desktop.
Driver example
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
var Driver = require('zetta').Driver; | |
var util = require('util'); | |
// Name your driver the device it's modeling | |
var Microphone = module.exports = function(port){ | |
Driver.call(this); | |
// not saved and not exposed in api | |
this._port = port; | |
// saved and exposed in api | |
this.amplitude = 123; | |
}; | |
util.inherits(Microphone, Driver); | |
// must include init function | |
Microphone.prototype.init = function(config) { | |
config | |
.state('ready') | |
.name('Matt\'s Sound Sensor') // name is optional but our examples should show it. | |
.type('sound') | |
.stream('amplitude', this.streamAmplitude); // .stream{Name} as function | |
} | |
Microphone.prototype.streamAmplitude = function(stream) { | |
var self = this; | |
this._port.on('data', function(d) { | |
var data = Number(d.toString()); | |
self.amplitude = data; | |
stream.write(data); | |
}); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment