Skip to content

Commit

Permalink
DelonghiAc: Add OffTimer support.
Browse files Browse the repository at this point in the history
Fixes #1096
  • Loading branch information
crankyoldgit committed May 3, 2020
1 parent b0aab18 commit 1a3631d
Show file tree
Hide file tree
Showing 4 changed files with 108 additions and 28 deletions.
48 changes: 41 additions & 7 deletions src/ir_Delonghi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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) {
Expand All @@ -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;
Expand Down Expand Up @@ -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;
}
24 changes: 18 additions & 6 deletions src/ir_Delonghi.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;


Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion test/IRac_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
62 changes: 48 additions & 14 deletions test/ir_Delonghi_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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());
}

0 comments on commit 1a3631d

Please sign in to comment.