-
Notifications
You must be signed in to change notification settings - Fork 517
namespace firmata #348
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
namespace firmata #348
Conversation
Continues to expose the API that was previously exposed, but also allows a consumer to use the complete API fully encapsulated in the `firmata` namespace
|
This allows firmata to pulled into bigger projects and ensures there will be no name collisions. This should be a no-op but it would still be good to test. |
|
I just confirmed it passes |
|
I initially did this for my project, but I just realized this addresses issue #253 However this approach does not break your API, and therefore does not need to wait for v3.0. However, you are free to eliminate everything not in a namespace at v3.0 or as you see fit. |
FirmataConstants.h
Outdated
| #undef SYSEX_REALTIME | ||
| #endif | ||
| #define SYSEX_REALTIME 0x7F // MIDI Reserved for realtime messages | ||
| static const int SERIAL_MESSAGE = 0x60; // communicate with serial devices, including other boards |
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.
do these each consume 16 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.
#defines are known as integer literals and treated as int so this shouldn't make any difference. Also both the #defines and static const will show up in the .data section of the memory map.
To confirm I ran side-by-side compiles looking at the "program storage space" and "dynamic memory". Neither change for the Uno, 101^ or ESP8266.
^101 only reports "program storage space"
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.
Yes, but they always did. #defines in the context above are also known as integer constants. Both static const int x = 0x7F; and #define 0x7F require the same amount of space in the .data segment.
In a side-by-side compile, there is no change in the "program storage space" or "dynamic memory" usage for the Uno, 101* and ESP8266.
*The 101 only reports "program storage space".
|
|
||
| #include "Boards.h" /* Hardware Abstraction Layer + Wiring/Arduino */ | ||
| #include "FirmataConstants.h" | ||
| #include "FirmataDefines.h" |
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.
I don't think this filename change was intentional.
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 nevermind... I see you split FimrataConstants into 2 files.
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 split allows big project users to have all the constants under the firmata namespace, while Arduino users get to keep the global preprocessor defines.
The global preprocessor defines are based off the constants, so there is a single point of reference. Also, the clean separation of the defines, allows them to be removed at a later date (v3.0) if desired.
| void attach(uint8_t command, ::systemCallbackFunction newFunction); | ||
| void attach(uint8_t command, ::stringCallbackFunction newFunction); | ||
| void attach(uint8_t command, ::sysexCallbackFunction newFunction); | ||
| void attach(uint8_t command, callbackFunction newFunction); |
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.
when to use :: ?
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.
When referring to Firmata components, the less we can use :: the better, because it points to the global namespace (which is what we are trying to get away from).
I tucked the callback types into FirmataClass (as they are related to its implementation), and now I am referencing them there. A good example of why this is important is a name like systemCallbackFunction, which can be considered ambiguous.
I updated the pre-existing globals to be based on these new, scoped types so they can be referenced by existing sketches, but can be easily removed in the future (v3.0).
|
Do all of these new declarations consume memory? |
|
There should be no additional run-time tax for these declarations. They are only duplicate type definitions (which amount to text), and will be optimized away by the compiler. Which there seems to be evidence of, especially when compiling side-by-side. |
FirmataConstants.h
Outdated
| #define FIRMATA_FIRMWARE_MAJOR_VERSION 2 | ||
| #define FIRMATA_FIRMWARE_MINOR_VERSION 5 | ||
| #define FIRMATA_FIRMWARE_BUGFIX_VERSION 4 | ||
| static const int FIRMATA_FIRMWARE_MAJOR_VERSION = 2; |
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.
remove FIRMATA_ from this since it's no longer necessary due to the namespace (we'll need to keep it in the define however)
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.
complete
FirmataConstants.h
Outdated
| #define FIRMATA_PROTOCOL_MAJOR_VERSION 2 // for non-compatible changes | ||
| #define FIRMATA_PROTOCOL_MINOR_VERSION 5 // for backwards compatible changes | ||
| #define FIRMATA_PROTOCOL_BUGFIX_VERSION 1 // for bugfix releases | ||
| static const int FIRMATA_PROTOCOL_MAJOR_VERSION = 2; // for non-compatible changes |
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.
remove FIRMATA_
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.
complete
FirmataConstants.h
Outdated
| #undef SYSEX_REALTIME | ||
| #endif | ||
| #define SYSEX_REALTIME 0x7F // MIDI Reserved for realtime messages | ||
| static const int SERIAL_MESSAGE = 0x60; // communicate with serial devices, including other boards |
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 would also be a good time to align on terminology. I've been debating between _MESSAGE and _DATA and unifying. Traditionally it's been _DATA, but when I added Serial I thought _MESSAGE may make more sense since that's a midi term. I need to think about this some 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.
As soon as you figure out how you want this handled, I will be happy to switch it up. Also happy to have this in place and be able to code against it!
IMO, everything adhering to a protocol is a message, and when you have bytes outside the protocol they are data. I think of data as bytes that pass through a transport (i.e. Serial). Don't know if that provides any clarity, but thats what you made me think of.
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.
Also, you can always pull these changes, and the namespaced names can be changed at any time before you stamp it with a version.
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.
@soundanalogous After reading the MIDI spec this morning, I'm going to take another stab at this. I think of the framing bytes and its payload as a (midi) message. While it is true the data encapsulated by the Firmata protocol is indeed a serial message, the actual description of the payload itself is serial data. That being said, my vote is for SERIAL_DATA.
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.
SGTM and keeps requires far fewer changes moving forward. I'll update in the protocol documentation as well.
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.
I've updated SERIAL_MESSAGE to SERIAL_DATA. I think DIGITAL_MESSAGE and ANALOG_MESSAGE are named correctly. Are there any others we should change while we are doing this?
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.
that's all I can think of for now
|
Ran this through all of my tests with no issues. @zfields good to go unless there is anything else you wanted to add here. |
|
@soundanalogous I am ready for you to pull. The only thing not secured by the |
Continues to expose the API that was previously exposed, but also allows a consumer to use the complete API fully encapsulated in the
firmatanamespace