Skip to content

Commit

Permalink
Compatibility fixes for some models of air conditioners (#9)
Browse files Browse the repository at this point in the history
* Don't let to overread the status response

* Handle reported fan settings on msabbu-12hrdn1

* Apply suggestions from code review

Co-authored-by: Sergey Dudanov <sergey.dudanov@gmail.com>

---------

Co-authored-by: Sergey Dudanov <sergey.dudanov@gmail.com>
  • Loading branch information
andrasbiro and dudanov committed Aug 7, 2023
1 parent 3bbd505 commit 5f58f2e
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 4 deletions.
2 changes: 1 addition & 1 deletion include/Appliance/AirConditioner/StatusData.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class StatusData : public FrameData {
void setMode(Mode mode);

/* FAN SPEED */
FanMode getFanMode() const { return static_cast<FanMode>(this->m_getValue(3)); }
FanMode getFanMode() const;
void setFanMode(FanMode mode) { this->m_setValue(3, mode); };

/* SWING MODE */
Expand Down
4 changes: 1 addition & 3 deletions include/Frame/FrameData.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,7 @@ class FrameData {
static uint8_t m_getID() { return FrameData::m_id++; }
static uint8_t m_getRandom() { return random(256); }
uint8_t m_calcCRC() const;
uint8_t m_getValue(uint8_t idx, uint8_t mask = 255, uint8_t shift = 0) const {
return (this->m_data[idx] >> shift) & mask;
}
uint8_t m_getValue(uint8_t idx, uint8_t mask = 255, uint8_t shift = 0) const;
void m_setValue(uint8_t idx, uint8_t value, uint8_t mask = 255, uint8_t shift = 0) {
this->m_data[idx] &= ~(mask << shift);
this->m_data[idx] |= (value << shift);
Expand Down
11 changes: 11 additions & 0 deletions src/Appliance/AirConditioner/StatusData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,17 @@ void StatusData::setMode(Mode mode) {
}
}

FanMode StatusData::getFanMode() const {
//some ACs return 30 for LOW and 50 for MEDIUM. Note though, in appMode, this device still uses 40/60
uint8_t fanMode = this->m_getValue(3);
if (fanMode == 30) {
fanMode = FAN_LOW;
} else if (fanMode == 50) {
fanMode = FAN_MEDIUM;
}
return static_cast<FanMode>(fanMode);
}

Preset StatusData::getPreset() const {
if (this->m_getEco())
return Preset::PRESET_ECO;
Expand Down
6 changes: 6 additions & 0 deletions src/Frame/FrameData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ uint8_t FrameData::m_calcCRC() const {
return crc;
}

uint8_t FrameData::m_getValue(uint8_t idx, uint8_t mask, uint8_t shift) const {
if (idx < this->m_data.size())
return (this->m_data[idx] >> shift) & mask;
return 0;
}

void NetworkNotifyData::setIP(const IPAddress &ip) {
this->m_data[3] = ip[3];
this->m_data[4] = ip[2];
Expand Down

0 comments on commit 5f58f2e

Please sign in to comment.