-
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -15,7 +15,7 @@ | |
| #define Firmata_h | ||
|
|
||
| #include "Boards.h" /* Hardware Abstraction Layer + Wiring/Arduino */ | ||
| #include "FirmataConstants.h" | ||
| #include "FirmataDefines.h" | ||
| #include "FirmataMarshaller.h" | ||
| #include "FirmataParser.h" | ||
|
|
||
|
|
@@ -48,18 +48,17 @@ | |
| #define ENCODER 0x09 // same as PIN_MODE_ENCODER | ||
| #define IGNORE 0x7F // same as PIN_MODE_IGNORE | ||
|
|
||
| extern "C" { | ||
| // callback function types | ||
| typedef void (*callbackFunction)(uint8_t, int); | ||
| typedef void (*systemCallbackFunction)(void); | ||
| typedef void (*stringCallbackFunction)(char *); | ||
| typedef void (*sysexCallbackFunction)(uint8_t command, uint8_t argc, uint8_t *argv); | ||
| } | ||
| namespace firmata { | ||
|
|
||
| // TODO make it a subclass of a generic Serial/Stream base class | ||
| class FirmataClass | ||
| { | ||
| public: | ||
| typedef void (*callbackFunction)(uint8_t, int); | ||
| typedef void (*systemCallbackFunction)(void); | ||
| typedef void (*stringCallbackFunction)(char *); | ||
| typedef void (*sysexCallbackFunction)(uint8_t command, uint8_t argc, uint8_t *argv); | ||
|
|
||
| FirmataClass(); | ||
|
|
||
| /* Arduino constructors */ | ||
|
|
@@ -92,10 +91,10 @@ class FirmataClass | |
| void write(byte c); | ||
|
|
||
| /* attach & detach callback functions to messages */ | ||
| void attach(uint8_t command, ::callbackFunction newFunction); | ||
| 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); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. when to use
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When referring to Firmata components, the less we can use I tucked the callback types into 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). |
||
| void attach(uint8_t command, systemCallbackFunction newFunction); | ||
| void attach(uint8_t command, stringCallbackFunction newFunction); | ||
| void attach(uint8_t command, sysexCallbackFunction newFunction); | ||
| void detach(uint8_t command); | ||
|
|
||
| /* access pin state and config */ | ||
|
|
@@ -156,7 +155,17 @@ class FirmataClass | |
| inline static void staticSystemResetCallback (void *) { if ( currentSystemResetCallback ) { currentSystemResetCallback(); } } | ||
| }; | ||
|
|
||
| extern FirmataClass Firmata; | ||
| } // namespace firmata | ||
|
|
||
| extern "C" { | ||
| // callback function types | ||
| typedef firmata::FirmataClass::callbackFunction callbackFunction; | ||
| typedef firmata::FirmataClass::systemCallbackFunction systemCallbackFunction; | ||
| typedef firmata::FirmataClass::stringCallbackFunction stringCallbackFunction; | ||
| typedef firmata::FirmataClass::sysexCallbackFunction sysexCallbackFunction; | ||
| } | ||
|
|
||
| extern firmata::FirmataClass Firmata; | ||
|
|
||
| /*============================================================================== | ||
| * MACROS | ||
|
|
||
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.
Uh oh!
There was an error while loading. Please reload this page.
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.