Skip to content

Commit

Permalink
Improve model detection and fan speed output text.
Browse files Browse the repository at this point in the history
* Tweak `IRLgAc::setRaw()` to accept an optional protocol parameter.
* Add model string handling unit tests.
* Improve model detection code & tests.
* Improve fan speed text output handling.

For #1513
  • Loading branch information
crankyoldgit committed Jul 11, 2021
1 parent acfa5ce commit deec821
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 19 deletions.
18 changes: 2 additions & 16 deletions src/IRac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3573,14 +3573,7 @@ namespace IRAcUtils {
case decode_type_t::LG:
case decode_type_t::LG2: {
IRLgAc ac(kGpioUnused);
ac.setRaw(result->value); // Like Coolix, use value instead of state.
switch (result->decode_type) {
case decode_type_t::LG2:
ac.setModel(lg_ac_remote_model_t::AKB75215403);
break;
default:
ac.setModel(lg_ac_remote_model_t::GE6711AR2853M);
}
ac.setRaw(result->value, result->decode_type); // Use value, not state.
return ac.isValidLgAc() ? ac.toString() : "";
}
#endif // DECODE_LG
Expand Down Expand Up @@ -3845,15 +3838,8 @@ namespace IRAcUtils {
case decode_type_t::LG:
case decode_type_t::LG2: {
IRLgAc ac(kGpioUnused);
ac.setRaw(decode->value); // Uses value instead of state.
ac.setRaw(decode->value, decode->decode_type); // Use value, not state.
if (!ac.isValidLgAc()) return false;
switch (decode->decode_type) {
case decode_type_t::LG2:
ac.setModel(lg_ac_remote_model_t::AKB75215403);
break;
default:
ac.setModel(lg_ac_remote_model_t::GE6711AR2853M);
}
*result = ac.toCommon();
break;
}
Expand Down
19 changes: 17 additions & 2 deletions src/ir_LG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,22 @@ uint32_t IRLgAc::getRaw(void) {

/// Set the internal state from a valid code for this protocol.
/// @param[in] new_code A valid code for this protocol.
void IRLgAc::setRaw(const uint32_t new_code) {
/// @param[in] protocol A valid decode protocol type to use.
void IRLgAc::setRaw(const uint32_t new_code, const decode_type_t protocol) {
_.raw = new_code;
// Set the default model for this protocol, if the protocol is supplied.
switch (protocol) {
case decode_type_t::LG:
setModel(lg_ac_remote_model_t::GE6711AR2853M);
break;
case decode_type_t::LG2:
setModel(lg_ac_remote_model_t::AKB75215403);
break;
default:
// Don't change anything if it isn't an expected protocol.
break;
}
// Look for model specific settings/features to improve model detection.
if (_isAKB74955603()) setModel(lg_ac_remote_model_t::AKB74955603);
_temp = 15; // Ensure there is a "sane" previous temp.
_temp = getTemp();
Expand Down Expand Up @@ -509,7 +523,8 @@ String IRLgAc::toString(void) const {
result += addModeToString(_.Mode, kLgAcAuto, kLgAcCool,
kLgAcHeat, kLgAcDry, kLgAcFan);
result += addTempToString(getTemp());
result += addFanToString(_.Fan, kLgAcFanHigh, kLgAcFanLow,
result += addFanToString(_.Fan, kLgAcFanHigh,
_isAKB74955603() ? kLgAcFanLowAlt : kLgAcFanLow,
kLgAcFanAuto, kLgAcFanLowest, kLgAcFanMedium,
kLgAcFanMax);
}
Expand Down
3 changes: 2 additions & 1 deletion src/ir_LG.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ class IRLgAc {
void setMode(const uint8_t mode);
uint8_t getMode(void) const;
uint32_t getRaw(void);
void setRaw(const uint32_t new_code);
void setRaw(const uint32_t new_code,
const decode_type_t protocol = decode_type_t::UNKNOWN);
static uint8_t convertMode(const stdAc::opmode_t mode);
static stdAc::opmode_t toCommonMode(const uint8_t mode);
static stdAc::fanspeed_t toCommonFanSpeed(const uint8_t speed);
Expand Down
30 changes: 30 additions & 0 deletions test/ir_LG_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -676,6 +676,19 @@ TEST(TestUtils, Housekeeping) {
ASSERT_TRUE(IRac::isProtocolSupported(decode_type_t::LG2));
ASSERT_EQ(kLgBits, IRsendTest::defaultBits(decode_type_t::LG2));
ASSERT_EQ(kLgDefaultRepeat, IRsendTest::minRepeats(decode_type_t::LG2));

ASSERT_EQ(lg_ac_remote_model_t::GE6711AR2853M,
IRac::strToModel(irutils::modelToStr(
decode_type_t::LG,
lg_ac_remote_model_t::GE6711AR2853M).c_str()));
ASSERT_EQ(lg_ac_remote_model_t::AKB75215403,
IRac::strToModel(irutils::modelToStr(
decode_type_t::LG2,
lg_ac_remote_model_t::AKB75215403).c_str()));
ASSERT_EQ(lg_ac_remote_model_t::AKB74955603,
IRac::strToModel(irutils::modelToStr(
decode_type_t::LG2,
lg_ac_remote_model_t::AKB74955603).c_str()));
}

TEST(TestIRLgAcClass, KnownExamples) {
Expand Down Expand Up @@ -912,12 +925,29 @@ TEST(TestIRLgAcClass, FanSpeedIssue1513) {

TEST(TestIRLgAcClass, DetectAKB74955603) {
IRLgAc ac(kGpioUnused);
IRrecv capture(kGpioUnused);

ac.stateReset();
ASSERT_NE(lg_ac_remote_model_t::AKB74955603, ac.getModel());
ac.setRaw(0x880A3A7);
EXPECT_EQ(lg_ac_remote_model_t::AKB74955603, ac.getModel());

ac.stateReset();
// https://docs.google.com/spreadsheets/d/1zF0FI2ENvbLdk4zaWBY9ZYVM3MB_4oxro9wCM7ETX4Y/edit#gid=1319765817&range=A2:C2
ac.setRaw(0x880A396);
EXPECT_EQ(lg_ac_remote_model_t::AKB74955603, ac.getModel());
char expected[] =
"Model: 3 (AKB74955603), Power: On, Mode: 2 (Fan), Temp: 18C, "
"Fan: 9 (Low)";
ASSERT_EQ(expected, ac.toString());

ac._irsend.reset();
ac.send();
ac._irsend.makeDecodeResult();
EXPECT_TRUE(capture.decode(&ac._irsend.capture));
ASSERT_EQ(LG2, ac._irsend.capture.decode_type); // Not "LG"
ASSERT_EQ(kLgBits, ac._irsend.capture.bits);
ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture));
stdAc::state_t r, p;
ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p));
}

0 comments on commit deec821

Please sign in to comment.