diff --git a/src/ir_Delonghi.cpp b/src/ir_Delonghi.cpp index 7a829350b..7f6c3158a 100644 --- a/src/ir_Delonghi.cpp +++ b/src/ir_Delonghi.cpp @@ -321,12 +321,12 @@ bool IRDelonghiAc::getSleep(void) { return GETBIT64(remote_state, kDelonghiAcSleepBit); } -void IRDelonghiAc::setTimerEnabled(const bool on) { - setBit(&remote_state, kDelonghiAcTimerEnableBit, on); +void IRDelonghiAc::setOnTimerEnabled(const bool on) { + setBit(&remote_state, kDelonghiAcOnTimerEnableBit, on); } -bool IRDelonghiAc::getTimerEnabled(void) { - return GETBIT64(remote_state, kDelonghiAcTimerEnableBit); +bool IRDelonghiAc::getOnTimerEnabled(void) { + return GETBIT64(remote_state, kDelonghiAcOnTimerEnableBit); } // Set the On timer to activate in nr of minutes. @@ -340,7 +340,7 @@ void IRDelonghiAc::setOnTimer(const uint16_t nr_of_mins) { setBits(&remote_state, kDelonghiAcOnTimerHoursOffset, kDelonghiAcHoursSize, value / 60); // Hours. // Enable or not? - setTimerEnabled(getTimerEnabled() || value); + setOnTimerEnabled(value > 0); } uint16_t IRDelonghiAc::getOnTimer(void) { @@ -350,6 +350,35 @@ uint16_t IRDelonghiAc::getOnTimer(void) { kDelonghiAcMinsSize); } +void IRDelonghiAc::setOffTimerEnabled(const bool on) { + setBit(&remote_state, kDelonghiAcOffTimerEnableBit, on); +} + +bool IRDelonghiAc::getOffTimerEnabled(void) { + return GETBIT64(remote_state, kDelonghiAcOffTimerEnableBit); +} + +// Set the Off timer to activate in nr of minutes. +// Args: +// nr_of_mins: Total nr of mins to wait before waking the device. +// (Max 23 hrs and 59 minutes. i.e. 1439 mins) +void IRDelonghiAc::setOffTimer(const uint16_t nr_of_mins) { + uint16_t value = std::min(kDelonghiAcTimerMax, nr_of_mins); + setBits(&remote_state, kDelonghiAcOffTimerMinsOffset, kDelonghiAcMinsSize, + value % 60); // Minutes. + setBits(&remote_state, kDelonghiAcOffTimerHoursOffset, kDelonghiAcHoursSize, + value / 60); // Hours. + // Enable or not? + setOffTimerEnabled(value > 0); +} + +uint16_t IRDelonghiAc::getOffTimer(void) { + return GETBITS64(remote_state, kDelonghiAcOffTimerHoursOffset, + kDelonghiAcHoursSize) * 60 + + GETBITS64(remote_state, kDelonghiAcOffTimerMinsOffset, + kDelonghiAcMinsSize); +} + // Convert the A/C state to it's common equivalent. stdAc::state_t IRDelonghiAc::toCommon(void) { stdAc::state_t result; @@ -388,8 +417,13 @@ String IRDelonghiAc::toString(void) { result += addTempToString(getTemp(), !getTempUnit()); result += addBoolToString(getBoost(), kTurboStr); result += addBoolToString(getSleep(), kSleepStr); - result += addBoolToString(getTimerEnabled(), kTimerStr); uint16_t mins = getOnTimer(); - result += addLabeledString(mins ? minsToString(mins) : kOffStr, kOnTimerStr); + result += addLabeledString((mins && getOnTimerEnabled()) ? minsToString(mins) + : kOffStr, + kOnTimerStr); + mins = getOffTimer(); + result += addLabeledString((mins && getOffTimerEnabled()) ? minsToString(mins) + : kOffStr, + kOffTimerStr); return result; } diff --git a/src/ir_Delonghi.h b/src/ir_Delonghi.h index a93bc12dc..8ba8e90f4 100644 --- a/src/ir_Delonghi.h +++ b/src/ir_Delonghi.h @@ -78,16 +78,24 @@ const uint8_t kDelonghiAcBoostBit = kDelonghiAcModeOffset + kDelonghiAcModeSize; // 20 (Aka Turbo) const uint8_t kDelonghiAcSleepBit = kDelonghiAcBoostBit + 1; // 21 // Two zero bits -const uint8_t kDelonghiAcTimerEnableBit = kDelonghiAcSleepBit + 3; // 24 +const uint8_t kDelonghiAcOnTimerEnableBit = kDelonghiAcSleepBit + 3; // 24 const uint8_t kDelonghiAcHoursSize = 5; // Max 23 hrs const uint8_t kDelonghiAcMinsSize = 6; // Max 59 mins const uint16_t kDelonghiAcTimerMax = 23 * 60 + 59; -const uint8_t kDelonghiAcOnTimerHoursOffset = kDelonghiAcTimerEnableBit + +const uint8_t kDelonghiAcOnTimerHoursOffset = kDelonghiAcOnTimerEnableBit + 1; // 25 const uint8_t kDelonghiAcOnTimerMinsOffset = kDelonghiAcOnTimerHoursOffset + kDelonghiAcHoursSize + 2; // 32 (inc another two zero bits) -// Next available bit is kDelonghiAcOnTimerMinsOffset + kDelonghiAcMinsSize = 38 -const uint8_t kDelonghiAcChecksumOffset = 56; +// Two zero bits +const uint8_t kDelonghiAcOffTimerEnableBit = kDelonghiAcOnTimerMinsOffset + + kDelonghiAcMinsSize + 2; // 40 +const uint8_t kDelonghiAcOffTimerHoursOffset = kDelonghiAcOffTimerEnableBit + + 1; // 41 +const uint8_t kDelonghiAcOffTimerMinsOffset = kDelonghiAcOffTimerHoursOffset + + kDelonghiAcHoursSize + 2; // 48 (inc another two zero bits) +// Two zero bits +const uint8_t kDelonghiAcChecksumOffset = kDelonghiAcOffTimerMinsOffset + + kDelonghiAcMinsSize + 2; // 56 const uint8_t kDelonghiAcChecksumSize = 8; @@ -122,10 +130,14 @@ class IRDelonghiAc { bool getBoost(); // Aka Turbo void setSleep(const bool on); bool getSleep(); - void setTimerEnabled(const bool on); - bool getTimerEnabled(void); + void setOnTimerEnabled(const bool on); + bool getOnTimerEnabled(void); void setOnTimer(const uint16_t nr_of_mins); uint16_t getOnTimer(void); + void setOffTimerEnabled(const bool on); + bool getOffTimerEnabled(void); + void setOffTimer(const uint16_t nr_of_mins); + uint16_t getOffTimer(void); uint64_t getRaw(); void setRaw(const uint64_t state); uint8_t convertMode(const stdAc::opmode_t mode); diff --git a/test/IRac_test.cpp b/test/IRac_test.cpp index e9b64d3d9..c96deed04 100644 --- a/test/IRac_test.cpp +++ b/test/IRac_test.cpp @@ -384,7 +384,7 @@ TEST(TestIRac, DelonghiAc) { IRrecv capture(kGpioUnused); char expected[] = "Power: On, Mode: 0 (Cool), Fan: 2 (Medium), Temp: 77F, " - "Turbo: On, Sleep: On, Timer: Off, On Timer: Off"; + "Turbo: On, Sleep: On, On Timer: Off, Off Timer: Off"; ac.begin(); irac.delonghiac(&ac, diff --git a/test/ir_Delonghi_test.cpp b/test/ir_Delonghi_test.cpp index 769ee9fad..577435f55 100644 --- a/test/ir_Delonghi_test.cpp +++ b/test/ir_Delonghi_test.cpp @@ -67,7 +67,7 @@ TEST(TestDecodeDelonghiAc, RealExample) { EXPECT_EQ(0, irsend.capture.address); EXPECT_EQ( "Power: On, Mode: 0 (Cool), Fan: 3 (Low), Temp: 90F, " - "Turbo: Off, Sleep: Off, Timer: On, On Timer: 06:13", + "Turbo: Off, Sleep: Off, On Timer: 06:13, Off Timer: Off", IRAcUtils::resultAcToString(&irsend.capture)); stdAc::state_t r, p; ASSERT_TRUE(IRAcUtils::decodeToState(&irsend.capture, &r, &p)); @@ -287,32 +287,66 @@ TEST(TestIRDelonghiAcClass, OnTimer) { IRDelonghiAc ac(kGpioUnused); ac.begin(); - ac.setTimerEnabled(false); - EXPECT_FALSE(ac.getTimerEnabled()); - ac.setTimerEnabled(true); - EXPECT_TRUE(ac.getTimerEnabled()); - ac.setTimerEnabled(false); - EXPECT_FALSE(ac.getTimerEnabled()); + ac.setOnTimerEnabled(false); + EXPECT_FALSE(ac.getOnTimerEnabled()); + ac.setOnTimerEnabled(true); + EXPECT_TRUE(ac.getOnTimerEnabled()); + ac.setOnTimerEnabled(false); + EXPECT_FALSE(ac.getOnTimerEnabled()); ac.setOnTimer(0); - EXPECT_FALSE(ac.getTimerEnabled()); + EXPECT_FALSE(ac.getOnTimerEnabled()); EXPECT_EQ(0, ac.getOnTimer()); ac.setOnTimer(1); - EXPECT_TRUE(ac.getTimerEnabled()); + EXPECT_TRUE(ac.getOnTimerEnabled()); EXPECT_EQ(1, ac.getOnTimer()); ac.setOnTimer(61); - EXPECT_TRUE(ac.getTimerEnabled()); + EXPECT_TRUE(ac.getOnTimerEnabled()); EXPECT_EQ(61, ac.getOnTimer()); - ac.setTimerEnabled(false); + ac.setOnTimerEnabled(false); ac.setOnTimer(23 * 60 + 59); - EXPECT_TRUE(ac.getTimerEnabled()); + EXPECT_TRUE(ac.getOnTimerEnabled()); EXPECT_EQ(23 * 60 + 59, ac.getOnTimer()); - ac.setTimerEnabled(false); + ac.setOnTimerEnabled(false); ac.setOnTimer(24 * 60); - EXPECT_TRUE(ac.getTimerEnabled()); + EXPECT_TRUE(ac.getOnTimerEnabled()); EXPECT_EQ(23 * 60 + 59, ac.getOnTimer()); } + +TEST(TestIRDelonghiAcClass, OffTimer) { + IRDelonghiAc ac(kGpioUnused); + ac.begin(); + + ac.setOffTimerEnabled(false); + EXPECT_FALSE(ac.getOffTimerEnabled()); + ac.setOffTimerEnabled(true); + EXPECT_TRUE(ac.getOffTimerEnabled()); + ac.setOffTimerEnabled(false); + EXPECT_FALSE(ac.getOffTimerEnabled()); + + ac.setOffTimer(0); + EXPECT_FALSE(ac.getOffTimerEnabled()); + EXPECT_EQ(0, ac.getOffTimer()); + + ac.setOffTimer(1); + EXPECT_TRUE(ac.getOffTimerEnabled()); + EXPECT_EQ(1, ac.getOffTimer()); + + ac.setOffTimer(61); + EXPECT_TRUE(ac.getOffTimerEnabled()); + EXPECT_EQ(61, ac.getOffTimer()); + + ac.setOffTimerEnabled(false); + ac.setOffTimer(23 * 60 + 59); + EXPECT_TRUE(ac.getOffTimerEnabled()); + EXPECT_EQ(23 * 60 + 59, ac.getOffTimer()); + + ac.setOffTimerEnabled(false); + ac.setOffTimer(24 * 60); + EXPECT_TRUE(ac.getOffTimerEnabled()); + EXPECT_EQ(23 * 60 + 59, ac.getOffTimer()); +}