diff --git a/libs/AnalogInput.Serial.js b/libs/AnalogInput.Serial.js deleted file mode 100644 index d2333ad..0000000 --- a/libs/AnalogInput.Serial.js +++ /dev/null @@ -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; diff --git a/libs/AnalogInput.js b/libs/AnalogInput.js deleted file mode 100644 index 5fad303..0000000 --- a/libs/AnalogInput.js +++ /dev/null @@ -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; \ No newline at end of file diff --git a/libs/Board.Serial.js b/libs/Board.Serial.js deleted file mode 100644 index 4ad455a..0000000 --- a/libs/Board.Serial.js +++ /dev/null @@ -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; diff --git a/libs/Board.js b/libs/Board.js deleted file mode 100644 index af7990e..0000000 --- a/libs/Board.js +++ /dev/null @@ -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; diff --git a/libs/Button.Serial.js b/libs/Button.Serial.js deleted file mode 100644 index 2fad50d..0000000 --- a/libs/Button.Serial.js +++ /dev/null @@ -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; diff --git a/libs/Button.js b/libs/Button.js deleted file mode 100644 index d543ded..0000000 --- a/libs/Button.js +++ /dev/null @@ -1,3 +0,0 @@ -var Button = require('./DigitalInput'); - -module.exports = Button; \ No newline at end of file diff --git a/libs/Connection.Serial.js b/libs/Connection.Serial.js deleted file mode 100644 index e69de29..0000000 diff --git a/libs/Connection.Socket.js b/libs/Connection.Socket.js deleted file mode 100644 index e69de29..0000000 diff --git a/libs/DigitalInput.Serial.js b/libs/DigitalInput.Serial.js deleted file mode 100644 index 3b475ed..0000000 --- a/libs/DigitalInput.Serial.js +++ /dev/null @@ -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; diff --git a/libs/DigitalInput.js b/libs/DigitalInput.js deleted file mode 100644 index 98f4c3b..0000000 --- a/libs/DigitalInput.js +++ /dev/null @@ -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; \ No newline at end of file diff --git a/libs/DigitalOutput.Serial.js b/libs/DigitalOutput.Serial.js deleted file mode 100644 index 1260ad4..0000000 --- a/libs/DigitalOutput.Serial.js +++ /dev/null @@ -1,6 +0,0 @@ -function DigitalOutputSerial(options) { - if (false === (this instanceof DigitalOutputSerial)) { - return new DigitalOutputSerial(options); } -}; - -module.exports = DigitalOutputSerial; diff --git a/libs/DigitalOutput.js b/libs/DigitalOutput.js deleted file mode 100644 index 7cb90a4..0000000 --- a/libs/DigitalOutput.js +++ /dev/null @@ -1,56 +0,0 @@ -function DigitalOutput(options) { - if (false === (this instanceof DigitalOutput)) { - return new DigitalOutput(options); } - - this.pin = options.pin; - this.board = options.board; - this.mode = this.board.LOW; - this.events = {}; - - if (options.type) { - this.setType(options.type); } -}; - -DigitalOutput.prototype.setOn = function(callback) { - if (!this.active) { - this.active = true; - this.set(this.board.HIGH, callback); - this.emit('on'); - } -}; - -DigitalOutput.prototype.setOff = function(callback) { - if (this.active) { - this.active = false; - this.set(this.board.LOW, callback); - this.emit('off'); - } -}; - -DigitalOutput.prototype.set = function(mode, callback) { - this.mode = mode; - this.board.digitalWrite(this.pin, mode, callback); -}; - -DigitalOutput.prototype.on = function(event, callback) { - if (!this.events[event]) { - this.events[event] = []; } - this.events[event].push(callback); -}; - -DigitalOutput.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); } -}; - -DigitalOutput.prototype.setType = function(type) { - switch (type) { - case 'serial': var Connection = require('./DigitalOutput.Serial'); this.c = new Connection(this.options); break; - case 'socket': var Connection = require('./DigitalOutput.Socket'); this.c = new Connection(this.options); break; - default: throw new Error('Unknown connection type: ' + type); break; - } -}; - -module.exports = DigitalOutput; diff --git a/libs/LED.js b/libs/LED.js deleted file mode 100644 index 1323a9c..0000000 --- a/libs/LED.js +++ /dev/null @@ -1,18 +0,0 @@ -var LED = require('./DigitalOutput'); - -LED.prototype.toggle = function(callback) { - if (this.mode == this.board.LOW) { - return this.set(this.board.HIGH, callback); } - this.set(this.board.LOW, callback); -}; - -LED.prototype.blink = function(interval) { - if (interval*1 < 25) { - interval = 50; } - var that = this; - setInterval(function(){ - that.toggle(); - }, interval); -}; - -module.exports = LED; diff --git a/libs/No.js b/libs/No.js deleted file mode 100644 index 4d5eeb7..0000000 --- a/libs/No.js +++ /dev/null @@ -1,9 +0,0 @@ -var No = function() { - -}; - -No.prototype.DigitalOut = require('./DigitalOutput'); -No.prototype.LED = require('./LED'); -No.prototype.Speaker = require('./LED'); - -export.modules = No; \ No newline at end of file diff --git a/libs/NoObject.js b/libs/NoObject.js deleted file mode 100644 index 414655a..0000000 --- a/libs/NoObject.js +++ /dev/null @@ -1,24 +0,0 @@ -var NoObject = function(name) { - this.name = name; - this.events = {}; -} - -NoObject.prototype.withName = function(name) { - return new NoObject(name); -}; - -NoObject.prototype.on = function(event, callback) { - if (!this.events[event]) { - this.events[event] = []; } - this.events[event].push(callback); -}; - -NoObject.prototype.emit = function(event, callback) { - if (!this.events[event]) { - return; } - for (var i = 0; i < this.events[event].length; i++) { - this.events[event][i](); - } -}; - -module.exports = NoObject; \ No newline at end of file diff --git a/libs/Noduino.Serial.js b/libs/Noduino.Serial.js deleted file mode 100644 index fc89633..0000000 --- a/libs/Noduino.Serial.js +++ /dev/null @@ -1,17 +0,0 @@ -function SerialNoduino (options) { - if (false === (this instanceof SerialNoduino)) { - return new SerialNoduino(options); } - this.options = options; -}; - -SerialNoduino.prototype.connect = function(options, next) { - var Board = require('../duino/lib/board.js'); - new Board({'debug': this.options.debug || false}, function(err, board) { - if (err) { return next(new Error('Unable to connect')); } - - board.on('ready', function(){ - next(null, board); }); - }); -} - -module.exports = SerialNoduino; \ No newline at end of file diff --git a/libs/Noduino.Socket.js b/libs/Noduino.Socket.js deleted file mode 100644 index 04ebad3..0000000 --- a/libs/Noduino.Socket.js +++ /dev/null @@ -1,11 +0,0 @@ -function SerialNoduino (options) { - if (false === (this instanceof SerialNoduino)) { - return new SerialNoduino(); - } -}; - -SerialNoduino.prototype.connect = function(options, callback) { - callback(null, {'board': '11'}); -} - -module.exports = SerialNoduino; \ No newline at end of file diff --git a/libs/Noduino.js b/libs/Noduino.js deleted file mode 100644 index 3f73330..0000000 --- a/libs/Noduino.js +++ /dev/null @@ -1,38 +0,0 @@ -var objBoard = require('./Board.js'); - -/** - * Create Noduini object for handling general access - * @param object options - */ -function Noduino(options) { - if (false === (this instanceof Noduino)) { - return new Noduino(options); } - this.options = options; - this.type = options.type; - this.setType(options.type); -}; - -Noduino.prototype.setType = function(type) { - this.type = type; - - switch (type) { - case 'serial': var Connection = require('./Noduino.Serial'); this.c = new Connection(this.options); break; - case 'socket': var Connection = require('./Noduino.Socket'); this.c = new Connection(this.options); break; - default: throw new Error('Unknown connection type: ' + type); break; - } -} - -Noduino.prototype.connect = function(options, callback) { - if (!callback) { - callback = options; options = {}; } - var that = this; - return this.c.connect(options, function(err, board) { - if (err) { return callback(err); } - - options.type = that.type; - options.board = board; - callback(null, new objBoard(options)); - }); -} - -module.exports = Noduino; \ No newline at end of file diff --git a/libs/Speaker.js b/libs/Speaker.js deleted file mode 100644 index ed38060..0000000 --- a/libs/Speaker.js +++ /dev/null @@ -1,7 +0,0 @@ -var Speaker = require('./DigitalOutput'); - -Speaker.prototype.isMuted = function() { - return !this.active; -}; - -module.exports = Speaker; \ No newline at end of file diff --git a/public/styles/init.css b/public/styles/init.css index 4e2760b..cd7416d 100644 --- a/public/styles/init.css +++ b/public/styles/init.css @@ -92,3 +92,4 @@ form.well{padding:14px;} .response{line-height:28px;margin-left:12px;} .response.error{color:red;} label.label{display:inline;} +#e2-secondStep select{margin-right:4px;} diff --git a/public/styles/init.less b/public/styles/init.less index a53343c..64f07cf 100755 --- a/public/styles/init.less +++ b/public/styles/init.less @@ -810,4 +810,8 @@ background-position: 0 40px; } .response.error { color: red; } -label.label { display: inline; } \ No newline at end of file +label.label { display: inline; } + +#e2-secondStep select { + margin-right: 4px; +} \ No newline at end of file diff --git a/test.blinkLED.js b/test.blinkLED.js index a534705..1fe51cf 100644 --- a/test.blinkLED.js +++ b/test.blinkLED.js @@ -1,8 +1,17 @@ -var Noduino = new require('./libs/Noduino')({'debug': true}); -Noduino.connect({'type': 'serial'}, function(err, board) { - if (err) { return console.log(err); } - board.withLED({pin: 13}, function(err, LED) { +var requirejs = require('requirejs'); +requirejs.config({nodeRequire: require}); + +requirejs(['public/scripts/libs/Noduino', 'public/scripts/libs/Noduino.Serial'], function (NoduinoObj, NoduinoConnector) { + + var Noduino = new NoduinoObj({'debug': true}, NoduinoConnector); + Noduino.connect(function(err, board) { if (err) { return console.log(err); } - LED.blink(250); + + board.withLED({pin: 13}, function(err, LED) { + if (err) { return console.log(err); } + + LED.blink(250); + }); }); + }); \ No newline at end of file diff --git a/test.check.js b/test.check.js index 86ba2ab..87b5ff7 100644 --- a/test.check.js +++ b/test.check.js @@ -1,87 +1,76 @@ var requirejs = require('requirejs'); +requirejs.config({nodeRequire: require}); -requirejs.config({ - //Pass the top-level main.js/index.js require - //function to requirejs so that node modules - //are loaded relative to the top-level JS file. - nodeRequire: require -}); +requirejs(['libs/Noduino', 'libs/Noduino.Serial'], function (NoduinoObj, NoduinoConnector) { + var maxLEDs = 6; + var current = 1; + var direction = -1; + var curInterval = 100; + var currentStepper = null; + var LEDlist = []; + var sorting = [13, 12, 11, 10, 9, 8]; + function readyLED(led) { + LEDlist[sorting.indexOf(led.pin)] = led; + if (LEDlist.length == maxLEDs) { + startSequence(-1, curInterval); } + } -var maxLEDs = 6; -var current = 1; -var direction = -1; -var curInterval = 100; -var currentStepper = null; -var LEDlist = []; -var sorting = [13, 12, 11, 10, 9, 8]; - -function readyLED(led) { - LEDlist[sorting.indexOf(led.pin)] = led; - if (LEDlist.length == maxLEDs) { - startSequence(-1, curInterval); } -} - -function addButton(Button, dir) { - Button.on('push', function(e) { - var newDirection = direction; + function addButton(Button, dir) { + Button.on('push', function(e) { + var newDirection = direction; - switch (Button.pin) { - case 6: newDirection = -1; break; - case 3: newDirection = 1; break; - } + switch (Button.pin) { + case 6: newDirection = -1; break; + case 3: newDirection = 1; break; + } - if (newDirection != direction) { - startSequence(newDirection, curInterval); - } - }); -} + if (newDirection != direction) { + startSequence(newDirection, curInterval); + } + }); + } -function stepper() { - var next = current + direction; - if (next == maxLEDs + 1) { - next = 1; } - if (next == 0) { - next = maxLEDs; } - current = next; - for (var i = 1; i <= maxLEDs; i++) { - LEDlist[i-1].setOff(); } - LEDlist[(current-1)].setOn(); -} + function stepper() { + var next = current + direction; + if (next == maxLEDs + 1) { + next = 1; } + if (next == 0) { + next = maxLEDs; } + current = next; + for (var i = 1; i <= maxLEDs; i++) { + LEDlist[i-1].setOff(); } + LEDlist[(current-1)].setOn(); + } -function startSequence(step, interval) { - if (LEDlist.length != maxLEDs) { - return; }; + function startSequence(step, interval) { + if (LEDlist.length != maxLEDs) { + return; }; - clearInterval(currentStepper); - direction = step || 1; - currentStepper = setInterval(function() { - return stepper(); - }, interval); -} + clearInterval(currentStepper); + direction = step || 1; + currentStepper = setInterval(function() { + return stepper(); + }, interval); + } -var Noduino = new require('./libs/Noduino')({'debug': false, 'type': 'serial'}); -Noduino.connect(function(err, board) { - if (err) { return console.log(err); } + var Noduino = new NoduinoObj({'debug': true}, NoduinoConnector); + Noduino.connect(function(err, board) { + if (err) { return console.log(err); } - var Speaker = null; - var SpeakerTimeout = null; - board.withLED({pin: 13}, function(err, LED) { readyLED(LED); }); - board.withLED({pin: 12}, function(err, LED) { readyLED(LED); }); - board.withLED({pin: 11}, function(err, LED) { readyLED(LED); }); - board.withLED({pin: 10}, function(err, LED) { readyLED(LED); }); - board.withLED({pin: 9}, function(err, LED) { readyLED(LED); }); - board.withLED({pin: 8}, function(err, LED) { readyLED(LED); }); - board.withButton({pin: 3}, function(err, Button) { addButton(Button); }); - board.withButton({pin: 6}, function(err, Button) { addButton(Button); }); - - board.withSpeaker({pin: 7}, function(err, DigitalSpeaker) { - Speaker = DigitalSpeaker; - }); - board.withAnalogInput({pin: 'A0'}, function(err, AnalogInput) { - AnalogInput.on('change', function(a) { - curInterval = a.value; startSequence(direction, curInterval); + board.withLED({pin: 13}, function(err, LED) { readyLED(LED); }); + board.withLED({pin: 12}, function(err, LED) { readyLED(LED); }); + board.withLED({pin: 11}, function(err, LED) { readyLED(LED); }); + board.withLED({pin: 10}, function(err, LED) { readyLED(LED); }); + board.withLED({pin: 9}, function(err, LED) { readyLED(LED); }); + board.withLED({pin: 8}, function(err, LED) { readyLED(LED); }); + board.withButton({pin: 3}, function(err, Button) { addButton(Button); }); + board.withButton({pin: 6}, function(err, Button) { addButton(Button); }); + board.withAnalogInput({pin: 'A0'}, function(err, AnalogInput) { + AnalogInput.on('change', function(a) { + curInterval = a.value; startSequence(direction, curInterval); + }); }); }); }); \ No newline at end of file diff --git a/test.ledwalk.js b/test.ledwalk.js deleted file mode 100644 index 86ba2ab..0000000 --- a/test.ledwalk.js +++ /dev/null @@ -1,87 +0,0 @@ -var requirejs = require('requirejs'); - -requirejs.config({ - //Pass the top-level main.js/index.js require - //function to requirejs so that node modules - //are loaded relative to the top-level JS file. - nodeRequire: require -}); - - -var maxLEDs = 6; -var current = 1; -var direction = -1; -var curInterval = 100; -var currentStepper = null; -var LEDlist = []; -var sorting = [13, 12, 11, 10, 9, 8]; - -function readyLED(led) { - LEDlist[sorting.indexOf(led.pin)] = led; - if (LEDlist.length == maxLEDs) { - startSequence(-1, curInterval); } -} - -function addButton(Button, dir) { - Button.on('push', function(e) { - var newDirection = direction; - - switch (Button.pin) { - case 6: newDirection = -1; break; - case 3: newDirection = 1; break; - } - - if (newDirection != direction) { - startSequence(newDirection, curInterval); - } - }); -} - -function stepper() { - var next = current + direction; - if (next == maxLEDs + 1) { - next = 1; } - if (next == 0) { - next = maxLEDs; } - current = next; - for (var i = 1; i <= maxLEDs; i++) { - LEDlist[i-1].setOff(); } - LEDlist[(current-1)].setOn(); -} - -function startSequence(step, interval) { - if (LEDlist.length != maxLEDs) { - return; }; - - clearInterval(currentStepper); - direction = step || 1; - currentStepper = setInterval(function() { - return stepper(); - }, interval); -} - -var Noduino = new require('./libs/Noduino')({'debug': false, 'type': 'serial'}); -Noduino.connect(function(err, board) { - if (err) { return console.log(err); } - - var Speaker = null; - var SpeakerTimeout = null; - - board.withLED({pin: 13}, function(err, LED) { readyLED(LED); }); - board.withLED({pin: 12}, function(err, LED) { readyLED(LED); }); - board.withLED({pin: 11}, function(err, LED) { readyLED(LED); }); - board.withLED({pin: 10}, function(err, LED) { readyLED(LED); }); - board.withLED({pin: 9}, function(err, LED) { readyLED(LED); }); - board.withLED({pin: 8}, function(err, LED) { readyLED(LED); }); - board.withButton({pin: 3}, function(err, Button) { addButton(Button); }); - board.withButton({pin: 6}, function(err, Button) { addButton(Button); }); - - board.withSpeaker({pin: 7}, function(err, DigitalSpeaker) { - Speaker = DigitalSpeaker; - }); - board.withAnalogInput({pin: 'A0'}, function(err, AnalogInput) { - AnalogInput.on('change', function(a) { - curInterval = a.value; startSequence(direction, curInterval); - }); - }); -}); \ No newline at end of file diff --git a/views/home.jade b/views/home.jade index 4d5794c..dac01e4 100755 --- a/views/home.jade +++ b/views/home.jade @@ -1 +1,116 @@ -input(type="range", class="range", id="range", name="rangeEl", value="0", min="0", max="255", step="1") \ No newline at end of file +header.jumbotron.subhead#overview + h1 noduino + p.lead A simple and flexible JavaScript and Node.js Framework for accessing basic Arduino controls from Web Applications using HTML5, Socket.IO and Node.js. +.row.marketing#homeBoxes + .span4 + img.bs-icon(src="/images/glyphicons_155_show_thumbnails.png") + h2 Easy Arduino Access + p Initialize your Arduino board, define registered pins and send commands. Use digital and analog read or write to use control buttons or switch connected LEDs. Listen for events happening on your Arduino to control your Web Application with analog controls… + .span4 + img.bs-icon(src="/images/glyphicons_009_magic.png") + h2 JS Proof of Concept + p The first version of + a(href="") noduino + | was completely built for fun. I had bought an Arduino, wanted to play and for no good reason tried sending commands with JavaScript using a nice HTML5 interface with to my Arduino. Imagine controlling browser games with an old NES game pad! + .span4 + img.bs-icon(src="/images/glyphicons_214_resize_small.png") + h2 Client and Server in JS + p Thanks to Node.js and modern web browsers all server code as well as all client code is written in JavaScript. There is no difference in accessing your Arduino over WebSocket or a Serial connection. All methods and objects remain the same, written code is highly portable. +section#homeContent + .page-header + h1 Connect HTML Interface to Arduino + .row + .span3 + p Make sure your + strong Arduino + | is connected with your computer, this commands works fine for Mac OS X. + .span9 + pre.prettyprint.linenums=examples.basics + .row + .span3 + p + strong Download + | Node.js, installed needed packages with npm and start + a(href="#") noduino + | to see this page. + .span9 + pre.prettyprint.linenums=examples.node + .row + .span3 + p See the provided + strong Examples + | or establish a connection to Arduino by yourself. + .span9 + pre.prettyprint.linenums=examples.connect + .row.example + .span12#e1-exampleConnection + p + a.btn(href="#")#e1-buttonConnect + i.icon-refresh + | Connect to Arduino + .alert.alert-info Please connect to your Arduino using the button. + .alert.hide.alert-error Unable to connect to Arduino! + .alert.hide.alert-success Connection to Arduino established! + + .page-header + h1 Switching LED modes + small Simple methods for switching LED modes, blinking and fading… + .row + .span3 + p When using the example from above to connect to your + strong Arduino + | it is very easy to + strong toggle an LED + | connected to pin 13. All communication between the web browser and server is handled with Socket.IO, on the server commands are send to Arduino using + a(href="#") duino. + | + strong Noduino + | enables + strong Real-Time Arduino + | control using WebSockets! + .span9 + pre.prettyprint.linenums=examples.toggleLED + .row.example + .span12#e2-exampleConnection + p + a.btn(href="#")#e2-buttonConnect + i.icon-refresh + | Connect to Arduino + .alert.alert-info Please connect to your Arduino using the button. + .alert.hide.alert-error Unable to connect to Arduino! + .alert.hide.alert-success Connection to Arduino established! + .span12#e2-secondStep + p + select.span2#e2-pinValue + option(value=13) PIN: 13 + input.span3#e2-interval(type="text",placeholder="Interval in Miliseconds") + | + a.btn(href="#", style="margin-top: 1px;")#e2-buttonStart + i.icon-retweet + | Start blinking LED + | + label.label#e2-status(style="position: relative; top: -2px;") LED off + .alert.hide.alert-info Please connect to your Arduino using the button. + .alert.hide.alert-error Connect to Arduino first! + .alert.hide.alert-success Connection to Arduino established! + + + + .page-header + h1 Listening for Events on Arduino + small Catch a button push event and fade on your LED + .row + .span3 + p Buttons and LEDs provide a simple interface to listen for events. Use Button.on() or LED.on() for triggering your code if a button is pushed or your LED is switching modes. Multiple events for a single event are called the order they have been assigned. + p Use Board.receive() for catching all incoming data streams. You probably need this if you plan to create a Real-Time Web Application with noduino. Buzzword… + .span9 + pre.prettyprint.linenums=examples.listenButton + .row.example + .span12#e3-exampleConnection + p + a.btn(href="#")#e3-buttonConnect + i.icon-refresh + | Connect to Arduino + .alert.alert-info Please connect to your Arduino using the button. + .alert.hide.alert-error Unable to connect to Arduino! + .alert.hide.alert-success Connected! Button is \ No newline at end of file diff --git a/views/layout.jade b/views/layout.jade index 5110fe2..4ce9172 100755 --- a/views/layout.jade +++ b/views/layout.jade @@ -5,11 +5,11 @@ html(lang="en") link(rel="stylesheet", href="/styles/bootstrap/init.css") link(rel="stylesheet", href="/styles/prettify.css") link(rel="stylesheet", href="/styles/init.css") - script(type="text/javascript", src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js") + script(data-main="scripts/main", type="text/javascript", src="/scripts/require-jquery.js") script(type="text/javascript", src="http://localhost:8090/socket.io/socket.io.js") - script(type="text/javascript", src="/scripts/init.js") - script(type="text/javascript", src="/scripts/prettify.js") - body(onload="prettyPrint()") + // script(type="text/javascript", src="/scripts/init.js") + // script(type="text/javascript", src="/scripts/prettify.js") + body .navbar.navbar-fixed-top(style="z-index: 4;position:absolute;") .navbar-inner .container @@ -26,122 +26,7 @@ html(lang="en") a(href="#") img(style="position: absolute; top: 0; right: 0; border: 0; z-index: 10;",src="/images/forkme.png",alt="Fork me on GitHub") - .container - header.jumbotron.subhead#overview - h1 noduino - p.lead A simple and flexible JavaScript and Node.js Framework for accessing basic Arduino controls from Web Applications using HTML5, Socket.IO and Node.js. - .row.marketing#homeBoxes - .span4 - img.bs-icon(src="/images/glyphicons_155_show_thumbnails.png") - h2 Easy Arduino Access - p Initialize your Arduino board, define registered pins and send commands. Use digital and analog read or write to use control buttons or switch connected LEDs. Listen for events happening on your Arduino to control your Web Application with analog controls… - .span4 - img.bs-icon(src="/images/glyphicons_009_magic.png") - h2 Entirely built for fun - p The first version of - a(href="") noduino - | was completely built for fun. I had bought an Arduino, wanted to play and for no good reason tried sending commands with JavaScript using a nice HTML5 interface with to my Arduino. Imagine controlling browser games with an old NES game pad! - .span4 - img.bs-icon(src="/images/glyphicons_214_resize_small.png") - h2 Client and Server in JS - p Thanks to Node.js and modern web browsers all server code as well as all client code is written in JavaScript. There is no difference in accessing your Arduino over WebSocket or a Serial connection. All methods and objects remain the same, written code is highly portable. - section#homeContent - .page-header - h1 Connect HTML Interface to Arduino - .row - .span3 - p Make sure your - strong Arduino - | is connected with your computer, this commands works fine for Mac OS X. - .span9 - pre.prettyprint.linenums=examples.basics - .row - .span3 - p - strong Download - | Node.js, installed needed packages with npm and start - a(href="#") noduino - | to see this page. - .span9 - pre.prettyprint.linenums=examples.node - .row - .span3 - p See the provided - strong Examples - | or establish a connection to Arduino by yourself. - .span9 - pre.prettyprint.linenums=examples.connect - .row.example - .span12#exampleConnection - p - a.btn(href="#")#buttonConnect - i.icon-refresh - | Connect to Arduino - .alert.alert-info Please connect to your Arduino using the button. - .alert.hide.alert-error Unable to connect to Arduino! - .alert.hide.alert-success Connection to Arduino established! - - .page-header - h1 Switching LED modes - small Simple methods for switching LED modes, blinking and fading… - .row - .span3 - p When using the example from above to connect to your - strong Arduino - | it is very easy to - strong toggle an LED - | connected to pin 13. All communication between the web browser and server is handled with Socket.IO, on the server commands are send to Arduino using - a(href="#") duino. - | - strong Noduino - | enables - strong Real-Time Arduino - | control using WebSockets! - .span9 - pre.prettyprint.linenums=examples.toggleLED - .row.example - .span12#exampleLEDBlink - p - a.btn(href="#")#buttonConnect - i.icon-refresh - | Connect to Arduino - .alert.alert-info Please connect to your Arduino using the button. - .alert.hide.alert-error Unable to connect to Arduino! - .alert.hide.alert-success Connection to Arduino established! - p - input.span3(type="text",placeholder="Interval in Miliseconds") - | - a.btn(href="#", style="margin-top: 1px;")#buttonConnect - i.icon-retweet - | Start blinking LED - | - label.label(style="position: relative; top: -2px;") LED off - .alert.hide.alert-info Please connect to your Arduino using the button. - .alert.alert-error Connect to Arduino first! - .alert.hide.alert-success Connection to Arduino established! - - - - .page-header - h1 Listening for Events on Arduino - small Catch a button push event and fade on your LED - .row - .span3 - p Buttons and LEDs provide a simple interface to listen for events. Use Button.on() or LED.on() for triggering your code if a button is pushed or your LED is switching modes. Multiple events for a single event are called the order they have been assigned. - p Use Board.receive() for catching all incoming data streams. You probably need this if you plan to create a Real-Time Web Application with noduino. Buzzword… - .span9 - pre.prettyprint.linenums=examples.listenButton - .row.example - .span12#exampleLEDBlink - p - a.btn(href="#")#buttonConnect - i.icon-refresh - | Connect to Arduino - .alert.alert-info Please connect to your Arduino using the button. - .alert.hide.alert-error Unable to connect to Arduino! - .alert.alert-success Connected! Button is - .alert.alert-success Connected! Button is for 8.23 seconds now! - .alert.alert-success Connected! Button is 4.32 secods remaining with LED on… + .container!=body footer.footer p.pull-right a(href="#") Back to top