Skip to content

Commit

Permalink
Another attempt at fixing swingv
Browse files Browse the repository at this point in the history
For #1134
  • Loading branch information
crankyoldgit committed May 30, 2020
1 parent 01f3b22 commit d4007b8
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 9 deletions.
16 changes: 11 additions & 5 deletions src/IRac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -786,11 +786,13 @@ void IRac::hitachi344(IRHitachiAc344 *ac,
const bool on, const stdAc::opmode_t mode,
const float degrees, const stdAc::fanspeed_t fan,
const stdAc::swingv_t swingv,
const stdAc::swingv_t prev_swingv,
const stdAc::swingh_t swingh) {
ac->begin();
ac->setMode(ac->convertMode(mode));
ac->setTemp(degrees);
ac->setFan(ac->convertFan(fan));
ac->setSwingV(swingv != stdAc::swingv_t::kOff);
ac->setSwingH(ac->convertSwingH(swingh));
ac->setPower(on);
// No Quiet setting available.
Expand All @@ -802,9 +804,13 @@ void IRac::hitachi344(IRHitachiAc344 *ac,
// No Sleep setting available.
// No Clock setting available.

// Do Swing(V) last as it appears that it's the only way to make it respond
// to the SwingV command. i.e. It reliese on the `setButton()` value.
ac->setSwingV(swingv != stdAc::swingv_t::kOff);
// Needs to be done last.
// Toggle when swingv & prev_swingv are changing.
// i.e from "any on" to off, or from off to "any on".
ac->setSwingVToggle((swingv != stdAc::swingv_t::kOff &&
prev_swingv == stdAc::swingv_t::kOff) ||
(swingv == stdAc::swingv_t::kOff &&
prev_swingv != stdAc::swingv_t::kOff));
ac->send();
}
#endif // SEND_HITACHI_AC344
Expand Down Expand Up @@ -1656,8 +1662,8 @@ bool IRac::sendAc(const stdAc::state_t desired, const stdAc::state_t *prev) {
case HITACHI_AC344:
{
IRHitachiAc344 ac(_pin, _inverted, _modulation);
hitachi344(&ac, send.power, send.mode, degC, send.fanspeed, send.swingv,
send.swingh);
hitachi344(&ac, send.power, send.mode, degC, send.fanspeed,
send.swingv, prev->swingv, send.swingh);
break;
}
#endif // SEND_HITACHI_AC344
Expand Down
4 changes: 3 additions & 1 deletion src/IRac.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,9 @@ void electra(IRElectraAc *ac,
void hitachi344(IRHitachiAc344 *ac,
const bool on, const stdAc::opmode_t mode,
const float degrees, const stdAc::fanspeed_t fan,
const stdAc::swingv_t swingv, const stdAc::swingh_t swingh);
const stdAc::swingv_t swingv,
const stdAc::swingv_t prev_swingv,
const stdAc::swingh_t swingh);
#endif // SEND_HITACHI_AC344
#if SEND_HITACHI_AC424
void hitachi424(IRHitachiAc424 *ac,
Expand Down
28 changes: 25 additions & 3 deletions test/IRac_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -730,7 +730,7 @@ TEST(TestIRac, Hitachi344) {
IRHitachiAc344 ac(kGpioUnused);
IRac irac(kGpioUnused);
IRrecv capture(kGpioUnused);
char expected[] =
char expected_swingon[] =
"Power: On, Mode: 6 (Heat), Temp: 25C, Fan: 6 (Max), "
"Button: 129 (Swing(V)), Swing(V): On, Swing(H): 2 (Right)";

Expand All @@ -741,20 +741,42 @@ TEST(TestIRac, Hitachi344) {
25, // Celsius
stdAc::fanspeed_t::kMax, // Fan speed
stdAc::swingv_t::kAuto, // Swing(V)
stdAc::swingv_t::kOff, // Previous Swing(V)
stdAc::swingh_t::kRight); // Swing(H)

ASSERT_EQ(expected, ac.toString());
ASSERT_EQ(expected_swingon, ac.toString());
ac._irsend.makeDecodeResult();
EXPECT_TRUE(capture.decode(&ac._irsend.capture));
ASSERT_EQ(HITACHI_AC344, ac._irsend.capture.decode_type);
ASSERT_EQ(kHitachiAc344Bits, ac._irsend.capture.bits);
ASSERT_EQ(expected, IRAcUtils::resultAcToString(&ac._irsend.capture));
ASSERT_EQ(expected_swingon, IRAcUtils::resultAcToString(&ac._irsend.capture));
stdAc::state_t r, p;
ASSERT_TRUE(IRAcUtils::decodeToState(&ac._irsend.capture, &r, &p));
EXPECT_EQ(decode_type_t::HITACHI_AC344, r.protocol);
EXPECT_TRUE(r.power);
EXPECT_EQ(stdAc::opmode_t::kHeat, r.mode);
EXPECT_EQ(25, r.degrees);

char expected_swingoff[] =
"Power: On, Mode: 6 (Heat), Temp: 25C, Fan: 6 (Max), "
"Button: 129 (Swing(V)), Swing(V): Off, Swing(H): 2 (Right)";

ac._irsend.reset();
irac.hitachi344(&ac,
true, // Power
stdAc::opmode_t::kHeat, // Mode
25, // Celsius
stdAc::fanspeed_t::kMax, // Fan speed
stdAc::swingv_t::kOff, // Swing(V)
stdAc::swingv_t::kAuto, // Previous Swing(V)
stdAc::swingh_t::kRight); // Swing(H)
ASSERT_EQ(expected_swingoff, ac.toString());
ac._irsend.makeDecodeResult();
EXPECT_TRUE(capture.decode(&ac._irsend.capture));
ASSERT_EQ(HITACHI_AC344, ac._irsend.capture.decode_type);
ASSERT_EQ(kHitachiAc344Bits, ac._irsend.capture.bits);
ASSERT_EQ(expected_swingoff,
IRAcUtils::resultAcToString(&ac._irsend.capture));
}

TEST(TestIRac, Hitachi424) {
Expand Down

0 comments on commit d4007b8

Please sign in to comment.