Permalink
Browse files

First arg is err for all new and updated modules

Signed-off-by: Rick Waldron waldron.rick@gmail.com <waldron.rick@gmail.com>
  • Loading branch information...
rwaldron committed Mar 18, 2012
1 parent efa684c commit ba695e736df2d065dff686445c5a91cfa365fbec
Showing with 25 additions and 20 deletions.
  1. +1 −1 examples/ping.js
  2. +1 −1 examples/sensor.js
  3. +10 −4 examples/servo.js
  4. +5 −2 lib/button.js
  5. +3 −2 lib/ping.js
  6. +2 −1 lib/sensor.js
  7. +2 −9 lib/servo.js
  8. +1 −0 src/du.ino
View
@@ -11,7 +11,7 @@ ping = new arduino.Ping({
});
// 'read' events fire approx ~50ms
-ping.on('read', function() {
+ping.on('read', function(err) {
// Current sensor data stored in properties
// of this Ping instance:
View
@@ -10,7 +10,7 @@ ldr = new arduino.Sensor({
pin: 'A0'
});
-ldr.on('read', function(value) {
+ldr.on('read', function(err, value) {
// |value| is reading of the light dependent resistor
console.log(value);
View
@@ -28,18 +28,18 @@ servo = new arduino.Servo({
//
// - execute full sweep
-servo.on('attached', function() {
+servo.on('attached', function(err) {
console.log('attached');
- this.on('read', function(pos) {
+ this.on('read', function(err, pos) {
console.log(pos);
});
- this.on('detached', function() {
+ this.on('detached', function(err) {
console.log('detached');
});
- this.on('aftersweep', function() {
+ this.on('aftersweep', function(err) {
led.blink();
this.read();
@@ -48,3 +48,9 @@ servo.on('attached', function() {
this.sweep();
});
+
+// To test, use the following:
+// http://arduino.cc/en/uploads/Tutorial/sweep_BB.png
+//
+// More information:
+// http://www.ladyada.net/learn/sensors/pir.html
View
@@ -18,16 +18,19 @@ var Button = function (options) {
}, 50);
this.board.on('data', function (m) {
m = m.slice(0, -1).split('::');
+
+ var err = null;
+
if (m.length > 1 && m[0] == self.pin) {
// 0 is up
// 1 is down
if (m[1] == 0 && self.down) {
self.down = false;
- self.emit('up');
+ self.emit('up', err);
}
if (m[1] == 1 && !self.down) {
self.down = true;
- self.emit('down');
+ self.emit('down', err);
}
}
});
View
@@ -27,13 +27,14 @@ var Ping = function (options) {
this.board.on('data', function (message) {
var m = message.slice(0, -1).split('::'),
+ err = null,
pin, type, data;
if (!m.length) {
return;
}
- pin = m[0]
+ pin = m[0];
type = m[1];
data = m.length === 3 ? m[2] : null;
@@ -50,7 +51,7 @@ var Ping = function (options) {
// object we take half of the distance travelled.
this.centimeters = data / 29 / 2;
- this.emit(type, data);
+ this.emit(type, err, data);
}
}.bind(this));
};
View
@@ -21,6 +21,7 @@ var Sensor = function (options) {
// match pin to instance pin value
this.board.on('data', function (m) {
var m = message.slice(0, -1).split('::'),
+ err = null,
pin, data;
if (!m.length) {
@@ -31,7 +32,7 @@ var Sensor = function (options) {
data = m.length === 2 ? m[1] : null;
if (pin === this.pin) {
- this.emit('read', data);
+ this.emit('read', err, data);
}
}.bind(this));
};
View
@@ -24,6 +24,7 @@ var Servo = function (options) {
this.board.on('data', function (message) {
var m = message.slice(0, -1).split('::'),
+ err = null,
pin, type, data;
if (!m.length) {
@@ -35,7 +36,7 @@ var Servo = function (options) {
data = m.length === 3 ? m[2] : null;
if (pin === this.pin && types[type]) {
- this.emit(type, data);
+ this.emit(type, err, data);
}
}.bind(this));
};
@@ -111,20 +112,14 @@ Servo.prototype.sweep = function (options) {
this.write(moveTo);
moves++;
-
- // this.board.log( 'info', 'moves: ', moves );
};
this.on('read', doSweep);
- // this.write(1);
-
// Initialize sweep; wait for for stack unwind.
timeout.outer = setTimeout(function loop() {
// Read the current position, will trigger
// 'read' event with position data;
-
-
if (moves < 2) {
this.read();
@@ -139,8 +134,6 @@ Servo.prototype.sweep = function (options) {
this.removeListener('read', doSweep);
this.emit.call(this, 'aftersweep');
-
- // this.board.log('info', this);
}
}.bind(this), 0);
};
View
@@ -223,6 +223,7 @@ void handleServo(char *pin, char *val, char *aux) {
Serial.println(atoi(aux));
// Write to servo
servo.write(atoi(aux));
+ delay(15);
// TODO: Experiment with microsecond pulses
// digitalWrite(pin, HIGH); // start the pulse

0 comments on commit ba695e7

Please sign in to comment.