Skip to content

Added support for Intel's Galileo Board #96

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

Closed
wants to merge 31 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
d083c3a
fixes file path issue for windows in setFirmwareNameAndVersion
soundanalogous Feb 14, 2013
bcb7ca3
Merge branch 'dev' into win-report-firmware-fix
soundanalogous Apr 6, 2013
b1c78c5
fixed memory leak in string buffer
soundanalogous Aug 1, 2013
04b04d5
updated to decode incoming string within input buffer to save memory
soundanalogous Aug 4, 2013
9e5d2b8
increased input data buffer size from 32 to 64 bytes
soundanalogous Aug 4, 2013
f1c6f12
removed string memory leak test
soundanalogous Aug 4, 2013
90b6a9b
Merge branch 'master' into win-report-firmware-fix
soundanalogous Aug 4, 2013
678f428
updating to allow user specified filename
soundanalogous Aug 4, 2013
53515bd
fixed typo in comment
soundanalogous Aug 4, 2013
1fe1dcc
Merge pull request #76 from firmata/memory-leak-fix
soundanalogous Aug 10, 2013
3426280
Merge pull request #30 from soundanalogous/win-report-firmware-fix
soundanalogous Aug 10, 2013
0d644bc
removed commented out method
soundanalogous Aug 10, 2013
6f4fb3f
adding version and date to header files
soundanalogous Aug 10, 2013
2d9c999
echoing change to comment from firmata in arduino repo
soundanalogous Aug 10, 2013
02ebba0
adding defines for new commands used in ConfigurableFirmata to reserv…
soundanalogous Aug 10, 2013
92a41bf
bumping minor version
soundanalogous Aug 10, 2013
1d25e00
adding properties file and moving license to extras dir per new libra…
soundanalogous Aug 10, 2013
dd5a424
simplified test directory and updated test readme
soundanalogous Aug 10, 2013
f0a43ca
updated examples to set current version
soundanalogous Aug 10, 2013
1a68c52
fixed IS_PIN_SPI ifndef in boards.h
soundanalogous Aug 10, 2013
4c2c60f
update keywords file
soundanalogous Aug 10, 2013
2d0fa27
changing flush() to FirmataSerial->flush
soundanalogous Aug 10, 2013
7e7a36c
shortening error message strings to save a few bytes of ram
soundanalogous Aug 10, 2013
6be6a86
removed flush. will revisit later
soundanalogous Aug 10, 2013
25e5128
writePort now returns 1. addresses issue #31
soundanalogous Aug 10, 2013
9c789b9
fixed conditional expression in I2C_STOP_READING case
soundanalogous Aug 10, 2013
1efd966
changed samplingInterval from int to unsigned int to remove compiler …
soundanalogous Aug 10, 2013
c8220d8
renamed FirmataSerial to FirmataStream
soundanalogous Aug 10, 2013
e2ae488
updated readme
soundanalogous Aug 11, 2013
1299ac5
removed makefiles from examples
soundanalogous Aug 24, 2013
1c2c750
remove release script from gitignore
soundanalogous Oct 28, 2013
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
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1 @@
.DS_Store
release.sh
4 changes: 3 additions & 1 deletion Boards.h
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ writePort(port, value, bitmask): Write an 8 bit port.
#endif

// as long this is not defined for all boards:
#ifndef IS_PIN_SPI(p)
#ifndef IS_PIN_SPI
#define IS_PIN_SPI(p) 0
#endif

Expand Down Expand Up @@ -400,6 +400,7 @@ static inline unsigned char writePort(byte port, byte value, byte bitmask)
PORTC = (PORTC & maskC) | valC;
sei();
}
return 1;
#else
byte pin=port*8;
if ((bitmask & 0x01)) digitalWrite(PIN_TO_DIGITAL(pin+0), (value & 0x01));
Expand All @@ -410,6 +411,7 @@ static inline unsigned char writePort(byte port, byte value, byte bitmask)
if ((bitmask & 0x20)) digitalWrite(PIN_TO_DIGITAL(pin+5), (value & 0x20));
if ((bitmask & 0x40)) digitalWrite(PIN_TO_DIGITAL(pin+6), (value & 0x40));
if ((bitmask & 0x80)) digitalWrite(PIN_TO_DIGITAL(pin+7), (value & 0x80));
return 1;
#endif
}

Expand Down
107 changes: 56 additions & 51 deletions Firmata.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Firmata.cpp - Firmata library
Firmata.cpp - Firmata library v2.4.0 - 2013-08-09
Copyright (C) 2006-2008 Hans-Christoph Steiner. All rights reserved.

