Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
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
26 changes: 18 additions & 8 deletions examples/StandardFirmata/StandardFirmata.ino
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ unsigned int samplingInterval = 19; // how often to run the main loop (
/* i2c data */
struct i2c_device_info {
byte addr;
byte reg;
int reg;
byte bytes;
};

Expand Down Expand Up @@ -329,10 +329,10 @@ void sysexCallback(byte command, byte argc, byte *argv)
{
byte mode;
byte slaveAddress;
byte slaveRegister;
byte data;
unsigned int delayTime;

int slaveRegister;
unsigned int delayTime;

switch(command) {
case I2C_REQUEST:
mode = argv[1] & I2C_READ_WRITE_MODE_MASK;
Expand Down Expand Up @@ -363,24 +363,34 @@ void sysexCallback(byte command, byte argc, byte *argv)
// a slave register is specified
slaveRegister = argv[2] + (argv[3] << 7);
data = argv[4] + (argv[5] << 7); // bytes to read
readAndReportData(slaveAddress, (int)slaveRegister, data);
}
else {
// a slave register is NOT specified
slaveRegister = REGISTER_NOT_SPECIFIED;
data = argv[2] + (argv[3] << 7); // bytes to read
readAndReportData(slaveAddress, (int)REGISTER_NOT_SPECIFIED, data);
}
readAndReportData(slaveAddress, (int)slaveRegister, data);
break;
case I2C_READ_CONTINUOUSLY:
if ((queryIndex + 1) >= MAX_QUERIES) {
// too many queries, just ignore
Firmata.sendString("too many queries");
break;
}
if (argc == 6) {
// a slave register is specified
slaveRegister = argv[2] + (argv[3] << 7);
data = argv[4] + (argv[5] << 7); // bytes to read
}
else {
// a slave register is NOT specified
slaveRegister = (int)REGISTER_NOT_SPECIFIED;
data = argv[2] + (argv[3] << 7); // bytes to read
}
queryIndex++;
query[queryIndex].addr = slaveAddress;
query[queryIndex].reg = argv[2] + (argv[3] << 7);
query[queryIndex].bytes = argv[4] + (argv[5] << 7);
query[queryIndex].reg = slaveRegister;
query[queryIndex].bytes = data;
break;
case I2C_STOP_READING:
byte queryIndexToSkip;
Expand Down
16 changes: 13 additions & 3 deletions utility/I2CFirmata.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,8 @@ void I2CFirmata::handleI2CRequest(byte argc, byte *argv)
{
byte mode;
byte slaveAddress;
byte slaveRegister;
byte data;
int slaveRegister;
mode = argv[1] & I2C_READ_WRITE_MODE_MASK;
if (argv[1] & I2C_10BIT_ADDRESS_MODE_MASK) {
Firmata.sendString("10-bit addressing not supported");
Expand Down Expand Up @@ -157,10 +157,20 @@ void I2CFirmata::handleI2CRequest(byte argc, byte *argv)
Firmata.sendString("too many queries");
break;
}
if (argc == 6) {
// a slave register is specified
slaveRegister = argv[2] + (argv[3] << 7);
data = argv[4] + (argv[5] << 7); // bytes to read
}
else {
// a slave register is NOT specified
slaveRegister = (int)REGISTER_NOT_SPECIFIED;
data = argv[2] + (argv[3] << 7); // bytes to read
}
queryIndex++;
query[queryIndex].addr = slaveAddress;
query[queryIndex].reg = argv[2] + (argv[3] << 7);
query[queryIndex].bytes = argv[4] + (argv[5] << 7);
query[queryIndex].reg = slaveRegister;
query[queryIndex].bytes = data;
break;
case I2C_STOP_READING:
byte queryIndexToSkip;
Expand Down
2 changes: 1 addition & 1 deletion utility/I2CFirmata.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
/* i2c data */
struct i2c_device_info {
byte addr;
byte reg;
int reg;
byte bytes;
};

Expand Down