diff --git a/docs/accelerometer-pan-tilt.md b/docs/accelerometer-pan-tilt.md index 6e680595e..c555c7dd0 100644 --- a/docs/accelerometer-pan-tilt.md +++ b/docs/accelerometer-pan-tilt.md @@ -50,7 +50,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/docs/classic-controller.md b/docs/classic-controller.md index 28a5589a3..110666aca 100644 --- a/docs/classic-controller.md +++ b/docs/classic-controller.md @@ -58,7 +58,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], @@ -66,7 +66,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], @@ -98,7 +98,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/docs/ir-motion.md b/docs/ir-motion.md index 5cdc39f34..bac3691c8 100644 --- a/docs/ir-motion.md +++ b/docs/ir-motion.md @@ -39,19 +39,19 @@ board.on("ready", function() { // "calibrated" occurs once, at the beginning of a session, motion.on("calibrated", function() { - console.log("calibrated"); + 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() { - console.log("motionstart"); + 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() { - console.log("motionend"); + console.log("motionend", Date.now()); }); }); diff --git a/docs/ir-reflect-array.md b/docs/ir-reflect-array.md index c4919a474..58da06af8 100644 --- a/docs/ir-reflect-array.md +++ b/docs/ir-reflect-array.md @@ -29,7 +29,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(); @@ -37,7 +37,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/docs/ir-reflect.md b/docs/ir-reflect.md index d68d01157..8fac04911 100644 --- a/docs/ir-reflect.md +++ b/docs/ir-reflect.md @@ -39,7 +39,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/docs/joystick-motor-led.md b/docs/joystick-motor-led.md index 5798b04e8..e0a85ded7 100644 --- a/docs/joystick-motor-led.md +++ b/docs/joystick-motor-led.md @@ -51,7 +51,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/docs/motor-3-pin.md b/docs/motor-3-pin.md index fd02ad5b5..a1e7765c2 100644 --- a/docs/motor-3-pin.md +++ b/docs/motor-3-pin.md @@ -40,7 +40,7 @@ board.on("ready", function() { pwm: 9 dir: 8 cdir: 11 - + Motor B pwm: 10 dir: 12 @@ -51,7 +51,7 @@ board.on("ready", function() { pwm: 6 dir: 5 cdir: 7 - + Motor B pwm: 4 dir: 3 @@ -75,20 +75,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() { @@ -96,8 +96,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/docs/motor-PCA9685.md b/docs/motor-PCA9685.md index fe04d3c69..d0da3b1ef 100644 --- a/docs/motor-PCA9685.md +++ b/docs/motor-PCA9685.md @@ -47,7 +47,7 @@ board.on("ready", function() { // "start" events fire when the motor is started. motor.on("start", function() { - console.log("start"); + console.log("start", Date.now()); // Demonstrate motor stop in 2 seconds board.wait(2000, function() { @@ -57,7 +57,7 @@ board.on("ready", function() { // "stop" events fire when the motor is started. motor.on("stop", function() { - console.log("stop"); + console.log("stop", Date.now()); }); // Motor API diff --git a/docs/motor-brake.md b/docs/motor-brake.md index 78c0275a3..0c173eb9a 100644 --- a/docs/motor-brake.md +++ b/docs/motor-brake.md @@ -61,19 +61,19 @@ board.on("ready", function() { }); motor.on("start", function() { - console.log("start"); + console.log("start", Date.now()); }); motor.on("stop", function() { - console.log("automated stop on timer"); + console.log("automated stop on timer", Date.now()); }); motor.on("brake", function() { - console.log("automated brake on timer"); + console.log("automated brake on timer", Date.now()); }); motor.on("forward", function() { - console.log("forward"); + console.log("forward", Date.now()); // demonstrate switching to reverse after 5 seconds board.wait(5000, function() { @@ -82,7 +82,7 @@ board.on("ready", function() { }); motor.on("reverse", function() { - console.log("reverse"); + console.log("reverse", Date.now()); // demonstrate stopping after 5 seconds board.wait(5000, function() { diff --git a/docs/motor-current.md b/docs/motor-current.md index 298fa6251..7d12b40d8 100644 --- a/docs/motor-current.md +++ b/docs/motor-current.md @@ -74,19 +74,19 @@ board.on("ready", function() { }); motor.on("start", function() { - console.log("start"); + console.log("start", Date.now()); }); motor.on("stop", function() { - console.log("automated stop on timer"); + console.log("automated stop on timer", Date.now()); }); motor.on("brake", function() { - console.log("automated brake on timer"); + console.log("automated brake on timer", Date.now()); }); motor.on("forward", function() { - console.log("forward"); + console.log("forward", Date.now()); // demonstrate switching to reverse after 5 seconds board.wait(5000, function() { @@ -95,7 +95,7 @@ board.on("ready", function() { }); motor.on("reverse", function() { - console.log("reverse"); + console.log("reverse", Date.now()); // demonstrate stopping after 5 seconds board.wait(5000, function() { diff --git a/docs/motor-directional.md b/docs/motor-directional.md index ee9ad04f2..cfa881382 100644 --- a/docs/motor-directional.md +++ b/docs/motor-directional.md @@ -92,15 +92,15 @@ board.on("ready", function() { }); motor.on("start", function() { - console.log("start"); + console.log("start", Date.now()); }); motor.on("stop", function() { - console.log("automated stop on timer"); + console.log("automated stop on timer", Date.now()); }); motor.on("forward", function() { - console.log("forward"); + console.log("forward", Date.now()); // demonstrate switching to reverse after 5 seconds board.wait(5000, function() { @@ -109,7 +109,7 @@ board.on("ready", function() { }); motor.on("reverse", function() { - console.log("reverse"); + console.log("reverse", Date.now()); // demonstrate stopping after 5 seconds board.wait(5000, function() { diff --git a/docs/motor-hbridge.md b/docs/motor-hbridge.md index 08af20320..9a12bdf1a 100644 --- a/docs/motor-hbridge.md +++ b/docs/motor-hbridge.md @@ -65,15 +65,15 @@ board.on("ready", function() { }); motor.on("start", function() { - console.log("start"); + console.log("start", Date.now()); }); motor.on("stop", function() { - console.log("automated stop on timer"); + console.log("automated stop on timer", Date.now()); }); motor.on("forward", function() { - console.log("forward"); + console.log("forward", Date.now()); // demonstrate switching to reverse after 5 seconds board.wait(5000, function() { @@ -82,7 +82,7 @@ board.on("ready", function() { }); motor.on("reverse", function() { - console.log("reverse"); + console.log("reverse", Date.now()); // demonstrate stopping after 5 seconds board.wait(5000, function() { diff --git a/docs/motor.md b/docs/motor.md index 304a7e633..d7ca6ee41 100644 --- a/docs/motor.md +++ b/docs/motor.md @@ -51,7 +51,7 @@ board.on("ready", function() { // "start" events fire when the motor is started. motor.on("start", function() { - console.log("start"); + console.log("start", Date.now()); // Demonstrate motor stop in 2 seconds board.wait(2000, function() { @@ -61,7 +61,7 @@ board.on("ready", function() { // "stop" events fire when the motor is stopped. motor.on("stop", function() { - console.log("stop"); + console.log("stop", Date.now()); }); // Motor API diff --git a/docs/navigator.md b/docs/navigator.md index a83cd9e64..04c0409b6 100644 --- a/docs/navigator.md +++ b/docs/navigator.md @@ -478,7 +478,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/docs/nunchuk.md b/docs/nunchuk.md index 67985307c..27fa4b661 100644 --- a/docs/nunchuk.md +++ b/docs/nunchuk.md @@ -55,7 +55,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], @@ -68,7 +68,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], @@ -100,7 +100,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/docs/ping.md b/docs/ping.md index 9730f5723..78da84bd8 100644 --- a/docs/ping.md +++ b/docs/ping.md @@ -49,7 +49,6 @@ board.on("ready", function() { // Calculated distance to object in centimeters // - ping.on("change", function() { console.log("Object is " + this.in + " inches away"); }); diff --git a/docs/servo-slider.md b/docs/servo-slider.md index e4a80b14b..60cae58c4 100644 --- a/docs/servo-slider.md +++ b/docs/servo-slider.md @@ -29,32 +29,18 @@ node eg/servo-slider.js ```javascript -var five = require("johnny-five"), - board, slider, servo, scalingRange; - -board = new five.Board(); +var five = require("johnny-five"); +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: 10, - 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/docs/sonar-scan.md b/docs/sonar-scan.md index 6dedecc7c..4074a5664 100644 --- a/docs/sonar-scan.md +++ b/docs/sonar-scan.md @@ -130,7 +130,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/docs/tinkerkit-accelerometer.md b/docs/tinkerkit-accelerometer.md index f7cf493a6..b8600a2d0 100644 --- a/docs/tinkerkit-accelerometer.md +++ b/docs/tinkerkit-accelerometer.md @@ -18,10 +18,8 @@ node eg/tinkerkit-accelerometer.js ```javascript -var five = require("johnny-five"), - board, accel; - -board = new five.Board(); +var five = require("johnny-five"); +var board = new five.Board(); board.on("ready", function() { @@ -32,7 +30,7 @@ board.on("ready", function() { // - Dual Axis http://tinkerkit.tihhs.nl/accelerometer/ // - accel = new five.Accelerometer({ + var accel = new five.Accelerometer({ pins: ["I0", "I1"], freq: 100 }); @@ -44,7 +42,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); }); @@ -53,7 +51,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/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 ae51e898e..a5e8a07ff 100644 --- a/eg/ir-motion.js +++ b/eg/ir-motion.js @@ -8,18 +8,18 @@ board.on("ready", function() { // "calibrated" occurs once, at the beginning of a session, motion.on("calibrated", function() { - console.log("calibrated"); + 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() { - console.log("motionstart"); + 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() { - console.log("motionend"); + console.log("motionend", Date.now()); }); }); 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/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 430851338..325643347 100644 --- a/eg/motor-PCA9685.js +++ b/eg/motor-PCA9685.js @@ -27,7 +27,7 @@ board.on("ready", function() { // "start" events fire when the motor is started. motor.on("start", function() { - console.log("start"); + console.log("start", Date.now()); // Demonstrate motor stop in 2 seconds board.wait(2000, function() { @@ -37,7 +37,7 @@ board.on("ready", function() { // "stop" events fire when the motor is started. motor.on("stop", function() { - console.log("stop"); + console.log("stop", Date.now()); }); // Motor API diff --git a/eg/motor-brake.js b/eg/motor-brake.js index a724cc619..540359aa1 100644 --- a/eg/motor-brake.js +++ b/eg/motor-brake.js @@ -30,19 +30,19 @@ board.on("ready", function() { }); motor.on("start", function() { - console.log("start"); + console.log("start", Date.now()); }); motor.on("stop", function() { - console.log("automated stop on timer"); + console.log("automated stop on timer", Date.now()); }); motor.on("brake", function() { - console.log("automated brake on timer"); + console.log("automated brake on timer", Date.now()); }); motor.on("forward", function() { - console.log("forward"); + console.log("forward", Date.now()); // demonstrate switching to reverse after 5 seconds board.wait(5000, function() { @@ -51,7 +51,7 @@ board.on("ready", function() { }); motor.on("reverse", function() { - console.log("reverse"); + 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 81385c20d..2529461ab 100644 --- a/eg/motor-current.js +++ b/eg/motor-current.js @@ -43,19 +43,19 @@ board.on("ready", function() { }); motor.on("start", function() { - console.log("start"); + console.log("start", Date.now()); }); motor.on("stop", function() { - console.log("automated stop on timer"); + console.log("automated stop on timer", Date.now()); }); motor.on("brake", function() { - console.log("automated brake on timer"); + console.log("automated brake on timer", Date.now()); }); motor.on("forward", function() { - console.log("forward"); + console.log("forward", Date.now()); // demonstrate switching to reverse after 5 seconds board.wait(5000, function() { @@ -64,7 +64,7 @@ board.on("ready", function() { }); motor.on("reverse", function() { - console.log("reverse"); + 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 b5cc051c2..11ad9daf9 100644 --- a/eg/motor-directional.js +++ b/eg/motor-directional.js @@ -61,15 +61,15 @@ board.on("ready", function() { }); motor.on("start", function() { - console.log("start"); + console.log("start", Date.now()); }); motor.on("stop", function() { - console.log("automated stop on timer"); + console.log("automated stop on timer", Date.now()); }); motor.on("forward", function() { - console.log("forward"); + console.log("forward", Date.now()); // demonstrate switching to reverse after 5 seconds board.wait(5000, function() { @@ -78,7 +78,7 @@ board.on("ready", function() { }); motor.on("reverse", function() { - console.log("reverse"); + 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 92ed27d36..f5decdb1c 100644 --- a/eg/motor-hbridge.js +++ b/eg/motor-hbridge.js @@ -34,15 +34,15 @@ board.on("ready", function() { }); motor.on("start", function() { - console.log("start"); + console.log("start", Date.now()); }); motor.on("stop", function() { - console.log("automated stop on timer"); + console.log("automated stop on timer", Date.now()); }); motor.on("forward", function() { - console.log("forward"); + console.log("forward", Date.now()); // demonstrate switching to reverse after 5 seconds board.wait(5000, function() { @@ -51,7 +51,7 @@ board.on("ready", function() { }); motor.on("reverse", function() { - console.log("reverse"); + 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 7c5c616e2..d3487db56 100644 --- a/eg/motor.js +++ b/eg/motor.js @@ -20,7 +20,7 @@ board.on("ready", function() { // "start" events fire when the motor is started. motor.on("start", function() { - console.log("start"); + console.log("start", Date.now()); // Demonstrate motor stop in 2 seconds board.wait(2000, function() { @@ -30,7 +30,7 @@ board.on("ready", function() { // "stop" events fire when the motor is stopped. motor.on("stop", function() { - console.log("stop"); + 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 be3c38f9e..7d91ca413 100644 --- a/eg/ping.js +++ b/eg/ping.js @@ -18,7 +18,6 @@ board.on("ready", function() { // Calculated distance to object in centimeters // - ping.on("change", function() { console.log("Object is " + this.in + " inches away"); }); diff --git a/eg/servo-slider.js b/eg/servo-slider.js index cb630b87e..468c9dfac 100644 --- a/eg/servo-slider.js +++ b/eg/servo-slider.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: 10, - 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/slider-log.js b/eg/slider-log.js new file mode 100644 index 000000000..546d2d735 --- /dev/null +++ b/eg/slider-log.js @@ -0,0 +1,11 @@ +var five = require("../lib/johnny-five.js"); +var board = new five.Board(); + +board.on("ready", function() { + + var slider = new five.Sensor("A0"); + + 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 new file mode 100644 index 000000000..c53da496a --- /dev/null +++ b/eg/slider-pan.js @@ -0,0 +1,18 @@ +var five = require("../lib/johnny-five.js"); +var board = new five.Board(); + +board.on("ready", function() { + + var range = [0, 170]; + var slider = new five.Sensor("A0"); + var tilt = new five.Servo({ + pin: 10, + range: range + }); + + slider.scale(range).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/tinkerkit-accelerometer.js b/eg/tinkerkit-accelerometer.js index f99d8dbd6..dae79d774 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://tinkerkit.tihhs.nl/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/ir.js b/lib/ir.js index 3ff6bc9fa..dce9bc143 100644 --- a/lib/ir.js +++ b/lib/ir.js @@ -28,15 +28,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, { @@ -77,11 +76,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/motor.js b/lib/motor.js index 840b5809f..d5da7b526 100644 --- a/lib/motor.js +++ b/lib/motor.js @@ -315,6 +315,7 @@ var Devices = { saveSpeed: false, braking: true }); + process.nextTick(this.emit.bind(this, "brake")); if (duration) { diff --git a/lib/ping.js b/lib/ping.js index 13a998d77..a1fea4694 100644 --- a/lib/ping.js +++ b/lib/ping.js @@ -49,29 +49,18 @@ function Ping(opts) { // Interval for throttled event setInterval(function() { - var err = null; - if (state.value === null) { 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 c274f1ed9..ff37bce2c 100644 --- a/lib/pir.js +++ b/lib/pir.js @@ -30,8 +30,7 @@ function Pir(opts) { // Analog Read event loop // TODO: make this "throttle-able" this.io.digitalRead(this.pin, function(data) { - var timestamp = Date.now(), - err = null; + var timestamp = Date.now(); // If this is not a calibration event if (this.value != null && this.value !== +data) { @@ -42,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); } } @@ -57,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 55b41c311..705615596 100644 --- a/lib/reflectancearray.js +++ b/lib/reflectancearray.js @@ -58,15 +58,15 @@ function onData(sensorState, value) { allRead = __.every(state.sensorStates, "dataReceived"); if (allRead) { - this.emit("data", null, this.raw); + this.emit("data", this.raw); if (state.autoCalibrate) { setCalibration(state.calibration, 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) { @@ -244,7 +244,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) { setCalibration(state.calibration, values); this.emit("calibrated"); diff --git a/lib/sensor.js b/lib/sensor.js index ff8bfe39c..d42f7e3b7 100644 --- a/lib/sensor.js +++ b/lib/sensor.js @@ -121,11 +121,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); // Update the instance-local `last` value. last = value; @@ -138,18 +138,15 @@ function Sensor(opts) { // Filter the accumulated sample values to reduce analog reading noise median = arrayMedian(samples); } - // @DEPRECATE - this.emit("read", err, median); - // The "read" event has been deprecated in - // favor of a "data" event. - this.emit("data", err, median); + + this.emit("data", median); // If the filtered (median) value for this interval is at least ± the // configured threshold from last, fire change events if (median <= (last - this.threshold) || median >= (last + this.threshold)) { // Include all aliases aliases.change.forEach(function(change) { - this.emit(change, err, median); + this.emit(change, median); }, this); // Update the instance-local `last` value (only) when a new change event // has been emitted. For comparison in the next interval @@ -165,11 +162,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 898480613..bc3dc27ae 100644 --- a/lib/sonar.js +++ b/lib/sonar.js @@ -64,8 +64,6 @@ function Sonar(opts) { // Throttle setInterval(function() { - var err = null; - // Nothing read since previous interval if (state.samples.length === 0) { return; @@ -74,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 fca55831f..2fe7427da 100644 --- a/lib/temperature.js +++ b/lib/temperature.js @@ -513,11 +513,11 @@ function Temperature(opts) { data.F = data.fahrenheit = this.fahrenheit; data.K = data.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 ab00e1712..9e740d67e 100644 --- a/lib/wii.js +++ b/lib/wii.js @@ -124,11 +124,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 caa4a1f9b..7ee5595b2 100644 --- a/test/reflectancearray.js +++ b/test/reflectancearray.js @@ -146,7 +146,7 @@ exports["ReflectanceArray"] = { 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(); }, @@ -297,7 +297,7 @@ exports["ReflectanceArray"] = { 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(); }, @@ -319,7 +319,7 @@ exports["ReflectanceArray"] = { 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(); @@ -342,7 +342,7 @@ exports["ReflectanceArray"] = { 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(); diff --git a/test/sensor.js b/test/sensor.js index 13dd2165f..19aa530c2 100644 --- a/test/sensor.js +++ b/test/sensor.js @@ -216,7 +216,7 @@ exports["Sensor - Analog"] = { dataSpy = sinon.spy(), chgSpy = sinon.spy(), tickDelta, tickAccum, spyCall, raw, filtered; - test.expect(41); + test.expect(37); this.sensor.on("data", dataSpy); this.sensor.on("change", chgSpy); @@ -270,12 +270,10 @@ exports["Sensor - Analog"] = { test.strictEqual(this.sensor.value, raw, "tick " + tickAccum + ": sensor value property expected to be the last value (" + raw + ") injected"); // Check the arguments and context provided for the emitted events spyCall = dataSpy.getCall(0); - test.strictEqual(spyCall.args[0], null, "data event err argument expected to be null"); - test.strictEqual(spyCall.args[1], filtered, "data event value expected to be the median (" + filtered + ") value"); + test.strictEqual(spyCall.args[0], filtered, "data event value expected to be the median (" + filtered + ") value"); test.ok(spyCall.calledOn(this.sensor), "data event 'this' parameter expected to be source sensor object"); spyCall = chgSpy.getCall(0); - test.strictEqual(spyCall.args[0], null, "change event err argument expected to be null"); - test.strictEqual(spyCall.args[1], filtered, "change event value expected to be the median (" + filtered + ") value"); + test.strictEqual(spyCall.args[0], filtered, "change event value expected to be the median (" + filtered + ") value"); test.ok(spyCall.calledOn(this.sensor), "change event 'this' parameter expected to be source sensor object"); // Check for non-integer median value (when even number of data points and odd delta between middle two) @@ -312,12 +310,10 @@ exports["Sensor - Analog"] = { // Check that both events provide the correct median value and context spyCall = dataSpy.getCall(1); - test.strictEqual(spyCall.args[0], null, "data event err argument expected to be null"); - test.strictEqual(spyCall.args[1], filtered, "data event value expected to be the median (" + filtered + ") value"); + test.strictEqual(spyCall.args[0], filtered, "data event value expected to be the median (" + filtered + ") value"); test.ok(spyCall.calledOn(this.sensor), "data event 'this' parameter expected to be source sensor object"); spyCall = chgSpy.getCall(1); - test.strictEqual(spyCall.args[0], null, "change event err argument expected to be null"); - test.strictEqual(spyCall.args[1], filtered, "change event value expected to be the median (" + filtered + ") value"); + test.strictEqual(spyCall.args[0], filtered, "change event value expected to be the median (" + filtered + ") value"); test.ok(spyCall.calledOn(this.sensor), "change event 'this' parameter expected to be source sensor object"); // Check that no events are emitted before the end of the next throttling interval @@ -339,7 +335,7 @@ exports["Sensor - Analog"] = { test.strictEqual(this.sensor.value, raw, "sensor value property expected to be the last value (" + raw + ") read (injected)"); // Check that the data event has the same filtered value as the previous event spyCall = dataSpy.getCall(2); - test.strictEqual(spyCall.args[1], filtered, "data event value expected to be still the median (" + filtered + ") value"); + test.strictEqual(spyCall.args[0], filtered, "data event value expected to be still the median (" + filtered + ") value"); test.done(); },// ./filtered: function(test) @@ -369,7 +365,7 @@ exports["Sensor - Analog"] = { // elapsed (fake) time is at the end of the first (event throttling) interval tickAccum += tickDelta; test.ok(spy.calledOnce, "tick " + tickAccum + ": change event handler should have been called first time at tick " + this.defShape.freq); - test.strictEqual(spy.getCall(0).args[1], chgValue, "first change event value expected to be " + chgValue); + test.strictEqual(spy.getCall(0).args[0], chgValue, "first change event value expected to be " + chgValue); // Make sure that no change event is emitted before the end of the next throttling interval tickDelta = this.defShape.freq - 1; @@ -403,7 +399,7 @@ exports["Sensor - Analog"] = { // elapsed time is now at the end of the third event throttling interval tickAccum += tickDelta; test.ok(spy.calledTwice, "tick " + tickAccum + ": change event handler should be called second time at tick " + (this.defShape.freq * 3)); - test.strictEqual(spy.getCall(1).args[1], chgValue, "second change event value expected to be " + chgValue); + test.strictEqual(spy.getCall(1).args[0], chgValue, "second change event value expected to be " + chgValue); test.done(); },// ./change: function(test) @@ -413,7 +409,7 @@ exports["Sensor - Analog"] = { var callback = this.analogRead.args[0][1], spy = sinon.spy(), tickDelta, tickAccum, spyCall, raw, filtered, newShape; - test.expect(50); + test.expect(45); this.sensor.on("change", spy); @@ -442,8 +438,7 @@ exports["Sensor - Analog"] = { // Verify the arguments and context for the call to the event handler spyCall = spy.getCall(0); - test.strictEqual(spyCall.args[0], null, "change event err argument expected to be null"); - test.strictEqual(spyCall.args[1], filtered, + test.strictEqual(spyCall.args[0], filtered, "change event value expected to be the median (" + filtered + ") value"); test.ok(spyCall.calledOn(this.sensor), "change event 'this' parameter expected to be source sensor object"); @@ -496,8 +491,7 @@ exports["Sensor - Analog"] = { // Verify the arguments and context for the call to the event handler spyCall = spy.getCall(1); - test.strictEqual(spyCall.args[0], null, "change event err argument expected to be null"); - test.strictEqual(spyCall.args[1], filtered, "change event value expected to be the median (" + filtered + ") value"); + test.strictEqual(spyCall.args[0], filtered, "change event value expected to be the median (" + filtered + ") value"); test.ok(spyCall.calledOn(this.sensor), "change event 'this' parameter expected to be source sensor object"); // Check that no new change event is emitted when the (filtered) value changes (down) by (just) less than the threshold @@ -582,8 +576,7 @@ exports["Sensor - Analog"] = { // Verify the arguments and context for the call to the event handler spyCall = spy.getCall(2); - test.strictEqual(spyCall.args[0], null, "change event err argument expected to be null"); - test.strictEqual(spyCall.args[1], filtered, "change event value expected to be the median (" + filtered + ") value"); + test.strictEqual(spyCall.args[0], filtered, "change event value expected to be the median (" + filtered + ") value"); test.ok(spyCall.calledOn(this.sensor), "change event 'this' parameter expected to be source sensor object"); // Only changes of 10 or more should trigger a change event @@ -671,8 +664,7 @@ exports["Sensor - Analog"] = { // Verify the arguments and context for the call to the event handler spyCall = spy.getCall(3); - test.strictEqual(spyCall.args[0], null, "change event err argument expected to be null"); - test.strictEqual(spyCall.args[1], filtered, "change event value expected to be the median (" + filtered + ") value"); + test.strictEqual(spyCall.args[0], filtered, "change event value expected to be the median (" + filtered + ") value"); test.ok(spyCall.calledOn(this.sensor), "change event 'this' parameter expected to be source sensor object"); // do a new read at the end of the current interval, after the event has been emitted. @@ -708,8 +700,7 @@ exports["Sensor - Analog"] = { // Verify the arguments and context for the call to the event handler spyCall = spy.getCall(4); - test.strictEqual(spyCall.args[0], null, "change event err argument expected to be null"); - test.strictEqual(spyCall.args[1], filtered, "change event value expected to be the median (" + filtered + ") value"); + test.strictEqual(spyCall.args[0], filtered, "change event value expected to be the median (" + filtered + ") value"); test.ok(spyCall.calledOn(this.sensor), "change event 'this' parameter expected to be source sensor object"); test.done(); @@ -769,7 +760,7 @@ exports["Sensor - Analog"] = { tickAccum += tickDelta; test.strictEqual(dataSpy.callCount, 1, "tick " + tickAccum + ": data event handler should be called first time at tick " + this.defShape.freq); - test.strictEqual(dataSpy.getCall(0).args[1], filtered, "data event value expected to be the median (" + filtered + ") value"); + test.strictEqual(dataSpy.getCall(0).args[0], filtered, "data event value expected to be the median (" + filtered + ") value"); test.strictEqual(limitSpy.callCount + lowerSpy.callCount + upperSpy.callCount, 0, "tick " + tickAccum + ": no limit event handlers should be called while limit is null"); @@ -790,7 +781,7 @@ exports["Sensor - Analog"] = { tickAccum += tickDelta; test.strictEqual(dataSpy.callCount, 2, "tick " + tickAccum + ": data event handler should be called again time at tick " + this.defShape.freq * 2); - test.strictEqual(dataSpy.getCall(1).args[1], filtered, "data event value expected to be the median (" + filtered + ") value"); + test.strictEqual(dataSpy.getCall(1).args[0], filtered, "data event value expected to be the median (" + filtered + ") value"); test.strictEqual(limitSpy.callCount + lowerSpy.callCount + upperSpy.callCount, 0, "tick " + tickAccum + ": no limit event handlers should be called while limit is null"); @@ -839,7 +830,7 @@ exports["Sensor - Analog"] = { tickAccum += tickDelta; test.strictEqual(dataSpy.callCount, 3, "tick " + tickAccum + ": data event handler should be called every multiple of " + this.defShape.freq + " ticks"); - test.strictEqual(dataSpy.getCall(2).args[1], filtered, "data event value expected to be the median (" + filtered + ") value"); + test.strictEqual(dataSpy.getCall(2).args[0], filtered, "data event value expected to be the median (" + filtered + ") value"); test.strictEqual(limitSpy.callCount + lowerSpy.callCount + upperSpy.callCount, 0, "tick " + tickAccum + ": no limit event handlers should be called while value is within the limits"); @@ -861,7 +852,7 @@ exports["Sensor - Analog"] = { tickAccum += tickDelta; test.strictEqual(dataSpy.callCount, 4, "tick " + tickAccum + ": data event handler should be called every multiple of " + this.defShape.freq + " ticks"); - test.strictEqual(dataSpy.getCall(3).args[1], filtered, "data event value expected to be the median (" + filtered + ") value"); + test.strictEqual(dataSpy.getCall(3).args[0], filtered, "data event value expected to be the median (" + filtered + ") value"); test.strictEqual(limitSpy.callCount + lowerSpy.callCount + upperSpy.callCount, 0, "tick " + tickAccum + ": no limit event handlers should be called while value is within the limits"); @@ -881,10 +872,10 @@ exports["Sensor - Analog"] = { ": limit:lower event handler should be called at " + this.defShape.freq + " ticks; value at lower limit"); test.strictEqual(upperSpy.callCount, 0, "tick " + tickAccum + ": limit:upper event handler should not be called at " + this.defShape.freq + " ticks; value at lower limit"); - test.strictEqual(dataSpy.getCall(4).args[1], filtered, "data event value expected to be the median (" + filtered + ") value"); - test.deepEqual(limitSpy.getCall(0).args[1], { boundary: "lower", value: filtered }, + test.strictEqual(dataSpy.getCall(4).args[0], filtered, "data event value expected to be the median (" + filtered + ") value"); + test.deepEqual(limitSpy.getCall(0).args[0], { boundary: "lower", value: filtered }, "limit event value expected to be the lower boundary with the median (" + filtered + ") value"); - test.strictEqual(lowerSpy.getCall(0).args[1], filtered, "limit:lower event value expected to be the median (" + filtered + ") value"); + test.strictEqual(lowerSpy.getCall(0).args[0], filtered, "limit:lower event value expected to be the median (" + filtered + ") value"); // check that a value matching the upper limit emits limit and limit:upper events raw = 550; @@ -902,10 +893,10 @@ exports["Sensor - Analog"] = { ": limit:lower event handler should not be called at " + this.defShape.freq + " ticks; value at upper limit"); test.strictEqual(upperSpy.callCount, 1, "tick " + tickAccum + ": limit:upper event handler should be called at " + this.defShape.freq + " ticks; value at upper limit"); - test.strictEqual(dataSpy.getCall(5).args[1], filtered, "data event value expected to be the median (" + filtered + ") value"); - test.deepEqual(limitSpy.getCall(1).args[1], { boundary: "upper", value: filtered }, + test.strictEqual(dataSpy.getCall(5).args[0], filtered, "data event value expected to be the median (" + filtered + ") value"); + test.deepEqual(limitSpy.getCall(1).args[0], { boundary: "upper", value: filtered }, "limit event value expected to be the lower boundary with the median (" + filtered + ") value"); - test.strictEqual(upperSpy.getCall(0).args[1], filtered, "limit:upper event value expected to be the median (" + filtered + ") value"); + test.strictEqual(upperSpy.getCall(0).args[0], filtered, "limit:upper event value expected to be the median (" + filtered + ") value"); // check that a very low value emits limit and limit:lower events raw = 0; @@ -923,10 +914,10 @@ exports["Sensor - Analog"] = { ": limit:lower event handler should be called at " + this.defShape.freq + " ticks; value at lower limit"); test.strictEqual(upperSpy.callCount, 1, "tick " + tickAccum + ": limit:upper event handler should not be called at " + this.defShape.freq + " ticks; value at lower limit"); - test.strictEqual(dataSpy.getCall(6).args[1], filtered, "data event value expected to be the median (" + filtered + ") value"); - test.deepEqual(limitSpy.getCall(2).args[1], { boundary: "lower", value: filtered }, + test.strictEqual(dataSpy.getCall(6).args[0], filtered, "data event value expected to be the median (" + filtered + ") value"); + test.deepEqual(limitSpy.getCall(2).args[0], { boundary: "lower", value: filtered }, "limit event value expected to be the lower boundary with the median (" + filtered + ") value"); - test.strictEqual(lowerSpy.getCall(1).args[1], filtered, "limit:lower event value expected to be the median (" + filtered + ") value"); + test.strictEqual(lowerSpy.getCall(1).args[0], filtered, "limit:lower event value expected to be the median (" + filtered + ") value"); // check that a very high value emits limit and limit:upper events raw = 1023; @@ -944,10 +935,10 @@ exports["Sensor - Analog"] = { ": limit:lower event handler should not be called at " + this.defShape.freq + " ticks; value at upper limit"); test.strictEqual(upperSpy.callCount, 2, "tick " + tickAccum + ": limit:upper event handler should be called at " + this.defShape.freq + " ticks; value at upper limit"); - test.strictEqual(dataSpy.getCall(7).args[1], filtered, "data event value expected to be the median (" + filtered + ") value"); - test.deepEqual(limitSpy.getCall(3).args[1], { boundary: "upper", value: filtered }, + test.strictEqual(dataSpy.getCall(7).args[0], filtered, "data event value expected to be the median (" + filtered + ") value"); + test.deepEqual(limitSpy.getCall(3).args[0], { boundary: "upper", value: filtered }, "limit event value expected to be the lower boundary with the median (" + filtered + ") value"); - test.strictEqual(upperSpy.getCall(1).args[1], filtered, "limit:upper event value expected to be the median (" + filtered + ") value"); + test.strictEqual(upperSpy.getCall(1).args[0], filtered, "limit:upper event value expected to be the median (" + filtered + ") value"); test.done(); },// ./limit: function(test) @@ -1273,11 +1264,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(); }, @@ -1304,8 +1295,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 4cff17de5..15ec79b8c 100644 --- a/test/temperature.js +++ b/test/temperature.js @@ -99,7 +99,7 @@ function makeTestAnalogConversion(opts) { test.equal(spy.callCount, 1); - var data = spy.firstCall.args[1]; + var data = spy.firstCall.args[0]; test.equal(Math.round(data.C), opts.C, "data.C"); test.equal(Math.round(data.celsius), opts.C, "data.celsius"); test.equal(Math.round(data.K), opts.K, "data.K"); @@ -550,9 +550,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(); }, @@ -599,8 +599,8 @@ exports["Temperature -- DS18B20"] = { this.clock.tick(100); - test.equals(Math.round(spyA.args[0][1].celsius), 32); - test.equals(Math.round(spyB.args[0][1].celsius), 64); + test.equals(Math.round(spyA.getCall(0).args[0].celsius), 32); + test.equals(Math.round(spyB.getCall(0).args[0].celsius), 64); test.done(); }, @@ -687,9 +687,9 @@ 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(); } @@ -863,9 +863,9 @@ exports["Temperature -- SI7020"] = { this.clock.tick(10); test.ok(spy.calledOnce); - test.equals(Math.round(spy.args[0][1].celsius), 24); - test.equals(Math.round(spy.args[0][1].fahrenheit), 75); - test.equals(Math.round(spy.args[0][1].kelvin), 297); + test.equals(Math.round(spy.getCall(0).args[0].celsius), 24); + test.equals(Math.round(spy.getCall(0).args[0].fahrenheit), 75); + test.equals(Math.round(spy.getCall(0).args[0].kelvin), 297); test.done(); } @@ -950,9 +950,9 @@ exports["Temperature -- HTU21D"] = { this.clock.tick(10); test.ok(spy.calledOnce); - test.equals(Math.round(spy.args[0][1].celsius), 24); - test.equals(Math.round(spy.args[0][1].fahrenheit), 75); - test.equals(Math.round(spy.args[0][1].kelvin), 297); + test.equals(Math.round(spy.getCall(0).args[0].celsius), 24); + test.equals(Math.round(spy.getCall(0).args[0].fahrenheit), 75); + test.equals(Math.round(spy.getCall(0).args[0].kelvin), 297); test.done(); } @@ -1081,9 +1081,9 @@ exports["Temperature -- MPL3115A2"] = { this.clock.tick(10); test.ok(spy.calledOnce); - test.equals(Math.round(spy.args[0][1].celsius), 24); - test.equals(Math.round(spy.args[0][1].fahrenheit), 75); - test.equals(Math.round(spy.args[0][1].kelvin), 297); + test.equals(Math.round(spy.getCall(0).args[0].celsius), 24); + test.equals(Math.round(spy.getCall(0).args[0].fahrenheit), 75); + test.equals(Math.round(spy.getCall(0).args[0].kelvin), 297); test.done(); }, @@ -1147,12 +1147,12 @@ exports["Temperature -- MPL3115A2"] = { this.clock.tick(10); test.ok(spy.calledTwice); - test.equals(Math.round(spy.args[0][1].celsius), 24); - test.equals(Math.round(spy.args[0][1].fahrenheit), 75); - test.equals(Math.round(spy.args[0][1].kelvin), 297); - test.equals(Math.round(spy.args[1][1].celsius), 40); - test.equals(Math.round(spy.args[1][1].fahrenheit), 104); - test.equals(Math.round(spy.args[1][1].kelvin), 313); + test.equals(Math.round(spy.getCall(0).args[0].celsius), 24); + test.equals(Math.round(spy.getCall(0).args[0].fahrenheit), 75); + test.equals(Math.round(spy.getCall(0).args[0].kelvin), 297); + test.equals(Math.round(spy.getCall(1).args[0].celsius), 40); + test.equals(Math.round(spy.getCall(1).args[0].fahrenheit), 104); + test.equals(Math.round(spy.getCall(1).args[0].kelvin), 313); test.done(); }