Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Gree] Add SwingH & Econo control. #1653

Merged
merged 2 commits into from
Nov 10, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/IRac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1039,15 +1039,18 @@ void IRac::goodweather(IRGoodweatherAc *ac,
/// @param[in] degrees The temperature setting in degrees.
/// @param[in] fan The speed setting for the fan.
/// @param[in] swingv The vertical swing setting.
/// @param[in] swingh The horizontal swing setting.
/// @param[in] turbo Run the device in turbo/powerful mode.
/// @param[in] econo Toggle the device's economical mode.
/// @param[in] light Turn on the LED/Display mode.
/// @param[in] clean Turn on the self-cleaning mode. e.g. Mould, dry filters etc
/// @param[in] sleep Nr. of minutes for sleep mode. -1 is Off, >= 0 is on.
void IRac::gree(IRGreeAC *ac, const gree_ac_remote_model_t model,
const bool on, const stdAc::opmode_t mode, const bool celsius,
const float degrees, const stdAc::fanspeed_t fan,
const stdAc::swingv_t swingv, const bool turbo,
const bool light, const bool clean, const int16_t sleep) {
const stdAc::swingv_t swingv, const stdAc::swingh_t swingh,
const bool turbo, const bool econo, const bool light,
const bool clean, const int16_t sleep) {
ac->begin();
ac->setModel(model);
ac->setPower(on);
Expand All @@ -1056,11 +1059,12 @@ void IRac::gree(IRGreeAC *ac, const gree_ac_remote_model_t model,
ac->setFan(ac->convertFan(fan));
ac->setSwingVertical(swingv == stdAc::swingv_t::kAuto, // Set auto flag.
ac->convertSwingV(swingv));
ac->setSwingHorizontal(ac->convertSwingH(swingh));
ac->setLight(light);
ac->setTurbo(turbo);
ac->setEcono(econo);
ac->setXFan(clean);
ac->setSleep(sleep >= 0); // Sleep on this A/C is either on or off.
// No Horizontal Swing setting available.
// No Econo setting available.
// No Filter setting available.
// No Beep setting available.
Expand Down Expand Up @@ -2779,8 +2783,8 @@ bool IRac::sendAc(const stdAc::state_t desired, const stdAc::state_t *prev) {
IRGreeAC ac(_pin, (gree_ac_remote_model_t)send.model, _inverted,
_modulation);
gree(&ac, (gree_ac_remote_model_t)send.model, send.power, send.mode,
send.celsius, send.degrees, send.fanspeed, send.swingv, send.turbo,
send.light, send.clean, send.sleep);
send.celsius, send.degrees, send.fanspeed, send.swingv, send.swingh,
send.turbo, send.econo, send.light, send.clean, send.sleep);
break;
}
#endif // SEND_GREE
Expand Down
3 changes: 2 additions & 1 deletion src/IRac.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,8 @@ void electra(IRElectraAc *ac,
void gree(IRGreeAC *ac, const gree_ac_remote_model_t model,
const bool on, const stdAc::opmode_t mode, const bool celsius,
const float degrees, const stdAc::fanspeed_t fan,
const stdAc::swingv_t swingv, const bool turbo, const bool light,
const stdAc::swingv_t swingv, const stdAc::swingh_t swingh,
const bool turbo, const bool econo, const bool light,
const bool clean, const int16_t sleep = -1);
#endif // SEND_GREE
#if SEND_HAIER_AC
Expand Down
175 changes: 96 additions & 79 deletions src/ir_Gree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ using irutils::addLabeledString;
using irutils::addModeToString;
using irutils::addModelToString;
using irutils::addFanToString;
using irutils::addSwingHToString;
using irutils::addTempToString;
using irutils::minsToString;

Expand Down Expand Up @@ -220,15 +221,11 @@ bool IRGreeAC::getPower(void) const {
/// Set the default temperature units to use.
/// @param[in] on Use Fahrenheit as the units.
/// true is Fahrenheit, false is Celsius.
void IRGreeAC::setUseFahrenheit(const bool on) {
_.UseFahrenheit = on;
}
void IRGreeAC::setUseFahrenheit(const bool on) { _.UseFahrenheit = on; }

/// Get the default temperature units in use.
/// @return true is Fahrenheit, false is Celsius.
bool IRGreeAC::getUseFahrenheit(void) const {
return _.UseFahrenheit;
}
bool IRGreeAC::getUseFahrenheit(void) const { return _.UseFahrenheit; }

/// Set the temp. in degrees
/// @param[in] temp Desired temperature in Degrees.
Expand Down Expand Up @@ -281,9 +278,7 @@ void IRGreeAC::setFan(const uint8_t speed) {

/// Get the current fan speed setting.
/// @return The current fan speed.
uint8_t IRGreeAC::getFan(void) const {
return _.Fan;
}
uint8_t IRGreeAC::getFan(void) const { return _.Fan; }

/// Set the operating mode of the A/C.
/// @param[in] new_mode The desired operating mode.
Expand All @@ -305,81 +300,63 @@ void IRGreeAC::setMode(const uint8_t new_mode) {

/// Get the operating mode setting of the A/C.
/// @return The current operating mode setting.
uint8_t IRGreeAC::getMode(void) const {
return _.Mode;
}
uint8_t IRGreeAC::getMode(void) const { return _.Mode; }

/// Set the Light (LED) setting of the A/C.
/// @param[in] on true, the setting is on. false, the setting is off.
void IRGreeAC::setLight(const bool on) {
_.Light = on;
}
void IRGreeAC::setLight(const bool on) { _.Light = on; }

/// Get the Light (LED) setting of the A/C.
/// @return true, the setting is on. false, the setting is off.
bool IRGreeAC::getLight(void) const {
return _.Light;
}
bool IRGreeAC::getLight(void) const { return _.Light; }

/// Set the IFeel setting of the A/C.
/// @param[in] on true, the setting is on. false, the setting is off.
void IRGreeAC::setIFeel(const bool on) {
_.IFeel = on;
}
void IRGreeAC::setIFeel(const bool on) { _.IFeel = on; }

/// Get the IFeel setting of the A/C.
/// @return true, the setting is on. false, the setting is off.
bool IRGreeAC::getIFeel(void) const {
return _.IFeel;
}
bool IRGreeAC::getIFeel(void) const { return _.IFeel; }

/// Set the Wifi (enabled) setting of the A/C.
/// @param[in] on true, the setting is on. false, the setting is off.
void IRGreeAC::setWiFi(const bool on) {
_.WiFi = on;
}
void IRGreeAC::setWiFi(const bool on) { _.WiFi = on; }

/// Get the Wifi (enabled) setting of the A/C.
/// @return true, the setting is on. false, the setting is off.
bool IRGreeAC::getWiFi(void) const {
return _.WiFi;
}
bool IRGreeAC::getWiFi(void) const { return _.WiFi; }

/// Set the XFan (Mould) setting of the A/C.
/// @param[in] on true, the setting is on. false, the setting is off.
void IRGreeAC::setXFan(const bool on) {
_.Xfan = on;
}
void IRGreeAC::setXFan(const bool on) { _.Xfan = on; }

/// Get the XFan (Mould) setting of the A/C.
/// @return true, the setting is on. false, the setting is off.
bool IRGreeAC::getXFan(void) const {
return _.Xfan;
}
bool IRGreeAC::getXFan(void) const { return _.Xfan; }

/// Set the Sleep setting of the A/C.
/// @param[in] on true, the setting is on. false, the setting is off.
void IRGreeAC::setSleep(const bool on) {
_.Sleep = on;
}
void IRGreeAC::setSleep(const bool on) { _.Sleep = on; }

/// Get the Sleep setting of the A/C.
/// @return true, the setting is on. false, the setting is off.
bool IRGreeAC::getSleep(void) const {
return _.Sleep;
}
bool IRGreeAC::getSleep(void) const { return _.Sleep; }

/// Set the Turbo setting of the A/C.
/// @param[in] on true, the setting is on. false, the setting is off.
void IRGreeAC::setTurbo(const bool on) {
_.Turbo = on;
}
void IRGreeAC::setTurbo(const bool on) { _.Turbo = on; }

/// Get the Turbo setting of the A/C.
/// @return true, the setting is on. false, the setting is off.
bool IRGreeAC::getTurbo(void) const {
return _.Turbo;
}
bool IRGreeAC::getTurbo(void) const { return _.Turbo; }

/// Set the Econo setting of the A/C.
/// @param[in] on true, the setting is on. false, the setting is off.
void IRGreeAC::setEcono(const bool on) { _.Econo = on; }

/// Get the Econo setting of the A/C.
/// @return true, the setting is on. false, the setting is off.
bool IRGreeAC::getEcono(void) const { return _.Econo; }

/// Set the Vertical Swing mode of the A/C.
/// @param[in] automatic Do we use the automatic setting?
Expand Down Expand Up @@ -409,32 +386,37 @@ void IRGreeAC::setSwingVertical(const bool automatic, const uint8_t position) {
new_position = kGreeSwingAuto;
}
}
_.Swing = new_position;
_.SwingV = new_position;
}

/// Get the Vertical Swing Automatic mode setting of the A/C.
/// @return true, the setting is on. false, the setting is off.
bool IRGreeAC::getSwingVerticalAuto(void) const {
return _.SwingAuto;
}
bool IRGreeAC::getSwingVerticalAuto(void) const { return _.SwingAuto; }

/// Get the Vertical Swing position setting of the A/C.
/// @return The native position/mode.
uint8_t IRGreeAC::getSwingVerticalPosition(void) const {
return _.Swing;
uint8_t IRGreeAC::getSwingVerticalPosition(void) const { return _.SwingV; }

/// Get the Horizontal Swing position setting of the A/C.
/// @return The native position/mode.
uint8_t IRGreeAC::getSwingHorizontal(void) const { return _.SwingH; }

/// Set the Horizontal Swing mode of the A/C.
/// @param[in] position The position/mode to set the vanes to.
void IRGreeAC::setSwingHorizontal(const uint8_t position) {
if (position <= kGreeSwingHMaxRight)
_.SwingH = position;
else
_.SwingH = kGreeSwingHOff;
}

/// Set the timer enable setting of the A/C.
/// @param[in] on true, the setting is on. false, the setting is off.
void IRGreeAC::setTimerEnabled(const bool on) {
_.TimerEnabled = on;
}
void IRGreeAC::setTimerEnabled(const bool on) { _.TimerEnabled = on; }

/// Get the timer enabled setting of the A/C.
/// @return true, the setting is on. false, the setting is off.
bool IRGreeAC::getTimerEnabled(void) const {
return _.TimerEnabled;
}
bool IRGreeAC::getTimerEnabled(void) const { return _.TimerEnabled; }

/// Get the timer time value from the A/C.
/// @return The number of minutes the timer is set for.
Expand Down Expand Up @@ -478,9 +460,7 @@ void IRGreeAC::setDisplayTempSource(const uint8_t mode) {
/// Get the temperature display mode.
/// i.e. Internal, External temperature sensing.
/// @return The current temp source being displayed.
uint8_t IRGreeAC::getDisplayTempSource(void) const {
return _.DisplayTemp;
}
uint8_t IRGreeAC::getDisplayTempSource(void) const { return _.DisplayTemp; }

/// Convert a stdAc::opmode_t enum into its native mode.
/// @param[in] mode The enum to be converted.
Expand Down Expand Up @@ -523,16 +503,31 @@ uint8_t IRGreeAC::convertSwingV(const stdAc::swingv_t swingv) {
}
}

/// Convert a stdAc::swingh_t enum into it's native setting.
/// @param[in] swingh The enum to be converted.
/// @return The native equivalent of the enum.
uint8_t IRGreeAC::convertSwingH(const stdAc::swingh_t swingh) {
switch (swingh) {
case stdAc::swingh_t::kAuto: return kGreeSwingHAuto;
case stdAc::swingh_t::kLeftMax: return kGreeSwingHMaxLeft;
case stdAc::swingh_t::kLeft: return kGreeSwingHLeft;
case stdAc::swingh_t::kMiddle: return kGreeSwingHMiddle;
case stdAc::swingh_t::kRight: return kGreeSwingHRight;
case stdAc::swingh_t::kRightMax: return kGreeSwingHMaxRight;
default: return kGreeSwingHOff;
}
}

/// Convert a native mode into its stdAc equivalent.
/// @param[in] mode The native setting to be converted.
/// @return The stdAc equivalent of the native setting.
stdAc::opmode_t IRGreeAC::toCommonMode(const uint8_t mode) {
switch (mode) {
case kGreeCool: return stdAc::opmode_t::kCool;
case kGreeHeat: return stdAc::opmode_t::kHeat;
case kGreeDry: return stdAc::opmode_t::kDry;
case kGreeFan: return stdAc::opmode_t::kFan;
default: return stdAc::opmode_t::kAuto;
case kGreeDry: return stdAc::opmode_t::kDry;
case kGreeFan: return stdAc::opmode_t::kFan;
default: return stdAc::opmode_t::kAuto;
}
}

Expand All @@ -541,10 +536,10 @@ stdAc::opmode_t IRGreeAC::toCommonMode(const uint8_t mode) {
/// @return The stdAc equivalent of the native setting.
stdAc::fanspeed_t IRGreeAC::toCommonFanSpeed(const uint8_t speed) {
switch (speed) {
case kGreeFanMax: return stdAc::fanspeed_t::kMax;
case kGreeFanMax: return stdAc::fanspeed_t::kMax;
case kGreeFanMax - 1: return stdAc::fanspeed_t::kMedium;
case kGreeFanMin: return stdAc::fanspeed_t::kMin;
default: return stdAc::fanspeed_t::kAuto;
case kGreeFanMin: return stdAc::fanspeed_t::kMin;
default: return stdAc::fanspeed_t::kAuto;
}
}

Expand All @@ -553,12 +548,27 @@ stdAc::fanspeed_t IRGreeAC::toCommonFanSpeed(const uint8_t speed) {
/// @return The stdAc equivalent of the native setting.
stdAc::swingv_t IRGreeAC::toCommonSwingV(const uint8_t pos) {
switch (pos) {
case kGreeSwingUp: return stdAc::swingv_t::kHighest;
case kGreeSwingMiddleUp: return stdAc::swingv_t::kHigh;
case kGreeSwingMiddle: return stdAc::swingv_t::kMiddle;
case kGreeSwingUp: return stdAc::swingv_t::kHighest;
case kGreeSwingMiddleUp: return stdAc::swingv_t::kHigh;
case kGreeSwingMiddle: return stdAc::swingv_t::kMiddle;
case kGreeSwingMiddleDown: return stdAc::swingv_t::kLow;
case kGreeSwingDown: return stdAc::swingv_t::kLowest;
default: return stdAc::swingv_t::kAuto;
case kGreeSwingDown: return stdAc::swingv_t::kLowest;
default: return stdAc::swingv_t::kAuto;
}
}

/// Convert a native Horizontal Swing into its stdAc equivalent.
/// @param[in] pos The native setting to be converted.
/// @return The stdAc equivalent of the native setting.
stdAc::swingh_t IRGreeAC::toCommonSwingH(const uint8_t pos) {
switch (pos) {
case kGreeSwingHAuto: return stdAc::swingh_t::kAuto;
case kGreeSwingHMaxLeft: return stdAc::swingh_t::kLeftMax;
case kGreeSwingHLeft: return stdAc::swingh_t::kLeft;
case kGreeSwingHMiddle: return stdAc::swingh_t::kMiddle;
case kGreeSwingHRight: return stdAc::swingh_t::kRight;
case kGreeSwingHMaxRight: return stdAc::swingh_t::kRightMax;
default: return stdAc::swingh_t::kOff;
}
}

Expand All @@ -576,15 +586,15 @@ stdAc::state_t IRGreeAC::toCommon(void) {
if (_.SwingAuto)
result.swingv = stdAc::swingv_t::kAuto;
else
result.swingv = toCommonSwingV(_.Swing);
result.swingv = toCommonSwingV(_.SwingV);
result.swingh = toCommonSwingH(_.SwingH);
result.turbo = _.Turbo;
result.econo = _.Econo;
result.light = _.Light;
result.clean = _.Xfan;
result.sleep = _.Sleep ? 0 : -1;
// Not supported.
result.swingh = stdAc::swingh_t::kOff;
result.quiet = false;
result.econo = false;
result.filter = false;
result.beep = false;
result.clock = -1;
Expand All @@ -604,16 +614,17 @@ String IRGreeAC::toString(void) {
result += addFanToString(_.Fan, kGreeFanMax, kGreeFanMin, kGreeFanAuto,
kGreeFanAuto, kGreeFanMed);
result += addBoolToString(_.Turbo, kTurboStr);
result += addBoolToString(_.Econo, kEconoStr);
result += addBoolToString(_.IFeel, kIFeelStr);
result += addBoolToString(_.WiFi, kWifiStr);
result += addBoolToString(_.Xfan, kXFanStr);
result += addBoolToString(_.Light, kLightStr);
result += addBoolToString(_.Sleep, kSleepStr);
result += addLabeledString(_.SwingAuto ? kAutoStr : kManualStr,
kSwingVModeStr);
result += addIntToString(_.Swing, kSwingVStr);
result += addIntToString(_.SwingV, kSwingVStr);
result += kSpaceLBraceStr;
switch (_.Swing) {
switch (_.SwingV) {
case kGreeSwingLastPos:
result += kLastStr;
break;
Expand All @@ -623,6 +634,12 @@ String IRGreeAC::toString(void) {
default: result += kUnknownStr;
}
result += ')';
result += addSwingHToString(_.SwingH, kGreeSwingHAuto, kGreeSwingHMaxLeft,
kGreeSwingHLeft, kGreeSwingHMiddle,
kGreeSwingHRight, kGreeSwingHMaxRight,
kGreeSwingHOff,
// rest are unused.
0xFF, 0xFF, 0xFF, 0xFF);
result += addLabeledString(
_.TimerEnabled ? minsToString(getTimer()) : kOffStr, kTimerStr);
uint8_t src = _.DisplayTemp;
Expand Down
Loading