Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' of tuxcode.org:buzzIface

  • Loading branch information...
commit ad0318597779bb5008d2fabd1ba0f54c9a02be04 2 parents c2b6d9b + fb8bb64
@tuxcodejohn tuxcodejohn authored
Showing with 57 additions and 0 deletions.
  1. +6 −0 node_lib/README.md
  2. +39 −0 node_lib/buzz.js
  3. +12 −0 node_lib/test.js
View
6 node_lib/README.md
@@ -0,0 +1,6 @@
+# buzz node lib
+
+## Dependencies
+
+* https://github.com/voodootikigod/node-serialport
+
View
39 node_lib/buzz.js
@@ -0,0 +1,39 @@
+var serialport = require('serialport');
+var events = require('events');
+
+function Buzz(device) {
+ var options = {
+ baudrate: 115200,
+ databits: 8,
+ parity: 0,
+ stopbits: 1,
+ parser: serialport.parsers.readline("\n\r"),
+ }
+
+ var that = this;
+
+ this.port = port = new serialport.SerialPort(device, options);
+
+ port.on("data", function(data) {
+ that.emit("button", data[1] - '0'.charCodeAt(0));
+ });
+}
+
+Buzz.prototype = new events.EventEmitter();
+
+Buzz.prototype.set_led = function (led, brightness) {
+ buf = new Buffer("L$$\n\r");
+
+ buf[1] = '0'.charCodeAt(0) + led;
+ buf[2] = brightness ? 0xff : 0x00;
+
+ // async?
+ this.port.write(buf);
+};
+
+Buzz.prototype.close = function () {
+ this.port.close();
+}
+
+exports.Buzz = Buzz
+
View
12 node_lib/test.js
@@ -0,0 +1,12 @@
+var buzz = require('./buzz.js');
+
+b = new buzz.Buzz("/dev/ttyUSB0");
+
+b.set_led(1, 0);
+
+b.on("button", function(key) {
+ console.log(key);
+});
+
+//b.close();
+
Please sign in to comment.
Something went wrong with that request. Please try again.