Skip to content

Commit a6d99d2

Browse files
committed
Update to new Wire API proposal
1 parent d8b6333 commit a6d99d2

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

src/utility/ECC508.cpp

+7-3
Original file line numberDiff line numberDiff line change
@@ -478,8 +478,9 @@ int ECC508Class::lock(int zone)
478478

479479
int ECC508Class::sendCommand(uint8_t opcode, uint8_t param1, uint16_t param2, const byte data[], size_t dataLength)
480480
{
481-
byte command[8 + dataLength]; // 1 for type, 1 for length, 1 for opcode, 1 for param1, 2 for param2, 2 for crc
482-
481+
int commandLength = 8 + dataLength; // 1 for type, 1 for length, 1 for opcode, 1 for param1, 2 for param2, 2 for crc
482+
byte command[commandLength];
483+
483484
command[0] = 0x03;
484485
command[1] = sizeof(command) - 1;
485486
command[2] = opcode;
@@ -490,7 +491,10 @@ int ECC508Class::sendCommand(uint8_t opcode, uint8_t param1, uint16_t param2, co
490491
uint16_t crc = crc16(&command[1], 8 - 3 + dataLength);
491492
memcpy(&command[6 + dataLength], &crc, sizeof(crc));
492493

493-
if (_wire->sendTo(_address, command, 8 + dataLength) != 0) {
494+
// begin transmission with external buffer which is pre-populated with data
495+
_wire->beginTransmission(_address, command, commandLength, commandLength);
496+
497+
if (_wire->endTransmission() != 0) {
494498
return 0;
495499
}
496500

0 commit comments

Comments
 (0)