Skip to content

Commit

Permalink
Support using lib as ESP IDF component.
Browse files Browse the repository at this point in the history
ESP32 faster, we can lower delay.
Use UART custom define pin when retry.
  • Loading branch information
dzungpv committed Oct 28, 2023
1 parent ce460c3 commit 3085196
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 6 deletions.
16 changes: 16 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
set(COMPONENT_SRCDIRS
"src"
)

set(COMPONENT_ADD_INCLUDEDIRS
"src"
)

set(COMPONENT_REQUIRES
"arduino-esp32"
)

register_component()

target_compile_definitions(${COMPONENT_TARGET} PUBLIC -DESP32)
target_compile_options(${COMPONENT_TARGET} PRIVATE -fno-rtti)
16 changes: 10 additions & 6 deletions src/HeatPump.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,13 +109,13 @@ bool HeatPump::connect(HardwareSerial *serial, int bitrate, int rx, int tx) {
if (rx >= 0 && tx >= 0) {
#if defined(ESP32)
rxPin = rx;
txPin = tx;
txPin = tx;
_HardSerial->begin(bitrate, SERIAL_8E1, rx, tx);
#else
_HardSerial->begin(bitrate, SERIAL_8E1);
#endif
#endif
} else {
#if defined(ESP32)
#if defined(ESP32)
_HardSerial->begin(bitrate, SERIAL_8E1, rxPin, txPin);
#else
_HardSerial->begin(bitrate, SERIAL_8E1);
Expand All @@ -125,8 +125,12 @@ bool HeatPump::connect(HardwareSerial *serial, int bitrate, int rx, int tx) {
onConnectCallback();
}

// settle before we start sending packets
// settle before we start sending packets
#if defined(ESP32)
delay(1000);
#else
delay(2000);
#endif

// send the CONNECT packet twice - need to copy the CONNECT packet locally
byte packet[CONNECT_LEN];
Expand All @@ -136,7 +140,7 @@ bool HeatPump::connect(HardwareSerial *serial, int bitrate, int rx, int tx) {
while(!canRead()) { delay(10); }
int packetType = readPacket();
if(packetType != RCVD_PKT_CONNECT_SUCCESS && retry){
return connect(serial, 9600, rx, tx);
return connect(serial, 9600, rxPin, txPin);
}
connected = (packetType == RCVD_PKT_CONNECT_SUCCESS);
return connected;
Expand Down Expand Up @@ -637,7 +641,7 @@ int HeatPump::readPacket() {
receivedSettings.fan = lookupByteMapValue(FAN_MAP, FAN, 6, data[6]);
receivedSettings.vane = lookupByteMapValue(VANE_MAP, VANE, 7, data[7]);
receivedSettings.wideVane = lookupByteMapValue(WIDEVANE_MAP, WIDEVANE, 7, data[10] & 0x0F);
wideVaneAdj = (data[10] & 0xF0) == 0x80 ? true : false;
wideVaneAdj = (data[10] & 0xF0) == 0x80 ? true : false;

if(settingsChangedCallback && receivedSettings != currentSettings) {
currentSettings = receivedSettings;
Expand Down

0 comments on commit 3085196

Please sign in to comment.