Skip to content

Commit

Permalink
Handle power control slightly better.
Browse files Browse the repository at this point in the history
* Reduce redundant code in `setPower()`
* Update Unit Tests to correctly recreate Known Good states.
* Handle previous power in Common A/C API for SharpAc.

TODO: Still have to work out `state[10]`/`ByteManual`, as with code as 
currently is, we can't recreate some known good messages. i.e. a Unit 
test is failing.
  • Loading branch information
crankyoldgit committed Apr 4, 2020
1 parent e37224c commit ddd28b9
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 8 deletions.
9 changes: 6 additions & 3 deletions src/IRac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1023,10 +1023,11 @@ void IRac::samsung(IRSamsungAc *ac,

#if SEND_SHARP_AC
void IRac::sharp(IRSharpAc *ac,
const bool on, const stdAc::opmode_t mode,
const bool on, const bool prev_power,
const stdAc::opmode_t mode,
const float degrees, const stdAc::fanspeed_t fan) {
ac->begin();
ac->setPower(on);
ac->setPower(on, prev_power);
ac->setMode(ac->convertMode(mode));
ac->setTemp(degrees);
ac->setFan(ac->convertFan(fan));
Expand Down Expand Up @@ -1606,7 +1607,9 @@ bool IRac::sendAc(const stdAc::state_t desired, const stdAc::state_t *prev) {
case SHARP_AC:
{
IRSharpAc ac(_pin, _inverted, _modulation);
sharp(&ac, send.power, send.mode, degC, send.fanspeed);
bool prev_power = !send.power;
if (prev != NULL) prev_power = prev->power;
sharp(&ac, send.power, prev_power, send.mode, degC, send.fanspeed);
break;
}
#endif // SEND_SHARP_AC
Expand Down
2 changes: 1 addition & 1 deletion src/IRac.h
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,7 @@ void electra(IRElectraAc *ac,
#endif // SEND_SAMSUNG_AC
#if SEND_SHARP_AC
void sharp(IRSharpAc *ac,
const bool on, const stdAc::opmode_t mode,
const bool on, const bool prev_power, const stdAc::opmode_t mode,
const float degrees, const stdAc::fanspeed_t fan);
#endif // SEND_SHARP_AC
#if SEND_TCL112AC
Expand Down
5 changes: 3 additions & 2 deletions src/ir_Sharp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -340,12 +340,13 @@ void IRSharpAc::on(void) { setPower(true); }
void IRSharpAc::off(void) { setPower(false); }

void IRSharpAc::setPower(const bool on) {
setBit(&remote[kSharpAcBytePower], kSharpAcBitPreviousPowerOffset,
getPower() != on);
setBit(&remote[kSharpAcBytePower], kSharpAcBitPowerOffset, on);
setBit(&remote[kSharpAcBytePower], kSharpAcBitPreviousPowerOffset, !on);
}

void IRSharpAc::setPower(const bool on, const bool prev) {
setBit(&remote[kSharpAcBytePower], kSharpAcBitPowerOffset, on);
setPower(on);
setBit(&remote[kSharpAcBytePower], kSharpAcBitPreviousPowerOffset, prev);
}

Expand Down
1 change: 1 addition & 0 deletions test/IRac_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1044,6 +1044,7 @@ TEST(TestIRac, Sharp) {
ac.begin();
irac.sharp(&ac,
true, // Power
true, // Previous Power
stdAc::opmode_t::kCool, // Mode
28, // Celsius
stdAc::fanspeed_t::kMedium); // Fan speed
Expand Down
4 changes: 2 additions & 2 deletions test/ir_Sharp_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -587,7 +587,7 @@ TEST(TestSharpAcClass, ReconstructKnownState) {
uint8_t on_auto_auto[kSharpAcStateLength] = {
0xAA, 0x5A, 0xCF, 0x10, 0x00, 0x11, 0x20, 0x00, 0x08, 0x80, 0x00, 0xE0,
0x01};
ac.on();
ac.setPower(true, false);
ac.setMode(kSharpAcAuto);
ac.setTemp(kSharpAcMinTemp);
ac.setFan(kSharpAcFanAuto);
Expand All @@ -599,7 +599,7 @@ TEST(TestSharpAcClass, ReconstructKnownState) {
0xAA, 0x5A, 0xCF, 0x10, 0xCD, 0x31, 0x22, 0x00, 0x08, 0x80, 0x04, 0xE0,
0x51};
ac.stateReset();
ac.on();
ac.setPower(true, true);
ac.setMode(kSharpAcCool);
ac.setTemp(28);
ac.setFan(kSharpAcFanAuto);
Expand Down

1 comment on commit ddd28b9

@juliussin
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how to pull this request to my branch?

Please sign in to comment.