Permalink
Browse files

Current nice working version

  • Loading branch information...
1 parent 49b41cd commit 35fe330c77ab7f2ca31b211e19278613a04aaa15 @sbstjn sbstjn committed Mar 5, 2012
Showing with 967 additions and 660 deletions.
  1. +1 −0 README.md
  2. +0 −96 app-old.js
  3. +0 −96 app.js
  4. +24 −52 examples.snippet
  5. +0 −21 examples/http_analogled.js
  6. +0 −26 examples/http_ledonoff.js
  7. +18 −0 examples/test.blinkLED.js
  8. +15 −0 examples/test.readAnalogIn.js
  9. +90 −0 examples/test.walkLED.js
  10. BIN public/images/glyphicons-halflings-white.png
  11. +7 −0 public/scripts/app.main.js
  12. +112 −0 public/scripts/app.walkLED.js
  13. +2 −4 public/scripts/example-1.js
  14. +7 −3 public/scripts/example-2.js
  15. +3 −3 public/scripts/example-3.js
  16. +5 −0 public/scripts/{events.js → examples.js}
  17. +0 −23 public/scripts/init.js
  18. +52 −18 public/scripts/libs/AnalogInput.js
  19. +81 −30 public/scripts/libs/Board.js
  20. +11 −1 public/scripts/libs/Button.js
  21. +11 −1 public/scripts/libs/DigitalInput.js
  22. +8 −4 public/scripts/libs/LED.js
  23. +62 −0 public/scripts/libs/Logger.HTML.js
  24. +29 −0 public/scripts/libs/Logger.js
  25. +25 −47 public/scripts/libs/Noduino.Serial.js
  26. +34 −34 public/scripts/libs/Noduino.Socket.js
  27. +30 −4 public/scripts/libs/Noduino.js
  28. +1 −1 public/scripts/libs/Speaker.js
  29. +0 −6 public/scripts/main.js
  30. 0 public/scripts/{ → vendor}/domready.js
  31. +92 −0 public/scripts/vendor/dropdown.js
  32. 0 public/scripts/{ → vendor}/prettify.js
  33. 0 public/scripts/{ → vendor}/require-jquery.js
  34. +5 −0 public/styles/init.css
  35. +29 −1 public/styles/init.less
  36. BIN public/wiring/walkLED.fzz
  37. BIN public/wiring/walkLED.png
  38. +15 −2 srv.app.js
  39. +49 −13 srv.socket.js
  40. +12 −0 srv.web.js
  41. +0 −17 test.blinkLED.js
  42. +0 −76 test.check.js
  43. +0 −74 test.walkLED.js
  44. +80 −0 views/example-walkLED.jade
  45. +47 −1 views/home.jade
  46. +0 −2 views/includes/snippet.jade
  47. +10 −4 views/layout.jade
