From 6b6b38c9e26e9b2e45ca44b6d41d33f0bf57182f Mon Sep 17 00:00:00 2001 From: crankyoldgit Date: Tue, 6 Jul 2021 15:10:50 +1000 Subject: [PATCH] Improve model detection and fan speed output text. * 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 --- src/IRac.cpp | 18 ++---------------- src/ir_LG.cpp | 19 +++++++++++++++++-- src/ir_LG.h | 3 ++- test/ir_LG_test.cpp | 30 ++++++++++++++++++++++++++++++ 4 files changed, 51 insertions(+), 19 deletions(-) diff --git a/src/IRac.cpp b/src/IRac.cpp index f59b7e1c7..3d13e42b6 100644 --- a/src/IRac.cpp +++ b/src/IRac.cpp @@ -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 @@ -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; } diff --git a/src/ir_LG.cpp b/src/ir_LG.cpp index b8fc937d1..b798ce91a 100644 --- a/src/ir_LG.cpp +++ b/src/ir_LG.cpp @@ -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(); @@ -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); } diff --git a/src/ir_LG.h b/src/ir_LG.h index 954f0d85f..94da33f33 100644 --- a/src/ir_LG.h +++ b/src/ir_LG.h @@ -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); diff --git a/test/ir_LG_test.cpp b/test/ir_LG_test.cpp index 11dda43af..dc340de9b 100644 --- a/test/ir_LG_test.cpp +++ b/test/ir_LG_test.cpp @@ -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) { @@ -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)); }