Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Firmata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@
#include "Firmata.h"
#include "HardwareSerial.h"

extern "C" {
#include <string.h>
#include <stdlib.h>
}

using namespace firmata;

//******************************************************************************
//* Static Members
Expand Down
35 changes: 22 additions & 13 deletions Firmata.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#define Firmata_h

#include "Boards.h" /* Hardware Abstraction Layer + Wiring/Arduino */
#include "FirmataConstants.h"
#include "FirmataDefines.h"
Copy link
Member

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.

Copy link
Member

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.

Copy link
Contributor Author

@zfields zfields Feb 24, 2017

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.

#include "FirmataMarshaller.h"
#include "FirmataParser.h"

Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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);
Copy link
Member

@soundanalogous soundanalogous Feb 24, 2017

Choose a reason for hiding this comment

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

when to use :: ?

Copy link
Contributor Author

@zfields zfields Feb 24, 2017

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

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 */
Expand Down Expand Up @@ -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
Expand Down
Loading