View
@@ -0,0 +1 @@
+Welcome
View
@@ -1,96 +0,0 @@
-var kickstart = require('kickstart').withConfig({'name': 'localhost', 'port': 8080, 'path': __dirname});
-var Noduino = new require('./libs/Noduino')({'debug': true});
-var Socket = function(options) { this.io = null; this.sockets = {}; this.arduinos = []; this.checkSocket(); };
-Socket.prototype.checkSocket = function() { if (this.io == null) { this.io = require('socket.io'); } };
-Socket.prototype.bootstrap = function() {
- var that = this;
- this.io.sockets.on('connection', function(socket) {
- that.sockets[socket.id] = socket;
-
- /**
- * Handle incoming requests for connect to an arduino board
- */
- that.sockets[socket.id].on('board.connect', function(data) {
- if (!data) {
- var data = {}; }
- if (!data.id) {
- data.id = 0; }
-
- if (that.arduinos[data.id]) {
- return socket.emit('response', {'msg': 'board.connect', 'response': 'ready' }); }
- Noduino.connect({'type': 'serial'}, function(err, board) {
- that.arduinos[data.id] = board;
- socket.emit('response', {'msg': 'board.connect', 'response': (!err ? 'ready' : 'failed') });
- });
- });
- });
-};
-Socket.prototype.listen = function(port) { this.io = this.io.listen(port); this.bootstrap(); };
-
-var NoduinoServer = new Socket();
-NoduinoServer.listen(8090);
-
-var srv = kickstart.srv();
-
-srv.all('/', function(req, res) {
- var examples = {
- 'basics': [ '> ls /dev | grep usb',
- 'crw-rw-rw- 1 root wheel 18, 17 24 Feb 22:54 cu.usbmodem1d11',
- 'crw-rw-rw- 1 root wheel 18, 16 24 Feb 22:00 tty.usbmodem1d11'].join('\n'),
- 'node': [ '> npm install',
- '> node app.js',
- 'Listening on http://localhost:8080'].join('\n'),
- 'toggleLED': ["var Noduino = new require('./libs/Noduino')({'debug': true});",
- "Noduino.connect({'type': 'socket'}, function(err, board) {",
- " if (err) { return console.log(err); }",
- " board.withLED({pin: 13}, function(err, LED) {",
- " if (err) { return console.log(err); }",
- "",
- " LED.blink(250);",
- " });",
- "});"].join('\n'),
- 'connect': [ "var Noduino = new require('./libs/Noduino')({'debug': true});",
- "Noduino.connect({'type': 'socket'}, function(err, board) {",
- " if (err) { return console.log(err); }",
- " ",
- " console.log('Connected to board');",
- "});"].join('\n'),
- 'listenButton': [ "var Noduino = new require('./libs/Noduino')({'debug': true});",
- "Noduino.connect({'type': 'socket'}, function(err, board) {",
- " if (err) { return console.log(err); }",
- " ",
- " board.withButton({pin: 9}, function(err, Button)) {",
- " Button.on(cnst.HIGH, function(mode) {",
- " console.log('pushed!');",
- " });",
- " Button.on(cnst.LOW, function(mode) {",
- " console.log('released!');",
- " });",
- " })",
- "});"].join('\n'),
- 'analogRead': [ 'noduino.connect(function(err, board) {',
- ' if (err) { return console.log(\'failed to connect!\'); }',
- ' console.log(\'connected\');',
- '});'].join('\n'),
- 'digitalRead': [ 'noduino.connect(function(err, board) {',
- ' board.registerPin({pin: 9}, function(err, pin) {',
- ' pin.digitalRead(function(err, value) {',
- ' console.log(\'received value: \' + value);',
- ' });',
- ' })',
- '});'].join('\n'),
- 'digitalWrite': [ 'noduino.connect(function(err, board) {',
- ' board.registerPin({pin: 9}, function(err, pin) {',
- ' pin.digitalWrite(const.HIGH, function(err, value) {',
- ' console.log(\'set pin to value: \' + value);',
- ' });',
- ' })',
- '});'].join('\n')
-
-
- }
- res.render('home', {title: 'noduino', 'examples': examples});
-});
-
-var router = kickstart.listen();
-console.log("Listening on http://%s:%d", kickstart.conf().name, router.address().port);
View
96 app.js
@@ -1,96 +0,0 @@
-var kickstart = require('kickstart').withConfig({'name': 'localhost', 'port': 8080, 'path': __dirname});
-var Noduino = new require('./libs/Noduino')({'debug': true});
-var Socket = function(options) { this.io = null; this.sockets = {}; this.arduinos = []; this.checkSocket(); };
-Socket.prototype.checkSocket = function() { if (this.io == null) { this.io = require('socket.io'); } };
-Socket.prototype.bootstrap = function() {
- var that = this;
- this.io.sockets.on('connection', function(socket) {
- that.sockets[socket.id] = socket;
-
- /**
- * Handle incoming requests for connect to an arduino board
- */
- that.sockets[socket.id].on('board.connect', function(data) {
- if (!data) {
- var data = {}; }
- if (!data.id) {
- data.id = 0; }
-
- if (that.arduinos[data.id]) {
- return socket.emit('response', {'msg': 'board.connect', 'response': 'ready' }); }
- Noduino.connect({'type': 'serial'}, function(err, board) {
- that.arduinos[data.id] = board;
- socket.emit('response', {'msg': 'board.connect', 'response': (!err ? 'ready' : 'failed') });
- });
- });
- });
-};
-Socket.prototype.listen = function(port) { this.io = this.io.listen(port); this.bootstrap(); };
-
-var NoduinoServer = new Socket();
-NoduinoServer.listen(8090);
-
-var srv = kickstart.srv();
-
-srv.all('/', function(req, res) {
- var examples = {
- 'basics': [ '> ls /dev | grep usb',
- 'crw-rw-rw- 1 root wheel 18, 17 24 Feb 22:54 cu.usbmodem1d11',
- 'crw-rw-rw- 1 root wheel 18, 16 24 Feb 22:00 tty.usbmodem1d11'].join('\n'),
- 'node': [ '> npm install',
- '> node app.js',
- 'Listening on http://localhost:8080'].join('\n'),
- 'toggleLED': ["var Noduino = new require('./libs/Noduino')({'debug': true});",
- "Noduino.connect({'type': 'socket'}, function(err, board) {",
- " if (err) { return console.log(err); }",
- " board.withLED({pin: 13}, function(err, LED) {",
- " if (err) { return console.log(err); }",
- "",
- " LED.blink(250);",
- " });",
- "});"].join('\n'),
- 'connect': [ "var Noduino = new require('./libs/Noduino')({'debug': true});",
- "Noduino.connect({'type': 'socket'}, function(err, board) {",
- " if (err) { return console.log(err); }",
- " ",
- " console.log('Connected to board');",
- "});"].join('\n'),
- 'listenButton': [ "var Noduino = new require('./libs/Noduino')({'debug': true});",
- "Noduino.connect({'type': 'socket'}, function(err, board) {",
- " if (err) { return console.log(err); }",
- " ",
- " board.withButton({pin: 9}, function(err, Button)) {",
- " Button.on(cnst.HIGH, function(mode) {",
- " console.log('pushed!');",
- " });",
- " Button.on(cnst.LOW, function(mode) {",
- " console.log('released!');",
- " });",
- " })",
- "});"].join('\n'),
- 'analogRead': [ 'noduino.connect(function(err, board) {',
- ' if (err) { return console.log(\'failed to connect!\'); }',
- ' console.log(\'connected\');',
- '});'].join('\n'),
- 'digitalRead': [ 'noduino.connect(function(err, board) {',
- ' board.registerPin({pin: 9}, function(err, pin) {',
- ' pin.digitalRead(function(err, value) {',
- ' console.log(\'received value: \' + value);',
- ' });',
- ' })',
- '});'].join('\n'),
- 'digitalWrite': [ 'noduino.connect(function(err, board) {',
- ' board.registerPin({pin: 9}, function(err, pin) {',
- ' pin.digitalWrite(const.HIGH, function(err, value) {',
- ' console.log(\'set pin to value: \' + value);',
- ' });',
- ' })',
- '});'].join('\n')
-
-
- }
- res.render('home', {title: 'noduino', 'examples': examples});
-});
-
-var router = kickstart.listen();
-console.log("Listening on http://%s:%d", kickstart.conf().name, router.address().port);
View
@@ -8,68 +8,40 @@ crw-rw-rw- 1 root wheel 18, 16 24 Feb 22:00 tty.usbmodem1d11
> node app.js
Listening on http://localhost:8080
-###toggleLED
-require(['libs/Noduino', 'libs/Noduino.Socket'], function(NoduinoObj, Connector) {
- var Noduino = new NoduinoObj({debug: true, host: 'http://localhost:8090'}, Connector);
- Noduino.connect(function(err, board) {
- if (err) { return console.log(err); }
- board.withLED({pin: 13}, function(err, LED) {
- if (err) { return console.log(err); }
-
- LED.blink(250);
- LED.on('change', function() }
- console.log('LED changed to ' + (data.mode == Noduino.HIGH ? '[on]' : '[off]'));
- });
- });
- })
-});
###connect
-require(['libs/Noduino', 'libs/Noduino.Socket'], function(NoduinoObj, Connector) {
- var Noduino = new NoduinoObj({debug: true, host: 'http://localhost:8090'}, Connector);
- Noduino.connect(function(err, board) {
- if (err) { return console.log(err); }
+var Noduino = new NoduinoObj({debug: true, host: 'http://localhost:8090'}, Connector);
+Noduino.connect(function(err, board) {
+ if (err) { return console.log(err); }
- console.log('Connected to board');
- });
+ console.log('Connected to board');
});
-###listenButton
-var Noduino = new require('./libs/Noduino')({'debug': true});
-Noduino.connect({'type': 'socket'}, function(err, board) {
+###toggleLED
+var Noduino = new NoduinoObj({debug: true, host: 'http://localhost:8090'}, Connector);
+Noduino.connect(function(err, board) {
if (err) { return console.log(err); }
- board.withButton({pin: 9}, function(err, Button)) {
- Button.on(cnst.HIGH, function(mode) {
- console.log('pushed!');
- });
-
- Button.on(cnst.LOW, function(mode) {
- console.log('released!');
+ board.withLED({pin: 13}, function(err, LED) {
+ if (err) { return console.log(err); }
+
+ LED.blink(250);
+ LED.on('on', function() }
+ console.log('LED is on!');
});
- })
+ });
});
-
-###analogRead
-noduino.connect(function(err, board) {
- if (err) { return console.log('failed to connect!'); }
- console.log('connected');
-});
+###listenButton
+var Noduino = new NoduinoObj({debug: true, host: 'http://localhost:8090'}, Connector);
+Noduino.connect(function(err, board) {
+ if (err) { return console.log(err); }
+ board.withButton({pin: 13}, function(err, Button) {
+ if (err) { return console.log(err); }
-###digitalRead
-noduino.connect(function(err, board) {
- board.registerPin({pin: 9}, function(err, pin) {
- pin.digitalRead(function(err, value) {
- console.log('received value: ' + value);
+ Button.on('push', function() }
+ console.log('Button pushed');
});
+
+ Button.push();
});
});
-
-###digitalWrite
-noduino.connect(function(err, board) {
- board.registerPin({pin: 9}, function(err, pin) {
- pin.digitalWrite(const.HIGH, function(err, value) {
- console.log('set pin to value: ' + value);
- });
- })
-});
View
@@ -1,21 +0,0 @@
-var arduino = require('./duino/');
-
-var board = new arduino.Board({debug: true});
-var aled = new arduino.Led({board: board, pin: 9});
-
-board.on('ready', function(){
- var app = require('express').createServer();
-
- app.get('/', function(req, res){
- res.send('<!DOCTYPE html><html><head><script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script><script>$(document).ready(function(e){console.log("a");$("#range").change(function(e) { console.log($("#range").val()); $.ajax( "/fade/" + $("#range").val()); })});</script></head><body><input type="range" class="range" id="range" name="rangeEl" value="1" min="0" max="255" step="1"></body></html>');
- });
-
- app.get('/fade/:level', function(req, res){
- aled.brightLevel(req.param('level'));
- res.send('set to: ' + req.param('level'));
- });
-
- app.listen(8080);
-
- console.log('Listening on http://127.0.0.1:8080');
-});
View
@@ -1,26 +0,0 @@
-var arduino = require('../duino/');
-
-var board = new arduino.Board({debug: true});
-var led = new arduino.Led({board: board});
-
-board.on('ready', function(){
- var app = require('express').createServer();
-
- app.get('/', function(req, res){
- res.send('<a href="/on">ON</a> <a href="/off">OFF</a>');
- });
-
- app.get('/on', function(req, res){
- led.on();
- res.redirect('/');
- });
-
- app.get('/off', function(req, res){
- led.off();
- res.redirect('/');
- });
-
- app.listen(8080);
-
- console.log('Listening on http://127.0.0.1:8080');
-});
View
@@ -0,0 +1,18 @@
+var requirejs = require('requirejs');
+requirejs.config({nodeRequire: require});
+
+requirejs(['../public/scripts/libs/Noduino', '../public/scripts/libs/Noduino.Serial', '../public/scripts/libs/Logger'], function (NoduinoObj, NoduinoConnector, Logger) {
+ var Noduino = new NoduinoObj({'debug': false}, NoduinoConnector, Logger);
+ Noduino.connect(function(err, board) {
+ if (err) { return console.log(err); }
+
+ board.withLED({pin: 12}, function(err, LED) {
+ if (err) { return console.log(err); }
+
+ LED.blink(250);
+ LED.on('on', function(e) {
+ console.log('LED is on!');
+ });
+ });
+ });
+});
@@ -0,0 +1,15 @@
+var requirejs = require('requirejs');
+requirejs.config({nodeRequire: require});
+
+requirejs(['../public/scripts/libs/Noduino', '../public/scripts/libs/Noduino.Serial', '../public/scripts/libs/Logger'], function (NoduinoObj, NoduinoConnector, Logger) {
+ var Noduino = new NoduinoObj({'debug': false}, NoduinoConnector, Logger);
+ Noduino.connect(function(err, board) {
+ if (err) { return console.log(err); }
+
+ board.withAnalogInput({pin: 'A0'}, function(err, AnalogInput) {
+ AnalogInput.on('change', function(a) {
+ console.log('read value: ' + a.value);
+ });
+ });
+ });
+});
Oops, something went wrong.

0 comments on commit 35fe330

Please sign in to comment.