18 #include "FirmataDefines.h"
19 #include "FirmataMarshaller.h"
20 #include "FirmataParser.h"
25 #define FIRMATA_MAJOR_VERSION 2 // same as FIRMATA_PROTOCOL_MAJOR_VERSION
26 #define FIRMATA_MINOR_VERSION 5 // same as FIRMATA_PROTOCOL_MINOR_VERSION
27 #define FIRMATA_BUGFIX_VERSION 1 // same as FIRMATA_PROTOCOL_BUGFIX_VERSION
32 #define FIRMATA_STRING 0x71 // same as STRING_DATA
33 #define SYSEX_I2C_REQUEST 0x76 // same as I2C_REQUEST
34 #define SYSEX_I2C_REPLY 0x77 // same as I2C_REPLY
35 #define SYSEX_SAMPLING_INTERVAL 0x7A // same as SAMPLING_INTERVAL
41 #define ANALOG 0x02 // same as PIN_MODE_ANALOG
42 #define PWM 0x03 // same as PIN_MODE_PWM
43 #define SERVO 0x04 // same as PIN_MODE_SERVO
44 #define SHIFT 0x05 // same as PIN_MODE_SHIFT
45 #define I2C 0x06 // same as PIN_MODE_I2C
46 #define ONEWIRE 0x07 // same as PIN_MODE_ONEWIRE
47 #define STEPPER 0x08 // same as PIN_MODE_STEPPER
48 #define ENCODER 0x09 // same as PIN_MODE_ENCODER
49 #define IGNORE 0x7F // same as PIN_MODE_IGNORE
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);
67 void begin(Stream &s);
81 void parse(
unsigned char value);
86 void sendDigital(
byte pin,
int value);
89 void sendString(
byte command,
const char *
string);
90 void sendSysex(
byte command,
byte bytec,
byte *bytev);
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);
98 void detach(uint8_t command);
114 uint8_t parserBuffer[MAX_DATA_BYTES];
117 Stream *FirmataStream;
120 byte firmwareVersionCount;
121 byte *firmwareVersionVector;
124 byte pinConfig[TOTAL_PINS];
125 int pinState[TOTAL_PINS];
127 boolean blinkVersionDisabled;
130 void strobeBlinkPin(
byte pin,
int count,
int onInterval,
int offInterval);
131 friend void FirmataMarshaller::encodeByteStream (
size_t bytec, uint8_t * bytev,
size_t max_bytes = 0)
const;
134 static callbackFunction currentAnalogCallback;
135 static callbackFunction currentDigitalCallback;
136 static callbackFunction currentPinModeCallback;
137 static callbackFunction currentPinValueCallback;
138 static callbackFunction currentReportAnalogCallback;
139 static callbackFunction currentReportDigitalCallback;
140 static stringCallbackFunction currentStringCallback;
141 static sysexCallbackFunction currentSysexCallback;
142 static systemCallbackFunction currentSystemResetCallback;
145 inline static void staticAnalogCallback (
void *, uint8_t command, uint16_t value) {
if ( currentAnalogCallback ) { currentAnalogCallback(command,(
int)value); } }
146 inline static void staticDigitalCallback (
void *, uint8_t command, uint16_t value) {
if ( currentDigitalCallback ) { currentDigitalCallback(command, (
int)value); } }
147 inline static void staticPinModeCallback (
void *, uint8_t command, uint16_t value) {
if ( currentPinModeCallback ) { currentPinModeCallback(command, (
int)value); } }
148 inline static void staticPinValueCallback (
void *, uint8_t command, uint16_t value) {
if ( currentPinValueCallback ) { currentPinValueCallback(command, (
int)value); } }
149 inline static void staticReportAnalogCallback (
void *, uint8_t command, uint16_t value) {
if ( currentReportAnalogCallback ) { currentReportAnalogCallback(command, (
int)value); } }
150 inline static void staticReportDigitalCallback (
void *, uint8_t command, uint16_t value) {
if ( currentReportDigitalCallback ) { currentReportDigitalCallback(command, (
int)value); } }
151 inline static void staticStringCallback (
void *,
const char * c_str) {
if ( currentStringCallback ) { currentStringCallback((
char *)c_str); } }
152 inline static void staticSysexCallback (
void *, uint8_t command,
size_t argc, uint8_t *argv) {
if ( currentSysexCallback ) { currentSysexCallback(command, (uint8_t)argc, argv); } }
153 inline static void staticReportFirmwareCallback (
void * context,
size_t,
size_t,
const char *) {
if ( context ) { ((
FirmataClass *)context)->printFirmwareVersion(); } }
154 inline static void staticReportVersionCallback (
void * context) {
if ( context ) { ((
FirmataClass *)context)->printVersion(); } }
155 inline static void staticSystemResetCallback (
void *) {
if ( currentSystemResetCallback ) { currentSystemResetCallback(); } }
162 typedef firmata::FirmataClass::callbackFunction callbackFunction;
163 typedef firmata::FirmataClass::systemCallbackFunction systemCallbackFunction;
164 typedef firmata::FirmataClass::stringCallbackFunction stringCallbackFunction;
165 typedef firmata::FirmataClass::sysexCallbackFunction sysexCallbackFunction;
178 #define setFirmwareVersion(x, y) setFirmwareNameAndVersion(__FILE__, x, y)