SwiCago / HeatPump

Arduino library to control Mitsubishi Heat Pumps via connector cn105
GNU General Public License v3.0
828 stars 230 forks source link

Read all packets in buffer during sync and before update #182

Closed sethkinast closed 2 years ago

sethkinast commented 2 years ago

Currently we strictly read one packet each time sync() is called. This means that if writePacket() is ever called twice in a row before reading, a packet will be permanently buffered.

In cases where you expect to write a packet and receive a response in the next packet, such as during update(), having buffered packets guarantees you won't receive the correct packet next.

Changing sync() and update() to flush the serial buffer makes the behavior much more robust and in my testing has always given me the 0x41 0x61 pair successfully when I call update().

Closes #181