Skip to content

Commit

Permalink
Add HITACHI_AC1 to Common A/C api.
Browse files Browse the repository at this point in the history
* Add IRac::hitachi1
* Adjust `sendAc()`
* Adjust `resultAcToString()`
* Add/update unit tests.

Fixes #1056
Fixes #1061
  • Loading branch information
crankyoldgit committed Apr 2, 2020
1 parent db4454b commit b44de67
Show file tree
Hide file tree
Showing 4 changed files with 75 additions and 1 deletion.
43 changes: 43 additions & 0 deletions src/IRac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ bool IRac::isProtocolSupported(const decode_type_t protocol) {
#if SEND_HITACHI_AC
case decode_type_t::HITACHI_AC:
#endif
#if SEND_HITACHI_AC1
case decode_type_t::HITACHI_AC1:
#endif
#if SEND_HITACHI_AC424
case decode_type_t::HITACHI_AC424:
#endif
Expand Down Expand Up @@ -674,6 +677,30 @@ void IRac::hitachi(IRHitachiAc *ac,
}
#endif // SEND_HITACHI_AC

#if SEND_HITACHI_AC1
void IRac::hitachi1(IRHitachiAc1 *ac,
const bool on, const stdAc::opmode_t mode,
const float degrees, const stdAc::fanspeed_t fan,
const stdAc::swingv_t swingv) {
ac->begin();
ac->setPower(on);
ac->setMode(ac->convertMode(mode));
ac->setTemp(degrees);
ac->setFan(ac->convertFan(fan));
ac->setSwing(swingv != stdAc::swingv_t::kOff);
// No Swing(H) setting available.
// No Quiet setting available.
// No Turbo setting available.
// No Light setting available.
// No Filter setting available.
// No Clean setting available.
// No Beep setting available.
// No Sleep setting available.
// No Clock setting available.
ac->send();
}
#endif // SEND_HITACHI_AC1

#if SEND_HITACHI_AC424
void IRac::hitachi424(IRHitachiAc424 *ac,
const bool on, const stdAc::opmode_t mode,
Expand Down Expand Up @@ -1457,6 +1484,14 @@ bool IRac::sendAc(const stdAc::state_t desired, const stdAc::state_t *prev) {
break;
}
#endif // SEND_HITACHI_AC
#if SEND_HITACHI_AC1
case HITACHI_AC1:
{
IRHitachiAc1 ac(_pin, _inverted, _modulation);
hitachi1(&ac, send.power, send.mode, degC, send.fanspeed, send.swingv);
break;
}
#endif // SEND_HITACHI_AC1
#if SEND_HITACHI_AC424
case HITACHI_AC424:
{
Expand Down Expand Up @@ -2368,6 +2403,14 @@ namespace IRAcUtils {
break;
}
#endif // (DECODE_HITACHI_AC || DECODE_HITACHI_AC2)
#if DECODE_HITACHI_AC1
case decode_type_t::HITACHI_AC1: {
IRHitachiAc1 ac(kGpioUnused);
ac.setRaw(decode->state);
*result = ac.toCommon();
break;
}
#endif // DECODE_HITACHI_AC1
#if DECODE_HITACHI_AC424
case decode_type_t::HITACHI_AC424: {
IRHitachiAc424 ac(kGpioUnused);
Expand Down
6 changes: 6 additions & 0 deletions src/IRac.h
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,12 @@ void electra(IRElectraAc *ac,
const float degrees, const stdAc::fanspeed_t fan,
const stdAc::swingv_t swingv, const stdAc::swingh_t swingh);
#endif // SEND_HITACHI_AC
#if SEND_HITACHI_AC1
void hitachi1(IRHitachiAc1 *ac,
const bool on, const stdAc::opmode_t mode,
const float degrees, const stdAc::fanspeed_t fan,
const stdAc::swingv_t swingv);
#endif // SEND_HITACHI_AC1
#if SEND_HITACHI_AC424
void hitachi424(IRHitachiAc424 *ac,
const bool on, const stdAc::opmode_t mode,
Expand Down
25 changes: 25 additions & 0 deletions test/IRac_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -571,6 +571,31 @@ TEST(TestIRac, Hitachi) {
ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture));
}

TEST(TestIRac, Hitachi1) {
IRHitachiAc1 ac(kGpioUnused);
IRac irac(kGpioUnused);
IRrecv capture(kGpioUnused);
char expected[] =
"Power: On, Mode: 15 (Auto), Temp: 19C, Fan: 4 (Medium), Swing: Off";

ac.begin();
irac.hitachi1(&ac,
true, // Power
stdAc::opmode_t::kAuto, // Mode
19, // Celsius
stdAc::fanspeed_t::kMedium, // Fan speed
stdAc::swingv_t::kOff); // Veritcal swing

ASSERT_EQ(expected, ac.toString());
ac._irsend.makeDecodeResult();
EXPECT_TRUE(capture.decode(&ac._irsend.capture));
ASSERT_EQ(HITACHI_AC1, ac._irsend.capture.decode_type);
ASSERT_EQ(kHitachiAc1Bits, 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));
}

TEST(TestIRac, Hitachi424) {
IRHitachiAc424 ac(0);
IRac irac(0);
Expand Down
2 changes: 1 addition & 1 deletion test/ir_Hitachi_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -809,7 +809,7 @@ TEST(TestUtils, Housekeeping) {
ASSERT_EQ("HITACHI_AC1", typeToString(decode_type_t::HITACHI_AC1));
ASSERT_EQ(decode_type_t::HITACHI_AC1, strToDecodeType("HITACHI_AC1"));
ASSERT_TRUE(hasACState(decode_type_t::HITACHI_AC1));
ASSERT_FALSE(IRac::isProtocolSupported(decode_type_t::HITACHI_AC1));
ASSERT_TRUE(IRac::isProtocolSupported(decode_type_t::HITACHI_AC1));

ASSERT_EQ("HITACHI_AC2", typeToString(decode_type_t::HITACHI_AC2));
ASSERT_EQ(decode_type_t::HITACHI_AC2, strToDecodeType("HITACHI_AC2"));
Expand Down

0 comments on commit b44de67

Please sign in to comment.