Skip to content

Commit bf3f08f

Browse files
Merge pull request #348 from zfields/namespace
namespace firmata
2 parents 2bd457a + 3cd149c commit bf3f08f

File tree

8 files changed

+378
-257
lines changed

8 files changed

+378
-257
lines changed

Firmata.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@
1818
#include "Firmata.h"
1919
#include "HardwareSerial.h"
2020

21-
extern "C" {
2221
#include <string.h>
2322
#include <stdlib.h>
24-
}
23+
24+
using namespace firmata;
2525

2626
//******************************************************************************
2727
//* Static Members

Firmata.h

Lines changed: 22 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
#define Firmata_h
1616

1717
#include "Boards.h" /* Hardware Abstraction Layer + Wiring/Arduino */
18-
#include "FirmataConstants.h"
18+
#include "FirmataDefines.h"
1919
#include "FirmataMarshaller.h"
2020
#include "FirmataParser.h"
2121

@@ -48,18 +48,17 @@
4848
#define ENCODER 0x09 // same as PIN_MODE_ENCODER
4949
#define IGNORE 0x7F // same as PIN_MODE_IGNORE
5050

51-
extern "C" {
52-
// callback function types
53-
typedef void (*callbackFunction)(uint8_t, int);
54-
typedef void (*systemCallbackFunction)(void);
55-
typedef void (*stringCallbackFunction)(char *);
56-
typedef void (*sysexCallbackFunction)(uint8_t command, uint8_t argc, uint8_t *argv);
57-
}
51+
namespace firmata {
5852

5953
// TODO make it a subclass of a generic Serial/Stream base class
6054
class FirmataClass
6155
{
6256
public:
57+
typedef void (*callbackFunction)(uint8_t, int);
58+
typedef void (*systemCallbackFunction)(void);
59+
typedef void (*stringCallbackFunction)(char *);
60+
typedef void (*sysexCallbackFunction)(uint8_t command, uint8_t argc, uint8_t *argv);
61+
6362
FirmataClass();
6463

6564
/* Arduino constructors */
@@ -92,10 +91,10 @@ class FirmataClass
9291
void write(byte c);
9392

9493
/* attach & detach callback functions to messages */
95-
void attach(uint8_t command, ::callbackFunction newFunction);
96-
void attach(uint8_t command, ::systemCallbackFunction newFunction);
97-
void attach(uint8_t command, ::stringCallbackFunction newFunction);
98-
void attach(uint8_t command, ::sysexCallbackFunction newFunction);
94+
void attach(uint8_t command, callbackFunction newFunction);
95+
void attach(uint8_t command, systemCallbackFunction newFunction);
96+
void attach(uint8_t command, stringCallbackFunction newFunction);
97+
void attach(uint8_t command, sysexCallbackFunction newFunction);
9998
void detach(uint8_t command);
10099

101100
/* access pin state and config */
@@ -156,7 +155,17 @@ class FirmataClass
156155
inline static void staticSystemResetCallback (void *) { if ( currentSystemResetCallback ) { currentSystemResetCallback(); } }
157156
};
158157

159-
extern FirmataClass Firmata;
158+
} // namespace firmata
159+
160+
extern "C" {
161+
// callback function types
162+
typedef firmata::FirmataClass::callbackFunction callbackFunction;
163+
typedef firmata::FirmataClass::systemCallbackFunction systemCallbackFunction;
164+
typedef firmata::FirmataClass::stringCallbackFunction stringCallbackFunction;
165+
typedef firmata::FirmataClass::sysexCallbackFunction sysexCallbackFunction;
166+
}
167+
168+
extern firmata::FirmataClass Firmata;
160169

161170
/*==============================================================================
162171
* MACROS

0 commit comments

Comments
 (0)