Skip to content

Commit

Permalink
SamsungAc: Add support for Econo (Eco) setting.
Browse files Browse the repository at this point in the history
* Add `setEcono()` & `getEcono()`
* Add to `IRac` as well.
* Improve Unit tests.

For #1277
  • Loading branch information
crankyoldgit committed Nov 10, 2021
1 parent 5a5956a commit 25d9636
Show file tree
Hide file tree
Showing 6 changed files with 152 additions and 65 deletions.
13 changes: 8 additions & 5 deletions src/IRac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1844,6 +1844,7 @@ void IRac::panasonic32(IRPanasonicAc32 *ac,
/// @param[in] swingh The horizontal swing setting.
/// @param[in] quiet Run the device in quiet/silent mode.
/// @param[in] turbo Run the device in turbo/powerful mode.
/// @param[in] econo Run the device in economical mode.
/// @param[in] light Turn on the LED/Display mode.
/// @param[in] filter Turn on the (ion/pollen/etc) filter mode.
/// @param[in] clean Turn on the self-cleaning mode. e.g. Mould, dry filters etc
Expand All @@ -1857,7 +1858,8 @@ void IRac::samsung(IRSamsungAc *ac,
const float degrees,
const stdAc::fanspeed_t fan,
const stdAc::swingv_t swingv, const stdAc::swingh_t swingh,
const bool quiet, const bool turbo, const bool light,
const bool quiet, const bool turbo, const bool econo,
const bool light,
const bool filter, const bool clean,
const bool beep, const int16_t sleep,
const bool prevpower, const int16_t prevsleep,
Expand All @@ -1871,9 +1873,9 @@ void IRac::samsung(IRSamsungAc *ac,
ac->setSwing(swingv != stdAc::swingv_t::kOff);
ac->setSwingH(swingh != stdAc::swingh_t::kOff);
ac->setQuiet(quiet);
ac->setPowerful(turbo);
ac->setPowerful(turbo); // FYI, `setEcono(true)` will override this.
ac->setDisplay(light);
// No Econo setting available.
ac->setEcono(econo);
ac->setIon(filter);
ac->setClean(clean);
ac->setBeep(beep);
Expand Down Expand Up @@ -3005,8 +3007,9 @@ bool IRac::sendAc(const stdAc::state_t desired, const stdAc::state_t *prev) {
{
IRSamsungAc ac(_pin, _inverted, _modulation);
samsung(&ac, send.power, send.mode, degC, send.fanspeed, send.swingv,
send.swingh, send.quiet, send.turbo, send.light, send.filter,
send.clean, send.beep, send.sleep, prev_power, prev_sleep);
send.swingh, send.quiet, send.turbo, send.econo, send.light,
send.filter, send.clean, send.beep, send.sleep,
prev_power, prev_sleep);
break;
}
#endif // SEND_SAMSUNG_AC
Expand Down
4 changes: 2 additions & 2 deletions src/IRac.h
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,8 @@ void electra(IRElectraAc *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 bool quiet, const bool turbo, const bool light,
const bool filter, const bool clean,
const bool quiet, const bool turbo, const bool econo,
const bool light, const bool filter, const bool clean,
const bool beep, const int16_t sleep = -1,
const bool prevpower = true, const int16_t prevsleep = -1,
const bool forceextended = true);
Expand Down
35 changes: 29 additions & 6 deletions src/ir_Samsung.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@ const uint8_t kSamsungAcSwingOff = 0b111;
const uint8_t kSamsungAcFanSpecialOff = 0b000;
const uint8_t kSamsungAcPowerfulOn = 0b011;
const uint8_t kSamsungAcBreezeOn = 0b101;
const uint8_t kSamsungAcEconoOn = 0b111;

using irutils::addBoolToString;
using irutils::addFanToString;
Expand Down Expand Up @@ -639,8 +640,8 @@ bool IRSamsungAc::getPowerful(void) const {
/// Set the Powerful (Turbo) setting of the A/C.
/// @param[in] on true, the setting is on. false, the setting is off.
void IRSamsungAc::setPowerful(const bool on) {
uint8_t off_value = getBreeze() ? kSamsungAcBreezeOn
: kSamsungAcFanSpecialOff;
uint8_t off_value = (getBreeze() || getEcono()) ? _.FanSpecial
: kSamsungAcFanSpecialOff;
_.FanSpecial = (on ? kSamsungAcPowerfulOn : off_value);
if (on) {
// Powerful mode sets fan speed to Turbo.
Expand All @@ -664,15 +665,36 @@ bool IRSamsungAc::getBreeze(void) const {
/// @param[in] on true, the setting is on. false, the setting is off.
/// @see https://github.com/crankyoldgit/IRremoteESP8266/issues/1062
void IRSamsungAc::setBreeze(const bool on) {
const uint8_t off_value = getPowerful() ? kSamsungAcPowerfulOn
: kSamsungAcFanSpecialOff;
const uint8_t off_value = (getPowerful() ||
getEcono()) ? _.FanSpecial
: kSamsungAcFanSpecialOff;
_.FanSpecial = (on ? kSamsungAcBreezeOn : off_value);
if (on) {
setFan(kSamsungAcFanAuto);
setSwing(false);
}
}

/// Get the current Economy (Eco) setting of the A/C.
/// @return true, the setting is on. false, the setting is off.
bool IRSamsungAc::getEcono(void) const {
return (_.FanSpecial == kSamsungAcEconoOn) &&
(_.Fan == kSamsungAcFanAuto && getSwing());
}

/// Set the current Economy (Eco) setting of the A/C.
/// @param[in] on true, the setting is on. false, the setting is off.
void IRSamsungAc::setEcono(const bool on) {
const uint8_t off_value = (getBreeze() ||
getPowerful()) ? _.FanSpecial
: kSamsungAcFanSpecialOff;
_.FanSpecial = (on ? kSamsungAcEconoOn : off_value);
if (on) {
setFan(kSamsungAcFanAuto);
setSwing(true);
}
}

/// Get the Display (Light/LED) setting of the A/C.
/// @return true, the setting is on. false, the setting is off.
bool IRSamsungAc::getDisplay(void) const { return _.Display; }
Expand Down Expand Up @@ -858,13 +880,13 @@ stdAc::state_t IRSamsungAc::toCommon(void) const {
result.swingh = getSwingH() ? stdAc::swingh_t::kAuto : stdAc::swingh_t::kOff;
result.quiet = getQuiet();
result.turbo = getPowerful();
result.econo = getEcono();
result.clean = getClean();
result.beep = _.Beep;
result.light = _.Display;
result.filter = _.Ion;
result.sleep = _Sleep ? getSleepTimer() : -1;
// Not supported.
result.econo = false;
result.clock = -1;
return result;
}
Expand All @@ -873,7 +895,7 @@ stdAc::state_t IRSamsungAc::toCommon(void) const {
/// @return A human readable string.
String IRSamsungAc::toString(void) const {
String result = "";
result.reserve(220); // Reserve some heap for the string to reduce fragging.
result.reserve(230); // Reserve some heap for the string to reduce fragging.
result += addBoolToString(getPower(), kPowerStr, false);
result += addModeToString(_.Mode, kSamsungAcAuto, kSamsungAcCool,
kSamsungAcHeat, kSamsungAcDry,
Expand Down Expand Up @@ -909,6 +931,7 @@ String IRSamsungAc::toString(void) const {
result += addBoolToString(getClean(), kCleanStr);
result += addBoolToString(getQuiet(), kQuietStr);
result += addBoolToString(getPowerful(), kPowerfulStr);
result += addBoolToString(getEcono(), kEconoStr);
result += addBoolToString(getBreeze(), kBreezeStr);
result += addBoolToString(_.Display, kLightStr);
result += addBoolToString(_.Ion, kIonStr);
Expand Down
4 changes: 3 additions & 1 deletion src/ir_Samsung.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ union SamsungProtocol{
uint8_t :1;
// Byte 10
uint8_t :1;
uint8_t FanSpecial :3; // Powerful, Breeze/WindFree
uint8_t FanSpecial :3; // Powerful, Breeze/WindFree, Econo
uint8_t Display :1;
uint8_t :2;
uint8_t Clean10 :1;
Expand Down Expand Up @@ -222,6 +222,8 @@ class IRSamsungAc {
bool getPowerful(void) const;
void setBreeze(const bool on);
bool getBreeze(void) const;
void setEcono(const bool on);
bool getEcono(void) const;
void setDisplay(const bool on);
bool getDisplay(void) const;
void setIon(const bool on);
Expand Down
7 changes: 5 additions & 2 deletions test/IRac_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1625,7 +1625,7 @@ TEST(TestIRac, Samsung) {
const char expected[] =
"Power: On, Mode: 0 (Auto), Temp: 28C, Fan: 6 (Auto), "
"Swing(V): On, Swing(H): On, "
"Beep: On, Clean: On, Quiet: On, Powerful: Off, Breeze: Off, "
"Beep: On, Clean: On, Quiet: On, Powerful: Off, Econo: Off, Breeze: Off, "
"Light: On, Ion: Off";

ac.begin();
Expand All @@ -1638,6 +1638,7 @@ TEST(TestIRac, Samsung) {
stdAc::swingh_t::kAuto, // Horizontal swing
true, // Quiet
false, // Turbo
false, // Econo
true, // Light (Display)
false, // Filter (Ion)
true, // Clean
Expand Down Expand Up @@ -1665,6 +1666,7 @@ TEST(TestIRac, Samsung) {
stdAc::swingh_t::kAuto, // Horizontal swing
true, // Quiet
false, // Turbo
false, // Econo
true, // Light (Display)
false, // Filter (Ion)
true, // Clean
Expand All @@ -1686,7 +1688,7 @@ TEST(TestIRac, Samsung) {
const char sleep[] =
"Power: On, Mode: 0 (Auto), Temp: 28C, Fan: 6 (Auto), "
"Swing(V): On, Swing(H): Off, "
"Beep: On, Clean: On, Quiet: On, Powerful: Off, Breeze: Off, "
"Beep: On, Clean: On, Quiet: On, Powerful: Off, Econo: Off, Breeze: Off, "
"Light: On, Ion: Off, Sleep Timer: 08:00";
irac.samsung(&ac,
true, // Power
Expand All @@ -1697,6 +1699,7 @@ TEST(TestIRac, Samsung) {
stdAc::swingh_t::kOff, // Horizontal swing
true, // Quiet
false, // Turbo
false, // Econo
true, // Light (Display)
false, // Filter (Ion)
true, // Clean
Expand Down
Loading

0 comments on commit 25d9636

Please sign in to comment.