Skip to content

Commit

Permalink
Gree: Use less strict power mode detection.
Browse files Browse the repository at this point in the history
Reported data in #814 indicates state[0] is the only thing that changes 
for power on/off.

Leave the existing bit setting/clearing for setPower() etc, but don't 
require the state[2] bit for getPower().

Fixes #814
  • Loading branch information
crankyoldgit committed Jul 22, 2019
1 parent 0675afc commit 63d6059
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 5 deletions.
8 changes: 4 additions & 4 deletions src/ir_Gree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -174,12 +174,12 @@ bool IRGreeAC::validChecksum(const uint8_t state[], const uint16_t length) {

void IRGreeAC::on(void) {
remote_state[0] |= kGreePower1Mask;
remote_state[2] |= kGreePower2Mask;
remote_state[2] |= kGreePower2Mask; // May not be needed. See #814
}

void IRGreeAC::off(void) {
remote_state[0] &= ~kGreePower1Mask;
remote_state[2] &= ~kGreePower2Mask;
remote_state[2] &= ~kGreePower2Mask; // May not be needed. See #814
}

void IRGreeAC::setPower(const bool on) {
Expand All @@ -190,8 +190,8 @@ void IRGreeAC::setPower(const bool on) {
}

bool IRGreeAC::getPower(void) {
return (remote_state[0] & kGreePower1Mask) &&
(remote_state[2] & kGreePower2Mask);
// See #814. Not checking/requiring: (remote_state[2] & kGreePower2Mask)
return remote_state[0] & kGreePower1Mask;
}

// Set the temp. in deg C
Expand Down
3 changes: 2 additions & 1 deletion src/ir_Gree.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
// Brand: EKOKAI, Model: A/C
// Brand: RusClimate, Model: EACS/I-09HAR_X/N3 A/C
// Brand: RusClimate, Model: YAW1F remote
// Brand: Green, Model: YBOFB2 remote

#ifndef IR_GREE_H_
#define IR_GREE_H_
Expand Down Expand Up @@ -37,7 +38,7 @@ const uint8_t kGreeSleepMask = 0b10000000;
// Byte 2
const uint8_t kGreeTurboMask = 0b00010000;
const uint8_t kGreeLightMask = 0b00100000;
const uint8_t kGreePower2Mask = 0b01000000;
const uint8_t kGreePower2Mask = 0b01000000; // This might not be used. See #814
const uint8_t kGreeXfanMask = 0b10000000;
// Byte 4
const uint8_t kGreeSwingPosMask = 0b00001111;
Expand Down
15 changes: 15 additions & 0 deletions test/ir_Gree_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -609,3 +609,18 @@ TEST(TestGreeClass, toCommon) {
ASSERT_FALSE(ac.toCommon().beep);
ASSERT_EQ(-1, ac.toCommon().clock);
}

TEST(TestGreeClass, Issue814Power) {
IRGreeAC ac(0);
ac.begin();

// https://github.com/crankyoldgit/IRremoteESP8266/issues/814#issuecomment-511263921
uint8_t on[8] = {0x59, 0x07, 0x20, 0x50, 0x01, 0x20, 0x00, 0xC0};
uint8_t off[8] = {0x51, 0x07, 0x20, 0x50, 0x01, 0x20, 0x00, 0x40};

ac.on();
ac.setRaw(off);
EXPECT_FALSE(ac.getPower());
ac.setRaw(on);
EXPECT_TRUE(ac.getPower());
}

0 comments on commit 63d6059

Please sign in to comment.