From 080340dbc5e0decaf70c42429b2a220f1d6108a9 Mon Sep 17 00:00:00 2001 From: Rick Waldron Date: Mon, 5 Jan 2015 11:32:18 -0500 Subject: [PATCH] Remove bogus `null` arguments from emitters. Fixes gh-561 --- eg/accelerometer-pan-tilt.js | 2 +- eg/classic-controller.js | 6 +-- eg/gripper.js | 4 +- eg/ir-motion.js | 12 +++--- eg/ir-proximity.js | 2 +- eg/ir-reflect-array.js | 4 +- eg/ir-reflect.js | 2 +- eg/joystick-motor-led.js | 2 +- eg/joystick.js | 2 +- eg/motor-3-pin.js | 24 ++++++------ eg/motor-PCA9685.js | 8 ++-- eg/motor-brake.js | 20 +++++----- eg/motor-current.js | 20 +++++----- eg/motor-directional.js | 16 ++++---- eg/motor-hbridge.js | 16 ++++---- eg/motor.js | 8 ++-- eg/navigator-original.js | 2 +- eg/navigator.js | 2 +- eg/nodeconf-navigator.js | 2 +- eg/nodeconf-radar.js | 2 +- eg/nodeconf-slider.js | 21 +++------- eg/nunchuk.js | 6 +-- eg/ping.js | 24 ++---------- eg/proximity.js | 4 +- eg/slider-log.js | 20 +++------- eg/slider-pan.js | 25 +++--------- eg/slider-servo-control.js | 28 ++++--------- eg/sonar-scan.js | 2 +- eg/temperature-ds18b20.js | 5 ++- eg/temperature-lm35.js | 2 +- eg/temperature-tmp36.js | 2 +- eg/tinkerkit-accelerometer.js | 12 +++--- lib/accelerometer.js | 2 +- lib/button.js | 2 +- lib/gyro.js | 2 +- lib/imu.js | 2 +- lib/ir.js | 11 +++--- lib/joystick.js | 2 +- lib/motor.js | 10 ++--- lib/ping.js | 13 +----- lib/pir.js | 8 ++-- lib/reflectancearray.js | 8 ++-- lib/sensor.js | 14 +++---- lib/sonar.js | 9 +---- lib/temperature.js | 6 +-- lib/wii.js | 6 +-- test/reflectancearray.js | 38 +++++++++--------- test/sensor.js | 16 ++++---- test/temperature.js | 74 +++++++++++++++++------------------ 49 files changed, 223 insertions(+), 307 deletions(-) diff --git a/eg/accelerometer-pan-tilt.js b/eg/accelerometer-pan-tilt.js index 40f066262..36f79990b 100644 --- a/eg/accelerometer-pan-tilt.js +++ b/eg/accelerometer-pan-tilt.js @@ -30,7 +30,7 @@ board.on("ready", function() { // Center all servos (five.Servos()).center(); - accel.on("acceleration", function(err, timestamp) { + accel.on("acceleration", function() { // console.log( "acceleration", this.axis ); tilt.to(Math.abs(Math.ceil(170 * this.pitch.toFixed(2)) - 180)); diff --git a/eg/classic-controller.js b/eg/classic-controller.js index 0db61ea8d..2c3a05316 100644 --- a/eg/classic-controller.js +++ b/eg/classic-controller.js @@ -38,7 +38,7 @@ board.on("ready", function() { // Fired when the joystick detects a change in // axis position. // - nunchuk.joystick.left.on("change", function(err, event) { + nunchuk.joystick.left.on("change", function(event) { console.log( "Left joystick " + event.axis, event.target[event.axis], @@ -46,7 +46,7 @@ board.on("ready", function() { ); }); - nunchuk.joystick.right.on("change", function(err, event) { + nunchuk.joystick.right.on("change", function(event) { console.log( "Right joystick " + event.axis, event.target[event.axis], @@ -78,7 +78,7 @@ board.on("ready", function() { ["down", "up", "hold"].forEach(function(type) { - nunchuk.on(type, function(err, event) { + nunchuk.on(type, function(event) { console.log( event.target.which + " is " + type, diff --git a/eg/gripper.js b/eg/gripper.js index 21922e66f..481c88670 100644 --- a/eg/gripper.js +++ b/eg/gripper.js @@ -52,13 +52,13 @@ var five = require("../lib/johnny-five.js"), // g.*() from REPL // // - motion.on("motionstart", function(err, ts) { + motion.on("motionstart", function() { chop(); }); // "motionstart" events are fired following a "motionstart event // when no movement has occurred in X ms - motion.on("motionend", function(err, ts) { + motion.on("motionend", function() { if (repeater) { repeater.stop(); repeater = null; diff --git a/eg/ir-motion.js b/eg/ir-motion.js index 776a16087..60b3be8fe 100644 --- a/eg/ir-motion.js +++ b/eg/ir-motion.js @@ -18,19 +18,19 @@ board.on("ready", function() { // Pir Event API // "calibrated" occurs once, at the beginning of a session, - motion.on("calibrated", function(err, ts) { - console.log("calibrated", ts); + motion.on("calibrated", function() { + console.log("calibrated", Date.now()); }); // "motionstart" events are fired when the "calibrated" // proximal area is disrupted, generally by some form of movement - motion.on("motionstart", function(err, ts) { - console.log("motionstart", ts); + motion.on("motionstart", function() { + console.log("motionstart", Date.now()); }); // "motionend" events are fired following a "motionstart" event // when no movement has occurred in X ms - motion.on("motionend", function(err, ts) { - console.log("motionend", ts); + motion.on("motionend", function() { + console.log("motionend", Date.now()); }); }); diff --git a/eg/ir-proximity.js b/eg/ir-proximity.js index 4551e324b..1448d402e 100644 --- a/eg/ir-proximity.js +++ b/eg/ir-proximity.js @@ -44,7 +44,7 @@ five.Board().on("ready", function() { // // Fires continuously, every 66ms. // - ir.on("data", function(err, timestamp) { + ir.on("data", function() { // console.log( "data" ); }); }); diff --git a/eg/ir-reflect-array.js b/eg/ir-reflect-array.js index 609f2c353..e409ab655 100644 --- a/eg/ir-reflect-array.js +++ b/eg/ir-reflect-array.js @@ -9,7 +9,7 @@ five.Board().on("ready", function() { // calibrate for two seconds eyes.calibrateUntil(function() { return !calibrating; }); - setTimeout(function() { calibrating = false; }, 2000); + setTimeout(function() { calibrating = false; }, 2000); eyes.enable(); @@ -17,7 +17,7 @@ five.Board().on("ready", function() { // // Fires continuously once calibrated // - eyes.on("line", function(err, line) { + eyes.on("line", function(line) { console.log("line: ", line); }); }); diff --git a/eg/ir-reflect.js b/eg/ir-reflect.js index daca85f6e..7bbd50150 100644 --- a/eg/ir-reflect.js +++ b/eg/ir-reflect.js @@ -19,7 +19,7 @@ five.Board().on("ready", function() { // // Fires continuously, every 66ms. // - ir.on("data", function(err, timestamp) { + ir.on("data", function() { console.log("data"); }); }); diff --git a/eg/joystick-motor-led.js b/eg/joystick-motor-led.js index 619d461cb..db0174142 100644 --- a/eg/joystick-motor-led.js +++ b/eg/joystick-motor-led.js @@ -37,7 +37,7 @@ board.on("ready", function() { // Pushing the joystick to up position should start the motor, // releasing it will turn the motor off. - joystick.on("axismove", function(err, timestamp) { + joystick.on("axismove", function() { if (!motor.isOn && this.axis.y > 0.51) { motor.start(); diff --git a/eg/joystick.js b/eg/joystick.js index d88785855..20b51a09c 100644 --- a/eg/joystick.js +++ b/eg/joystick.js @@ -24,7 +24,7 @@ board.on("ready", function() { // Joystick Event API - joystick.on("axismove", function(err, timestamp) { + joystick.on("axismove", function() { // Axis data is available on: // this.axis diff --git a/eg/motor-3-pin.js b/eg/motor-3-pin.js index 5a1a90d61..d44423f17 100644 --- a/eg/motor-3-pin.js +++ b/eg/motor-3-pin.js @@ -9,7 +9,7 @@ board.on("ready", function() { pwm: 9 dir: 8 cdir: 11 - + Motor B pwm: 10 dir: 12 @@ -20,7 +20,7 @@ board.on("ready", function() { pwm: 6 dir: 5 cdir: 7 - + Motor B pwm: 4 dir: 3 @@ -44,20 +44,20 @@ board.on("ready", function() { motor: motor }); - motor.on("start", function(err, timestamp) { - console.log("start", timestamp); + motor.on("start", function() { + console.log("start", Date.now()); }); - motor.on("stop", function(err, timestamp) { - console.log("automated stop on timer", timestamp); + motor.on("stop", function() { + console.log("automated stop on timer", Date.now()); }); - motor.on("brake", function(err, timestamp) { - console.log("automated brake on timer", timestamp); + motor.on("brake", function() { + console.log("automated brake on timer", Date.now()); }); - motor.on("forward", function(err, timestamp) { - console.log("forward", timestamp); + motor.on("forward", function() { + console.log("forward", Date.now()); // demonstrate switching to reverse after 5 seconds board.wait(5000, function() { @@ -65,8 +65,8 @@ board.on("ready", function() { }); }); - motor.on("reverse", function(err, timestamp) { - console.log("reverse", timestamp); + motor.on("reverse", function() { + console.log("reverse", Date.now()); // demonstrate braking after 5 seconds board.wait(5000, function() { diff --git a/eg/motor-PCA9685.js b/eg/motor-PCA9685.js index 225372837..7019606c4 100644 --- a/eg/motor-PCA9685.js +++ b/eg/motor-PCA9685.js @@ -26,8 +26,8 @@ board.on("ready", function() { // Motor Event API // "start" events fire when the motor is started. - motor.on("start", function(err, timestamp) { - console.log("start", timestamp); + motor.on("start", function() { + console.log("start", Date.now()); // Demonstrate motor stop in 2 seconds board.wait(2000, function() { @@ -36,8 +36,8 @@ board.on("ready", function() { }); // "stop" events fire when the motor is started. - motor.on("stop", function(err, timestamp) { - console.log("stop", timestamp); + motor.on("stop", function() { + console.log("stop", Date.now()); }); // Motor API diff --git a/eg/motor-brake.js b/eg/motor-brake.js index d811bbbb4..540359aa1 100644 --- a/eg/motor-brake.js +++ b/eg/motor-brake.js @@ -29,20 +29,20 @@ board.on("ready", function() { motor: motor }); - motor.on("start", function(err, timestamp) { - console.log("start", timestamp); + motor.on("start", function() { + console.log("start", Date.now()); }); - motor.on("stop", function(err, timestamp) { - console.log("automated stop on timer", timestamp); + motor.on("stop", function() { + console.log("automated stop on timer", Date.now()); }); - motor.on("brake", function(err, timestamp) { - console.log("automated brake on timer", timestamp); + motor.on("brake", function() { + console.log("automated brake on timer", Date.now()); }); - motor.on("forward", function(err, timestamp) { - console.log("forward", timestamp); + motor.on("forward", function() { + console.log("forward", Date.now()); // demonstrate switching to reverse after 5 seconds board.wait(5000, function() { @@ -50,8 +50,8 @@ board.on("ready", function() { }); }); - motor.on("reverse", function(err, timestamp) { - console.log("reverse", timestamp); + motor.on("reverse", function() { + console.log("reverse", Date.now()); // demonstrate stopping after 5 seconds board.wait(5000, function() { diff --git a/eg/motor-current.js b/eg/motor-current.js index 014b0a930..2529461ab 100644 --- a/eg/motor-current.js +++ b/eg/motor-current.js @@ -42,20 +42,20 @@ board.on("ready", function() { console.log("Motor A: " + this.value.toFixed(2) + "mA"); }); - motor.on("start", function(err, timestamp) { - console.log("start", timestamp); + motor.on("start", function() { + console.log("start", Date.now()); }); - motor.on("stop", function(err, timestamp) { - console.log("automated stop on timer", timestamp); + motor.on("stop", function() { + console.log("automated stop on timer", Date.now()); }); - motor.on("brake", function(err, timestamp) { - console.log("automated brake on timer", timestamp); + motor.on("brake", function() { + console.log("automated brake on timer", Date.now()); }); - motor.on("forward", function(err, timestamp) { - console.log("forward", timestamp); + motor.on("forward", function() { + console.log("forward", Date.now()); // demonstrate switching to reverse after 5 seconds board.wait(5000, function() { @@ -63,8 +63,8 @@ board.on("ready", function() { }); }); - motor.on("reverse", function(err, timestamp) { - console.log("reverse", timestamp); + motor.on("reverse", function() { + console.log("reverse", Date.now()); // demonstrate stopping after 5 seconds board.wait(5000, function() { diff --git a/eg/motor-directional.js b/eg/motor-directional.js index c6b5a8568..11ad9daf9 100644 --- a/eg/motor-directional.js +++ b/eg/motor-directional.js @@ -60,16 +60,16 @@ board.on("ready", function() { motor: motor }); - motor.on("start", function(err, timestamp) { - console.log("start", timestamp); + motor.on("start", function() { + console.log("start", Date.now()); }); - motor.on("stop", function(err, timestamp) { - console.log("automated stop on timer", timestamp); + motor.on("stop", function() { + console.log("automated stop on timer", Date.now()); }); - motor.on("forward", function(err, timestamp) { - console.log("forward", timestamp); + motor.on("forward", function() { + console.log("forward", Date.now()); // demonstrate switching to reverse after 5 seconds board.wait(5000, function() { @@ -77,8 +77,8 @@ board.on("ready", function() { }); }); - motor.on("reverse", function(err, timestamp) { - console.log("reverse", timestamp); + motor.on("reverse", function() { + console.log("reverse", Date.now()); // demonstrate stopping after 5 seconds board.wait(5000, function() { diff --git a/eg/motor-hbridge.js b/eg/motor-hbridge.js index 478b8ae6d..6b2001a49 100644 --- a/eg/motor-hbridge.js +++ b/eg/motor-hbridge.js @@ -33,16 +33,16 @@ board.on("ready", function() { motor: motor }); - motor.on("start", function(err, timestamp) { - console.log("start", timestamp); + motor.on("start", function() { + console.log("start", Date.now()); }); - motor.on("stop", function(err, timestamp) { - console.log("automated stop on timer", timestamp); + motor.on("stop", function() { + console.log("automated stop on timer", Date.now()); }); - motor.on("forward", function(err, timestamp) { - console.log("forward", timestamp); + motor.on("forward", function() { + console.log("forward", Date.now()); // demonstrate switching to reverse after 5 seconds board.wait(5000, function() { @@ -50,8 +50,8 @@ board.on("ready", function() { }); }); - motor.on("reverse", function(err, timestamp) { - console.log("reverse", timestamp); + motor.on("reverse", function() { + console.log("reverse", Date.now()); // demonstrate stopping after 5 seconds board.wait(5000, function() { diff --git a/eg/motor.js b/eg/motor.js index d6e48f5d8..fe01396ae 100644 --- a/eg/motor.js +++ b/eg/motor.js @@ -19,8 +19,8 @@ board.on("ready", function() { // Motor Event API // "start" events fire when the motor is started. - motor.on("start", function(err, timestamp) { - console.log("start", timestamp); + motor.on("start", function() { + console.log("start", Date.now()); // Demonstrate motor stop in 2 seconds board.wait(2000, function() { @@ -29,8 +29,8 @@ board.on("ready", function() { }); // "stop" events fire when the motor is started. - motor.on("stop", function(err, timestamp) { - console.log("stop", timestamp); + motor.on("stop", function() { + console.log("stop", Date.now()); }); // Motor API diff --git a/eg/navigator-original.js b/eg/navigator-original.js index 8b05e995a..a17ae2d6b 100644 --- a/eg/navigator-original.js +++ b/eg/navigator-original.js @@ -398,7 +398,7 @@ board.on("ready", function() { // [2] Sonar "change" events are emitted when the value of a // distance reading has changed since the previous reading // - sonar.on("change", function(err) { + sonar.on("change", function() { var turnTo; // Detect collideAt diff --git a/eg/navigator.js b/eg/navigator.js index d2fb0bc73..f09838064 100644 --- a/eg/navigator.js +++ b/eg/navigator.js @@ -458,7 +458,7 @@ Navigator.prototype.pivot = function(which, time) { // distance reading has changed since the previous reading // // TODO: Avoid false positives? - ping.on("data", function(err) { + ping.on("data", function() { var release = 750, distance = Math.abs(this.inches), isReverse = false, diff --git a/eg/nodeconf-navigator.js b/eg/nodeconf-navigator.js index 5c782410a..4e890e0de 100644 --- a/eg/nodeconf-navigator.js +++ b/eg/nodeconf-navigator.js @@ -416,7 +416,7 @@ board.on("ready", function() { // distance reading has changed since the previous reading // // TODO: Avoid false positives? - ping.on("data", function(err) { + ping.on("data", function() { var release = 750, distance = Math.abs(this.inches), isReverse = false, diff --git a/eg/nodeconf-radar.js b/eg/nodeconf-radar.js index 6d34f2818..9ce36c44c 100644 --- a/eg/nodeconf-radar.js +++ b/eg/nodeconf-radar.js @@ -109,7 +109,7 @@ board.on("ready", function() { soi = socket; - ping.on("read", function() { + ping.on("data", function() { if (last !== degrees) { io.sockets.emit("ping", { diff --git a/eg/nodeconf-slider.js b/eg/nodeconf-slider.js index 4f5c73501..6875a2b76 100644 --- a/eg/nodeconf-slider.js +++ b/eg/nodeconf-slider.js @@ -1,21 +1,10 @@ -var five = require("../lib/johnny-five.js"), - board, slider, servo, scalingRange; - -board = new five.Board(); +var five = require("../lib/johnny-five.js"); +var board = new five.Board(); board.on("ready", function() { + var slider = new five.Sensor("A0"); - slider = new five.Sensor({ - pin: "A0", - freq: 50 - }); - - // log out the slider values to the console. - slider.on("slide", function(err, value) { - if (err) { - console.log("error: ", err); - } else { - console.log(Math.floor(this.value)); - } + slider.on("slide", function(value) { + console.log(Math.floor(this.value)); }); }); diff --git a/eg/nunchuk.js b/eg/nunchuk.js index 92c2c9cfa..3ce2f7af4 100644 --- a/eg/nunchuk.js +++ b/eg/nunchuk.js @@ -35,7 +35,7 @@ board.on("ready", function() { // Fired when the joystick detects a change in // axis position. // - nunchuk.joystick.on("change", function(err, event) { + nunchuk.joystick.on("change", function(event) { console.log( "joystick " + event.axis, event.target[event.axis], @@ -48,7 +48,7 @@ board.on("ready", function() { // Fired when the accelerometer detects a change in // axis position. // - nunchuk.accelerometer.on("change", function(err, event) { + nunchuk.accelerometer.on("change", function(event) { console.log( "accelerometer " + event.axis, event.target[event.axis], @@ -80,7 +80,7 @@ board.on("ready", function() { ["down", "up", "hold"].forEach(function(type) { - nunchuk.on(type, function(err, event) { + nunchuk.on(type, function(event) { console.log( event.target.which + " is " + type, diff --git a/eg/ping.js b/eg/ping.js index 1aaacab18..b28f94101 100644 --- a/eg/ping.js +++ b/eg/ping.js @@ -1,20 +1,13 @@ -var five = require("../lib/johnny-five.js"), - board, ping; - -board = new five.Board(); +var five = require("../lib/johnny-five.js"); +var board = new five.Board(); board.on("ready", function() { // Create a new `ping` hardware instance. - ping = new five.Ping(7); + var ping = new five.Ping(7); // Properties - // ping.microseconds - // - // Roundtrip distance in microseconds - // - // ping.inches // // Calculated distance to object in inches @@ -25,16 +18,7 @@ board.on("ready", function() { // Calculated distance to object in centimeters // - - // Ping Event API - - // "data" get the current reading from the ping - ping.on("data", function(err, value) { - console.log("data", value); - }); - - ping.on("change", function(err, value) { - + ping.on("change", function() { console.log(typeof this.inches); console.log("Object is " + this.inches + "inches away"); }); diff --git a/eg/proximity.js b/eg/proximity.js index 8344601bd..e1578f26e 100644 --- a/eg/proximity.js +++ b/eg/proximity.js @@ -40,11 +40,11 @@ five.Board().on("ready", function() { // Fired following a "motionstart" event // when no movement has occurred in X ms // - prox.on("motionstart", function(err, timestamp) { + prox.on("motionstart", function() { led.on(); }); - prox.on("motionend", function(err, timestamp) { + prox.on("motionend", function() { led.off(); }); diff --git a/eg/slider-log.js b/eg/slider-log.js index 75c645d6d..546d2d735 100644 --- a/eg/slider-log.js +++ b/eg/slider-log.js @@ -1,21 +1,11 @@ -var five = require("../lib/johnny-five.js"), - board, slider, servo, scalingRange; - -board = new five.Board(); +var five = require("../lib/johnny-five.js"); +var board = new five.Board(); board.on("ready", function() { - slider = new five.Sensor({ - pin: "A0", - freq: 50 - }); + var slider = new five.Sensor("A0"); - // log out the slider values to the console. - slider.scale(0, 100).on("slide", function(err, value) { - if (err) { - console.log("error: ", err); - } else { - console.log(Math.floor(this.value)); - } + slider.scale(0, 100).on("slide", function() { + console.log(Math.floor(this.value)); }); }); diff --git a/eg/slider-pan.js b/eg/slider-pan.js index 03452890d..468c9dfac 100644 --- a/eg/slider-pan.js +++ b/eg/slider-pan.js @@ -1,27 +1,14 @@ -var five = require("../lib/johnny-five.js"), - board, slider, tilt, scalingRange; - -board = new five.Board(); +var five = require("../lib/johnny-five.js"); +var board = new five.Board(); board.on("ready", function() { - scalingRange = [0, 170]; - - slider = new five.Sensor({ - pin: "A0", - freq: 50 - }); + var slider = new five.Sensor("A0"); + var tilt = new five.Servo(9); - tilt = new five.Servo({ - pin: 9, - range: scalingRange - }); - - slider.scale(scalingRange).on("slide", function(err, value) { + slider.scale([0, 180]).on("slide", function() { // The slider's value will be scaled to match the tilt servo range - - tilt.to(Math.floor(this.value)); - + tilt.to(this.value); }); }); diff --git a/eg/slider-servo-control.js b/eg/slider-servo-control.js index fd203534f..468c9dfac 100644 --- a/eg/slider-servo-control.js +++ b/eg/slider-servo-control.js @@ -1,28 +1,14 @@ -var five = require("../lib/johnny-five.js"), - board, slider, servo, scalingRange; - -board = new five.Board(); +var five = require("../lib/johnny-five.js"); +var board = new five.Board(); board.on("ready", function() { - scalingRange = [0, 170]; - - slider = new five.Sensor({ - pin: "A0", - freq: 50 - }); - - servo = new five.Servo({ - pin: 9, - range: scalingRange - }); - - - // The slider's value will be scaled to match the servo's movement range - - slider.scale(scalingRange).on("slide", function(err, value) { + var slider = new five.Sensor("A0"); + var tilt = new five.Servo(9); - servo.to(Math.floor(this.value)); + slider.scale([0, 180]).on("slide", function() { + // The slider's value will be scaled to match the tilt servo range + tilt.to(this.value); }); }); diff --git a/eg/sonar-scan.js b/eg/sonar-scan.js index ca1ce69e2..0cf4ff4bf 100644 --- a/eg/sonar-scan.js +++ b/eg/sonar-scan.js @@ -110,7 +110,7 @@ board.on("ready", function() { // [2] Sonar "change" events are emitted when the value of a // distance reading has changed since the previous reading // - sonar.on("change", function(err) { + sonar.on("change", function() { var turnTo; // Detect collision diff --git a/eg/temperature-ds18b20.js b/eg/temperature-ds18b20.js index e52fc7ef2..5dc583804 100644 --- a/eg/temperature-ds18b20.js +++ b/eg/temperature-ds18b20.js @@ -1,13 +1,14 @@ var five = require("../lib/johnny-five"); five.Board().on("ready", function() { - // This requires OneWire support using the ConfigurableFirmata + // This requires OneWire support using ConfigurableFirmata + // https://github.com/firmata/arduino/tree/configurable var temperature = new five.Temperature({ controller: "DS18B20", pin: 2 }); - temperature.on("data", function(err, data) { + temperature.on("data", function(data) { console.log(data.celsius + "°C", data.fahrenheit + "°F"); }); }); diff --git a/eg/temperature-lm35.js b/eg/temperature-lm35.js index 7a11515fe..84c685387 100644 --- a/eg/temperature-lm35.js +++ b/eg/temperature-lm35.js @@ -6,7 +6,7 @@ five.Board().on("ready", function() { pin: "A0" }); - temperature.on("data", function(err, data) { + temperature.on("data", function(data) { console.log(data.celsius + "°C", data.fahrenheit + "°F"); }); }); diff --git a/eg/temperature-tmp36.js b/eg/temperature-tmp36.js index 7677959c5..16a89700c 100644 --- a/eg/temperature-tmp36.js +++ b/eg/temperature-tmp36.js @@ -6,7 +6,7 @@ five.Board().on("ready", function() { pin: "A0" }); - temperature.on("data", function(err, data) { + temperature.on("data", function(data) { console.log(data.celsius + "°C", data.fahrenheit + "°F"); }); }); diff --git a/eg/tinkerkit-accelerometer.js b/eg/tinkerkit-accelerometer.js index 0a0ccb9e6..33d3bde88 100644 --- a/eg/tinkerkit-accelerometer.js +++ b/eg/tinkerkit-accelerometer.js @@ -1,7 +1,5 @@ -var five = require("../lib/johnny-five.js"), - board, accel; - -board = new five.Board(); +var five = require("../lib/johnny-five.js"); +var board = new five.Board(); board.on("ready", function() { @@ -12,7 +10,7 @@ board.on("ready", function() { // - Dual Axis http://www.tinkerkit.com/accelerometer/ // - accel = new five.Accelerometer({ + var accel = new five.Accelerometer({ pins: ["I0", "I1"], freq: 100 }); @@ -24,7 +22,7 @@ board.on("ready", function() { // Fires once every N ms, equal to value of freg // Defaults to 500ms // - accel.on("acceleration", function(err, timestamp) { + accel.on("acceleration", function() { console.log("acceleration", this.pitch, this.roll); }); @@ -33,7 +31,7 @@ board.on("ready", function() { // // Fires only when X, Y or Z has changed // - accel.on("axischange", function(err, timestamp) { + accel.on("axischange", function() { console.log("axischange", this.raw); }); diff --git a/lib/accelerometer.js b/lib/accelerometer.js index 166c4b5ec..d372900b1 100644 --- a/lib/accelerometer.js +++ b/lib/accelerometer.js @@ -56,7 +56,7 @@ var Controllers = { state.sensitivity = opts.sensitivity || 16384; - driver.on("data", function(err, data) { + driver.on("data", function(data) { dataHandler.call(this, data.accelerometer); }.bind(this)); } diff --git a/lib/button.js b/lib/button.js index bf6855928..9a728d83f 100644 --- a/lib/button.js +++ b/lib/button.js @@ -126,7 +126,7 @@ function Button(opts) { timeout = setTimeout(function() { if (this.isDown) { - this.emit("hold", err); + this.emit("hold"); } }.bind(this), this.holdtime); } diff --git a/lib/gyro.js b/lib/gyro.js index 45cf34221..d0e6ac714 100644 --- a/lib/gyro.js +++ b/lib/gyro.js @@ -67,7 +67,7 @@ var Controllers = { state.sensitivity = opts.sensitivity || 131; - driver.on("data", function(err, data) { + driver.on("data", function(data) { dataHandler.call(this, data.gyro); }.bind(this)); } diff --git a/lib/imu.js b/lib/imu.js index 86dfc3cfa..920259156 100644 --- a/lib/imu.js +++ b/lib/imu.js @@ -56,7 +56,7 @@ var Drivers = { z: int16(data[12], data[13]) }; - this.emit("data", null, this.data); + this.emit("data", this.data); }.bind(this)); }, }, diff --git a/lib/ir.js b/lib/ir.js index f50fc9e54..8b44c4b49 100644 --- a/lib/ir.js +++ b/lib/ir.js @@ -29,15 +29,14 @@ Devices = { data: function(read, data) { var state = priv.get(this).state, value = data[0], - timestamp = new Date(), - err = null; + timestamp = new Date(); if (value !== state && value === 1) { - this.emit("motionstart", err, timestamp); + this.emit("motionstart", timestamp); } if (state === 1 && value === 3) { - this.emit("motionend", err, timestamp); + this.emit("motionend", timestamp); } priv.set(this, { @@ -78,11 +77,11 @@ Devices = { }; // if ( temp.left < 200 ) { - // this.emit( "left", err, timestamp ); + // this.emit( "left", timestamp ); // } // if ( temp.right < 200 ) { - // this.emit( "right", err, timestamp ); + // this.emit( "right", timestamp ); // } diff --git a/lib/joystick.js b/lib/joystick.js index 8835f0656..9478cea58 100644 --- a/lib/joystick.js +++ b/lib/joystick.js @@ -87,7 +87,7 @@ function Joystick(opts) { // Throttle event emitter setInterval(function() { - this.emit("axismove", err, new Date()); + this.emit("axismove", new Date()); }.bind(this), this.freq); diff --git a/lib/motor.js b/lib/motor.js index 30675715d..1264bb3ac 100644 --- a/lib/motor.js +++ b/lib/motor.js @@ -257,7 +257,7 @@ var Devices = { saveSpeed: false, braking: true }); - this.emit("brake", null, new Date()); + this.emit("brake", new Date()); if (duration) { var motor = this; @@ -561,7 +561,7 @@ Motor.prototype.start = function(speed) { // "start" event is fired when the motor is started if (speed > 0) { - this.emit("start", null, new Date()); + this.emit("start", new Date()); } return this; @@ -572,7 +572,7 @@ Motor.prototype.stop = function() { speed: 0, saveSpeed: false }); - this.emit("stop", null, new Date()); + this.emit("stop", new Date()); return this; }; @@ -591,7 +591,7 @@ Motor.prototype.brake = function(duration) { saveSpeed: false, braking: true }); - this.emit("brake", null, new Date()); + this.emit("brake", new Date()); if (duration) { var motor = this; @@ -606,7 +606,7 @@ Motor.prototype.brake = function(duration) { Motor.prototype.release = function() { this.resume(); - this.emit("release", null, new Date()); + this.emit("release", new Date()); return this; }; diff --git a/lib/ping.js b/lib/ping.js index 30d6e6a08..b0145f988 100644 --- a/lib/ping.js +++ b/lib/ping.js @@ -55,23 +55,14 @@ function Ping(opts) { return; } - // median = samples.sort()[samples.length / 2 | 0]; - - // if (!median) { - // median = last; - // } - - // @DEPRECATE - this.emit("read", err, state.value); - // The "read" event has been deprecated in // favor of a "data" event. - this.emit("data", err, state.value); + this.emit("data", state.value); // If the state.value for this interval is not the same as the // state.value in the last interval, fire a "change" event. if (state.value !== last) { - this.emit("change", err, state.value); + this.emit("change", state.value); } // Store state.value for comparison in next interval diff --git a/lib/pir.js b/lib/pir.js index 4ec782934..6f2720058 100644 --- a/lib/pir.js +++ b/lib/pir.js @@ -41,13 +41,13 @@ function Pir(opts) { // "motionstart" event fired when motion occurs // within the observable range of the PIR sensor if (data) { - this.emit("motionstart", err, timestamp); + this.emit("motionstart", timestamp); } // "motionend" event fired when motion has ceased // within the observable range of the PIR sensor if (!data) { - this.emit("motionend", err, timestamp); + this.emit("motionend", timestamp); } } @@ -56,12 +56,12 @@ function Pir(opts) { if (!this.isCalibrated) { this.isCalibrated = true; this.value = +data; - this.emit("calibrated", err, timestamp); + this.emit("calibrated", timestamp); } }.bind(this)); setInterval(function() { - this.emit("data", null, Date.now()); + this.emit("data", Date.now()); }.bind(this), this.freq); } diff --git a/lib/reflectancearray.js b/lib/reflectancearray.js index e54440cd7..10fc59a60 100644 --- a/lib/reflectancearray.js +++ b/lib/reflectancearray.js @@ -58,11 +58,11 @@ function onData(sensorState, value) { allRead = __.every(state.sensorStates, "dataReceived"); if (allRead) { - this.emit("data", null, this.raw); + this.emit("data", this.raw); if (this.isCalibrated) { - this.emit("calibratedData", null, this.values); - this.emit("line", null, this.line); + this.emit("calibratedData", this.values); + this.emit("line", this.line); } state.sensorStates.forEach(function(sensorState) { @@ -223,7 +223,7 @@ ReflectanceArray.prototype.disable = function() { ReflectanceArray.prototype.calibrate = function() { var state = priv.get(this); - this.once("data", function(err, values) { + this.once("data", function(values) { values.forEach(function(value, i) { if (state.calibration.min[i] === undefined || value < state.calibration.min[i]) { state.calibration.min[i] = value; diff --git a/lib/sensor.js b/lib/sensor.js index 44b03fd3f..0f773c9b4 100644 --- a/lib/sensor.js +++ b/lib/sensor.js @@ -81,11 +81,11 @@ function Sensor(opts) { // For digital sensors, skip the analog // noise filtering provided below. if (opts.type === "digital") { - this.emit("data", err, value); + this.emit("data", value); if (last !== value) { aliases.change.forEach(function(change) { - this.emit(change, err, value); + this.emit(change, value); }, this); } } else { @@ -121,10 +121,10 @@ function Sensor(opts) { }(samples)); // @DEPRECATE - this.emit("read", err, median); + this.emit("read", median); // The "read" event has been deprecated in // favor of a "data" event. - this.emit("data", err, median); + this.emit("data", median); // If the median value for this interval is outside last +/- a threshold // fire a change event @@ -137,7 +137,7 @@ function Sensor(opts) { // the last value to trigger a change event if (median < low || median > high) { aliases.change.forEach(function(change) { - this.emit(change, err, median); + this.emit(change, median); }, this); } @@ -151,11 +151,11 @@ function Sensor(opts) { } if (boundary) { - this.emit("limit", err, { + this.emit("limit", { boundary: boundary, value: median }); - this.emit("limit:" + boundary, err, median); + this.emit("limit:" + boundary, median); } } diff --git a/lib/sonar.js b/lib/sonar.js index 85f8f1489..f6b57cc9a 100644 --- a/lib/sonar.js +++ b/lib/sonar.js @@ -72,19 +72,14 @@ function Sonar(opts) { state.median = state.samples.sort()[Math.floor(state.samples.length / 2)]; this.value = state.median; - // @DEPRECATE - this.emit("read", err, state.median); - // The "read" event has been deprecated in - // favor of a "data" event. - this.emit("data", err, state.median); - + this.emit("data", state.median); // If the state.median value for this interval is not the same as the // state.median value in the last interval, fire a "change" event. // if (state.last && state.median && (state.median.toFixed(1) !== state.last.toFixed(1))) { - this.emit("change", err, state.median); + this.emit("change", state.median); } // Store this media value for comparison diff --git a/lib/temperature.js b/lib/temperature.js index 753a0bdba..cb308297f 100644 --- a/lib/temperature.js +++ b/lib/temperature.js @@ -142,7 +142,7 @@ var Controllers = { value: function(opts, dataHandler) { var IMU = require("../lib/imu"); var driver = IMU.Drivers.get(this.board, "MPU6050", opts); - driver.on("data", function(err, data) { + driver.on("data", function(data) { dataHandler.call(this, data.temperature); }.bind(this)); } @@ -246,11 +246,11 @@ function Temperature(opts) { kelvin: this.kelvin }; - this.emit("data", null, data); + this.emit("data", data); if (this.celsius !== last) { last = this.celsius; - this.emit("change", null, data); + this.emit("change", data); } }.bind(this), freq); } diff --git a/lib/wii.js b/lib/wii.js index 25035f103..4c2ec108d 100644 --- a/lib/wii.js +++ b/lib/wii.js @@ -125,11 +125,7 @@ function Wii(opts) { target: this }); - // @DEPRECATE - this.emit("read", null, event); - // The "read" event has been deprecated in - // favor of a "data" event. - this.emit("data", null, event); + this.emit("data", event); }.bind(this), this.freq); } diff --git a/test/reflectancearray.js b/test/reflectancearray.js index d4bffac9a..ab7400e47 100644 --- a/test/reflectancearray.js +++ b/test/reflectancearray.js @@ -107,14 +107,14 @@ exports["ReflectanceArray"] = { test.expect(1); this.eyes.on("data", dataSpy); - + this.sendAnalogValue(0, 55); this.sendAnalogValue(1, 66); this.sendAnalogValue(2, 77); this.clock.tick(25); - - test.deepEqual(dataSpy.getCall(0).args[1], [55, 66, 77]); - + + test.deepEqual(dataSpy.getCall(0).args[0], [55, 66, 77]); + test.done(); }, @@ -229,14 +229,14 @@ exports["ReflectanceArray"] = { }); this.eyes.on("calibratedData", dataSpy); - + this.sendAnalogValue(0, testValues[0].raw); this.sendAnalogValue(1, testValues[1].raw); this.sendAnalogValue(2, testValues[2].raw); this.clock.tick(25); - - test.deepEqual(dataSpy.getCall(0).args[1], __.pluck(testValues, "expected")); - + + test.deepEqual(dataSpy.getCall(0).args[0], __.pluck(testValues, "expected")); + test.done(); }, @@ -250,15 +250,15 @@ exports["ReflectanceArray"] = { }); this.eyes.on("line", dataSpy); - + this.sendAnalogValue(0, 50); this.sendAnalogValue(1, 300); this.sendAnalogValue(2, 50); this.clock.tick(25); - - test.deepEqual(dataSpy.getCall(0).args[1], 1000); + + test.deepEqual(dataSpy.getCall(0).args[0], 1000); test.equal(this.eyes.isOnLine, true); - + test.done(); }, @@ -272,21 +272,21 @@ exports["ReflectanceArray"] = { }); this.eyes.on("line", dataSpy); - + this.sendAnalogValue(0, 50); this.sendAnalogValue(1, 300); this.sendAnalogValue(2, 435); this.clock.tick(25); - - test.deepEqual(dataSpy.getCall(0).args[1], 1600); + + test.deepEqual(dataSpy.getCall(0).args[0], 1600); test.equal(this.eyes.isOnLine, true); - + test.done(); }, isOnLine: function(test) { test.expect(1); - + this.eyes.loadCalibration({ min: [30, 30, 30], max: [600, 600, 600] @@ -296,9 +296,9 @@ exports["ReflectanceArray"] = { this.sendAnalogValue(1, 50); this.sendAnalogValue(2, 50); this.clock.tick(25); - + test.equal(this.eyes.isOnLine, false); - + test.done(); } }; diff --git a/test/sensor.js b/test/sensor.js index e2b06edd1..724eb57c0 100644 --- a/test/sensor.js +++ b/test/sensor.js @@ -108,8 +108,8 @@ exports["Sensor - Analog"] = { callback(512); this.clock.tick(25); - test.equal(spy.getCall(0).args[1], 1023); - test.equal(spy.getCall(1).args[1], 512); + test.equal(spy.getCall(0).args[0], 1023); + test.equal(spy.getCall(1).args[0], 512); test.done(); }, @@ -288,11 +288,11 @@ exports["Sensor - Digital"] = { callback(0); this.clock.tick(25); - test.equal(data.getCall(0).args[1], 1); - test.equal(data.getCall(1).args[1], 0); + test.equal(data.getCall(0).args[0], 1); + test.equal(data.getCall(1).args[0], 0); - test.equal(change.getCall(0).args[1], 1); - test.equal(change.getCall(1).args[1], 0); + test.equal(change.getCall(0).args[0], 1); + test.equal(change.getCall(1).args[0], 0); test.done(); }, @@ -318,8 +318,8 @@ exports["Sensor - Digital"] = { callback(0); this.clock.tick(25); - test.equal(spy.getCall(0).args[1], 1); - test.equal(spy.getCall(1).args[1], 0); + test.equal(spy.getCall(0).args[0], 1); + test.equal(spy.getCall(1).args[0], 0); test.done(); }, diff --git a/test/temperature.js b/test/temperature.js index 212e2a0b7..4a85b12aa 100644 --- a/test/temperature.js +++ b/test/temperature.js @@ -64,14 +64,14 @@ exports["Temperature -- LM35"] = { this.temperature.on("data", spy); raw(100); - + this.clock.tick(100); test.ok(spy.calledOnce); - test.equals(Math.round(spy.args[0][1].celsius), 49); - test.equals(Math.round(spy.args[0][1].fahrenheit), 120); - test.equals(Math.round(spy.args[0][1].kelvin), 322); - + test.equals(Math.round(spy.getCall(0).args[0].celsius), 49); + test.equals(Math.round(spy.getCall(0).args[0].fahrenheit), 120); + test.equals(Math.round(spy.getCall(0).args[0].kelvin), 322); + test.done(); }, @@ -90,7 +90,7 @@ exports["Temperature -- LM35"] = { raw(200); this.clock.tick(100); - + raw(100); this.clock.tick(100); @@ -136,14 +136,14 @@ exports["Temperature -- TMP36"] = { this.temperature.on("data", spy); raw(150); - + this.clock.tick(100); test.ok(spy.calledOnce); - test.equals(Math.round(spy.args[0][1].celsius), 23); - test.equals(Math.round(spy.args[0][1].fahrenheit), 74); - test.equals(Math.round(spy.args[0][1].kelvin), 296); - + test.equals(Math.round(spy.getCall(0).args[0].celsius), 23); + test.equals(Math.round(spy.getCall(0).args[0].fahrenheit), 74); + test.equals(Math.round(spy.getCall(0).args[0].kelvin), 296); + test.done(); } }; @@ -161,7 +161,7 @@ function createDS18B20(pin, address) { exports["Temperature -- DS18B20"] = { setUp: function(done) { - + this.pin = 2; this.clock = sinon.useFakeTimers(); this.sendOneWireConfig = sinon.spy(board.io, "sendOneWireConfig"); @@ -195,7 +195,7 @@ exports["Temperature -- DS18B20"] = { search = this.sendOneWireSearch.args[0][1]; search(null, [device]); - + test.ok(this.sendOneWireConfig.calledOnce); test.equals(this.sendOneWireConfig.args[0][0], this.pin); @@ -228,7 +228,7 @@ exports["Temperature -- DS18B20"] = { test.ok(this.sendOneWireWrite.calledOnce); test.equals(this.sendOneWireWrite.args[0][0], this.pin); - test.equals(this.sendOneWireWrite.args[0][1], device); + test.equals(this.sendOneWireWrite.args[0][1], device); test.equals(this.sendOneWireWrite.args[0][2], 0x44); test.ok(this.sendOneWireDelay.calledOnce); @@ -245,9 +245,9 @@ exports["Temperature -- DS18B20"] = { this.clock.tick(100); - test.equals(Math.round(spy.args[0][1].celsius), 32); - test.equals(Math.round(spy.args[0][1].fahrenheit), 90); - test.equals(Math.round(spy.args[0][1].kelvin), 305); + test.equals(Math.round(spy.getCall(0).args[0].celsius), 32); + test.equals(Math.round(spy.getCall(0).args[0].fahrenheit), 90); + test.equals(Math.round(spy.getCall(0).args[0].kelvin), 305); test.done(); }, @@ -323,10 +323,10 @@ exports["Temperature -- MPU6050"] = { this.clock.tick(100); test.ok(spy.calledOnce); - test.equals(Math.round(spy.args[0][1].celsius), 49); - test.equals(Math.round(spy.args[0][1].fahrenheit), 121); - test.equals(Math.round(spy.args[0][1].kelvin), 323); - + test.equals(Math.round(spy.getCall(0).args[0].celsius), 49); + test.equals(Math.round(spy.getCall(0).args[0].fahrenheit), 121); + test.equals(Math.round(spy.getCall(0).args[0].kelvin), 323); + test.done(); } }; @@ -344,7 +344,7 @@ exports["Temperature -- ANALOG"] = { setUp: function(done) { this.clock = sinon.useFakeTimers(); this.analogRead = sinon.spy(board.io, "analogRead"); - + done(); }, @@ -363,14 +363,14 @@ exports["Temperature -- ANALOG"] = { temperature.on("data", spy); raw(50); - + this.clock.tick(100); test.ok(spy.calledOnce); - test.equals(Math.round(spy.args[0][1].celsius), 50); - test.equals(Math.round(spy.args[0][1].fahrenheit), 122); - test.equals(Math.round(spy.args[0][1].kelvin), 323); - + test.equals(Math.round(spy.getCall(0).args[0].celsius), 50); + test.equals(Math.round(spy.getCall(0).args[0].fahrenheit), 122); + test.equals(Math.round(spy.getCall(0).args[0].kelvin), 323); + test.done(); }, @@ -384,14 +384,14 @@ exports["Temperature -- ANALOG"] = { temperature.on("data", spy); raw(50); - + this.clock.tick(100); test.ok(spy.calledOnce); - test.equals(Math.round(spy.args[0][1].celsius), 22); - test.equals(Math.round(spy.args[0][1].fahrenheit), 72); - test.equals(Math.round(spy.args[0][1].kelvin), 295); - + test.equals(Math.round(spy.getCall(0).args[0].celsius), 22); + test.equals(Math.round(spy.getCall(0).args[0].fahrenheit), 72); + test.equals(Math.round(spy.getCall(0).args[0].kelvin), 295); + test.done(); } }; @@ -427,14 +427,14 @@ exports["Temperature -- GROVE"] = { this.temperature.on("data", spy); raw(659); - + this.clock.tick(100); test.ok(spy.calledOnce); - test.equals(Math.round(spy.args[0][1].celsius), 23); - test.equals(Math.round(spy.args[0][1].fahrenheit), 74); - test.equals(Math.round(spy.args[0][1].kelvin), 296); - + test.equals(Math.round(spy.getCall(0).args[0].celsius), 23); + test.equals(Math.round(spy.getCall(0).args[0].fahrenheit), 74); + test.equals(Math.round(spy.getCall(0).args[0].kelvin), 296); + test.done(); } };