Skip to content

Commit

Permalink
Fix ESP32 when not using custom UART pin
Browse files Browse the repository at this point in the history
  • Loading branch information
dzungpv committed Dec 1, 2023
1 parent 3085196 commit b4c34f1
Showing 1 changed file with 20 additions and 3 deletions.
23 changes: 20 additions & 3 deletions src/HeatPump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@ bool operator!=(const heatpumpTimers& lhs, const heatpumpTimers& rhs) {
// Constructor /////////////////////////////////////////////////////////////////

HeatPump::HeatPump() {
rxPin = 0;
txPin = 0;
lastWanted = millis();
lastSend = 0;
infoMode = 0;
Expand Down Expand Up @@ -116,7 +118,14 @@ bool HeatPump::connect(HardwareSerial *serial, int bitrate, int rx, int tx) {
#endif
} else {
#if defined(ESP32)
_HardSerial->begin(bitrate, SERIAL_8E1, rxPin, txPin);
if (rxPin > 0 && rxPin > 0) // check if custom pin previous set
{
_HardSerial->begin(bitrate, SERIAL_8E1, rxPin, txPin);
}
else // fall back to default hardware pins
{
_HardSerial->begin(bitrate, SERIAL_8E1);
}
#else
_HardSerial->begin(bitrate, SERIAL_8E1);
#endif
Expand All @@ -139,8 +148,16 @@ bool HeatPump::connect(HardwareSerial *serial, int bitrate, int rx, int tx) {
writePacket(packet, CONNECT_LEN);
while(!canRead()) { delay(10); }
int packetType = readPacket();
if(packetType != RCVD_PKT_CONNECT_SUCCESS && retry){
return connect(serial, 9600, rxPin, txPin);
if (packetType != RCVD_PKT_CONNECT_SUCCESS && retry)
{
if (rxPin > 0 && rxPin > 0) // check if custom pin previous set
{
return connect(serial, 9600, rxPin, txPin);
}
else
{
return connect(serial, 9600, rx, tx);
}
}
connected = (packetType == RCVD_PKT_CONNECT_SUCCESS);
return connected;
Expand Down

0 comments on commit b4c34f1

Please sign in to comment.