Closed rwaldron closed 11 years ago
This is a great idea, I came across this a bunch during nodebots. Would you want to throw an Error?
While we are on the topic of PWM pins I also noticed that the code for checking PWM is pretty much hard coded to the UNO and incompatible with the Mega which has different PWM pins. Thinking maybe a type option in Board(). Working on it here but it's currently untested
@divanvisagie oof, yeah, good call.
Need:
Thoughts?
Firmata.h, Firmata.cpp and Boards.h all know what kind of board is attached—I wish we could do this in a way that didn't require the user to explicitly specify anything
Firmata reports a lot when you ask =) http://firmata.org/wiki/Protocol#Capability_Query
I wasn't able to pursue this earlier—I'm in Boston without a board :(
EDIT: This looks like exactly what we need for the task
Im sure the above mentioned commit caused this issue so im putting it here instead of creating a new one.
When running the following code on an UNO everything works fine:
var five = require( 'johnny-five' ),
board;
board = new five.Board();
var led;
board.on( 'ready', function(){
led = new five.Led(13);
this.loop( 500, function(){
led.toggle();
});
} );
Things dont turn out too well however on my Spider:
/Users/divanvisagie/node_modules/johnny-five/lib/board.js:740
return Object.keys( translations ).reduce(function( pin, map ) {
^
TypeError: Object.keys called on non-object
at Function.keys (native)
at Function.Board.Pins.translate (/Users/divanvisagie/node_modules/johnny-five/lib/board.js:740:17)
at Function.Board.Pins.normalize (/Users/divanvisagie/node_modules/johnny-five/lib/board.js:654:20)
at Led.Board.Device (/Users/divanvisagie/node_modules/johnny-five/lib/board.js:554:21)
at new Led (/Users/divanvisagie/node_modules/johnny-five/lib/led.js:28:16)
at Board.<anonymous> (/Users/divanvisagie/Desktop/led.js:11:8)
at Board.EventEmitter.emit (events.js:95:17)
at Board.<anonymous> (/Users/divanvisagie/node_modules/johnny-five/lib/board.js:288:14)
at Board.<anonymous> (/Users/divanvisagie/node_modules/johnny-five/lib/board.js:130:18)
at null.<anonymous> (/Users/divanvisagie/node_modules/firmata/lib/firmata.js:330:25)
Will update any progress on this.
So far the problem looks like its here:
https://github.com/rwldrn/johnny-five/blob/master/lib/board.js#L739
Using the uno the value of translations
is:
{ tinker:
{ I0: 'A0',
I1: 'A1',
I2: 'A2',
I3: 'A3',
I4: 'A4',
I5: 'A5',
O0: 11,
O1: 10,
O2: 9,
O3: 6,
O4: 5,
O5: 3,
D13: 13,
D12: 12,
D8: 8,
D7: 7,
D4: 4,
D2: 2 } }
However on the spider translations
is undefined.
Looks like the problem is quite simple: The MEGA isn't mapped yet
var totalPins = {
20: {
UNO: [ 0, 0, 3, 4, 3, 4, 4, 3, 3, 4, 4, 4, 3, 3, 3, 3, 3, 3, 3, 3 ]
},
70: {
MEGA: [ ]
}
};
This was part of the issue, the other is that I needed to handle cases where no translations exist. I fixed that yesterday and pushed a new version to npm.
Still need analog mapping for mega!
@rwldrn wasn't that what this was for? https://gist.github.com/rwldrn/5792793
Huh—Yes. I never received any notifications about comments on the gist. shrugs
I was trying to get the Leonardo working, and found it is missing pin mappings. But I'm not sure this is the best approach. For one, there aren't different boards with the same number of pins, so this is unnecessary abstraction. Furthermore, the matching is done using only the number of modes a pin supports, which might be inaccurate. How about the following:
var totalPins = {
20: 'UNO',
30: 'LEONARDO',
70: 'MEGA'
};
and:
type = totalPins[length];
Plus a case should be added for when there's no match. Is a pull request more appropriate?
This was implemented, but has since been scaled back to a debug mode opt-in
It would be useful to display a warning in the REPL that makes a user aware that they've made a mistake in these (and other) cases:
others?