This library is free software; you can redistribute it and/or
Expand Down Expand Up @@ -28,18 +28,18 @@ extern "C" {

void FirmataClass::sendValueAsTwo7bitBytes(int value)
{
FirmataSerial->write(value & B01111111); // LSB
FirmataSerial->write(value >> 7 & B01111111); // MSB
FirmataStream->write(value & B01111111); // LSB
FirmataStream->write(value >> 7 & B01111111); // MSB
}

void FirmataClass::startSysex(void)
{
FirmataSerial->write(START_SYSEX);
FirmataStream->write(START_SYSEX);
}

void FirmataClass::endSysex(void)
{
FirmataSerial->write(END_SYSEX);
FirmataStream->write(END_SYSEX);
}

//******************************************************************************
Expand Down Expand Up @@ -67,7 +67,7 @@ void FirmataClass::begin(void)
void FirmataClass::begin(long speed)
{
Serial.begin(speed);
FirmataSerial = &Serial;
FirmataStream = &Serial;
blinkVersion();
printVersion();
printFirmwareVersion();
Expand All @@ -76,7 +76,7 @@ void FirmataClass::begin(long speed)
/* begin method for overriding default stream */
void FirmataClass::begin(Stream &s)
{
FirmataSerial = &s;
FirmataStream = &s;
// do not call blinkVersion() here because some hardware such as the
// Ethernet shield use pin 13
printVersion();
Expand All @@ -85,9 +85,9 @@ void FirmataClass::begin(Stream &s)

// output the protocol version message to the serial port
void FirmataClass::printVersion(void) {
FirmataSerial->write(REPORT_VERSION);
FirmataSerial->write(FIRMATA_MAJOR_VERSION);
FirmataSerial->write(FIRMATA_MINOR_VERSION);
FirmataStream->write(REPORT_VERSION);
FirmataStream->write(FIRMATA_MAJOR_VERSION);
FirmataStream->write(FIRMATA_MINOR_VERSION);
}

void FirmataClass::blinkVersion(void)
Expand All @@ -106,9 +106,9 @@ void FirmataClass::printFirmwareVersion(void)

if(firmwareVersionCount) { // make sure that the name has been set before reporting
startSysex();
FirmataSerial->write(REPORT_FIRMWARE);
FirmataSerial->write(firmwareVersionVector[0]); // major version number
FirmataSerial->write(firmwareVersionVector[1]); // minor version number
FirmataStream->write(REPORT_FIRMWARE);
FirmataStream->write(firmwareVersionVector[0]); // major version number
FirmataStream->write(firmwareVersionVector[1]); // minor version number
for(i=2; i<firmwareVersionCount; ++i) {
sendValueAsTwo7bitBytes(firmwareVersionVector[i]);
}
Expand All @@ -118,46 +118,48 @@ void FirmataClass::printFirmwareVersion(void)

void FirmataClass::setFirmwareNameAndVersion(const char *name, byte major, byte minor)
{
const char *filename;
char *extension;
const char *firmwareName;
const char *extension;

// parse out ".cpp" and "applet/" that comes from using __FILE__
extension = strstr(name, ".cpp");
filename = strrchr(name, '/') + 1; //points to slash, +1 gets to start of filename
// add two bytes for version numbers
if(extension && filename) {
firmwareVersionCount = extension - filename + 2;
} else {
firmwareVersionCount = strlen(name) + 2;
filename = name;
firmwareName = strrchr(name, '/');

if (!firmwareName) {
// windows
firmwareName = strrchr(name, '\\');
}
if (!firmwareName) {
// user passed firmware name
firmwareName = name;
}
else {
firmwareName ++;
}

if (!extension) {
firmwareVersionCount = strlen(firmwareName) + 2;
}
else {
firmwareVersionCount = extension - firmwareName + 2;
}

// in case anyone calls setFirmwareNameAndVersion more than once
free(firmwareVersionVector);

firmwareVersionVector = (byte *) malloc(firmwareVersionCount);
firmwareVersionVector[firmwareVersionCount] = 0;
firmwareVersionVector[0] = major;
firmwareVersionVector[1] = minor;
strncpy((char*)firmwareVersionVector + 2, filename, firmwareVersionCount - 2);
// alas, no snprintf on Arduino
// snprintf(firmwareVersionVector, MAX_DATA_BYTES, "%c%c%s",
// (char)major, (char)minor, firmwareVersionVector);
strncpy((char*)firmwareVersionVector + 2, firmwareName, firmwareVersionCount - 2);
}

// this method is only used for unit testing
// void FirmataClass::unsetFirmwareVersion()
// {
// firmwareVersionCount = 0;
// free(firmwareVersionVector);
// firmwareVersionVector = 0;
// }

//------------------------------------------------------------------------------
// Serial Receive Handling

int FirmataClass::available(void)
{
return FirmataSerial->available();
return FirmataStream->available();
}


Expand All @@ -170,17 +172,24 @@ void FirmataClass::processSysexMessage(void)
case STRING_DATA:
if(currentStringCallback) {
byte bufferLength = (sysexBytesRead - 1) / 2;
char *buffer = (char*)malloc(bufferLength * sizeof(char));
byte i = 1;
byte j = 0;
while(j < bufferLength) {
buffer[j] = (char)storedInputData[i];
// The string length will only be at most half the size of the
// stored input buffer so we can decode the string within the buffer.
storedInputData[j] = storedInputData[i];
i++;
buffer[j] += (char)(storedInputData[i] << 7);
storedInputData[j] += (storedInputData[i] << 7);
i++;
j++;
}
(*currentStringCallback)(buffer);
// Make sure string is null terminated. This may be the case for data
// coming from client libraries in languages that don't null terminate
// strings.
if (storedInputData[j-1] != '\0') {
storedInputData[j] = '\0';
}
(*currentStringCallback)((char*)&storedInputData[0]);
}
break;
default:
Expand All @@ -191,7 +200,7 @@ void FirmataClass::processSysexMessage(void)

void FirmataClass::processInput(void)
{
int inputData = FirmataSerial->read(); // this is 'int' to handle -1 when no data
int inputData = FirmataStream->read(); // this is 'int' to handle -1 when no data
int command;

// TODO make sure it handles -1 properly
Expand Down Expand Up @@ -259,7 +268,7 @@ void FirmataClass::processInput(void)
break;
case REPORT_ANALOG:
case REPORT_DIGITAL:
waitForData = 1; // two data bytes needed
waitForData = 1; // one data byte needed
executeMultiByteCommand = command;
break;
case START_SYSEX:
Expand All @@ -283,7 +292,7 @@ void FirmataClass::processInput(void)
void FirmataClass::sendAnalog(byte pin, int value)
{
// pin can only be 0-15, so chop higher bits
FirmataSerial->write(ANALOG_MESSAGE | (pin & 0xF));
FirmataStream->write(ANALOG_MESSAGE | (pin & 0xF));
sendValueAsTwo7bitBytes(value);
}

Expand Down Expand Up @@ -314,17 +323,17 @@ void FirmataClass::sendDigital(byte pin, int value)
// send an 8-bit port in a single digital message (protocol v2)
void FirmataClass::sendDigitalPort(byte portNumber, int portData)
{
FirmataSerial->write(DIGITAL_MESSAGE | (portNumber & 0xF));
FirmataSerial->write((byte)portData % 128); // Tx bits 0-6
FirmataSerial->write(portData >> 7); // Tx bits 7-13
FirmataStream->write(DIGITAL_MESSAGE | (portNumber & 0xF));
FirmataStream->write((byte)portData % 128); // Tx bits 0-6
FirmataStream->write(portData >> 7); // Tx bits 7-13
}


void FirmataClass::sendSysex(byte command, byte bytec, byte* bytev)
{
byte i;
startSysex();
FirmataSerial->write(command);
FirmataStream->write(command);
for(i=0; i<bytec; i++) {
sendValueAsTwo7bitBytes(bytev[i]);
}
Expand All @@ -346,7 +355,7 @@ void FirmataClass::sendString(const char* string)
// expose the write method
void FirmataClass::write(byte c)
{
FirmataSerial->write(c);
FirmataStream->write(c);
}


Expand Down Expand Up @@ -436,8 +445,6 @@ void FirmataClass::systemReset(void)

if(currentSystemResetCallback)
(*currentSystemResetCallback)();

//flush(); //TODO uncomment when Firmata is a subclass of HardwareSerial
}


Expand All @@ -459,5 +466,3 @@ void FirmataClass::strobeBlinkPin(int count, int onInterval, int offInterval)

// make one instance for the user to use
FirmataClass Firmata;


20 changes: 12 additions & 8 deletions Firmata.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
Firmata.h - Firmata library
Firmata.h - Firmata library v2.4.0 - 2013-08-09
Copyright (C) 2006-2008 Hans-Christoph Steiner. All rights reserved.

This library is free software; you can redistribute it and/or
Expand All @@ -20,10 +20,10 @@
* software can test whether it will be compatible with the currently
* installed firmware. */
#define FIRMATA_MAJOR_VERSION 2 // for non-compatible changes
#define FIRMATA_MINOR_VERSION 3 // for backwards compatible changes
#define FIRMATA_BUGFIX_VERSION 6 // for bugfix releases
#define FIRMATA_MINOR_VERSION 4 // for backwards compatible changes
#define FIRMATA_BUGFIX_VERSION 0 // for bugfix releases

#define MAX_DATA_BYTES 32 // max number of data bytes in non-Sysex messages
#define MAX_DATA_BYTES 64 // max number of data bytes in incoming messages

// message command bytes (128-255/0x80-0xFF)
#define DIGITAL_MESSAGE 0x90 // send data for a digital pin
Expand All @@ -43,6 +43,8 @@
/* 0x00-0x0F reserved for user-defined commands */
#define SERVO_CONFIG 0x70 // set max angle, minPulse, maxPulse, freq
#define STRING_DATA 0x71 // a string message with 14-bits per char
#define STEPPER_DATA 0x72 // control a stepper motor
#define ONEWIRE_DATA 0x73 // send an OneWire read/write/reset/select/skip/search request
#define SHIFT_DATA 0x75 // a bitstream to/from a shift register
#define I2C_REQUEST 0x76 // send an I2C read/write request
#define I2C_REPLY 0x77 // a reply to an I2C read request
Expand All @@ -56,6 +58,7 @@
#define ANALOG_MAPPING_RESPONSE 0x6A // reply with mapping info
#define REPORT_FIRMWARE 0x79 // report name and version of the firmware
#define SAMPLING_INTERVAL 0x7A // set the poll rate of the main loop
#define SCHEDULER_DATA 0x7B // send a createtask/deletetask/addtotask/schedule/querytasks/querytask request to the scheduler
#define SYSEX_NON_REALTIME 0x7E // MIDI Reserved for non-realtime messages
#define SYSEX_REALTIME 0x7F // MIDI Reserved for realtime messages
// these are DEPRECATED to make the naming more consistent
Expand All @@ -72,7 +75,10 @@
#define SERVO 0x04 // digital pin in Servo output mode
#define SHIFT 0x05 // shiftIn/shiftOut mode
#define I2C 0x06 // pin included in I2C setup
#define TOTAL_PIN_MODES 7
#define ONEWIRE 0x07 // pin configured for 1-wire
#define STEPPER 0x08 // pin configured for stepper motor
#define IGNORE 0x7F // pin configured to be ignored by digitalWrite and capabilityResponse
#define TOTAL_PIN_MODES 10

extern "C" {
// callback function types
Expand All @@ -98,7 +104,6 @@ class FirmataClass
void printFirmwareVersion(void);
//void setFirmwareVersion(byte major, byte minor); // see macro below
void setFirmwareNameAndVersion(const char *name, byte major, byte minor);
//void unsetFirmwareVersion(); // only used for unit test
/* serial receive handling */
int available(void);
void processInput(void);
Expand All @@ -118,7 +123,7 @@ class FirmataClass
void detach(byte command);

private:
Stream *FirmataSerial;
Stream *FirmataStream;
/* firmware name and version */
byte firmwareVersionCount;
byte *firmwareVersionVector;
Expand Down Expand Up @@ -162,4 +167,3 @@ extern FirmataClass Firmata;
#define setFirmwareVersion(x, y) setFirmwareNameAndVersion(__FILE__, x, y)

#endif /* Firmata_h */

2 changes: 1 addition & 1 deletion examples/AllInputsFirmata/AllInputsFirmata.ino
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ void setup()
{
byte i, port, status;

Firmata.setFirmwareVersion(0, 1);
Firmata.setFirmwareVersion(FIRMATA_MAJOR_VERSION, FIRMATA_MINOR_VERSION);

for(pin = 0; pin < TOTAL_PINS; pin++) {
if IS_PIN_DIGITAL(pin) pinMode(PIN_TO_DIGITAL(pin), INPUT);
Expand Down
2 changes: 1 addition & 1 deletion examples/AnalogFirmata/AnalogFirmata.ino
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void reportAnalogCallback(byte pin, int value)
*============================================================================*/
void setup()
{
Firmata.setFirmwareVersion(0, 2);
Firmata.setFirmwareVersion(FIRMATA_MAJOR_VERSION, FIRMATA_MINOR_VERSION);
Firmata.attach(ANALOG_MESSAGE, analogWriteCallback);
Firmata.attach(REPORT_ANALOG, reportAnalogCallback);

Expand Down
Loading