Permalink
Browse files

Web Examples and Node.js Examples

  • Loading branch information...
1 parent 3e79bb7 commit 37ad181570316bbbd95ca13039fcfc2783cdd27b @sbstjn sbstjn committed Mar 3, 2012
View
@@ -1,24 +0,0 @@
-function AnalogInputSerial(options) {
- if (false === (this instanceof AnalogInputSerial)) {
- return new AnalogInputSerial(options); }
-}
-
-AnalogInputSerial.prototype.watchInput = function(AnalogInput) {
- setInterval(function () {
- AnalogInput.board.board.analogRead(AnalogInput.pin);
- }, 50);
-
- AnalogInput.board.board.on('data', function(m) {
- m = m.split('::');
- var eventPin = m[0]*1;
- if (m[0].indexOf('A') > -1) {
- eventPin = m[0]; }
-
- var event = {pin: eventPin, 'state': m[1]*1};
- if (event.pin == AnalogInput.pin) {
- AnalogInput.set(event.state);
- }
- });
-}
-
-module.exports = AnalogInputSerial;
View
@@ -1,55 +0,0 @@
-// var NuObject = require('./NuObject')
-
-function AnalogInput(options) {
- if (false === (this instanceof AnalogInput)) {
- return new AnalogInput(options); }
- this.pin = options.pin;
- this.board = options.board;
- this.events = {};
- this.value = null;
-
- if (options.type) {
- this.setType(options.type);
- this.watchInput();
- }
-}
-
-AnalogInput.prototype.watchInput = function() {
- this.c.watchInput(this);
-}
-
-AnalogInput.prototype.on = function(event, callback) {
- if (!this.events[event]) {
- this.events[event] = []; }
- this.events[event].push(callback);
-};
-
-AnalogInput.prototype.set = function(value, callback) {
- var tmp = this.value - value;
- if (tmp > -2 && tmp < 2) {
- return; }
- if (this.value != value) {
- this.value = value;
- this.emit('change');
- }
-};
-
-AnalogInput.prototype.emit = function(event, callback) {
- if (!this.events[event]) {
- return; }
- for (var i = 0; i < this.events[event].length; i++) {
- this.events[event][i](this);
- }
-};
-
-AnalogInput.prototype.setType = function(type) {
- this.type = type;
-
- switch (type) {
- case 'serial': var Connection = require('./AnalogInput.Serial'); this.c = new Connection(this.options); break;
- case 'socket': var Connection = require('./AnalogInput.Socket'); this.c = new Connection(this.options); break;
- default: throw new Error('Unknown connection type: ' + type); break;
- }
-}
-
-module.exports = AnalogInput;
View
@@ -1,43 +0,0 @@
-var cnst = {
- 'LED': 0x31,
- 'BOTTON': 0x32,
- 'HIGH': 'on',
- 'LOW': 'off',
- MODE_OUT: 'out',
- MODE_IN: 'in'
-
-};
-
-function BoardSerial(options) {
- if (false === (this instanceof BoardSerial)) {
- return new BoardSerial(options); }
- this.options = options;
- this.board = options.board;
-};
-
-BoardSerial.prototype.withDigitalOutput = function(Board, pin, next) {
- Board.board.pinMode(pin, cnst.MODE_OUT);
- next(null, pin);
-};
-
-BoardSerial.prototype.withLED = function(Board, pin, next) {
- Board.board.pinMode(pin, cnst.MODE_OUT);
- next(null, pin);
-};
-
-BoardSerial.prototype.withAnalogInput = function(Board, pin, next) {
- Board.board.pinMode(pin, cnst.MODE_IN);
- next(null, pin);
-}
-
-BoardSerial.prototype.withButton = function(Board, pin, next) {
- Board.board.pinMode(pin, cnst.MODE_IN);
- next(null, pin);
-};
-
-BoardSerial.prototype.digitalWrite = function(Board, pin, mode, next) {
- Board.board.digitalWrite(pin, mode, next);
-};
-
-
-module.exports = BoardSerial;
View
@@ -1,121 +0,0 @@
-var cnst = {
- 'LED': 0x31,
- 'DIGITAL_OUT': 0x31,
- 'BOTTON': 0x32,
- 'ANALOG_IN': 0x33,
- 'HIGH': 'on',
- 'LOW': 'off',
-};
-
-var LEDObj = require('./LED.js');
-var ButtonObj = require('./Button.js');
-var AnalogInputObj = require('./AnalogInput.js');
-var DigitalOutObj = require('./DigitalOutput.js');
-var SpeakerObj = require('./Speaker.js');
-
-function Board(options) {
- if (false === (this instanceof Board)) {
- return new Board(options); }
- this.options = options;
- this.board = options.board;
- this.pinMapping = {};
- this.setType(options.type);
-};
-
-Board.prototype.HIGH = '255';
-Board.prototype.LOW = '000';
-
-Board.prototype.setBoard = function(board) {
- this.board = board;
-};
-
-Board.prototype.pinType = function(pin) {
- return this.pinMapping[pin];
-}
-
-Board.prototype.pinAvailable = function(pin) {
- return (this.pinMapping[pin]);
-};
-
-Board.prototype.digitalWrite = function(pin, mode, next) {
- this.c.digitalWrite(this, pin, mode, function(err) {
- if (err) { return next(err); }
- });
-};
-
-Board.prototype.withLED = function(options, next) {
- if (this.pinAvailable(options.pin)) {
- return next(new Error('PIN already in use')); }
-
- this.pinMapping[options.pin] = cnst.LED;
- var that = this;
- this.c.withLED(that, options.pin, function(err, pin) {
- if (err) { return next(err); }
-
- next(null, new LEDObj({"board": that, "pin": pin, "type": that.type}));
- });
-};
-
-Board.prototype.withSpeaker = function(options, next) {
- if (this.pinAvailable(options.pin)) {
- return next(new Error('PIN already in use')); }
-
- this.pinMapping[options.pin] = cnst.DIGITAL_OUT;
- var that = this;
- this.c.withDigitalOutput(that, options.pin, function(err, pin) {
- if (err) { return next(err); }
-
- next(null, new SpeakerObj({"board": that, "pin": pin, "type": that.type}));
- });
-};
-
-Board.prototype.withDigitalOutput = function(options, next) {
- if (this.pinAvailable(options.pin)) {
- return next(new Error('PIN already in use')); }
-
- this.pinMapping[options.pin] = cnst.DIGITAL_OUT;
- var that = this;
- this.c.withDigitalOutput(that, options.pin, function(err, pin) {
- if (err) { return next(err); }
-
- next(null, new DigitalOutObj({"board": that, "pin": pin, "type": that.type}));
- });
-};
-
-Board.prototype.withButton = function(options, next) {
- if (this.pinAvailable(options.pin)) {
- return next(new Error('PIN already in use')); }
-
- this.pinMapping[options.pin] = cnst.BUTTON;
- var that = this;
- this.c.withButton(that, options.pin, function(err, pin) {
- if (err) { return next(err); }
-
- next(null, new ButtonObj({"board": that, "pin": pin, "type": that.type}));
- });
-};
-
-Board.prototype.withAnalogInput = function(options, next) {
- if (this.pinAvailable(options.pin)) {
- return next(new Error('PIN already in use')); }
-
- this.pinMapping[options.pin] = cnst.ANALOG_IN;
- var that = this;
- this.c.withAnalogInput(that, options.pin, function(err, pin) {
- if (err) { return next(err); }
-
- next(null, new AnalogInputObj({"board": that, "pin": pin, "type": that.type}));
- });
-}
-
-Board.prototype.setType = function(type) {
- this.type = type;
-
- switch (type) {
- case 'serial': var Connection = require('./Board.Serial'); this.c = new Connection(this.options); break;
- case 'socket': var Connection = require('./Board.Socket'); this.c = new Connection(this.options); break;
- default: throw new Error('Unknown connection type: ' + type); break;
- }
-}
-
-module.exports = Board;
View
@@ -1,26 +0,0 @@
-function ButtonSerial(options) {
- if (false === (this instanceof ButtonSerial)) {
- return new ButtonSerial(options); }
-}
-
-ButtonSerial.prototype.watchButton = function(Button) {
- setInterval(function () {
- Button.board.board.digitalRead(Button.pin);
- }, 50);
-
- Button.board.board.on('data', function(m) {
- m = m.split('::');
- var event = {pin: m[0]*1, 'state': m[1]*1};
-
- if (event.pin == Button.pin) {
- if (event.state == 0 && Button.pushed) {
- Button.release();
- }
- if (event.state == 1 && !Button.pushed) {
- Button.push();
- }
- }
- });
-}
-
-module.exports = ButtonSerial;
View
@@ -1,3 +0,0 @@
-var Button = require('./DigitalInput');
-
-module.exports = Button;
No changes.
No changes.
@@ -1,26 +0,0 @@
-function DigitalInputSerial(options) {
- if (false === (this instanceof DigitalInputSerial)) {
- return new DigitalInputSerial(options); }
-}
-
-DigitalInputSerial.prototype.watchButton = function(Button) {
- setInterval(function () {
- Button.board.board.digitalRead(Button.pin);
- }, 50);
-
- Button.board.board.on('data', function(m) {
- m = m.split('::');
- var event = {pin: m[0]*1, 'state': m[1]*1};
-
- if (event.pin == Button.pin) {
- if (event.state == 0 && Button.pushed) {
- Button.release();
- }
- if (event.state == 1 && !Button.pushed) {
- Button.push();
- }
- }
- });
-}
-
-module.exports = DigitalInputSerial;
View
@@ -1,53 +0,0 @@
-function DigitalInput(options) {
- if (false === (this instanceof DigitalInput)) {
- return new DigitalInput(options); }
- this.pin = options.pin;
- this.board = options.board;
- this.pushed = false;
- this.events = {};
-
- if (options.type) {
- this.setType(options.type);
- this.watchButton();
- }
-}
-
-DigitalInput.prototype.watchButton = function() {
- this.c.watchButton(this);
-}
-
-DigitalInput.prototype.push = function(callback) {
- this.pushed = true;
- this.emit('push');
-};
-
-DigitalInput.prototype.release = function(callback) {
- this.pushed = false;
- this.emit('release');
-};
-
-DigitalInput.prototype.on = function(event, callback) {
- if (!this.events[event]) {
- this.events[event] = []; }
- this.events[event].push(callback);
-};
-
-DigitalInput.prototype.emit = function(event, callback) {
- if (!this.events[event]) {
- return; }
- for (var i = 0; i < this.events[event].length; i++) {
- this.events[event][i]();
- }
-};
-
-DigitalInput.prototype.setType = function(type) {
- this.type = type;
-
- switch (type) {
- case 'serial': var Connection = require('./DigitalInput.Serial'); this.c = new Connection(this.options); break;
- case 'socket': var Connection = require('./DigitalInput.Socket'); this.c = new Connection(this.options); break;
- default: throw new Error('Unknown connection type: ' + type); break;
- }
-}
-
-module.exports = DigitalInput;
@@ -1,6 +0,0 @@
-function DigitalOutputSerial(options) {
- if (false === (this instanceof DigitalOutputSerial)) {
- return new DigitalOutputSerial(options); }
-};
-
-module.exports = DigitalOutputSerial;
Oops, something went wrong.

0 comments on commit 37ad181

Please sign in to comment.