Permalink
Browse files

Major overhaul of Wii controller "ecosystem" including creation of fi…

…ve.Wii.* Constructors. Example programs, links and readme updated.

Signed-off-by: Rick Waldron <waldron.rick@gmail.com>
  • Loading branch information...
rwaldron committed Oct 19, 2012
1 parent d2810f4 commit dee033467f02c3ea77e06190025ec9625058b19d
Showing with 268 additions and 146 deletions.
  1. +1 −0 README.md
  2. +142 −0 docs/nunchuk-classic-controller.md
  3. +1 −1 docs/nunchuk.md
  4. +6 −7 eg/nunchuk-classic-controller.js
  5. +1 −1 eg/nunchuk.js
  6. +4 −0 lib/johnny-five.js
  7. +112 −137 lib/wii.js
  8. +1 −0 programs.json
View
@@ -164,6 +164,7 @@ board.on("ready", function() {
### Wii Nunchuk
- [Nunchuk](https://github.com/rwldrn/johnny-five/blob/master/docs/nunchuk.md)
+- [Nunchuk Classic Controller](https://github.com/rwldrn/johnny-five/blob/master/docs/nunchuk-classic-controller.md)
### Sensors
- [Accelerometer](https://github.com/rwldrn/johnny-five/blob/master/docs/accelerometer.md)
@@ -0,0 +1,142 @@
+# Nunchuk Classic Controller
+
+Run with:
+```bash
+node eg/nunchuk-classic-controller.js
+```
+
+
+```javascript
+var five = require("johnny-five"),
+ board, nunchuk;
+
+board = new five.Board();
+
+
+// Setup for bread board
+// Wire Color => Meaning => Arduino Pin Down
+// Yellow => SCK => A04
+// White => GND => Ground
+// Red => 5v => 5v
+// Green => SDA => A05
+
+
+board.on("ready", function() {
+
+ // Create a new `Wii.Classic` hardware instance,
+ // specifically the RVL-005 device (classic controller).
+ var classicController = five.Wii.Classic({
+ freq: 100
+ });
+
+
+ // Nunchuk Event API
+ //
+
+ // "read" (nunchuk)
+ //
+ // Fired when the joystick detects a change in
+ // axis position.
+ //
+ // nunchuk.on( "read", function( err ) {
+
+ // });
+
+ // "change", "axischange" (joystick)
+ //
+ // Fired when the joystick detects a change in
+ // axis position.
+ //
+ nunchuk.joystick.left.on( "change", function( err, event ) {
+ console.log(
+ "Left joystick " + event.axis,
+ event.target[ event.axis ],
+ event.axis, event.direction
+ );
+ });
+
+ nunchuk.joystick.right.on( "change", function( err, event ) {
+ console.log(
+ "Right joystick " + event.axis,
+ event.target[ event.axis ],
+ event.axis, event.direction
+ );
+ });
+
+ // "down"
+ // aliases: "press", "tap", "impact", "hit"
+ //
+ // Fired when any nunchuk button is "down"
+ //
+
+ // "up"
+ // alias: "release"
+ //
+ // Fired when any nunchuk button is "up"
+ //
+
+ // "hold"
+ //
+ // Fired when any nunchuk button is in the "down" state for
+ // a specified amount of time. Defaults to 500ms
+ //
+ // To specify a custom hold time, use the "holdtime"
+ // option of the Nunchuk constructor.
+ //
+
+
+ [ "down", "up", "hold" ].forEach(function( type ) {
+
+ nunchuk.on( type, function( err, event ) {
+ console.log(
+ event.target.which + " is " + type,
+
+ { isUp: event.target.isUp,
+ isDown: event.target.isDown
+ }
+ );
+ });
+
+ });
+
+
+// Further reading
+// http://media.pragprog.com/titles/msard/tinker.pdf
+// http://lizarum.com/assignments/physical_computing/2008/wii_nunchuck.html
+});
+
+```
+
+## Breadboard
+
+
+
+
+
+## Devices
+
+
+
+
+## Documentation
+
+_(Nothing yet)_
+
+
+
+
+
+
+
+
+
+## Contributing
+All contributions must adhere to the [Idiomatic.js Style Guide](https://github.com/rwldrn/idiomatic.js),
+by maintaining the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code using [grunt](https://github.com/cowboy/grunt).
+
+## Release History
+_(Nothing yet)_
+
+## License
+Copyright (c) 2012 Rick Waldron <waldron.rick@gmail.com>
+Licensed under the MIT license.
View
@@ -15,7 +15,7 @@ board = new five.Board();
board.on("ready", function() {
// Create a new `nunchuk` hardware instance.
- nunchuk = new five.Nunchuk({
+ nunchuk = new five.Wii.Nunchuk({
freq: 50
});
@@ -14,11 +14,10 @@ board = new five.Board();
board.on("ready", function() {
- // Create a new `nunchuk` hardware instance, specifically the RVL-005 device (classic controller).
- var classicController = five.Nunchuk({
- pins: ["A4", "A5"],
- freq: 100,
- device: "RVL-005"
+ // Create a new `Wii.Classic` hardware instance,
+ // specifically the RVL-005 device (classic controller).
+ var classicController = five.Wii.Classic({
+ freq: 100
});
@@ -39,15 +38,15 @@ board.on("ready", function() {
// Fired when the joystick detects a change in
// axis position.
//
- nunchuk.left_joystick.on( "change", function( err, event ) {
+ nunchuk.joystick.left.on( "change", function( err, event ) {
console.log(
"Left joystick " + event.axis,
event.target[ event.axis ],
event.axis, event.direction
);
});
- nunchuk.right_joystick.on( "change", function( err, event ) {
+ nunchuk.joystick.right.on( "change", function( err, event ) {
console.log(
"Right joystick " + event.axis,
event.target[ event.axis ],
View
@@ -6,7 +6,7 @@ board = new five.Board();
board.on("ready", function() {
// Create a new `nunchuk` hardware instance.
- nunchuk = new five.Nunchuk({
+ nunchuk = new five.Wii.Nunchuk({
freq: 50
});
View
@@ -79,3 +79,7 @@ module.exports.IR.Motion = function( opt ) {
// Short-handing, Aliases
module.exports.Servos = module.exports.Servo.Array;
module.exports.Leds = module.exports.Led.Array;
+
+
+// Back Compat
+module.exports.Nunchuk = module.exports.Wii.Nunchuk;
Oops, something went wrong.

0 comments on commit dee0334

Please sign in to comment.