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

Simplify code based on state_t being initialised by default. #1736

Merged
merged 1 commit into from
Jan 14, 2022
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
8 changes: 2 additions & 6 deletions src/IRac.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ IRac::IRac(const uint16_t pin, const bool inverted, const bool use_modulation) {
_pin = pin;
_inverted = inverted;
_modulation = use_modulation;
initState(&next);
this->markAsSent();
}

Expand Down Expand Up @@ -132,11 +131,8 @@ void IRac::initState(stdAc::state_t *state,
/// @param[out] state A Ptr to where the settings will be stored.
/// @note Sets all the parameters to reasonable base/automatic defaults.
void IRac::initState(stdAc::state_t *state) {
initState(state, decode_type_t::UNKNOWN, -1, false, stdAc::opmode_t::kOff,
25, true, // 25 degrees Celsius
stdAc::fanspeed_t::kAuto, stdAc::swingv_t::kOff,
stdAc::swingh_t::kOff, false, false, false, false, false, false,
false, -1, -1);
stdAc::state_t def;
*state = def;
}

/// Get the current internal A/C climate state.
Expand Down
36 changes: 18 additions & 18 deletions src/IRsend.h
Original file line number Diff line number Diff line change
Expand Up @@ -95,24 +95,24 @@ enum class swingh_t {

/// Structure to hold a common A/C state.
struct state_t {
decode_type_t protocol;
int16_t model;
bool power;
stdAc::opmode_t mode;
float degrees;
bool celsius;
stdAc::fanspeed_t fanspeed;
stdAc::swingv_t swingv;
stdAc::swingh_t swingh;
bool quiet;
bool turbo;
bool econo;
bool light;
bool filter;
bool clean;
bool beep;
int16_t sleep;
int16_t clock;
decode_type_t protocol = decode_type_t::UNKNOWN;
int16_t model = -1; // `-1` means unused.
bool power = false;
stdAc::opmode_t mode = stdAc::opmode_t::kOff;
float degrees = 25;
bool celsius = true;
stdAc::fanspeed_t fanspeed = stdAc::fanspeed_t::kAuto;
stdAc::swingv_t swingv = stdAc::swingv_t::kOff;
stdAc::swingh_t swingh = stdAc::swingh_t::kOff;
bool quiet = false;
bool turbo = false;
bool econo = false;
bool light = false;
bool filter = false;
bool clean = false;
bool beep = false;
int16_t sleep = -1; // `-1` means off.
int16_t clock = -1; // `-1` means not set.
};
}; // namespace stdAc

Expand Down
2 changes: 1 addition & 1 deletion src/ir_Airton.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ bool IRAirtonAc::getHealth(void) const { return _.Health; }
/// Convert the current internal state into its stdAc::state_t equivalent.
/// @return The stdAc equivalent of the native settings.
stdAc::state_t IRAirtonAc::toCommon(void) const {
stdAc::state_t result;
stdAc::state_t result{};
result.protocol = decode_type_t::AIRTON;
result.power = getPower();
result.mode = toCommonMode(getMode());
Expand Down
2 changes: 1 addition & 1 deletion src/ir_Airwell.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,7 @@ uint8_t IRAirwellAc::getTemp(void) const {
/// @param[in] prev Ptr to the previous state if required.
/// @return The stdAc equivalent of the native settings.
stdAc::state_t IRAirwellAc::toCommon(const stdAc::state_t *prev) const {
stdAc::state_t result;
stdAc::state_t result{};
// Start with the previous state if given it.
if (prev != NULL) {
result = *prev;
Expand Down
2 changes: 1 addition & 1 deletion src/ir_Amcor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ stdAc::fanspeed_t IRAmcorAc::toCommonFanSpeed(const uint8_t speed) {
/// Convert the current internal state into its stdAc::state_t equivalent.
/// @return The stdAc equivalent of the native settings.
stdAc::state_t IRAmcorAc::toCommon(void) const {
stdAc::state_t result;
stdAc::state_t result{};
result.protocol = decode_type_t::AMCOR;
result.power = getPower();
result.mode = toCommonMode(_.Mode);
Expand Down
2 changes: 1 addition & 1 deletion src/ir_Argo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ stdAc::fanspeed_t IRArgoAC::toCommonFanSpeed(const uint8_t speed) {
/// Convert the current internal state into its stdAc::state_t equivalent.
/// @return The stdAc equivalent of the native settings.
stdAc::state_t IRArgoAC::toCommon(void) const {
stdAc::state_t result;
stdAc::state_t result{};
result.protocol = decode_type_t::ARGO;
result.power = _.Power;
result.mode = toCommonMode(_.Mode);
Expand Down
2 changes: 1 addition & 1 deletion src/ir_Carrier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ String IRCarrierAc64::toString(void) const {
/// Convert the A/C state to it's common stdAc::state_t equivalent.
/// @return A stdAc::state_t state.
stdAc::state_t IRCarrierAc64::toCommon(void) const {
stdAc::state_t result;
stdAc::state_t result{};
result.protocol = decode_type_t::CARRIER_AC64;
result.model = -1; // No models used.
result.power = _.Power;
Expand Down
2 changes: 1 addition & 1 deletion src/ir_Coolix.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ stdAc::fanspeed_t IRCoolixAC::toCommonFanSpeed(const uint8_t speed) {
/// @param[in] prev Ptr to the previous state if required.
/// @return A stdAc::state_t state.
stdAc::state_t IRCoolixAC::toCommon(const stdAc::state_t *prev) const {
stdAc::state_t result;
stdAc::state_t result{};
// Start with the previous state if given it.
if (prev != NULL) {
result = *prev;
Expand Down
2 changes: 1 addition & 1 deletion src/ir_Corona.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -550,7 +550,7 @@ String IRCoronaAc::toString(void) const {
/// Convert the A/C state to it's common stdAc::state_t equivalent.
/// @return A stdAc::state_t state.
stdAc::state_t IRCoronaAc::toCommon() const {
stdAc::state_t result;
stdAc::state_t result{};
result.protocol = decode_type_t::CORONA_AC;
result.model = -1; // No models used.
result.power = _.Power;
Expand Down
16 changes: 8 additions & 8 deletions src/ir_Daikin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -529,7 +529,7 @@ stdAc::fanspeed_t IRDaikinESP::toCommonFanSpeed(const uint8_t speed) {
/// Convert the current internal state into its stdAc::state_t equivalent.
/// @return The stdAc equivalent of the native settings.
stdAc::state_t IRDaikinESP::toCommon(void) const {
stdAc::state_t result;
stdAc::state_t result{};
result.protocol = decode_type_t::DAIKIN;
result.model = -1; // No models used.
result.power = _.Power;
Expand Down Expand Up @@ -1199,7 +1199,7 @@ stdAc::swingh_t IRDaikin2::toCommonSwingH(const uint8_t setting) {
/// Convert the current internal state into its stdAc::state_t equivalent.
/// @return The stdAc equivalent of the native settings.
stdAc::state_t IRDaikin2::toCommon(void) const {
stdAc::state_t result;
stdAc::state_t result{};
result.protocol = decode_type_t::DAIKIN2;
result.model = -1; // No models used.
result.power = getPower();
Expand Down Expand Up @@ -1621,7 +1621,7 @@ bool IRDaikin216::getPowerful(void) const { return _.Powerful; }
/// Convert the current internal state into its stdAc::state_t equivalent.
/// @return The stdAc equivalent of the native settings.
stdAc::state_t IRDaikin216::toCommon(void) const {
stdAc::state_t result;
stdAc::state_t result{};
result.protocol = decode_type_t::DAIKIN216;
result.model = -1; // No models used.
result.power = _.Power;
Expand Down Expand Up @@ -1971,7 +1971,7 @@ stdAc::swingv_t IRDaikin160::toCommonSwingV(const uint8_t setting) {
/// Convert the current internal state into its stdAc::state_t equivalent.
/// @return The stdAc equivalent of the native settings.
stdAc::state_t IRDaikin160::toCommon(void) const {
stdAc::state_t result;
stdAc::state_t result{};
result.protocol = decode_type_t::DAIKIN160;
result.model = -1; // No models used.
result.power = _.Power;
Expand Down Expand Up @@ -2362,7 +2362,7 @@ stdAc::fanspeed_t IRDaikin176::toCommonFanSpeed(const uint8_t speed) {
/// Convert the current internal state into its stdAc::state_t equivalent.
/// @return The stdAc equivalent of the native settings.
stdAc::state_t IRDaikin176::toCommon(void) const {
stdAc::state_t result;
stdAc::state_t result{};
result.protocol = decode_type_t::DAIKIN176;
result.model = -1; // No models used.
result.power = _.Power;
Expand Down Expand Up @@ -2883,7 +2883,7 @@ String IRDaikin128::toString(void) const {
/// @param[in] prev Ptr to a previous state.
/// @return The stdAc equivalent of the native settings.
stdAc::state_t IRDaikin128::toCommon(const stdAc::state_t *prev) const {
stdAc::state_t result;
stdAc::state_t result{};
if (prev != NULL) result = *prev;
result.protocol = decode_type_t::DAIKIN128;
result.model = -1; // No models used.
Expand Down Expand Up @@ -3285,7 +3285,7 @@ bool IRDaikin152::getComfort(void) const { return _.Comfort; }
/// Convert the current internal state into its stdAc::state_t equivalent.
/// @return The stdAc equivalent of the native settings.
stdAc::state_t IRDaikin152::toCommon(void) const {
stdAc::state_t result;
stdAc::state_t result{};
result.protocol = decode_type_t::DAIKIN152;
result.model = -1; // No models used.
result.power = _.Power;
Expand Down Expand Up @@ -3710,7 +3710,7 @@ String IRDaikin64::toString(void) const {
/// @param[in] prev Ptr to a previous state.
/// @return The stdAc equivalent of the native settings.
stdAc::state_t IRDaikin64::toCommon(const stdAc::state_t *prev) const {
stdAc::state_t result;
stdAc::state_t result{};
if (prev != NULL) result = *prev;
result.protocol = decode_type_t::DAIKIN64;
result.model = -1; // No models used.
Expand Down
2 changes: 1 addition & 1 deletion src/ir_Delonghi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -421,7 +421,7 @@ uint16_t IRDelonghiAc::getOffTimer(void) const {
/// Convert the current internal state into its stdAc::state_t equivalent.
/// @return The stdAc equivalent of the native settings.
stdAc::state_t IRDelonghiAc::toCommon(void) const {
stdAc::state_t result;
stdAc::state_t result{};
result.protocol = decode_type_t::DELONGHI_AC;
result.power = _.Power;
// result.mode = toCommonMode(getMode());
Expand Down
2 changes: 1 addition & 1 deletion src/ir_Ecoclim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ void IREcoclimAc::disableOffTimer(void) {
/// Convert the current internal state into its stdAc::state_t equivalent.
/// @return The stdAc equivalent of the native settings.
stdAc::state_t IREcoclimAc::toCommon(void) const {
stdAc::state_t result;
stdAc::state_t result{};
result.protocol = decode_type_t::ECOCLIM;
result.power = _.Power;
result.mode = toCommonMode(getMode());
Expand Down
2 changes: 1 addition & 1 deletion src/ir_Electra.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,7 +359,7 @@ uint8_t IRElectraAc::getSensorTemp(void) const {
/// Convert the current internal state into its stdAc::state_t equivalent.
/// @return The stdAc equivalent of the native settings.
stdAc::state_t IRElectraAc::toCommon(void) const {
stdAc::state_t result;
stdAc::state_t result{};
result.protocol = decode_type_t::ELECTRA_AC;
result.power = _.Power;
result.mode = toCommonMode(_.Mode);
Expand Down
2 changes: 1 addition & 1 deletion src/ir_Fujitsu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ stdAc::fanspeed_t IRFujitsuAC::toCommonFanSpeed(const uint8_t speed) {
/// Convert the current internal state into its stdAc::state_t equivalent.
/// @return The stdAc equivalent of the native settings.
stdAc::state_t IRFujitsuAC::toCommon(void) const {
stdAc::state_t result;
stdAc::state_t result{};
result.protocol = decode_type_t::FUJITSU_AC;
result.model = _model;
result.power = getPower();
Expand Down
2 changes: 1 addition & 1 deletion src/ir_Goodweather.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ stdAc::fanspeed_t IRGoodweatherAc::toCommonFanSpeed(const uint8_t speed) {
/// Convert the current internal state into its stdAc::state_t equivalent.
/// @return The stdAc equivalent of the native settings.
stdAc::state_t IRGoodweatherAc::toCommon(void) const {
stdAc::state_t result;
stdAc::state_t result{};
result.protocol = decode_type_t::GOODWEATHER;
result.power = _.Power;
result.mode = toCommonMode(_.Mode);
Expand Down
2 changes: 1 addition & 1 deletion src/ir_Gree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ stdAc::swingh_t IRGreeAC::toCommonSwingH(const uint8_t pos) {
/// Convert the current internal state into its stdAc::state_t equivalent.
/// @return The stdAc equivalent of the native settings.
stdAc::state_t IRGreeAC::toCommon(void) {
stdAc::state_t result;
stdAc::state_t result{};
result.protocol = decode_type_t::GREE;
result.model = _model;
result.power = _.Power;
Expand Down
4 changes: 2 additions & 2 deletions src/ir_Haier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,7 @@ stdAc::swingv_t IRHaierAC::toCommonSwingV(const uint8_t pos) {
/// Convert the current internal state into its stdAc::state_t equivalent.
/// @return The stdAc equivalent of the native settings.
stdAc::state_t IRHaierAC::toCommon(void) const {
stdAc::state_t result;
stdAc::state_t result{};
result.protocol = decode_type_t::HAIER_AC;
result.model = -1; // No models used.
result.power = true;
Expand Down Expand Up @@ -1127,7 +1127,7 @@ stdAc::swingh_t IRHaierAC176::toCommonSwingH(const uint8_t pos) {
/// Convert the current internal state into its stdAc::state_t equivalent.
/// @return The stdAc equivalent of the native settings.
stdAc::state_t IRHaierAC176::toCommon(void) const {
stdAc::state_t result;
stdAc::state_t result{};
result.protocol = decode_type_t::HAIER_AC_YRW02;
result.model = getModel();
result.power = _.Power;
Expand Down
6 changes: 3 additions & 3 deletions src/ir_Hitachi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ stdAc::fanspeed_t IRHitachiAc::toCommonFanSpeed(const uint8_t speed) {
/// Convert the current internal state into its stdAc::state_t equivalent.
/// @return The stdAc equivalent of the native settings.
stdAc::state_t IRHitachiAc::toCommon(void) const {
stdAc::state_t result;
stdAc::state_t result{};
result.protocol = decode_type_t::HITACHI_AC;
result.model = -1; // No models used.
result.power = _.Power;
Expand Down Expand Up @@ -781,7 +781,7 @@ stdAc::fanspeed_t IRHitachiAc1::toCommonFanSpeed(const uint8_t speed) {
/// Convert the current internal state into its stdAc::state_t equivalent.
/// @return The stdAc equivalent of the native settings.
stdAc::state_t IRHitachiAc1::toCommon(void) const {
stdAc::state_t result;
stdAc::state_t result{};
result.protocol = decode_type_t::HITACHI_AC1;
result.model = getModel();
result.power = _.Power;
Expand Down Expand Up @@ -1261,7 +1261,7 @@ stdAc::fanspeed_t IRHitachiAc424::toCommonFanSpeed(const uint8_t speed) {
/// Convert the current internal state into its stdAc::state_t equivalent.
/// @return The stdAc equivalent of the native settings.
stdAc::state_t IRHitachiAc424::toCommon(void) const {
stdAc::state_t result;
stdAc::state_t result{};
result.protocol = decode_type_t::HITACHI_AC424;
result.model = -1; // No models used.
result.power = getPower();
Expand Down
2 changes: 1 addition & 1 deletion src/ir_Kelvinator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -401,7 +401,7 @@ stdAc::fanspeed_t IRKelvinatorAC::toCommonFanSpeed(const uint8_t speed) {
/// Convert the internal A/C object state to it's stdAc::state_t equivalent.
/// @return A stdAc::state_t containing the current settings.
stdAc::state_t IRKelvinatorAC::toCommon(void) const {
stdAc::state_t result;
stdAc::state_t result{};
result.protocol = decode_type_t::KELVINATOR;
result.model = -1; // Unused.
result.power = _.Power;
Expand Down
2 changes: 1 addition & 1 deletion src/ir_LG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -740,7 +740,7 @@ uint8_t IRLgAc::convertVaneSwingV(const stdAc::swingv_t swingv) {
/// @param[in] prev Ptr to the previous state if required.
/// @return The stdAc equivalent of the native settings.
stdAc::state_t IRLgAc::toCommon(const stdAc::state_t *prev) const {
stdAc::state_t result;
stdAc::state_t result{};
// Start with the previous state if given it.
if (prev != NULL) {
result = *prev;
Expand Down
2 changes: 1 addition & 1 deletion src/ir_Mirage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -733,7 +733,7 @@ stdAc::swingv_t IRMirageAc::toCommonSwingV(const uint8_t pos) {
/// Convert the current internal state into its stdAc::state_t equivalent.
/// @return The stdAc equivalent of the native settings.
stdAc::state_t IRMirageAc::toCommon(void) const {
stdAc::state_t result;
stdAc::state_t result{};
result.protocol = decode_type_t::MIRAGE;
result.model = _model;
result.power = getPower();
Expand Down
6 changes: 3 additions & 3 deletions src/ir_Mitsubishi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -781,7 +781,7 @@ stdAc::swingh_t IRMitsubishiAC::toCommonSwingH(const uint8_t pos) {
/// Convert the current internal state into its stdAc::state_t equivalent.
/// @return The stdAc equivalent of the native settings.
stdAc::state_t IRMitsubishiAC::toCommon(void) const {
stdAc::state_t result;
stdAc::state_t result{};
result.protocol = decode_type_t::MITSUBISHI_AC;
result.model = -1; // No models used.
result.power = _.Power;
Expand Down Expand Up @@ -1195,7 +1195,7 @@ stdAc::swingv_t IRMitsubishi136::toCommonSwingV(const uint8_t pos) {
/// Convert the current internal state into its stdAc::state_t equivalent.
/// @return The stdAc equivalent of the native settings.
stdAc::state_t IRMitsubishi136::toCommon(void) const {
stdAc::state_t result;
stdAc::state_t result{};
result.protocol = decode_type_t::MITSUBISHI136;
result.model = -1; // No models used.
result.power = _.Power;
Expand Down Expand Up @@ -1660,7 +1660,7 @@ stdAc::swingh_t IRMitsubishi112::toCommonSwingH(const uint8_t pos) {
/// Convert the current internal state into its stdAc::state_t equivalent.
/// @return The stdAc equivalent of the native settings.
stdAc::state_t IRMitsubishi112::toCommon(void) const {
stdAc::state_t result;
stdAc::state_t result{};
result.protocol = decode_type_t::MITSUBISHI112;
result.model = -1; // No models used.
result.power = _.Power;
Expand Down
4 changes: 2 additions & 2 deletions src/ir_MitsubishiHeavy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ stdAc::swingv_t IRMitsubishiHeavy152Ac::toCommonSwingV(const uint8_t pos) {
/// Convert the current internal state into its stdAc::state_t equivalent.
/// @return The stdAc equivalent of the native settings.
stdAc::state_t IRMitsubishiHeavy152Ac::toCommon(void) const {
stdAc::state_t result;
stdAc::state_t result{};
result.protocol = decode_type_t::MITSUBISHI_HEAVY_152;
result.model = -1; // No models used.
result.power = _.Power;
Expand Down Expand Up @@ -899,7 +899,7 @@ stdAc::swingv_t IRMitsubishiHeavy88Ac::toCommonSwingV(const uint8_t pos) {
/// Convert the current internal state into its stdAc::state_t equivalent.
/// @return The stdAc equivalent of the native settings.
stdAc::state_t IRMitsubishiHeavy88Ac::toCommon(void) const {
stdAc::state_t result;
stdAc::state_t result{};
result.protocol = decode_type_t::MITSUBISHI_HEAVY_88;
result.model = -1; // No models used.
result.power = _.Power;
Expand Down
2 changes: 1 addition & 1 deletion src/ir_Neoclima.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -484,7 +484,7 @@ bool IRNeoclimaAc::getFollow(void) const {
/// Convert the current internal state into its stdAc::state_t equivalent.
/// @return The stdAc equivalent of the native settings.
stdAc::state_t IRNeoclimaAc::toCommon(void) const {
stdAc::state_t result;
stdAc::state_t result{};
result.protocol = decode_type_t::NEOCLIMA;
result.model = -1; // No models used.
result.power = _.Power;
Expand Down
4 changes: 2 additions & 2 deletions src/ir_Panasonic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -760,7 +760,7 @@ stdAc::swingv_t IRPanasonicAc::toCommonSwingV(const uint8_t pos) {
/// Convert the current internal state into its stdAc::state_t equivalent.
/// @return The stdAc equivalent of the native settings.
stdAc::state_t IRPanasonicAc::toCommon(void) {
stdAc::state_t result;
stdAc::state_t result{};
result.protocol = decode_type_t::PANASONIC_AC;
result.model = getModel();
result.power = getPower();
Expand Down Expand Up @@ -1307,7 +1307,7 @@ String IRPanasonicAc32::toString(void) const {
/// @param[in] prev Ptr to the previous state if required.
/// @return The stdAc equivalent of the native settings.
stdAc::state_t IRPanasonicAc32::toCommon(const stdAc::state_t *prev) const {
stdAc::state_t result;
stdAc::state_t result{};
// Start with the previous state if given it.
if (prev != NULL) {
result = *prev;
Expand Down
Loading