Move print helpers to Hotdog.ino

This commit is contained in:
2023-12-09 09:56:47 +11:00
parent 207ffe9cc9
commit 33551d7e01
2 changed files with 22 additions and 19 deletions

View File

@@ -166,18 +166,3 @@ void calculateCRC() { // must be called after the buffer has been filled
buf[length + 2] = checksum1; // Checksum buf[length + 2] = checksum1; // Checksum
buf[length + 3] = checksum2; // 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();
}

View File

@@ -54,17 +54,17 @@ void onConnectionEstablished() {
uint16_t shadeID = 0x0400; uint16_t shadeID = 0x0400;
if (payload == "OPEN") { if (payload == "OPEN") {
constructUpPacket(shadeID); constructUpPacket(shadeID);
printByteArray(buf); printPacket(buf);
Serial.println(); Serial.println();
sendCommand(buf); sendCommand(buf);
} else if (payload == "CLOSE") { } else if (payload == "CLOSE") {
constructDownPacket(shadeID); constructDownPacket(shadeID);
printByteArray(buf); printPacket(buf);
Serial.println(); Serial.println();
sendCommand(buf); sendCommand(buf);
} else if (payload == "STOP") { } else if (payload == "STOP") {
constructStopPacket(shadeID); constructStopPacket(shadeID);
printByteArray(buf); printPacket(buf);
Serial.println(); Serial.println();
sendCommand(buf); sendCommand(buf);
} }
@@ -122,3 +122,21 @@ void sendCommand(byte * byteArray) //transmit a command
rollingCode1++; rollingCode1++;
rollingCode2++; rollingCode2++;
} }
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);
}