Skip to content

Pin resolutions#144

Closed
monteslu wants to merge 6 commits intofirmata:masterfrom
monteslu:pinResolutions
Closed

Pin resolutions#144
monteslu wants to merge 6 commits intofirmata:masterfrom
monteslu:pinResolutions

Conversation

@monteslu
Copy link
Copy Markdown
Contributor

@monteslu monteslu commented Dec 4, 2016

This adds resolution or label properties to pins.

Also adds a new test and a few more assertions

Fixes #105

Comment thread lib/firmata.js
if (board.currentBuffer[i] === 127) {
board.pins.push({
supportedModes: supportedModes(capability),
mode: undefined,
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the mode property was not carried over

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@soundanalogous
Copy link
Copy Markdown
Member

LGTM. I'll wait for @rwaldron to weigh-in in case he has any nits.

Comment thread lib/firmata.js
value: 0,
report: 1,
});
pin.supportedModes = supportedModes(capability);
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

var pin = {}; should be above this line.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added the comment for clarity on byte 127. Save refactor for ES2015+ in firmata v 3?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread lib/firmata.js
pin.value = 0;
pin.report = 1;
board.pins.push(pin);
pin = {};
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this line

Comment thread lib/firmata.js
if (!board.pins.length) {
var pin = {};
for (var i = 2, n = 0; i < board.currentBuffer.length - 1; i++) {
if (board.currentBuffer[i] === 127) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add the following comment above this line:
// 127 denotes the end of the pin's modes

Comment thread lib/firmata.js
continue;
}
if (n === 0) {
capability |= (1 << board.currentBuffer[i]);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could initialize the pin object here.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Comment thread lib/firmata.js
}
if (n === 0) {
capability |= (1 << board.currentBuffer[i]);
pin[modeNames[board.currentBuffer[i]] + "Resolution"] = board.currentBuffer[i + 1];
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@monteslu
Copy link
Copy Markdown
Contributor Author

monteslu commented Dec 4, 2016

Sounds good. Kinda wish we had Object.assign though. I'll do a for(in...

@soundanalogous
Copy link
Copy Markdown
Member

What is the state of ES2015 support in Node? Perhaps worth migrating firmata.js at some point in the near future?

@soundanalogous
Copy link
Copy Markdown
Member

Looks like johnny-five uses Object.assign. Could add the es6-shim module and then define something like this:

(!Array.from || !Object.assign || !Map) {
  require("es6-shim");
}

@rwaldron
Copy link
Copy Markdown
Collaborator

What is the state of ES2015 support in Node? Perhaps worth migrating firmata.js at some point in the near future?

I've had a WIP branch for about year, I suppose I could revive it

@soundanalogous
Copy link
Copy Markdown
Member

soundanalogous commented Jan 12, 2017

Here's what I think the next steps are here:

  • Undo the changes related to the Serial pin labels, I need to think more about how to handle that.
  • Add an array of pin modes that have resolution values (to use as a comparison so all pins modes don't end up with "<modeName>Resolution". I think we really only care about analog in (analogResolution) and analog out (pwmResolution) for now (for modes like Servo and Stepper, I'd rather add commands to query the resolution for those features directly as opposed to returning via capability query - I want to trim down the capability query response size for Firmata 3.0).

@rwaldron
Copy link
Copy Markdown
Collaborator

I'm presently working out how to make these consistent for all platforms and IO plugins that model their exposed API after Firmata.js

@rwaldron
Copy link
Copy Markdown
Collaborator

(to use as a comparison so all pins modes don't end up with "Resolution"

This matches the path I'm presently on as well.

I think we really only care about analog in (analogResolution) and analog out (pwmResolution) for now

I agree

@rwaldron
Copy link
Copy Markdown
Collaborator

@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.

@soundanalogous
Copy link
Copy Markdown
Member

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.

@rwaldron
Copy link
Copy Markdown
Collaborator

rwaldron commented Jan 12, 2017

Not that I'm aware of, but I also haven't looked into it in detail for a while

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 board.RESOLUTION.FOO, just as they would board.MODES.FOO

@soundanalogous
Copy link
Copy Markdown
Member

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).

@rwaldron
Copy link
Copy Markdown
Collaborator

That's awesome :) Yes, I think it will be relatively easy to adapt this.

@monteslu
Copy link
Copy Markdown
Contributor Author

This was resolved with #149

@monteslu monteslu closed this Jan 16, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants