diff --git a/README.md b/README.md
index 2a8ebb129..8967fa875 100644
--- a/README.md
+++ b/README.md
@@ -275,6 +275,8 @@ To interactively navigate the examples, visit the [Johnny-Five examples](http://
### Motion
- [Motion](https://github.com/rwaldron/johnny-five/blob/master/docs/motion.md)
- [Motion - GP2Y0D805Z0F](https://github.com/rwaldron/johnny-five/blob/master/docs/motion-gp2y0d805z0f.md)
+- [Motion - GP2Y0D810Z0F](https://github.com/rwaldron/johnny-five/blob/master/docs/motion-gp2y0d810z0f.md)
+- [Motion - GP2Y0D810Z0F](https://github.com/rwaldron/johnny-five/blob/master/docs/motion-gp2y0d815z0f.md)
### Joystick
- [Joystick](https://github.com/rwaldron/johnny-five/blob/master/docs/joystick.md)
diff --git a/docs/breadboard/GP2Y0D810Z0F.fzz b/docs/breadboard/GP2Y0D810Z0F.fzz
new file mode 100644
index 000000000..5ff29a8d1
Binary files /dev/null and b/docs/breadboard/GP2Y0D810Z0F.fzz differ
diff --git a/docs/breadboard/GP2Y0D810Z0F.png b/docs/breadboard/GP2Y0D810Z0F.png
new file mode 100644
index 000000000..d3909956c
Binary files /dev/null and b/docs/breadboard/GP2Y0D810Z0F.png differ
diff --git a/docs/breadboard/PCF8574.fzz b/docs/breadboard/PCF8574.fzz
new file mode 100644
index 000000000..fc8df6147
Binary files /dev/null and b/docs/breadboard/PCF8574.fzz differ
diff --git a/docs/motion-gp2y0d805z0f.md b/docs/motion-gp2y0d805z0f.md
index aafb9e799..d140c0575 100644
--- a/docs/motion-gp2y0d805z0f.md
+++ b/docs/motion-gp2y0d805z0f.md
@@ -3,7 +3,7 @@
# Motion - GP2Y0D805Z0F
-Basic GP2Y0D805Z0F detection.
+Basic GP2Y0D805Z0F motion detection.
Run with:
diff --git a/docs/motion-gp2y0d810z0f.md b/docs/motion-gp2y0d810z0f.md
new file mode 100644
index 000000000..cbffe41f4
--- /dev/null
+++ b/docs/motion-gp2y0d810z0f.md
@@ -0,0 +1,76 @@
+
+
+# Motion - GP2Y0D810Z0F
+
+
+
+Run with:
+```bash
+node eg/motion-gp2y0d810z0f.js
+```
+
+
+
+```javascript
+var five = require("johnny-five");
+var board = new five.Board();
+
+board.on("ready", function() {
+
+ // Create a new `motion` hardware instance.
+ var motion = new five.Motion({
+ controller: "GP2Y0D810Z0F",
+ pin: "A0"
+ });
+
+ // "calibrated" occurs once, at the beginning of a session,
+ motion.on("calibrated", function() {
+ console.log("calibrated");
+ });
+
+ // "motionstart" events are fired when the "calibrated"
+ // proximal area is disrupted, generally by some form of movement
+ motion.on("motionstart", function() {
+ console.log("motionstart");
+ });
+
+ // "motionend" events are fired following a "motionstart" event
+ // when no movement has occurred in X ms
+ motion.on("motionend", function() {
+ console.log("motionend");
+ });
+});
+
+```
+
+
+## Illustrations / Photos
+
+
+### Motion - GP2Y0D810Z0F
+
+
+Basic GP2Y0D810Z0F motion detection.
+
+
+![docs/breadboard/GP2Y0D810Z0F.png](breadboard/GP2Y0D810Z0F.png)
+
+Fritzing diagram: [docs/breadboard/GP2Y0D810Z0F.fzz](breadboard/GP2Y0D810Z0F.fzz)
+
+
+
+
+
+
+
+
+
+
+
+## License
+Copyright (c) 2012, 2013, 2014 Rick Waldron
+Licensed under the MIT license.
+Copyright (c) 2014, 2015 The Johnny-Five Contributors
+Licensed under the MIT license.
+
+
diff --git a/docs/motion-gp2y0d815z0f.md b/docs/motion-gp2y0d815z0f.md
new file mode 100644
index 000000000..29490a97c
--- /dev/null
+++ b/docs/motion-gp2y0d815z0f.md
@@ -0,0 +1,76 @@
+
+
+# Motion - GP2Y0D810Z0F
+
+
+
+Run with:
+```bash
+node eg/motion-gp2y0d815z0f.js
+```
+
+
+
+```javascript
+var five = require("johnny-five");
+var board = new five.Board();
+
+board.on("ready", function() {
+
+ // Create a new `motion` hardware instance.
+ var motion = new five.Motion({
+ controller: "GP2Y0D810Z0F",
+ pin: "A0"
+ });
+
+ // "calibrated" occurs once, at the beginning of a session,
+ motion.on("calibrated", function() {
+ console.log("calibrated");
+ });
+
+ // "motionstart" events are fired when the "calibrated"
+ // proximal area is disrupted, generally by some form of movement
+ motion.on("motionstart", function() {
+ console.log("motionstart");
+ });
+
+ // "motionend" events are fired following a "motionstart" event
+ // when no movement has occurred in X ms
+ motion.on("motionend", function() {
+ console.log("motionend");
+ });
+});
+
+```
+
+
+## Illustrations / Photos
+
+
+### Motion - GP2Y0D815Z0F
+
+
+Basic GP2Y0D815Z0F motion detection.
+
+
+![docs/breadboard/GP2Y0D810Z0F.png](breadboard/GP2Y0D810Z0F.png)
+
+Fritzing diagram: [docs/breadboard/GP2Y0D810Z0F.fzz](breadboard/GP2Y0D810Z0F.fzz)
+
+
+
+
+
+
+
+
+
+
+
+## License
+Copyright (c) 2012, 2013, 2014 Rick Waldron
+Licensed under the MIT license.
+Copyright (c) 2014, 2015 The Johnny-Five Contributors
+Licensed under the MIT license.
+
+
diff --git a/eg/motion-gp2y0d810z0f.js b/eg/motion-gp2y0d810z0f.js
new file mode 100644
index 000000000..4be3806f6
--- /dev/null
+++ b/eg/motion-gp2y0d810z0f.js
@@ -0,0 +1,28 @@
+var five = require("../lib/johnny-five.js");
+var board = new five.Board();
+
+board.on("ready", function() {
+
+ // Create a new `motion` hardware instance.
+ var motion = new five.Motion({
+ controller: "GP2Y0D810Z0F",
+ pin: "A0"
+ });
+
+ // "calibrated" occurs once, at the beginning of a session,
+ motion.on("calibrated", function() {
+ console.log("calibrated");
+ });
+
+ // "motionstart" events are fired when the "calibrated"
+ // proximal area is disrupted, generally by some form of movement
+ motion.on("motionstart", function() {
+ console.log("motionstart");
+ });
+
+ // "motionend" events are fired following a "motionstart" event
+ // when no movement has occurred in X ms
+ motion.on("motionend", function() {
+ console.log("motionend");
+ });
+});
diff --git a/eg/motion-gp2y0d815z0f.js b/eg/motion-gp2y0d815z0f.js
new file mode 100644
index 000000000..4be3806f6
--- /dev/null
+++ b/eg/motion-gp2y0d815z0f.js
@@ -0,0 +1,28 @@
+var five = require("../lib/johnny-five.js");
+var board = new five.Board();
+
+board.on("ready", function() {
+
+ // Create a new `motion` hardware instance.
+ var motion = new five.Motion({
+ controller: "GP2Y0D810Z0F",
+ pin: "A0"
+ });
+
+ // "calibrated" occurs once, at the beginning of a session,
+ motion.on("calibrated", function() {
+ console.log("calibrated");
+ });
+
+ // "motionstart" events are fired when the "calibrated"
+ // proximal area is disrupted, generally by some form of movement
+ motion.on("motionstart", function() {
+ console.log("motionstart");
+ });
+
+ // "motionend" events are fired following a "motionstart" event
+ // when no movement has occurred in X ms
+ motion.on("motionend", function() {
+ console.log("motionend");
+ });
+});
diff --git a/lib/motion.js b/lib/motion.js
index fd9bceaa0..9df394be6 100644
--- a/lib/motion.js
+++ b/lib/motion.js
@@ -56,14 +56,40 @@ var Controllers = {
return raw === 0;
}
}
+ },
+ GP2Y0D810Z0F: {
+ initialize: {
+ value: function(opts, dataHandler) {
+ var state = priv.get(this);
+
+ this.io.pinMode(opts.pin, this.io.MODES.ANALOG);
+
+ setTimeout(function() {
+ state.isCalibrated = true;
+ this.emit("calibrated");
+ }.bind(this), 10);
+
+ this.io.analogRead(opts.pin, dataHandler);
+ }
+ },
+ toBoolean: {
+ value: function(raw) {
+ return raw >> 9 === 0;
+ }
+ }
}
};
+Controllers.GP2Y0D815Z0F = Controllers.GP2Y0D810Z0F;
+
Controllers["HC-SR501"] = Controllers.PIR;
Controllers["HCSR501"] = Controllers.PIR;
Controllers["0D805"] = Controllers.GP2Y0D805Z0F;
Controllers["805"] = Controllers.GP2Y0D805Z0F;
-
+Controllers["0D810"] = Controllers.GP2Y0D810Z0F;
+Controllers["810"] = Controllers.GP2Y0D810Z0F;
+Controllers["0D815"] = Controllers.GP2Y0D815Z0F;
+Controllers["815"] = Controllers.GP2Y0D815Z0F;
/**
* Motion
diff --git a/package.json b/package.json
index c0603328f..e04b56096 100644
--- a/package.json
+++ b/package.json
@@ -1,8 +1,8 @@
{
"name": "johnny-five",
- "description": "The JavaScript Hardware Programming Framework. Use with: Arduino (all models), Electric Imp, Beagle Bone, Intel Galileo & Edison, Linino One, Pinoccio, Raspberry Pi, Spark Core, TI Launchpad and more!",
+ "description": "The JavaScript Robotics and Hardware Programming Framework. Use with: Arduino (all models), Electric Imp, Beagle Bone, Intel Galileo & Edison, Linino One, Pinoccio, Raspberry Pi, Spark Core, TI Launchpad and more!",
"version": "0.8.74",
- "homepage": "https://github.com/rwaldron/johnny-five",
+ "homepage": "https://johnny-five.io",
"author": {
"name": "Rick Waldron ",
"email": "waldron.rick@gmail.com"
diff --git a/test/motion.js b/test/motion.js
index 90192e28e..76e700907 100644
--- a/test/motion.js
+++ b/test/motion.js
@@ -303,3 +303,118 @@ exports["Motion - GP2Y0D805Z0F"] = {
test.done();
}
};
+
+exports["Motion - GP2Y0D810Z0F"] = {
+ setUp: function(done) {
+ this.clock = sinon.useFakeTimers();
+ this.pinMode = sinon.spy(MockFirmata.prototype, "pinMode");
+ this.analogRead = sinon.spy(MockFirmata.prototype, "analogRead");
+ this.motion = new Motion({
+ controller: "GP2Y0D810Z0F",
+ pin: "A0",
+ board: board
+ });
+
+ done();
+ },
+
+ tearDown: function(done) {
+ restore(this);
+ done();
+ },
+
+ initialize: function(test) {
+ test.expect(2);
+
+ test.ok(this.pinMode.calledOnce);
+ test.ok(this.analogRead.calledOnce);
+ test.done();
+ },
+
+ calibrated: function(test) {
+ var spy = sinon.spy();
+ test.expect(1);
+ this.motion.on("calibrated", spy);
+ this.clock.tick(10);
+ test.ok(spy.calledOnce);
+ test.done();
+ },
+
+ data: function(test) {
+ var spy = sinon.spy();
+ test.expect(1);
+ this.motion.on("data", spy);
+ this.clock.tick(25);
+ test.ok(spy.calledOnce);
+ test.done();
+ },
+
+ change: function(test) {
+ var spy = sinon.spy();
+ var callback = this.analogRead.firstCall.args[1];
+ test.expect(1);
+ this.motion.on("change", spy);
+ callback(1023);
+ this.clock.tick(25);
+ callback(100);
+ this.clock.tick(25);
+ callback(1023);
+ this.clock.tick(25);
+
+ test.ok(spy.calledTwice);
+ test.done();
+ },
+
+ noChange: function(test) {
+ test.expect(1);
+ var spy = sinon.spy();
+ var callback = this.analogRead.firstCall.args[1];
+ this.motion.on("change", spy);
+
+ callback(1023);
+ this.clock.tick(25);
+ callback(1023);
+ this.clock.tick(25);
+ callback(1023);
+ this.clock.tick(25);
+ callback(1023);
+ this.clock.tick(25);
+
+ test.ok(spy.notCalled);
+ test.done();
+ },
+
+ motionstart: function(test) {
+ var spy = sinon.spy();
+ var callback = this.analogRead.firstCall.args[1];
+
+ test.expect(1);
+ this.motion.on("motionstart", spy);
+
+ callback(100);
+ this.clock.tick(25);
+ callback(1023);
+ this.clock.tick(25);
+
+ test.ok(spy.calledOnce);
+ test.done();
+ },
+
+ motionend: function(test) {
+
+ // this.clock.tick(250);
+ var spy = sinon.spy();
+ var callback = this.analogRead.firstCall.args[1];
+
+ test.expect(1);
+ this.motion.on("motionend", spy);
+
+ callback(100);
+ this.clock.tick(25);
+ callback(1023);
+ this.clock.tick(25);
+
+ test.ok(spy.calledOnce);
+ test.done();
+ }
+};
diff --git a/tpl/programs.json b/tpl/programs.json
index 506d4ea62..c496694e7 100644
--- a/tpl/programs.json
+++ b/tpl/programs.json
@@ -506,7 +506,23 @@
{
"file": "motion-gp2y0d805z0f.js",
"title": "Motion - GP2Y0D805Z0F",
- "description": "Basic GP2Y0D805Z0F detection."
+ "description": "Basic GP2Y0D805Z0F motion detection."
+ },
+ {
+ "file": "motion-gp2y0d810z0f.js",
+ "title": "Motion - GP2Y0D810Z0F",
+ "breadboards": [
+ {"name": "GP2Y0D810Z0F", "title": "Motion - GP2Y0D810Z0F", "description": "Basic GP2Y0D810Z0F motion detection."}
+
+ ]
+ },
+ {
+ "file": "motion-gp2y0d815z0f.js",
+ "title": "Motion - GP2Y0D810Z0F",
+ "breadboards": [
+ {"name": "GP2Y0D810Z0F", "title": "Motion - GP2Y0D815Z0F", "description": "Basic GP2Y0D815Z0F motion detection."}
+
+ ]
}
]
},