-
Notifications
You must be signed in to change notification settings - Fork 516
Complete base API #350
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Complete base API #350
Conversation
FirmataMarshaller.cpp
Outdated
void FirmataMarshaller::sendPinStateQuery(uint8_t pin) | ||
const | ||
{ | ||
sendSysex(PIN_STATE_QUERY, sizeof(pin), &pin); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sendSysex
will send pin
as 2 bytes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
great catch! fixed.
ce5e8b2
to
4006e1d
Compare
includes support function transformByteStreamToMessageBytes(), which replaces sendValueAsTwo7bitBytes()
* @param bytev A pointer to the array of data bytes to send in the message. | ||
* @param max_bytes Force message to be n bytes, regardless of data bits. | ||
*/ | ||
void FirmataMarshaller::transformByteStreamToMessageBytes (size_t bytec, uint8_t * bytev, size_t max_bytes) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is a similar Encoder7Bit class in ConfigurableFirmata that both reads and writes: https://github.com/firmata/ConfigurableFirmata/blob/master/src/Encoder7Bit.cpp
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool, I wish I had seen it before! ;-) However, just looking at it (and mulling it over) briefly, it looks like another dependency that will need to be managed.
Since this is a self-contained, private function, we will be able to refactor it at any time, without impacting the external API. For now, I would like to move forward using the current implementation, at least until ConfigurableFirmata becomes a little more mainstream (or Encoder7Bit is refactored to consume/extend the FirmataMarshaller API) and gets pulled under the firmata
namespace.
@soundanalogous I responded inline to your suggestion. In short, I think it's a great idea, but is non-blocking and would be better suited during a larger refactoring. Otherwise, I have tested this with every means I have available, and everything looks good.
|
* @param value The value of the analog pin (0 - 1024 for 10-bit analog, 0 - 4096 for 12-bit, etc). | ||
* The maximum value is 14-bits (16384). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add this back in with the updated max. I assume it's 32 bits. However different firmata client libraries may interpret this in different ways (I think some only expect a max of 16 bits), but that shouldn't break anything unless a library looks for a specific number of bytes rather than accepting all bytes up to END_SYSEX (but that would be the fault of the client library).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is, in fact, still 14-bits. I removed it when I thought it would be changing. I have replaced the note. I amended the last commit because it was aptly named.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's limited to 14 bits when using ANALOG_MESSAGE, but sendAnalog now calls sendExtendedAnalog so larger values should be allowed. No cap is defined in the protocol documentation but I think 32-bit is probably reasonable (although not sure I've ever seen hardware that supports that resolution).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here's the equivalent in firmata.js for example: https://github.com/firmata/firmata.js/blob/master/lib/firmata.js#L776-L806
FirmataMarshaller.cpp
Outdated
FirmataStream->write(ANALOG_MESSAGE | (pin & 0xF)); | ||
sendValueAsTwo7bitBytes(value); | ||
|
||
if ( (0xF >= pin) && (0x3FFF >= value) ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this should be ||
rather than &&
since it's possible to have a pin number > 15 with a value > 14 bits
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
oh wait, this is fine as is. I'm not used to the static value being on the left side of the comparison so it confused me for a second.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ha! Yeah, I used to be teaching assistant, so I always taught the kids to put it on the left because you can't accidentally set it when trying to compare.
Should we add something around the reset functionality while we are doing this? Got any names in mind? |
It's purely a software reset. A user crafting their own Firmata sketch can do anything they want in the callback. StandardFirmata initializes everything to a known state. FirmataParser resets the buffer. So naming is a bit tricky. |
292aa1e
to
42960d3
Compare
Please review the three new functions |
Sounds good. Have you compiled against a bunch of boards in the IDE (even if you don't have those actual boards - including ones like the Intel boards which have the fussier c++ compiler)? |
It compiles on ESP8266, 101 and AVR without warning (at least not caused by me ;-) ). |
Just downloaded the SAMD toolchain, and it builds for MKR1000 |
Ran through my usual compile tests in Arduino 1.8.1 (I really need to spend time to figure out a way to automate this at some point). Also tested with Arduino 1.6.12, 1.5.8 and 1.0.6. Fails with Arduino 1.6.11 but it appears to be an issue with arduino-builder, not Firmata (have noticed this previously as well... I guess Arduino is not testing older versions anymore, or maybe they only test the most recent 2 versions). One thing to be mindful of is the increase in program memory. Compiling StandardFirmataPlus for an Arduino Uno in Arduino 1.8.1 with Firmata v2.5.4 consumes 13924 bytes of Flash and 1244 bytes of SRAM. However with this most recent PR we are up to 15278 bytes of Flash (increase of 1354 bytes - this is all changes since v2.5.4 was released... not just this PR) and 1298 bytes of RAM. I'm not too concerned about the increased RAM since it's only +54 bytes, but we should keep and eye on the Flash increase since we've added 1354 bytes so far without adding any new Firmata features. |
Fair point. I expect much of this has to do with allowing the callbacks to have context, which automatically doubles the storage required for each callback, but allows for multiple instances and provides enormous functional gains. Not to mention, I had to make a callback abstraction to patch between the old static callbacks and the new stateful callbacks. Depending on where you are looking to go with the FirmataParser I could see it taking on a little more water or shedding a little weight. However, I believe an honest, deliberate refactor can produce a significant memory footprint improvement. It's usually stuff you don't expect, but I would advise against cutting functionality as it is usually not necessary. |
Yeah I figure we can reduce usage through a refactor in the future. Cleaning up the StandardFirmata variants at some point will probably also help bring the Flash usage size down. |
This commit is intended to be the first of many addressing any missing APIs listed in issue #349