From 33551d7e014d976829c1959967b6c667d5b8ac44 Mon Sep 17 00:00:00 2001 From: Matt Way Date: Sat, 9 Dec 2023 09:56:47 +1100 Subject: [PATCH] Move print helpers to Hotdog.ino --- HDPacketBuilder.h | 15 --------------- Hotdog.ino | 26 ++++++++++++++++++++++---- 2 files changed, 22 insertions(+), 19 deletions(-) diff --git a/HDPacketBuilder.h b/HDPacketBuilder.h index 6ce943d..695bbf8 100644 --- a/HDPacketBuilder.h +++ b/HDPacketBuilder.h @@ -166,18 +166,3 @@ void calculateCRC() { // must be called after the buffer has been filled buf[length + 2] = checksum1; // Checksum buf[length + 3] = checksum2; // Checksum } - -void printHex(uint8_t num) { //print a byte as two hex chars - char hexCar[3]; - sprintf(hexCar, "%02X", num); - Serial.print(hexCar); -} - -void printBuffer() //print a byte array as hex chars -{ - uint8_t bytecount = buf[0] + 3; - for (int i = 0; i < bytecount; i++) { - printHex(buf[i]); - } - Serial.println(); -} \ No newline at end of file diff --git a/Hotdog.ino b/Hotdog.ino index 0701753..fcf02c5 100644 --- a/Hotdog.ino +++ b/Hotdog.ino @@ -54,17 +54,17 @@ void onConnectionEstablished() { uint16_t shadeID = 0x0400; if (payload == "OPEN") { constructUpPacket(shadeID); - printByteArray(buf); + printPacket(buf); Serial.println(); sendCommand(buf); } else if (payload == "CLOSE") { constructDownPacket(shadeID); - printByteArray(buf); + printPacket(buf); Serial.println(); sendCommand(buf); } else if (payload == "STOP") { constructStopPacket(shadeID); - printByteArray(buf); + printPacket(buf); Serial.println(); sendCommand(buf); } @@ -121,4 +121,22 @@ void sendCommand(byte * byteArray) //transmit a command rollingCode1++; rollingCode2++; -} \ No newline at end of file +} + +void printHex(const uint8_t num) { //print a byte as two hex chars + if (num < 0x10) { + Serial.print("0"); + } + Serial.print(num, HEX); +} + +void printByteArray(const uint8_t * byteArray, const int arraySize) { //print a byte array as hex chars + for (int i = 0; i < arraySize; i++) { + printHex(byteArray[i]); + } +} + +void printPacket(const uint8_t *buffer) { + uint8_t length = buffer[1] + 4; + printByteArray(buffer, length); +}