Conversation
| if (board.currentBuffer[i] === 127) { | ||
| board.pins.push({ | ||
| supportedModes: supportedModes(capability), | ||
| mode: undefined, |
There was a problem hiding this comment.
the mode property was not carried over
|
LGTM. I'll wait for @rwaldron to weigh-in in case he has any nits. |
| value: 0, | ||
| report: 1, | ||
| }); | ||
| pin.supportedModes = supportedModes(capability); |
There was a problem hiding this comment.
var pin = {}; should be above this line.
There was a problem hiding this comment.
Problem is that the 127 comes at the end of the pin definition in the byte stream. I need to attach the new properties before that.
There was a problem hiding this comment.
Ok, I see now. I still think this should be refactored, to avoid this strange pin binding reassignment, but I think we can come back to it later (ie. not this PR).
There was a problem hiding this comment.
Added the comment for clarity on byte 127. Save refactor for ES2015+ in firmata v 3?
There was a problem hiding this comment.
@soundanalogous @rwaldron Are we good for now? I think I don't really have anything else to do if we're going to refactor this as ES2015+ in a later version.
There was a problem hiding this comment.
I'm good with the pin resolution changes, however I've been rethinking how to represent the Serial pins. I need to think more about how that information would be used (since you don't really need to think about pins when using a UART - you just need to know if it's Serial1, Serial2, Serial3, etc). One option is to revert the Serial pin changes for now and revisit once I have a better idea how to use them.
| pin.value = 0; | ||
| pin.report = 1; | ||
| board.pins.push(pin); | ||
| pin = {}; |
| if (!board.pins.length) { | ||
| var pin = {}; | ||
| for (var i = 2, n = 0; i < board.currentBuffer.length - 1; i++) { | ||
| if (board.currentBuffer[i] === 127) { |
There was a problem hiding this comment.
Add the following comment above this line:
// 127 denotes the end of the pin's modes
| continue; | ||
| } | ||
| if (n === 0) { | ||
| capability |= (1 << board.currentBuffer[i]); |
There was a problem hiding this comment.
You could initialize the pin object here.
There was a problem hiding this comment.
although it's probably not good practice to initialize a variable in a block where that variable is also used out side that block (even though it works with var)
| } | ||
| if (n === 0) { | ||
| capability |= (1 << board.currentBuffer[i]); | ||
| pin[modeNames[board.currentBuffer[i]] + "Resolution"] = board.currentBuffer[i + 1]; |
There was a problem hiding this comment.
Maybe a better strategy is to not apply these properties directly to the pin object here. Apply them to a temporary object and then apply to pin only in the above block. That way all assignment occurs within the same block much like how capability is applied to the pin in the above block as well.
|
Sounds good. Kinda wish we had Object.assign though. I'll do a |
|
What is the state of ES2015 support in Node? Perhaps worth migrating firmata.js at some point in the near future? |
|
Looks like johnny-five uses (!Array.from || !Object.assign || !Map) {
require("es6-shim");
} |
I've had a WIP branch for about year, I suppose I could revive it |
|
Here's what I think the next steps are here:
|
|
I'm presently working out how to make these consistent for all platforms and IO plugins that model their exposed API after Firmata.js |
This matches the path I'm presently on as well.
I agree |
|
@soundanalogous how likely is it that a given board will have more than one resolution for a specific "kind" of thing? I cannot recall ever encountering a board that had, for example, two different ADC chips, where one was 10-bit and the other 12-bit. Just so there's no misunderstanding, it is common to see ADC X-bit, PWM Y-bit and DAC Z-bit. |
|
Not that I'm aware of, but I also haven't looked into it in detail for a while. At least with Arduino, on some boards you can change between 2 analog read or write resolutions, but this is global. |
I've looked through all of the boards that are currently supported via the "io-plugin" interface and none have such a concept. I'm sure there is some silly Intel board somewhere that does that, but I'm not going to worry about it. Given that, I've refactored as such 6c0e0fa In most other platforms, implementation will be as trivial as adding the properties with hard values. Then consumers of Firmata.js instances can access the value as |
|
I think the null check is okay for now, but at some point I'm going to add support for the user to change the analog resolution value: firmata/protocol#8. I guess we can just change the logic when that lands (not likely for a while). |
|
That's awesome :) Yes, I think it will be relatively easy to adapt this. |
|
This was resolved with #149 |
This adds resolution or label properties to pins.
Also adds a new test and a few more assertions
Fixes #105