Skip to content

Commit

Permalink
DelonghiAc: Add On Timer support.
Browse files Browse the repository at this point in the history
For #1096
  • Loading branch information
crankyoldgit committed May 2, 2020
1 parent c37795a commit 1b3d6b7
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 4 deletions.
34 changes: 34 additions & 0 deletions src/ir_Delonghi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,9 @@
using irutils::addBoolToString;
using irutils::addModeToString;
using irutils::addFanToString;
using irutils::addLabeledString;
using irutils::addTempToString;
using irutils::minsToString;
using irutils::setBit;
using irutils::setBits;

Expand Down Expand Up @@ -310,6 +312,35 @@ bool IRDelonghiAc::getSleep(void) {
return GETBIT64(remote_state, kDelonghiAcSleepBit);
}

void IRDelonghiAc::setTimerEnabled(const bool on) {
setBit(&remote_state, kDelonghiAcTimerEnableBit, on);
}

bool IRDelonghiAc::getTimerEnabled(void) {
return GETBIT64(remote_state, kDelonghiAcTimerEnableBit);
}

// Set the On 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::setOnTimer(const uint16_t nr_of_mins) {
uint16_t value = std::min(kDelonghiAcTimerMax, nr_of_mins);
setBits(&remote_state, kDelonghiAcOnTimerMinsOffset, kDelonghiAcMinsSize,
value % 60); // Minutes.
setBits(&remote_state, kDelonghiAcOnTimerHoursOffset, kDelonghiAcHoursSize,
value / 60); // Hours.
// Enable or not?
setTimerEnabled(getTimerEnabled() || value);
}

uint16_t IRDelonghiAc::getOnTimer(void) {
return GETBITS64(remote_state, kDelonghiAcOnTimerHoursOffset,
kDelonghiAcHoursSize) * 60 +
GETBITS64(remote_state, kDelonghiAcOnTimerMinsOffset,
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 @@ -348,5 +379,8 @@ 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);
return result;
}
18 changes: 16 additions & 2 deletions src/ir_Delonghi.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,18 @@ const uint8_t kDelonghiAcDry = 0b001;
const uint8_t kDelonghiAcFan = 0b010;
const uint8_t kDelonghiAcAuto = 0b100;
const uint8_t kDelonghiAcBoostBit = kDelonghiAcModeOffset +
kDelonghiAcModeSize; // 17 (Aka Turbo)
const uint8_t kDelonghiAcSleepBit = kDelonghiAcBoostBit + 1; // 18
kDelonghiAcModeSize; // 20 (Aka Turbo)
const uint8_t kDelonghiAcSleepBit = kDelonghiAcBoostBit + 1; // 21
// Two zero bits
const uint8_t kDelonghiAcTimerEnableBit = 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 +
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;
const uint8_t kDelonghiAcChecksumSize = 8;

Expand Down Expand Up @@ -112,6 +122,10 @@ class IRDelonghiAc {
bool getBoost(); // Aka Turbo
void setSleep(const bool on);
bool getSleep();
void setTimerEnabled(const bool on);
bool getTimerEnabled(void);
void setOnTimer(const uint16_t nr_of_mins);
uint16_t getOnTimer(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";
"Turbo: On, Sleep: On, Timer: Off, On Timer: Off";

ac.begin();
irac.delonghiac(&ac,
Expand Down
36 changes: 35 additions & 1 deletion 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",
"Turbo: Off, Sleep: Off, Timer: On, On Timer: 06:13",
IRAcUtils::resultAcToString(&irsend.capture));
stdAc::state_t r, p;
ASSERT_TRUE(IRAcUtils::decodeToState(&irsend.capture, &r, &p));
Expand Down Expand Up @@ -264,3 +264,37 @@ TEST(TestIRDelonghiAcClass, Sleep) {
ac.setSleep(false);
EXPECT_FALSE(ac.getSleep());
}

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.setOnTimer(0);
EXPECT_FALSE(ac.getTimerEnabled());
EXPECT_EQ(0, ac.getOnTimer());

ac.setOnTimer(1);
EXPECT_TRUE(ac.getTimerEnabled());
EXPECT_EQ(1, ac.getOnTimer());

ac.setOnTimer(61);
EXPECT_TRUE(ac.getTimerEnabled());
EXPECT_EQ(61, ac.getOnTimer());

ac.setTimerEnabled(false);
ac.setOnTimer(23 * 60 + 59);
EXPECT_TRUE(ac.getTimerEnabled());
EXPECT_EQ(23 * 60 + 59, ac.getOnTimer());

ac.setTimerEnabled(false);
ac.setOnTimer(24 * 60);
EXPECT_TRUE(ac.getTimerEnabled());
EXPECT_EQ(23 * 60 + 59, ac.getOnTimer());
}

0 comments on commit 1b3d6b7

Please sign in to comment.