From 69c39acc6830d1a07d3f4a65a358a3bc8b3b3023 Mon Sep 17 00:00:00 2001 From: Z <22781620+invis-z@users.noreply.github.com> Date: Sat, 12 Feb 2022 02:55:37 +0800 Subject: [PATCH 1/6] Gree YAP0F8 (Detected as Kelvinator) vertical position set support This should not break the compatibility since the SwingV option is getting expanded and the bit indicating auto is still set correctly. --- src/IRac.cpp | 3 +- src/ir_Kelvinator.cpp | 77 ++++++++++++++++++++++++++++++++++++------- src/ir_Kelvinator.h | 34 ++++++++++++++++--- 3 files changed, 96 insertions(+), 18 deletions(-) diff --git a/src/IRac.cpp b/src/IRac.cpp index 4b700ff87..a9f35ff5c 100644 --- a/src/IRac.cpp +++ b/src/IRac.cpp @@ -1465,7 +1465,8 @@ void IRac::kelvinator(IRKelvinatorAC *ac, ac->setMode(ac->convertMode(mode)); ac->setTemp(degrees); ac->setFan((uint8_t)fan); // No conversion needed. - ac->setSwingVertical((int8_t)swingv >= 0); + ac->setSwingVertical(swingv == stdAc::swingv_t::kAuto, // Set auto flag. + ac->convertSwingV(swingv)); ac->setSwingHorizontal((int8_t)swingh >= 0); ac->setQuiet(quiet); ac->setTurbo(turbo); diff --git a/src/ir_Kelvinator.cpp b/src/ir_Kelvinator.cpp index b674e98b8..b13b3b9c5 100644 --- a/src/ir_Kelvinator.cpp +++ b/src/ir_Kelvinator.cpp @@ -274,24 +274,50 @@ void IRKelvinatorAC::setMode(const uint8_t mode) { } } -/// Control the current vertical swing setting. -/// @param[in] on The desired setting. -void IRKelvinatorAC::setSwingVertical(const bool on) { - _.SwingV = on; - _.VentSwing = (on || _.SwingH); +/// Set the Vertical Swing mode of the A/C. +/// @param[in] automatic Do we use the automatic setting? +/// @param[in] position The position/mode to set the vanes to. +void IRKelvinatorAC::setSwingVertical(const bool automatic, const uint8_t position) { + _.SwingAuto = automatic; + uint8_t new_position = position; + if (!automatic) { + switch (position) { + case kKelvinatorSwingUp: + case kKelvinatorSwingMiddleUp: + case kKelvinatorSwingMiddle: + case kKelvinatorSwingMiddleDown: + case kKelvinatorSwingDown: + break; + default: + new_position = kKelvinatorSwingLastPos; + } + } else { + switch (position) { + case kKelvinatorSwingAuto: + case kKelvinatorSwingDownAuto: + case kKelvinatorSwingMiddleAuto: + case kKelvinatorSwingUpAuto: + break; + default: + new_position = kKelvinatorSwingAuto; + } + } + _.SwingV = new_position; } -/// Is the vertical swing setting on? -/// @return The current value. -bool IRKelvinatorAC::getSwingVertical(void) const { - return _.SwingV; -} +/// Get the Vertical Swing Automatic mode setting of the A/C. +/// @return true, the setting is on. false, the setting is off. +bool IRKelvinatorAC::getSwingVerticalAuto(void) const { return _.SwingAuto; } + +/// Get the Vertical Swing position setting of the A/C. +/// @return The native position/mode. +uint8_t IRKelvinatorAC::getSwingVerticalPosition(void) const { return _.SwingV; } /// Control the current horizontal swing setting. /// @param[in] on The desired setting. void IRKelvinatorAC::setSwingHorizontal(const bool on) { _.SwingH = on; - _.VentSwing = (on || _.SwingV); + _.SwingAuto = (on || _.SwingV); } /// Is the horizontal swing setting on? @@ -378,6 +404,20 @@ uint8_t IRKelvinatorAC::convertMode(const stdAc::opmode_t mode) { } } +/// Convert a stdAc::swingv_t enum into it's native setting. +/// @param[in] swingv The enum to be converted. +/// @return The native equivalent of the enum. +uint8_t IRKelvinatorAC::convertSwingV(const stdAc::swingv_t swingv) { + switch (swingv) { + case stdAc::swingv_t::kHighest: return kKelvinatorSwingUp; + case stdAc::swingv_t::kHigh: return kKelvinatorSwingMiddleUp; + case stdAc::swingv_t::kMiddle: return kKelvinatorSwingMiddle; + case stdAc::swingv_t::kLow: return kKelvinatorSwingMiddleDown; + case stdAc::swingv_t::kLowest: return kKelvinatorSwingDown; + default: return kKelvinatorSwingAuto; + } +} + /// Convert a native mode to it's stdAc::opmode_t equivalent. /// @param[in] mode A native operating mode value. /// @return The stdAc::opmode_t equivalent. @@ -442,7 +482,20 @@ String IRKelvinatorAC::toString(void) const { result += addBoolToString(_.IonFilter, kIonStr); result += addBoolToString(_.Light, kLightStr); result += addBoolToString(_.SwingH, kSwingHStr); - result += addBoolToString(_.SwingV, kSwingVStr); + result += addLabeledString(_.SwingAuto ? kAutoStr : kManualStr, + kSwingVModeStr); + result += addIntToString(_.SwingV, kSwingVStr); + result += kSpaceLBraceStr; + switch (_.SwingV) { + case kKelvinatorSwingLastPos: + result += kLastStr; + break; + case kKelvinatorSwingAuto: + result += kAutoStr; + break; + default: result += kUnknownStr; + } + result += ')'; return result; } diff --git a/src/ir_Kelvinator.h b/src/ir_Kelvinator.h index 74371d8ef..003dd7101 100644 --- a/src/ir_Kelvinator.h +++ b/src/ir_Kelvinator.h @@ -14,6 +14,7 @@ // Brand: Kelvinator, Model: KSV70HRC A/C // Brand: Kelvinator, Model: KSV80HRC A/C // Brand: Green, Model: YAPOF3 remote +// Brand: Gree, Model: YAP0F8 remote // Brand: Sharp, Model: YB1FA remote // Brand: Sharp, Model: A5VEY A/C @@ -39,7 +40,7 @@ union KelvinatorProtocol{ uint8_t Mode :3; uint8_t Power :1; uint8_t BasicFan :2; - uint8_t VentSwing :1; + uint8_t SwingAuto :1; uint8_t :1; // Sleep Modes 1 & 3 (1 = On, 0 = Off) // Byte 1 uint8_t Temp :4; // Degrees C. @@ -56,8 +57,7 @@ union KelvinatorProtocol{ uint8_t :2; // End of command block (B01) // (B010 marker and a gap of 20ms) // Byte 4 - uint8_t SwingV :1; - uint8_t :3; + uint8_t SwingV :4; uint8_t SwingH :1; uint8_t :3; // Byte 5~6 @@ -103,6 +103,17 @@ const uint8_t kKelvinatorMinTemp = 16; // 16C const uint8_t kKelvinatorMaxTemp = 30; // 30C const uint8_t kKelvinatorAutoTemp = 25; // 25C +const uint8_t kKelvinatorSwingLastPos = 0b0000; // 0 +const uint8_t kKelvinatorSwingAuto = 0b0001; // 1 +const uint8_t kKelvinatorSwingUp = 0b0010; // 2 +const uint8_t kKelvinatorSwingMiddleUp = 0b0011; // 3 +const uint8_t kKelvinatorSwingMiddle = 0b0100; // 4 +const uint8_t kKelvinatorSwingMiddleDown = 0b0101; // 5 +const uint8_t kKelvinatorSwingDown = 0b0110; // 6 +const uint8_t kKelvinatorSwingDownAuto = 0b0111; // 7 +const uint8_t kKelvinatorSwingMiddleAuto = 0b1001; // 9 +const uint8_t kKelvinatorSwingUpAuto = 0b1011; // 11 + // Legacy defines (Deprecated) #define KELVINATOR_MIN_TEMP kKelvinatorMinTemp #define KELVINATOR_MAX_TEMP kKelvinatorMaxTemp @@ -115,6 +126,16 @@ const uint8_t kKelvinatorAutoTemp = 25; // 25C #define KELVINATOR_BASIC_FAN_MAX kKelvinatorBasicFanMax #define KELVINATOR_AUTO_TEMP kKelvinatorAutoTemp #define KELVINATOR_AUTO kKelvinatorAuto +#define KELVINATOR_SWING_LAST_POS kKelvinatorSwingLastPos +#define KELVINATOR_SWING_AUTO kKelvinatorSwingAuto +#define KELVINATOR_SWING_UP kKelvinatorSwingUp +#define KELVINATOR_SWING_MIDDLE_UP kKelvinatorSwingMiddleUp +#define KELVINATOR_SWING_MIDDLE kKelvinatorSwingMiddle +#define KELVINATOR_SWING_MIDDLE_DOWN kKelvinatorSwingMiddleDown +#define KELVINATOR_SWING_DOWN kKelvinatorSwingDown +#define KELVINATOR_SWING_DOWN_AUTO kKelvinatorSwingDownAuto +#define KELVINATOR_SWING_MIDDLE_AUTO kKelvinatorSwingMiddleAuto +#define KELVINATOR_SWING_UP_AUTO kKelvinatorSwingUpAuto // Classes /// Class for handling detailed Kelvinator A/C messages. @@ -142,8 +163,11 @@ class IRKelvinatorAC { uint8_t getFan(void) const; void setMode(const uint8_t mode); uint8_t getMode(void) const; - void setSwingVertical(const bool on); - bool getSwingVertical(void) const; + void setSwingVertical(const bool automatic, const uint8_t position); + bool getSwingVerticalAuto(void) const; + uint8_t getSwingVerticalPosition(void) const; + static uint8_t convertSwingV(const stdAc::swingv_t swingv); + static stdAc::swingv_t toCommonSwingV(const uint8_t pos); void setSwingHorizontal(const bool on); bool getSwingHorizontal(void) const; void setQuiet(const bool on); From 27e225ad5addbe414aecc21b0b9e8842747c62a8 Mon Sep 17 00:00:00 2001 From: Z <22781620+invis-z@users.noreply.github.com> Date: Sat, 12 Feb 2022 04:54:01 +0800 Subject: [PATCH 2/6] Fix lint $ define --- src/ir_Kelvinator.cpp | 7 +++++-- src/ir_Kelvinator.h | 10 ---------- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/src/ir_Kelvinator.cpp b/src/ir_Kelvinator.cpp index b13b3b9c5..e70fada0f 100644 --- a/src/ir_Kelvinator.cpp +++ b/src/ir_Kelvinator.cpp @@ -277,7 +277,8 @@ void IRKelvinatorAC::setMode(const uint8_t mode) { /// Set the Vertical Swing mode of the A/C. /// @param[in] automatic Do we use the automatic setting? /// @param[in] position The position/mode to set the vanes to. -void IRKelvinatorAC::setSwingVertical(const bool automatic, const uint8_t position) { +void IRKelvinatorAC::setSwingVertical(const bool automatic, + const uint8_t position) { _.SwingAuto = automatic; uint8_t new_position = position; if (!automatic) { @@ -311,7 +312,9 @@ bool IRKelvinatorAC::getSwingVerticalAuto(void) const { return _.SwingAuto; } /// Get the Vertical Swing position setting of the A/C. /// @return The native position/mode. -uint8_t IRKelvinatorAC::getSwingVerticalPosition(void) const { return _.SwingV; } +uint8_t IRKelvinatorAC::getSwingVerticalPosition(void) const { + return _.SwingV; +} /// Control the current horizontal swing setting. /// @param[in] on The desired setting. diff --git a/src/ir_Kelvinator.h b/src/ir_Kelvinator.h index 003dd7101..05d36c315 100644 --- a/src/ir_Kelvinator.h +++ b/src/ir_Kelvinator.h @@ -126,16 +126,6 @@ const uint8_t kKelvinatorSwingUpAuto = 0b1011; // 11 #define KELVINATOR_BASIC_FAN_MAX kKelvinatorBasicFanMax #define KELVINATOR_AUTO_TEMP kKelvinatorAutoTemp #define KELVINATOR_AUTO kKelvinatorAuto -#define KELVINATOR_SWING_LAST_POS kKelvinatorSwingLastPos -#define KELVINATOR_SWING_AUTO kKelvinatorSwingAuto -#define KELVINATOR_SWING_UP kKelvinatorSwingUp -#define KELVINATOR_SWING_MIDDLE_UP kKelvinatorSwingMiddleUp -#define KELVINATOR_SWING_MIDDLE kKelvinatorSwingMiddle -#define KELVINATOR_SWING_MIDDLE_DOWN kKelvinatorSwingMiddleDown -#define KELVINATOR_SWING_DOWN kKelvinatorSwingDown -#define KELVINATOR_SWING_DOWN_AUTO kKelvinatorSwingDownAuto -#define KELVINATOR_SWING_MIDDLE_AUTO kKelvinatorSwingMiddleAuto -#define KELVINATOR_SWING_UP_AUTO kKelvinatorSwingUpAuto // Classes /// Class for handling detailed Kelvinator A/C messages. From 691b8f4fc49bcd8d21e1afa5c741b9371c0fa539 Mon Sep 17 00:00:00 2001 From: Z <22781620+invis-z@users.noreply.github.com> Date: Sat, 12 Feb 2022 05:56:52 +0800 Subject: [PATCH 3/6] Partial fix --- .../TurnOnKelvinatorAC/TurnOnKelvinatorAC.ino | 2 +- src/ir_Kelvinator.cpp | 21 ++------ test/ir_Kelvinator_test.cpp | 48 +++++++++++++------ 3 files changed, 40 insertions(+), 31 deletions(-) diff --git a/examples/TurnOnKelvinatorAC/TurnOnKelvinatorAC.ino b/examples/TurnOnKelvinatorAC/TurnOnKelvinatorAC.ino index ebdb7536b..93390c2c7 100644 --- a/examples/TurnOnKelvinatorAC/TurnOnKelvinatorAC.ino +++ b/examples/TurnOnKelvinatorAC/TurnOnKelvinatorAC.ino @@ -57,7 +57,7 @@ void setup() { ac.setFan(1); ac.setMode(kKelvinatorCool); ac.setTemp(26); - ac.setSwingVertical(false); + ac.setSwingVertical(false, kKelvinatorSwingLastPos); ac.setSwingHorizontal(true); ac.setXFan(true); ac.setIonFilter(false); diff --git a/src/ir_Kelvinator.cpp b/src/ir_Kelvinator.cpp index e70fada0f..6cf6d4ecf 100644 --- a/src/ir_Kelvinator.cpp +++ b/src/ir_Kelvinator.cpp @@ -279,7 +279,7 @@ void IRKelvinatorAC::setMode(const uint8_t mode) { /// @param[in] position The position/mode to set the vanes to. void IRKelvinatorAC::setSwingVertical(const bool automatic, const uint8_t position) { - _.SwingAuto = automatic; + _.SwingAuto = (automatic || _.SwingH); uint8_t new_position = position; if (!automatic) { switch (position) { @@ -308,7 +308,9 @@ void IRKelvinatorAC::setSwingVertical(const bool automatic, /// Get the Vertical Swing Automatic mode setting of the A/C. /// @return true, the setting is on. false, the setting is off. -bool IRKelvinatorAC::getSwingVerticalAuto(void) const { return _.SwingAuto; } +bool IRKelvinatorAC::getSwingVerticalAuto(void) const { + return _.SwingV & 0b0001; +} /// Get the Vertical Swing position setting of the A/C. /// @return The native position/mode. @@ -320,7 +322,7 @@ uint8_t IRKelvinatorAC::getSwingVerticalPosition(void) const { /// @param[in] on The desired setting. void IRKelvinatorAC::setSwingHorizontal(const bool on) { _.SwingH = on; - _.SwingAuto = (on || _.SwingV); + _.SwingAuto = (on || (_.SwingV & 0b0001)); } /// Is the horizontal swing setting on? @@ -485,20 +487,7 @@ String IRKelvinatorAC::toString(void) const { result += addBoolToString(_.IonFilter, kIonStr); result += addBoolToString(_.Light, kLightStr); result += addBoolToString(_.SwingH, kSwingHStr); - result += addLabeledString(_.SwingAuto ? kAutoStr : kManualStr, - kSwingVModeStr); result += addIntToString(_.SwingV, kSwingVStr); - result += kSpaceLBraceStr; - switch (_.SwingV) { - case kKelvinatorSwingLastPos: - result += kLastStr; - break; - case kKelvinatorSwingAuto: - result += kAutoStr; - break; - default: result += kUnknownStr; - } - result += ')'; return result; } diff --git a/test/ir_Kelvinator_test.cpp b/test/ir_Kelvinator_test.cpp index 73ad6581d..2a58a66a5 100644 --- a/test/ir_Kelvinator_test.cpp +++ b/test/ir_Kelvinator_test.cpp @@ -251,23 +251,43 @@ TEST(TestKelvinatorClass, VaneSwing) { irkelv.begin(); irkelv.setSwingHorizontal(true); - irkelv.setSwingVertical(false); + EXPECT_TRUE(irkelv.getSwingHorizontal()); - irkelv.setSwingHorizontal(true); + EXPECT_FALSE(irkelv.getSwingVerticalAuto()); + EXPECT_EQ(kKelvinatorSwingLastPos, irkelv.getSwingVerticalPosition()); + + irkelv.setSwingVertical(true, kKelvinatorSwingAuto); + EXPECT_TRUE(irkelv.getSwingVerticalAuto()); + EXPECT_EQ(kKelvinatorSwingAuto, irkelv.getSwingVerticalPosition()); EXPECT_TRUE(irkelv.getSwingHorizontal()); - EXPECT_FALSE(irkelv.getSwingVertical()); - irkelv.setSwingVertical(true); + irkelv.setSwingVertical(false, kKelvinatorSwingMiddle); + EXPECT_FALSE(irkelv.getSwingVerticalAuto()); + EXPECT_EQ(kKelvinatorSwingMiddle, irkelv.getSwingVerticalPosition()); EXPECT_TRUE(irkelv.getSwingHorizontal()); - EXPECT_TRUE(irkelv.getSwingVertical()); irkelv.setSwingHorizontal(false); EXPECT_FALSE(irkelv.getSwingHorizontal()); - EXPECT_TRUE(irkelv.getSwingVertical()); - irkelv.setSwingVertical(false); + irkelv.setSwingVertical(true, kKelvinatorSwingDownAuto); + EXPECT_TRUE(irkelv.getSwingVerticalAuto()); + EXPECT_EQ(kKelvinatorSwingDownAuto, irkelv.getSwingVerticalPosition()); EXPECT_FALSE(irkelv.getSwingHorizontal()); - EXPECT_FALSE(irkelv.getSwingVertical()); + + // Out of bounds. + irkelv.setSwingVertical(false, 255); + EXPECT_FALSE(irkelv.getSwingVerticalAuto()); + EXPECT_EQ(kKelvinatorSwingLastPos, irkelv.getSwingVerticalPosition()); + irkelv.setSwingVertical(false, kKelvinatorSwingAuto); + EXPECT_FALSE(irkelv.getSwingVerticalAuto()); + EXPECT_EQ(kKelvinatorSwingLastPos, irkelv.getSwingVerticalPosition()); + + irkelv.setSwingVertical(true, 255); + EXPECT_TRUE(irkelv.getSwingVerticalAuto()); + EXPECT_EQ(kKelvinatorSwingAuto, irkelv.getSwingVerticalPosition()); + irkelv.setSwingVertical(true, kKelvinatorSwingDown); + EXPECT_TRUE(irkelv.getSwingVerticalAuto()); + EXPECT_EQ(kKelvinatorSwingAuto, irkelv.getSwingVerticalPosition()); } TEST(TestKelvinatorClass, QuietMode) { @@ -425,7 +445,7 @@ TEST(TestKelvinatorClass, HumanReadable) { EXPECT_EQ( "Power: Off, Mode: 0 (Auto), Temp: 16C, Fan: 0 (Auto), Turbo: Off, " "Quiet: Off, XFan: Off, Ion: Off, Light: Off, " - "Swing(H): Off, Swing(V): Off", + "Swing(H): Off, Swing(V): 0", irkelv.toString()); irkelv.on(); irkelv.setMode(kKelvinatorCool); @@ -438,7 +458,7 @@ TEST(TestKelvinatorClass, HumanReadable) { EXPECT_EQ( "Power: On, Mode: 1 (Cool), Temp: 25C, Fan: 5 (High), Turbo: Off, " "Quiet: Off, XFan: On, Ion: On, Light: On, " - "Swing(H): On, Swing(V): Off", + "Swing(H): On, Swing(V): 0", irkelv.toString()); } @@ -451,7 +471,7 @@ TEST(TestKelvinatorClass, MessageConstuction) { irkelv.setFan(1); irkelv.setMode(kKelvinatorCool); irkelv.setTemp(27); - irkelv.setSwingVertical(false); + irkelv.setSwingVertical(false, kKelvinatorSwingLastPos); irkelv.setSwingHorizontal(true); irkelv.setIonFilter(true); irkelv.setQuiet(false); @@ -464,7 +484,7 @@ TEST(TestKelvinatorClass, MessageConstuction) { EXPECT_EQ(1, irkelv.getFan()); EXPECT_EQ(kKelvinatorCool, irkelv.getMode()); EXPECT_EQ(27, irkelv.getTemp()); - EXPECT_FALSE(irkelv.getSwingVertical()); + EXPECT_FALSE(irkelv.getSwingVerticalAuto()); EXPECT_TRUE(irkelv.getSwingHorizontal()); EXPECT_TRUE(irkelv.getIonFilter()); EXPECT_FALSE(irkelv.getQuiet()); @@ -523,7 +543,7 @@ TEST(TestDecodeKelvinator, NormalSynthetic) { EXPECT_EQ( "Power: On, Mode: 1 (Cool), Temp: 27C, Fan: 1 (Low), Turbo: Off, " "Quiet: Off, XFan: On, Ion: Off, Light: Off, " - "Swing(H): Off, Swing(V): Off", + "Swing(H): Off, Swing(V): 0", IRAcUtils::resultAcToString(&irsend.capture)); stdAc::state_t r, p; ASSERT_TRUE(IRAcUtils::decodeToState(&irsend.capture, &r, &p)); @@ -541,7 +561,7 @@ TEST(TestKelvinatorClass, toCommon) { ac.setTurbo(true); ac.setLight(true); ac.setSwingHorizontal(false); - ac.setSwingVertical(true); + ac.setSwingVertical(true, kKelvinatorSwingAuto); // Now test it. ASSERT_EQ(decode_type_t::KELVINATOR, ac.toCommon().protocol); From 83e084f35d3185da5c3ace583f2ce94cc39489bd Mon Sep 17 00:00:00 2001 From: Z <22781620+invis-z@users.noreply.github.com> Date: Sat, 12 Feb 2022 05:58:51 +0800 Subject: [PATCH 4/6] remove white space --- src/ir_Kelvinator.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ir_Kelvinator.cpp b/src/ir_Kelvinator.cpp index 6cf6d4ecf..e4d3b61ee 100644 --- a/src/ir_Kelvinator.cpp +++ b/src/ir_Kelvinator.cpp @@ -309,13 +309,13 @@ void IRKelvinatorAC::setSwingVertical(const bool automatic, /// Get the Vertical Swing Automatic mode setting of the A/C. /// @return true, the setting is on. false, the setting is off. bool IRKelvinatorAC::getSwingVerticalAuto(void) const { - return _.SwingV & 0b0001; + return _.SwingV & 0b0001; } /// Get the Vertical Swing position setting of the A/C. /// @return The native position/mode. uint8_t IRKelvinatorAC::getSwingVerticalPosition(void) const { - return _.SwingV; + return _.SwingV; } /// Control the current horizontal swing setting. From e93fd28e0f45d17092bdc9a20a8d32c5c622d600 Mon Sep 17 00:00:00 2001 From: Z <22781620+invis-z@users.noreply.github.com> Date: Sat, 12 Feb 2022 06:04:48 +0800 Subject: [PATCH 5/6] Fix tests --- test/IRac_test.cpp | 2 +- test/ir_Kelvinator_test.cpp | 2 +- tools/code_to_raw_test.sh | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/test/IRac_test.cpp b/test/IRac_test.cpp index 431a2ebe9..b005a8d90 100644 --- a/test/IRac_test.cpp +++ b/test/IRac_test.cpp @@ -1076,7 +1076,7 @@ TEST(TestIRac, Kelvinator) { char expected[] = "Power: On, Mode: 1 (Cool), Temp: 19C, Fan: 3 (Medium), Turbo: Off, " "Quiet: Off, XFan: On, Ion: On, Light: On, " - "Swing(H): Off, Swing(V): Off"; + "Swing(H): Off, Swing(V): 0"; ac.begin(); irac.kelvinator(&ac, diff --git a/test/ir_Kelvinator_test.cpp b/test/ir_Kelvinator_test.cpp index 2a58a66a5..38c93fff1 100644 --- a/test/ir_Kelvinator_test.cpp +++ b/test/ir_Kelvinator_test.cpp @@ -255,7 +255,7 @@ TEST(TestKelvinatorClass, VaneSwing) { EXPECT_FALSE(irkelv.getSwingVerticalAuto()); EXPECT_EQ(kKelvinatorSwingLastPos, irkelv.getSwingVerticalPosition()); - + irkelv.setSwingVertical(true, kKelvinatorSwingAuto); EXPECT_TRUE(irkelv.getSwingVerticalAuto()); EXPECT_EQ(kKelvinatorSwingAuto, irkelv.getSwingVerticalPosition()); diff --git a/tools/code_to_raw_test.sh b/tools/code_to_raw_test.sh index fd587f2ad..ff7181acd 100755 --- a/tools/code_to_raw_test.sh +++ b/tools/code_to_raw_test.sh @@ -56,7 +56,7 @@ unittest_success "${CODE_TO_RAW} --protocol SAMSUNG --code 0xE0E09966" "${OUT}" read -r -d '' OUT << xEOMx Code type: 18 (KELVINATOR) Code bits: 128 -Description: Power: On, Mode: 1 (Cool), Temp: 27C, Fan: 1 (Low), Turbo: Off, Quiet: Off, XFan: On, Ion: Off, Light: Off, Swing(H): Off, Swing(V): Off +Description: Power: On, Mode: 1 (Cool), Temp: 27C, Fan: 1 (Low), Turbo: Off, Quiet: Off, XFan: On, Ion: Off, Light: Off, Swing(H): Off, Swing(V): 0 uint16_t rawData[280] = {9010, 4504, 680, 1530, 680, 510, 680, 510, 680, 1530, 680, 1530, 680, 510, 680, 510, 680, 510, 680, 1530, 680, 1530, 680, 510, 680, 1530, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 1530, 680, 510, 680, 510, 680, 510, 680, 510, 680, 1530, 680, 510, 680, 1530, 680, 510, 680, 510, 680, 1530, 680, 510, 680, 19974, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 1530, 680, 1530, 680, 1530, 680, 39950, 9010, 4504, 680, 1530, 680, 510, 680, 510, 680, 1530, 680, 1530, 680, 510, 680, 510, 680, 510, 680, 1530, 680, 1530, 680, 510, 680, 1530, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 1530, 680, 510, 680, 510, 680, 510, 680, 510, 680, 1530, 680, 1530, 680, 1530, 680, 510, 680, 510, 680, 1530, 680, 510, 680, 19974, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 1530, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 1530, 680, 1530, 680, 1530, 680, 1530, 680, 39950 }; // KELVINATOR uint8_t state[16] = {0x19, 0x0B, 0x80, 0x50, 0x00, 0x00, 0x00, 0xE0, 0x19, 0x0B, 0x80, 0x70, 0x00, 0x00, 0x10, 0xF0}; From 80a6549680c48fd160132f5f7218c17e0868b589 Mon Sep 17 00:00:00 2001 From: Z <22781620+invis-z@users.noreply.github.com> Date: Sat, 12 Feb 2022 11:56:37 +0800 Subject: [PATCH 6/6] Change naming & tests --- .../TurnOnKelvinatorAC/TurnOnKelvinatorAC.ino | 2 +- src/ir_Kelvinator.cpp | 47 ++++++++++++------- src/ir_Kelvinator.h | 20 ++++---- test/IRac_test.cpp | 2 +- test/ir_Kelvinator_test.cpp | 36 +++++++------- tools/code_to_raw_test.sh | 2 +- 6 files changed, 60 insertions(+), 49 deletions(-) diff --git a/examples/TurnOnKelvinatorAC/TurnOnKelvinatorAC.ino b/examples/TurnOnKelvinatorAC/TurnOnKelvinatorAC.ino index 93390c2c7..974bb94fc 100644 --- a/examples/TurnOnKelvinatorAC/TurnOnKelvinatorAC.ino +++ b/examples/TurnOnKelvinatorAC/TurnOnKelvinatorAC.ino @@ -57,7 +57,7 @@ void setup() { ac.setFan(1); ac.setMode(kKelvinatorCool); ac.setTemp(26); - ac.setSwingVertical(false, kKelvinatorSwingLastPos); + ac.setSwingVertical(false, kKelvinatorSwingVOff); ac.setSwingHorizontal(true); ac.setXFan(true); ac.setIonFilter(false); diff --git a/src/ir_Kelvinator.cpp b/src/ir_Kelvinator.cpp index e4d3b61ee..c44f7c683 100644 --- a/src/ir_Kelvinator.cpp +++ b/src/ir_Kelvinator.cpp @@ -53,6 +53,7 @@ using irutils::addLabeledString; using irutils::addModeToString; using irutils::addFanToString; using irutils::addTempToString; +using irutils::addSwingVToString; #if SEND_KELVINATOR /// Send a Kelvinator A/C message. @@ -283,24 +284,24 @@ void IRKelvinatorAC::setSwingVertical(const bool automatic, uint8_t new_position = position; if (!automatic) { switch (position) { - case kKelvinatorSwingUp: - case kKelvinatorSwingMiddleUp: - case kKelvinatorSwingMiddle: - case kKelvinatorSwingMiddleDown: - case kKelvinatorSwingDown: + case kKelvinatorSwingVHighest: + case kKelvinatorSwingVUpperMiddle: + case kKelvinatorSwingVMiddle: + case kKelvinatorSwingVLowerMiddle: + case kKelvinatorSwingVLowest: break; default: - new_position = kKelvinatorSwingLastPos; + new_position = kKelvinatorSwingVOff; } } else { switch (position) { - case kKelvinatorSwingAuto: - case kKelvinatorSwingDownAuto: - case kKelvinatorSwingMiddleAuto: - case kKelvinatorSwingUpAuto: + case kKelvinatorSwingVAuto: + case kKelvinatorSwingVLowAuto: + case kKelvinatorSwingVMiddleAuto: + case kKelvinatorSwingVHighAuto: break; default: - new_position = kKelvinatorSwingAuto; + new_position = kKelvinatorSwingVAuto; } } _.SwingV = new_position; @@ -414,12 +415,12 @@ uint8_t IRKelvinatorAC::convertMode(const stdAc::opmode_t mode) { /// @return The native equivalent of the enum. uint8_t IRKelvinatorAC::convertSwingV(const stdAc::swingv_t swingv) { switch (swingv) { - case stdAc::swingv_t::kHighest: return kKelvinatorSwingUp; - case stdAc::swingv_t::kHigh: return kKelvinatorSwingMiddleUp; - case stdAc::swingv_t::kMiddle: return kKelvinatorSwingMiddle; - case stdAc::swingv_t::kLow: return kKelvinatorSwingMiddleDown; - case stdAc::swingv_t::kLowest: return kKelvinatorSwingDown; - default: return kKelvinatorSwingAuto; + case stdAc::swingv_t::kHighest: return kKelvinatorSwingVHighest; + case stdAc::swingv_t::kHigh: return kKelvinatorSwingVHighAuto; + case stdAc::swingv_t::kMiddle: return kKelvinatorSwingVMiddle; + case stdAc::swingv_t::kLow: return kKelvinatorSwingVLowAuto; + case stdAc::swingv_t::kLowest: return kKelvinatorSwingVLowest; + default: return kKelvinatorSwingVAuto; } } @@ -487,7 +488,17 @@ String IRKelvinatorAC::toString(void) const { result += addBoolToString(_.IonFilter, kIonStr); result += addBoolToString(_.Light, kLightStr); result += addBoolToString(_.SwingH, kSwingHStr); - result += addIntToString(_.SwingV, kSwingVStr); + result += addSwingVToString(_.SwingV, kKelvinatorSwingVAuto, + kKelvinatorSwingVHighest, + kKelvinatorSwingVHighAuto, + kKelvinatorSwingVUpperMiddle, + kKelvinatorSwingVMiddle, + kKelvinatorSwingVLowerMiddle, + kKelvinatorSwingVLowAuto, + kKelvinatorSwingVLowest, + kKelvinatorSwingVOff, + kKelvinatorSwingVAuto, kKelvinatorSwingVAuto, + kKelvinatorSwingVAuto); return result; } diff --git a/src/ir_Kelvinator.h b/src/ir_Kelvinator.h index 05d36c315..32cb3e1fa 100644 --- a/src/ir_Kelvinator.h +++ b/src/ir_Kelvinator.h @@ -103,16 +103,16 @@ const uint8_t kKelvinatorMinTemp = 16; // 16C const uint8_t kKelvinatorMaxTemp = 30; // 30C const uint8_t kKelvinatorAutoTemp = 25; // 25C -const uint8_t kKelvinatorSwingLastPos = 0b0000; // 0 -const uint8_t kKelvinatorSwingAuto = 0b0001; // 1 -const uint8_t kKelvinatorSwingUp = 0b0010; // 2 -const uint8_t kKelvinatorSwingMiddleUp = 0b0011; // 3 -const uint8_t kKelvinatorSwingMiddle = 0b0100; // 4 -const uint8_t kKelvinatorSwingMiddleDown = 0b0101; // 5 -const uint8_t kKelvinatorSwingDown = 0b0110; // 6 -const uint8_t kKelvinatorSwingDownAuto = 0b0111; // 7 -const uint8_t kKelvinatorSwingMiddleAuto = 0b1001; // 9 -const uint8_t kKelvinatorSwingUpAuto = 0b1011; // 11 +const uint8_t kKelvinatorSwingVOff = 0b0000; // 0 +const uint8_t kKelvinatorSwingVAuto = 0b0001; // 1 +const uint8_t kKelvinatorSwingVHighest = 0b0010; // 2 +const uint8_t kKelvinatorSwingVUpperMiddle = 0b0011; // 3 +const uint8_t kKelvinatorSwingVMiddle = 0b0100; // 4 +const uint8_t kKelvinatorSwingVLowerMiddle = 0b0101; // 5 +const uint8_t kKelvinatorSwingVLowest = 0b0110; // 6 +const uint8_t kKelvinatorSwingVLowAuto = 0b0111; // 7 +const uint8_t kKelvinatorSwingVMiddleAuto = 0b1001; // 9 +const uint8_t kKelvinatorSwingVHighAuto = 0b1011; // 11 // Legacy defines (Deprecated) #define KELVINATOR_MIN_TEMP kKelvinatorMinTemp diff --git a/test/IRac_test.cpp b/test/IRac_test.cpp index b005a8d90..59e1186a7 100644 --- a/test/IRac_test.cpp +++ b/test/IRac_test.cpp @@ -1076,7 +1076,7 @@ TEST(TestIRac, Kelvinator) { char expected[] = "Power: On, Mode: 1 (Cool), Temp: 19C, Fan: 3 (Medium), Turbo: Off, " "Quiet: Off, XFan: On, Ion: On, Light: On, " - "Swing(H): Off, Swing(V): 0"; + "Swing(H): Off, Swing(V): 0 (Off)"; ac.begin(); irac.kelvinator(&ac, diff --git a/test/ir_Kelvinator_test.cpp b/test/ir_Kelvinator_test.cpp index 38c93fff1..e4a335db0 100644 --- a/test/ir_Kelvinator_test.cpp +++ b/test/ir_Kelvinator_test.cpp @@ -254,40 +254,40 @@ TEST(TestKelvinatorClass, VaneSwing) { EXPECT_TRUE(irkelv.getSwingHorizontal()); EXPECT_FALSE(irkelv.getSwingVerticalAuto()); - EXPECT_EQ(kKelvinatorSwingLastPos, irkelv.getSwingVerticalPosition()); + EXPECT_EQ(kKelvinatorSwingVOff, irkelv.getSwingVerticalPosition()); - irkelv.setSwingVertical(true, kKelvinatorSwingAuto); + irkelv.setSwingVertical(true, kKelvinatorSwingVAuto); EXPECT_TRUE(irkelv.getSwingVerticalAuto()); - EXPECT_EQ(kKelvinatorSwingAuto, irkelv.getSwingVerticalPosition()); + EXPECT_EQ(kKelvinatorSwingVAuto, irkelv.getSwingVerticalPosition()); EXPECT_TRUE(irkelv.getSwingHorizontal()); - irkelv.setSwingVertical(false, kKelvinatorSwingMiddle); + irkelv.setSwingVertical(false, kKelvinatorSwingVMiddle); EXPECT_FALSE(irkelv.getSwingVerticalAuto()); - EXPECT_EQ(kKelvinatorSwingMiddle, irkelv.getSwingVerticalPosition()); + EXPECT_EQ(kKelvinatorSwingVMiddle, irkelv.getSwingVerticalPosition()); EXPECT_TRUE(irkelv.getSwingHorizontal()); irkelv.setSwingHorizontal(false); EXPECT_FALSE(irkelv.getSwingHorizontal()); - irkelv.setSwingVertical(true, kKelvinatorSwingDownAuto); + irkelv.setSwingVertical(true, kKelvinatorSwingVLowAuto); EXPECT_TRUE(irkelv.getSwingVerticalAuto()); - EXPECT_EQ(kKelvinatorSwingDownAuto, irkelv.getSwingVerticalPosition()); + EXPECT_EQ(kKelvinatorSwingVLowAuto, irkelv.getSwingVerticalPosition()); EXPECT_FALSE(irkelv.getSwingHorizontal()); // Out of bounds. irkelv.setSwingVertical(false, 255); EXPECT_FALSE(irkelv.getSwingVerticalAuto()); - EXPECT_EQ(kKelvinatorSwingLastPos, irkelv.getSwingVerticalPosition()); - irkelv.setSwingVertical(false, kKelvinatorSwingAuto); + EXPECT_EQ(kKelvinatorSwingVOff, irkelv.getSwingVerticalPosition()); + irkelv.setSwingVertical(false, kKelvinatorSwingVAuto); EXPECT_FALSE(irkelv.getSwingVerticalAuto()); - EXPECT_EQ(kKelvinatorSwingLastPos, irkelv.getSwingVerticalPosition()); + EXPECT_EQ(kKelvinatorSwingVOff, irkelv.getSwingVerticalPosition()); irkelv.setSwingVertical(true, 255); EXPECT_TRUE(irkelv.getSwingVerticalAuto()); - EXPECT_EQ(kKelvinatorSwingAuto, irkelv.getSwingVerticalPosition()); - irkelv.setSwingVertical(true, kKelvinatorSwingDown); + EXPECT_EQ(kKelvinatorSwingVAuto, irkelv.getSwingVerticalPosition()); + irkelv.setSwingVertical(true, kKelvinatorSwingVLowest); EXPECT_TRUE(irkelv.getSwingVerticalAuto()); - EXPECT_EQ(kKelvinatorSwingAuto, irkelv.getSwingVerticalPosition()); + EXPECT_EQ(kKelvinatorSwingVAuto, irkelv.getSwingVerticalPosition()); } TEST(TestKelvinatorClass, QuietMode) { @@ -445,7 +445,7 @@ TEST(TestKelvinatorClass, HumanReadable) { EXPECT_EQ( "Power: Off, Mode: 0 (Auto), Temp: 16C, Fan: 0 (Auto), Turbo: Off, " "Quiet: Off, XFan: Off, Ion: Off, Light: Off, " - "Swing(H): Off, Swing(V): 0", + "Swing(H): Off, Swing(V): 0 (Off)", irkelv.toString()); irkelv.on(); irkelv.setMode(kKelvinatorCool); @@ -458,7 +458,7 @@ TEST(TestKelvinatorClass, HumanReadable) { EXPECT_EQ( "Power: On, Mode: 1 (Cool), Temp: 25C, Fan: 5 (High), Turbo: Off, " "Quiet: Off, XFan: On, Ion: On, Light: On, " - "Swing(H): On, Swing(V): 0", + "Swing(H): On, Swing(V): 0 (Off)", irkelv.toString()); } @@ -471,7 +471,7 @@ TEST(TestKelvinatorClass, MessageConstuction) { irkelv.setFan(1); irkelv.setMode(kKelvinatorCool); irkelv.setTemp(27); - irkelv.setSwingVertical(false, kKelvinatorSwingLastPos); + irkelv.setSwingVertical(false, kKelvinatorSwingVOff); irkelv.setSwingHorizontal(true); irkelv.setIonFilter(true); irkelv.setQuiet(false); @@ -543,7 +543,7 @@ TEST(TestDecodeKelvinator, NormalSynthetic) { EXPECT_EQ( "Power: On, Mode: 1 (Cool), Temp: 27C, Fan: 1 (Low), Turbo: Off, " "Quiet: Off, XFan: On, Ion: Off, Light: Off, " - "Swing(H): Off, Swing(V): 0", + "Swing(H): Off, Swing(V): 0 (Off)", IRAcUtils::resultAcToString(&irsend.capture)); stdAc::state_t r, p; ASSERT_TRUE(IRAcUtils::decodeToState(&irsend.capture, &r, &p)); @@ -561,7 +561,7 @@ TEST(TestKelvinatorClass, toCommon) { ac.setTurbo(true); ac.setLight(true); ac.setSwingHorizontal(false); - ac.setSwingVertical(true, kKelvinatorSwingAuto); + ac.setSwingVertical(true, kKelvinatorSwingVAuto); // Now test it. ASSERT_EQ(decode_type_t::KELVINATOR, ac.toCommon().protocol); diff --git a/tools/code_to_raw_test.sh b/tools/code_to_raw_test.sh index ff7181acd..c95b3da8b 100755 --- a/tools/code_to_raw_test.sh +++ b/tools/code_to_raw_test.sh @@ -56,7 +56,7 @@ unittest_success "${CODE_TO_RAW} --protocol SAMSUNG --code 0xE0E09966" "${OUT}" read -r -d '' OUT << xEOMx Code type: 18 (KELVINATOR) Code bits: 128 -Description: Power: On, Mode: 1 (Cool), Temp: 27C, Fan: 1 (Low), Turbo: Off, Quiet: Off, XFan: On, Ion: Off, Light: Off, Swing(H): Off, Swing(V): 0 +Description: Power: On, Mode: 1 (Cool), Temp: 27C, Fan: 1 (Low), Turbo: Off, Quiet: Off, XFan: On, Ion: Off, Light: Off, Swing(H): Off, Swing(V): 0 (Off) uint16_t rawData[280] = {9010, 4504, 680, 1530, 680, 510, 680, 510, 680, 1530, 680, 1530, 680, 510, 680, 510, 680, 510, 680, 1530, 680, 1530, 680, 510, 680, 1530, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 1530, 680, 510, 680, 510, 680, 510, 680, 510, 680, 1530, 680, 510, 680, 1530, 680, 510, 680, 510, 680, 1530, 680, 510, 680, 19974, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 1530, 680, 1530, 680, 1530, 680, 39950, 9010, 4504, 680, 1530, 680, 510, 680, 510, 680, 1530, 680, 1530, 680, 510, 680, 510, 680, 510, 680, 1530, 680, 1530, 680, 510, 680, 1530, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 1530, 680, 510, 680, 510, 680, 510, 680, 510, 680, 1530, 680, 1530, 680, 1530, 680, 510, 680, 510, 680, 1530, 680, 510, 680, 19974, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 1530, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 510, 680, 1530, 680, 1530, 680, 1530, 680, 1530, 680, 39950 }; // KELVINATOR uint8_t state[16] = {0x19, 0x0B, 0x80, 0x50, 0x00, 0x00, 0x00, 0xE0, 0x19, 0x0B, 0x80, 0x70, 0x00, 0x00, 0x10, 0xF0};