From 3390e72877ac15c74f602151de4a2fb9a154bdb0 Mon Sep 17 00:00:00 2001 From: David Conran Date: Tue, 7 Jan 2025 21:20:19 +1000 Subject: [PATCH] Fix linter issues (#2173) It seems we have a new linter that is picking up lots of issues. Attempt to address them. Set cpplint to ignore whitespace/namespace issues --- CPPLINT.cfg | 1 + examples/IRMQTTServer/IRMQTTServer.ino | 22 +- examples/IRrecvDump/IRrecvDump.ino | 2 +- src/IRac.cpp | 1505 ++++++++++----------- src/IRac.h | 6 +- src/IRrecv.cpp | 24 +- src/IRremoteESP8266.h | 20 +- src/IRsend.cpp | 12 +- src/IRsend.h | 3 +- src/IRutils.cpp | 1715 ++++++++++++------------ src/IRutils.h | 197 +-- src/ir_Argo.cpp | 54 +- src/ir_Bosch.cpp | 1 + src/ir_Daikin.cpp | 12 +- src/ir_Ecoclim.cpp | 2 +- src/ir_GlobalCache.cpp | 3 +- src/ir_Goodweather.cpp | 2 +- src/ir_Haier.cpp | 38 +- src/ir_Kelon.cpp | 5 +- src/ir_Lego.cpp | 2 +- src/ir_Lutron.cpp | 2 +- src/ir_Midea.cpp | 4 +- src/ir_Mirage.cpp | 7 +- src/ir_Panasonic.cpp | 9 +- src/ir_Pioneer.cpp | 2 +- src/ir_Pronto.cpp | 3 +- src/ir_RC5_RC6.cpp | 7 +- src/ir_RCMM.cpp | 6 +- src/ir_Samsung.cpp | 2 +- src/ir_Sanyo.cpp | 3 +- src/ir_Sharp.cpp | 8 +- src/ir_Sherwood.cpp | 3 +- src/ir_Teco.cpp | 3 +- src/ir_Toshiba.cpp | 2 +- src/ir_Voltas.cpp | 4 +- src/ir_Xmp.cpp | 139 +- test/IRsend_test.cpp | 12 +- test/IRsend_test.h | 2 +- test/IRutils_test.cpp | 33 +- test/ir_Argo_test.cpp | 6 + test/ir_Gorenje_test.cpp | 2 + test/ir_Gree_test.cpp | 2 +- tools/code_to_raw.cpp | 1 + tools/gc_decode.cpp | 4 +- tools/mode2_decode.cpp | 3 +- 45 files changed, 1987 insertions(+), 1908 deletions(-) diff --git a/CPPLINT.cfg b/CPPLINT.cfg index 181f5204d..00d58a7ac 100644 --- a/CPPLINT.cfg +++ b/CPPLINT.cfg @@ -1,3 +1,4 @@ set noparent root=src linelength=80 +filter=-whitespace/indent_namespace diff --git a/examples/IRMQTTServer/IRMQTTServer.ino b/examples/IRMQTTServer/IRMQTTServer.ino index 35a528107..b301adac3 100644 --- a/examples/IRMQTTServer/IRMQTTServer.ino +++ b/examples/IRMQTTServer/IRMQTTServer.ino @@ -1659,11 +1659,13 @@ bool parseStringAndSendAirCon(IRsend *irsend, const decode_type_t irType, stateSize = inputLength / 2; // Every two hex chars is a byte. // Use at least the minimum size. stateSize = std::max(stateSize, - (uint16_t) (kFujitsuAcStateLengthShort - 1)); + static_cast(kFujitsuAcStateLengthShort - + 1)); // If we think it isn't a "short" message. if (stateSize > kFujitsuAcStateLengthShort) // Then it has to be at least the smaller version of the "normal" size. - stateSize = std::max(stateSize, (uint16_t) (kFujitsuAcStateLength - 1)); + stateSize = std::max(stateSize, + static_cast(kFujitsuAcStateLength - 1)); // Lastly, it should never exceed the maximum "normal" size. stateSize = std::min(stateSize, kFujitsuAcStateLength); break; @@ -1675,12 +1677,12 @@ bool parseStringAndSendAirCon(IRsend *irsend, const decode_type_t irType, stateSize = inputLength / 2; // Every two hex chars is a byte. // Use at least the minimum size. stateSize = std::max(stateSize, - (uint16_t) (kHitachiAc3MinStateLength)); + static_cast(kHitachiAc3MinStateLength)); // If we think it isn't a "short" message. if (stateSize > kHitachiAc3MinStateLength) // Then it probably the "normal" size. stateSize = std::max(stateSize, - (uint16_t) (kHitachiAc3StateLength)); + static_cast(kHitachiAc3StateLength)); // Lastly, it should never exceed the maximum "normal" size. stateSize = std::min(stateSize, kHitachiAc3StateLength); break; @@ -1691,7 +1693,7 @@ bool parseStringAndSendAirCon(IRsend *irsend, const decode_type_t irType, // the correct length/byte size. stateSize = inputLength / 2; // Every two hex chars is a byte. // Use at least the minimum size. - stateSize = std::max(stateSize, (uint16_t) 3); + stateSize = std::max(stateSize, static_cast(3)); // Cap the maximum size. stateSize = std::min(stateSize, kStateSizeMax); break; @@ -1702,12 +1704,13 @@ bool parseStringAndSendAirCon(IRsend *irsend, const decode_type_t irType, // the correct length/byte size. stateSize = inputLength / 2; // Every two hex chars is a byte. // Use at least the minimum size. - stateSize = std::max(stateSize, (uint16_t) (kSamsungAcStateLength)); + stateSize = std::max(stateSize, + static_cast(kSamsungAcStateLength)); // If we think it isn't a "normal" message. if (stateSize > kSamsungAcStateLength) // Then it probably the extended size. - stateSize = std::max(stateSize, - (uint16_t) (kSamsungAcExtendedStateLength)); + stateSize = std::max( + stateSize, static_cast(kSamsungAcExtendedStateLength)); // Lastly, it should never exceed the maximum "extended" size. stateSize = std::min(stateSize, kSamsungAcExtendedStateLength); break; @@ -2671,7 +2674,8 @@ void receivingMQTT(String const topic_name, String const callback_str) { switch (ircommand[0]) { case kPauseChar: { // It's a pause. Everything after the 'P' should be a number. - int32_t msecs = std::min((int32_t) strtoul(ircommand + 1, NULL, 10), + int32_t msecs = std::min(static_cast(strtoul(ircommand + 1, + NULL, 10)), kMaxPauseMs); delay(msecs); mqtt_client.publish(MqttAck.c_str(), diff --git a/examples/IRrecvDump/IRrecvDump.ino b/examples/IRrecvDump/IRrecvDump.ino index 2a65cb624..cb4c9eacd 100644 --- a/examples/IRrecvDump/IRrecvDump.ino +++ b/examples/IRrecvDump/IRrecvDump.ino @@ -87,7 +87,7 @@ void dump(decode_results *results) { Serial.print(results->rawbuf[i] * kRawTick, DEC); } else { Serial.print(", "); - Serial.print((uint32_t) results->rawbuf[i] * kRawTick, DEC); + Serial.print(static_cast(results->rawbuf[i] * kRawTick), DEC); } } Serial.println("};"); diff --git a/src/IRac.cpp b/src/IRac.cpp index b500303d9..da59af1b0 100644 --- a/src/IRac.cpp +++ b/src/IRac.cpp @@ -13,6 +13,7 @@ #include #endif #include +#include #if __cplusplus >= 201103L && defined(_GLIBCXX_USE_C99_MATH_TR1) using std::roundf; #else @@ -590,13 +591,19 @@ void IRac::argoWrem3_ConfigSet(IRArgoAC_WREM3 *ac, const uint8_t param, if (safe) { switch (param) { case 5: // temp. scale (note this is likely excess as not transmitted) - if (value > 1) { return; /* invalid */ } + if (value > 1) { + return; /* invalid */ + } break; case 6: // channel (note this is likely excess as not transmitted) - if (value > 3) { return; /* invalid */ } + if (value > 3) { + return; /* invalid */ + } break; case 12: // eco power limit - if (value < 30 || value > 99) { return; /* invalid */ } + if (value < 30 || value > 99) { + return; /* invalid */ + } break; default: return; /* invalid */ @@ -4058,1011 +4065,1011 @@ String IRac::swinghToString(const stdAc::swingh_t swingh) { } namespace IRAcUtils { - /// Display the human readable state of an A/C message if we can. - /// @param[in] result A Ptr to the captured `decode_results` that contains an - /// A/C mesg. - /// @return A string with the human description of the A/C message. - /// An empty string if we can't. - String resultAcToString(const decode_results * const result) { - switch (result->decode_type) { +/// Display the human readable state of an A/C message if we can. +/// @param[in] result A Ptr to the captured `decode_results` that contains an +/// A/C mesg. +/// @return A string with the human description of the A/C message. +/// An empty string if we can't. +String resultAcToString(const decode_results * const result) { + switch (result->decode_type) { #if DECODE_AIRTON - case decode_type_t::AIRTON: { - IRAirtonAc ac(kGpioUnused); - ac.setRaw(result->value); // AIRTON uses value instead of state. - return ac.toString(); - } + case decode_type_t::AIRTON: { + IRAirtonAc ac(kGpioUnused); + ac.setRaw(result->value); // AIRTON uses value instead of state. + return ac.toString(); + } #endif // DECODE_AIRTON #if DECODE_AIRWELL - case decode_type_t::AIRWELL: { - IRAirwellAc ac(kGpioUnused); - ac.setRaw(result->value); // AIRWELL uses value instead of state. - return ac.toString(); - } + case decode_type_t::AIRWELL: { + IRAirwellAc ac(kGpioUnused); + ac.setRaw(result->value); // AIRWELL uses value instead of state. + return ac.toString(); + } #endif // DECODE_AIRWELL #if DECODE_AMCOR - case decode_type_t::AMCOR: { - IRAmcorAc ac(kGpioUnused); - ac.setRaw(result->state); - return ac.toString(); - } + case decode_type_t::AMCOR: { + IRAmcorAc ac(kGpioUnused); + ac.setRaw(result->state); + return ac.toString(); + } #endif // DECODE_AMCOR #if DECODE_ARGO - case decode_type_t::ARGO: { - if (IRArgoAC_WREM3::isValidWrem3Message(result->state, result->bits, - true)) { - IRArgoAC_WREM3 ac(kGpioUnused); - ac.setRaw(result->state, result->bits / 8); - return ac.toString(); - } - IRArgoAC ac(kGpioUnused); + case decode_type_t::ARGO: { + if (IRArgoAC_WREM3::isValidWrem3Message(result->state, result->bits, + true)) { + IRArgoAC_WREM3 ac(kGpioUnused); ac.setRaw(result->state, result->bits / 8); return ac.toString(); } + IRArgoAC ac(kGpioUnused); + ac.setRaw(result->state, result->bits / 8); + return ac.toString(); + } #endif // DECODE_ARGO #if DECODE_BOSCH144 - case decode_type_t::BOSCH144: { - IRBosch144AC ac(kGpioUnused); - ac.setRaw(result->state); - return ac.toString(); - } + case decode_type_t::BOSCH144: { + IRBosch144AC ac(kGpioUnused); + ac.setRaw(result->state); + return ac.toString(); + } #endif // DECODE_BOSCH144 #if DECODE_CARRIER_AC64 - case decode_type_t::CARRIER_AC64: { - IRCarrierAc64 ac(kGpioUnused); - ac.setRaw(result->value); // CARRIER_AC64 uses value instead of state. - return ac.toString(); - } + case decode_type_t::CARRIER_AC64: { + IRCarrierAc64 ac(kGpioUnused); + ac.setRaw(result->value); // CARRIER_AC64 uses value instead of state. + return ac.toString(); + } #endif // DECODE_CARRIER_AC64 #if DECODE_COOLIX - case decode_type_t::COOLIX: { - IRCoolixAC ac(kGpioUnused); - ac.on(); - ac.setRaw(result->value); // Coolix uses value instead of state. - return ac.toString(); - } + case decode_type_t::COOLIX: { + IRCoolixAC ac(kGpioUnused); + ac.on(); + ac.setRaw(result->value); // Coolix uses value instead of state. + return ac.toString(); + } #endif // DECODE_COOLIX #if DECODE_CORONA_AC - case decode_type_t::CORONA_AC: { - IRCoronaAc ac(kGpioUnused); - ac.setRaw(result->state, result->bits / 8); - return ac.toString(); - } + case decode_type_t::CORONA_AC: { + IRCoronaAc ac(kGpioUnused); + ac.setRaw(result->state, result->bits / 8); + return ac.toString(); + } #endif // DECODE_CORONA_AC #if DECODE_DAIKIN - case decode_type_t::DAIKIN: { - IRDaikinESP ac(kGpioUnused); - ac.setRaw(result->state); - return ac.toString(); - } + case decode_type_t::DAIKIN: { + IRDaikinESP ac(kGpioUnused); + ac.setRaw(result->state); + return ac.toString(); + } #endif // DECODE_DAIKIN #if DECODE_DAIKIN128 - case decode_type_t::DAIKIN128: { - IRDaikin128 ac(kGpioUnused); - ac.setRaw(result->state); - return ac.toString(); - } + case decode_type_t::DAIKIN128: { + IRDaikin128 ac(kGpioUnused); + ac.setRaw(result->state); + return ac.toString(); + } #endif // DECODE_DAIKIN128 #if DECODE_DAIKIN152 - case decode_type_t::DAIKIN152: { - IRDaikin152 ac(kGpioUnused); - ac.setRaw(result->state); - return ac.toString(); - } + case decode_type_t::DAIKIN152: { + IRDaikin152 ac(kGpioUnused); + ac.setRaw(result->state); + return ac.toString(); + } #endif // DECODE_DAIKIN152 #if DECODE_DAIKIN160 - case decode_type_t::DAIKIN160: { - IRDaikin160 ac(kGpioUnused); - ac.setRaw(result->state); - return ac.toString(); - } + case decode_type_t::DAIKIN160: { + IRDaikin160 ac(kGpioUnused); + ac.setRaw(result->state); + return ac.toString(); + } #endif // DECODE_DAIKIN160 #if DECODE_DAIKIN176 - case decode_type_t::DAIKIN176: { - IRDaikin176 ac(kGpioUnused); - ac.setRaw(result->state); - return ac.toString(); - } + case decode_type_t::DAIKIN176: { + IRDaikin176 ac(kGpioUnused); + ac.setRaw(result->state); + return ac.toString(); + } #endif // DECODE_DAIKIN160 #if DECODE_DAIKIN2 - case decode_type_t::DAIKIN2: { - IRDaikin2 ac(kGpioUnused); - ac.setRaw(result->state); - return ac.toString(); - } + case decode_type_t::DAIKIN2: { + IRDaikin2 ac(kGpioUnused); + ac.setRaw(result->state); + return ac.toString(); + } #endif // DECODE_DAIKIN2 #if DECODE_DAIKIN216 - case decode_type_t::DAIKIN216: { - IRDaikin216 ac(kGpioUnused); - ac.setRaw(result->state); - return ac.toString(); - } + case decode_type_t::DAIKIN216: { + IRDaikin216 ac(kGpioUnused); + ac.setRaw(result->state); + return ac.toString(); + } #endif // DECODE_DAIKIN216 #if DECODE_DAIKIN64 - case decode_type_t::DAIKIN64: { - IRDaikin64 ac(kGpioUnused); - ac.setRaw(result->value); // Daikin64 uses value instead of state. - return ac.toString(); - } + case decode_type_t::DAIKIN64: { + IRDaikin64 ac(kGpioUnused); + ac.setRaw(result->value); // Daikin64 uses value instead of state. + return ac.toString(); + } #endif // DECODE_DAIKIN64 #if DECODE_DELONGHI_AC - case decode_type_t::DELONGHI_AC: { - IRDelonghiAc ac(kGpioUnused); - ac.setRaw(result->value); // DelonghiAc uses value instead of state. - return ac.toString(); - } + case decode_type_t::DELONGHI_AC: { + IRDelonghiAc ac(kGpioUnused); + ac.setRaw(result->value); // DelonghiAc uses value instead of state. + return ac.toString(); + } #endif // DECODE_DELONGHI_AC #if DECODE_ECOCLIM - case decode_type_t::ECOCLIM: { - if (result->bits == kEcoclimBits) { - IREcoclimAc ac(kGpioUnused); - ac.setRaw(result->value); // EcoClim uses value instead of state. - return ac.toString(); - } - return ""; + case decode_type_t::ECOCLIM: { + if (result->bits == kEcoclimBits) { + IREcoclimAc ac(kGpioUnused); + ac.setRaw(result->value); // EcoClim uses value instead of state. + return ac.toString(); } + return ""; + } #endif // DECODE_ECOCLIM #if DECODE_ELECTRA_AC - case decode_type_t::ELECTRA_AC: { - IRElectraAc ac(kGpioUnused); - ac.setRaw(result->state); - return ac.toString(); - } + case decode_type_t::ELECTRA_AC: { + IRElectraAc ac(kGpioUnused); + ac.setRaw(result->state); + return ac.toString(); + } #endif // DECODE_ELECTRA_AC #if DECODE_FUJITSU_AC - case decode_type_t::FUJITSU_AC: { - IRFujitsuAC ac(kGpioUnused); - ac.setRaw(result->state, result->bits / 8); - return ac.toString(); - } + case decode_type_t::FUJITSU_AC: { + IRFujitsuAC ac(kGpioUnused); + ac.setRaw(result->state, result->bits / 8); + return ac.toString(); + } #endif // DECODE_FUJITSU_AC #if DECODE_GOODWEATHER - case decode_type_t::GOODWEATHER: { - IRGoodweatherAc ac(kGpioUnused); - ac.setRaw(result->value); // Goodweather uses value instead of state. - return ac.toString(); - } + case decode_type_t::GOODWEATHER: { + IRGoodweatherAc ac(kGpioUnused); + ac.setRaw(result->value); // Goodweather uses value instead of state. + return ac.toString(); + } #endif // DECODE_GOODWEATHER #if DECODE_GREE - case decode_type_t::GREE: { - IRGreeAC ac(kGpioUnused); - ac.setRaw(result->state); - return ac.toString(); - } + case decode_type_t::GREE: { + IRGreeAC ac(kGpioUnused); + ac.setRaw(result->state); + return ac.toString(); + } #endif // DECODE_GREE #if DECODE_HAIER_AC - case decode_type_t::HAIER_AC: { - IRHaierAC ac(kGpioUnused); - ac.setRaw(result->state); - return ac.toString(); - } + case decode_type_t::HAIER_AC: { + IRHaierAC ac(kGpioUnused); + ac.setRaw(result->state); + return ac.toString(); + } #endif // DECODE_HAIER_AC #if DECODE_HAIER_AC160 - case decode_type_t::HAIER_AC160: { - IRHaierAC160 ac(kGpioUnused); - ac.setRaw(result->state); - return ac.toString(); - } + case decode_type_t::HAIER_AC160: { + IRHaierAC160 ac(kGpioUnused); + ac.setRaw(result->state); + return ac.toString(); + } #endif // DECODE_HAIER_AC160 #if DECODE_HAIER_AC176 - case decode_type_t::HAIER_AC176: { - IRHaierAC176 ac(kGpioUnused); - ac.setRaw(result->state); - return ac.toString(); - } + case decode_type_t::HAIER_AC176: { + IRHaierAC176 ac(kGpioUnused); + ac.setRaw(result->state); + return ac.toString(); + } #endif // DECODE_HAIER_AC176 #if DECODE_HAIER_AC_YRW02 - case decode_type_t::HAIER_AC_YRW02: { - IRHaierACYRW02 ac(kGpioUnused); - ac.setRaw(result->state); - return ac.toString(); - } + case decode_type_t::HAIER_AC_YRW02: { + IRHaierACYRW02 ac(kGpioUnused); + ac.setRaw(result->state); + return ac.toString(); + } #endif // DECODE_HAIER_AC_YRW02 #if DECODE_HITACHI_AC - case decode_type_t::HITACHI_AC: { - IRHitachiAc ac(kGpioUnused); - ac.setRaw(result->state); - return ac.toString(); - } + case decode_type_t::HITACHI_AC: { + IRHitachiAc ac(kGpioUnused); + ac.setRaw(result->state); + return ac.toString(); + } #endif // DECODE_HITACHI_AC #if DECODE_HITACHI_AC1 - case decode_type_t::HITACHI_AC1: { - IRHitachiAc1 ac(kGpioUnused); - ac.setRaw(result->state); - return ac.toString(); - } + case decode_type_t::HITACHI_AC1: { + IRHitachiAc1 ac(kGpioUnused); + ac.setRaw(result->state); + return ac.toString(); + } #endif // DECODE_HITACHI_AC1 #if DECODE_HITACHI_AC264 - case decode_type_t::HITACHI_AC264: { - IRHitachiAc264 ac(kGpioUnused); - ac.setRaw(result->state); - return ac.toString(); - } + case decode_type_t::HITACHI_AC264: { + IRHitachiAc264 ac(kGpioUnused); + ac.setRaw(result->state); + return ac.toString(); + } #endif // DECODE_HITACHI_AC264 #if DECODE_HITACHI_AC296 - case decode_type_t::HITACHI_AC296: { - IRHitachiAc296 ac(kGpioUnused); - ac.setRaw(result->state); - return ac.toString(); - } + case decode_type_t::HITACHI_AC296: { + IRHitachiAc296 ac(kGpioUnused); + ac.setRaw(result->state); + return ac.toString(); + } #endif // DECODE_HITACHI_AC296 #if DECODE_HITACHI_AC344 - case decode_type_t::HITACHI_AC344: { - IRHitachiAc344 ac(kGpioUnused); - ac.setRaw(result->state); - return ac.toString(); - } + case decode_type_t::HITACHI_AC344: { + IRHitachiAc344 ac(kGpioUnused); + ac.setRaw(result->state); + return ac.toString(); + } #endif // DECODE_HITACHI_AC344 #if DECODE_HITACHI_AC424 - case decode_type_t::HITACHI_AC424: { - IRHitachiAc424 ac(kGpioUnused); - ac.setRaw(result->state); - return ac.toString(); - } + case decode_type_t::HITACHI_AC424: { + IRHitachiAc424 ac(kGpioUnused); + ac.setRaw(result->state); + return ac.toString(); + } #endif // DECODE_HITACHI_AC424 #if DECODE_KELON - case decode_type_t::KELON: { - IRKelonAc ac(kGpioUnused); - ac.setRaw(result->value); - return ac.toString(); - } + case decode_type_t::KELON: { + IRKelonAc ac(kGpioUnused); + ac.setRaw(result->value); + return ac.toString(); + } #endif // DECODE_KELON #if DECODE_KELVINATOR - case decode_type_t::KELVINATOR: { - IRKelvinatorAC ac(kGpioUnused); - ac.setRaw(result->state); - return ac.toString(); - } + case decode_type_t::KELVINATOR: { + IRKelvinatorAC ac(kGpioUnused); + ac.setRaw(result->state); + return ac.toString(); + } #endif // DECODE_KELVINATOR #if DECODE_LG - case decode_type_t::LG: - case decode_type_t::LG2: { - IRLgAc ac(kGpioUnused); - ac.setRaw(result->value, result->decode_type); // Use value, not state. - return ac.isValidLgAc() ? ac.toString() : ""; - } + case decode_type_t::LG: + case decode_type_t::LG2: { + IRLgAc ac(kGpioUnused); + ac.setRaw(result->value, result->decode_type); // Use value, not state. + return ac.isValidLgAc() ? ac.toString() : ""; + } #endif // DECODE_LG #if DECODE_MIDEA - case decode_type_t::MIDEA: { - IRMideaAC ac(kGpioUnused); - ac.setRaw(result->value); // Midea uses value instead of state. - return ac.toString(); - } + case decode_type_t::MIDEA: { + IRMideaAC ac(kGpioUnused); + ac.setRaw(result->value); // Midea uses value instead of state. + return ac.toString(); + } #endif // DECODE_MIDEA #if DECODE_MIRAGE - case decode_type_t::MIRAGE: { - IRMirageAc ac(kGpioUnused); - ac.setRaw(result->state); - return ac.toString(); - } + case decode_type_t::MIRAGE: { + IRMirageAc ac(kGpioUnused); + ac.setRaw(result->state); + return ac.toString(); + } #endif // DECODE_MIRAGE #if DECODE_MITSUBISHI_AC - case decode_type_t::MITSUBISHI_AC: { - IRMitsubishiAC ac(kGpioUnused); - ac.setRaw(result->state); - return ac.toString(); - } + case decode_type_t::MITSUBISHI_AC: { + IRMitsubishiAC ac(kGpioUnused); + ac.setRaw(result->state); + return ac.toString(); + } #endif // DECODE_MITSUBISHI_AC #if DECODE_MITSUBISHI112 - case decode_type_t::MITSUBISHI112: { - IRMitsubishi112 ac(kGpioUnused); - ac.setRaw(result->state); - return ac.toString(); - } + case decode_type_t::MITSUBISHI112: { + IRMitsubishi112 ac(kGpioUnused); + ac.setRaw(result->state); + return ac.toString(); + } #endif // DECODE_MITSUBISHI112 #if DECODE_MITSUBISHI136 - case decode_type_t::MITSUBISHI136: { - IRMitsubishi136 ac(kGpioUnused); - ac.setRaw(result->state); - return ac.toString(); - } + case decode_type_t::MITSUBISHI136: { + IRMitsubishi136 ac(kGpioUnused); + ac.setRaw(result->state); + return ac.toString(); + } #endif // DECODE_MITSUBISHI136 #if DECODE_MITSUBISHIHEAVY - case decode_type_t::MITSUBISHI_HEAVY_88: { - IRMitsubishiHeavy88Ac ac(kGpioUnused); - ac.setRaw(result->state); - return ac.toString(); - } - case decode_type_t::MITSUBISHI_HEAVY_152: { - IRMitsubishiHeavy152Ac ac(kGpioUnused); - ac.setRaw(result->state); - return ac.toString(); - } + case decode_type_t::MITSUBISHI_HEAVY_88: { + IRMitsubishiHeavy88Ac ac(kGpioUnused); + ac.setRaw(result->state); + return ac.toString(); + } + case decode_type_t::MITSUBISHI_HEAVY_152: { + IRMitsubishiHeavy152Ac ac(kGpioUnused); + ac.setRaw(result->state); + return ac.toString(); + } #endif // DECODE_MITSUBISHIHEAVY #if DECODE_NEOCLIMA - case decode_type_t::NEOCLIMA: { - IRNeoclimaAc ac(kGpioUnused); - ac.setRaw(result->state); - return ac.toString(); - } + case decode_type_t::NEOCLIMA: { + IRNeoclimaAc ac(kGpioUnused); + ac.setRaw(result->state); + return ac.toString(); + } #endif // DECODE_NEOCLIMA #if DECODE_PANASONIC_AC - case decode_type_t::PANASONIC_AC: { - if (result->bits > kPanasonicAcShortBits) { - IRPanasonicAc ac(kGpioUnused); - ac.setRaw(result->state); - return ac.toString(); - } - return ""; + case decode_type_t::PANASONIC_AC: { + if (result->bits > kPanasonicAcShortBits) { + IRPanasonicAc ac(kGpioUnused); + ac.setRaw(result->state); + return ac.toString(); } + return ""; + } #endif // DECODE_PANASONIC_AC #if DECODE_PANASONIC_AC32 - case decode_type_t::PANASONIC_AC32: { - if (result->bits >= kPanasonicAc32Bits) { - IRPanasonicAc32 ac(kGpioUnused); - ac.setRaw(result->value); // Uses value instead of state. - return ac.toString(); - } - return ""; + case decode_type_t::PANASONIC_AC32: { + if (result->bits >= kPanasonicAc32Bits) { + IRPanasonicAc32 ac(kGpioUnused); + ac.setRaw(result->value); // Uses value instead of state. + return ac.toString(); } + return ""; + } #endif // DECODE_PANASONIC_AC #if DECODE_RHOSS - case decode_type_t::RHOSS: { - IRRhossAc ac(kGpioUnused); - ac.setRaw(result->state); - return ac.toString(); - } + case decode_type_t::RHOSS: { + IRRhossAc ac(kGpioUnused); + ac.setRaw(result->state); + return ac.toString(); + } #endif // DECODE_RHOSS #if DECODE_SAMSUNG_AC - case decode_type_t::SAMSUNG_AC: { - IRSamsungAc ac(kGpioUnused); - ac.setRaw(result->state, result->bits / 8); - return ac.toString(); - } + case decode_type_t::SAMSUNG_AC: { + IRSamsungAc ac(kGpioUnused); + ac.setRaw(result->state, result->bits / 8); + return ac.toString(); + } #endif // DECODE_SAMSUNG_AC #if DECODE_SANYO_AC - case decode_type_t::SANYO_AC: { - IRSanyoAc ac(kGpioUnused); - ac.setRaw(result->state); - return ac.toString(); - } + case decode_type_t::SANYO_AC: { + IRSanyoAc ac(kGpioUnused); + ac.setRaw(result->state); + return ac.toString(); + } #endif // DECODE_SANYO_AC #if DECODE_SANYO_AC88 - case decode_type_t::SANYO_AC88: { - IRSanyoAc88 ac(kGpioUnused); - ac.setRaw(result->state); - return ac.toString(); - } + case decode_type_t::SANYO_AC88: { + IRSanyoAc88 ac(kGpioUnused); + ac.setRaw(result->state); + return ac.toString(); + } #endif // DECODE_SANYO_AC88 #if DECODE_SHARP_AC - case decode_type_t::SHARP_AC: { - IRSharpAc ac(kGpioUnused); - ac.setRaw(result->state); - return ac.toString(); - } + case decode_type_t::SHARP_AC: { + IRSharpAc ac(kGpioUnused); + ac.setRaw(result->state); + return ac.toString(); + } #endif // DECODE_SHARP_AC #if (DECODE_TCL112AC || DECODE_TEKNOPOINT) - case decode_type_t::TCL112AC: - case decode_type_t::TEKNOPOINT: { - IRTcl112Ac ac(kGpioUnused); - ac.setRaw(result->state); - return ac.toString(); - } + case decode_type_t::TCL112AC: + case decode_type_t::TEKNOPOINT: { + IRTcl112Ac ac(kGpioUnused); + ac.setRaw(result->state); + return ac.toString(); + } #endif // (DECODE_TCL112AC || DECODE_TEKNOPOINT) #if DECODE_TECHNIBEL_AC - case decode_type_t::TECHNIBEL_AC: { - IRTechnibelAc ac(kGpioUnused); - ac.setRaw(result->value); // TechnibelAc uses value instead of state. - return ac.toString(); - } + case decode_type_t::TECHNIBEL_AC: { + IRTechnibelAc ac(kGpioUnused); + ac.setRaw(result->value); // TechnibelAc uses value instead of state. + return ac.toString(); + } #endif // DECODE_TECHNIBEL_AC #if DECODE_TECO - case decode_type_t::TECO: { - IRTecoAc ac(kGpioUnused); - ac.setRaw(result->value); // Like Coolix, use value instead of state. - return ac.toString(); - } + case decode_type_t::TECO: { + IRTecoAc ac(kGpioUnused); + ac.setRaw(result->value); // Like Coolix, use value instead of state. + return ac.toString(); + } #endif // DECODE_TECO #if DECODE_TOSHIBA_AC - case decode_type_t::TOSHIBA_AC: { - IRToshibaAC ac(kGpioUnused); - ac.setRaw(result->state, result->bits / 8); - return ac.toString(); - } + case decode_type_t::TOSHIBA_AC: { + IRToshibaAC ac(kGpioUnused); + ac.setRaw(result->state, result->bits / 8); + return ac.toString(); + } #endif // DECODE_TOSHIBA_AC #if DECODE_TRANSCOLD - case decode_type_t::TRANSCOLD: { - IRTranscoldAc ac(kGpioUnused); - ac.on(); - ac.setRaw(result->value); // TRANSCOLD uses value instead of state. - return ac.toString(); - } + case decode_type_t::TRANSCOLD: { + IRTranscoldAc ac(kGpioUnused); + ac.on(); + ac.setRaw(result->value); // TRANSCOLD uses value instead of state. + return ac.toString(); + } #endif // DECODE_TRANSCOLD #if DECODE_TROTEC - case decode_type_t::TROTEC: { - IRTrotecESP ac(kGpioUnused); - ac.setRaw(result->state); - return ac.toString(); - } + case decode_type_t::TROTEC: { + IRTrotecESP ac(kGpioUnused); + ac.setRaw(result->state); + return ac.toString(); + } #endif // DECODE_TROTEC #if DECODE_TROTEC_3550 - case decode_type_t::TROTEC_3550: { - IRTrotec3550 ac(kGpioUnused); - ac.setRaw(result->state); - return ac.toString(); - } + case decode_type_t::TROTEC_3550: { + IRTrotec3550 ac(kGpioUnused); + ac.setRaw(result->state); + return ac.toString(); + } #endif // DECODE_TROTEC_3550 #if DECODE_TRUMA - case decode_type_t::TRUMA: { - IRTrumaAc ac(kGpioUnused); - ac.setRaw(result->value); // Truma uses value instead of state. - return ac.toString(); - } + case decode_type_t::TRUMA: { + IRTrumaAc ac(kGpioUnused); + ac.setRaw(result->value); // Truma uses value instead of state. + return ac.toString(); + } #endif // DECODE_TRUMA #if DECODE_VESTEL_AC - case decode_type_t::VESTEL_AC: { - IRVestelAc ac(kGpioUnused); - ac.setRaw(result->value); // Like Coolix, use value instead of state. - return ac.toString(); - } + case decode_type_t::VESTEL_AC: { + IRVestelAc ac(kGpioUnused); + ac.setRaw(result->value); // Like Coolix, use value instead of state. + return ac.toString(); + } #endif // DECODE_VESTEL_AC #if DECODE_VOLTAS - case decode_type_t::VOLTAS: { - IRVoltas ac(kGpioUnused); - ac.setRaw(result->state); - return ac.toString(); - } + case decode_type_t::VOLTAS: { + IRVoltas ac(kGpioUnused); + ac.setRaw(result->state); + return ac.toString(); + } #endif // DECODE_VOLTAS #if DECODE_WHIRLPOOL_AC - case decode_type_t::WHIRLPOOL_AC: { - IRWhirlpoolAc ac(kGpioUnused); - ac.setRaw(result->state); - return ac.toString(); - } + case decode_type_t::WHIRLPOOL_AC: { + IRWhirlpoolAc ac(kGpioUnused); + ac.setRaw(result->state); + return ac.toString(); + } #endif // DECODE_WHIRLPOOL_AC #if DECODE_YORK - case decode_type_t::YORK: { - IRYorkAc ac(kGpioUnused); - ac.setRaw(result->state); - return ac.toString(); - } -#endif // DECODE_YORK - default: - return ""; + case decode_type_t::YORK: { + IRYorkAc ac(kGpioUnused); + ac.setRaw(result->state); + return ac.toString(); } +#endif // DECODE_YORK + default: + return ""; } +} - /// Convert a valid IR A/C remote message that we understand enough into a - /// Common A/C state. - /// @param[in] decode A PTR to a successful raw IR decode object. - /// @param[in] result A PTR to a state structure to store the result in. - /// @param[in] prev A PTR to a state structure which has the prev. state. - /// @return A boolean indicating success or failure. - bool decodeToState(const decode_results *decode, stdAc::state_t *result, - const stdAc::state_t *prev +/// Convert a valid IR A/C remote message that we understand enough into a +/// Common A/C state. +/// @param[in] decode A PTR to a successful raw IR decode object. +/// @param[in] result A PTR to a state structure to store the result in. +/// @param[in] prev A PTR to a state structure which has the prev. state. +/// @return A boolean indicating success or failure. +bool decodeToState(const decode_results *decode, stdAc::state_t *result, + const stdAc::state_t *prev /// @cond IGNORE // *prev flagged as "unused" due to potential compiler warning when some // protocols that use it are disabled. It really is used. - __attribute__((unused)) + __attribute__((unused)) /// @endcond - ) { - if (decode == NULL || result == NULL) return false; // Safety check. - switch (decode->decode_type) { + ) { + if (decode == NULL || result == NULL) return false; // Safety check. + switch (decode->decode_type) { #if DECODE_AIRTON - case decode_type_t::AIRTON: { - IRAirtonAc ac(kGpioUnused); - ac.setRaw(decode->value); // Uses value instead of state. - *result = ac.toCommon(); - break; - } + case decode_type_t::AIRTON: { + IRAirtonAc ac(kGpioUnused); + ac.setRaw(decode->value); // Uses value instead of state. + *result = ac.toCommon(); + break; + } #endif // DECODE_AIRTON #if DECODE_AIRWELL - case decode_type_t::AIRWELL: { - IRAirwellAc ac(kGpioUnused); - ac.setRaw(decode->value); // Uses value instead of state. - *result = ac.toCommon(prev); - break; - } + case decode_type_t::AIRWELL: { + IRAirwellAc ac(kGpioUnused); + ac.setRaw(decode->value); // Uses value instead of state. + *result = ac.toCommon(prev); + break; + } #endif // DECODE_AIRWELL #if DECODE_AMCOR - case decode_type_t::AMCOR: { - IRAmcorAc ac(kGpioUnused); - ac.setRaw(decode->state); - *result = ac.toCommon(); - break; - } + case decode_type_t::AMCOR: { + IRAmcorAc ac(kGpioUnused); + ac.setRaw(decode->state); + *result = ac.toCommon(); + break; + } #endif // DECODE_AMCOR #if DECODE_ARGO - case decode_type_t::ARGO: { - const uint16_t length = decode->bits / 8; - if (IRArgoAC_WREM3::isValidWrem3Message(decode->state, - decode->bits, true)) { - IRArgoAC_WREM3 ac(kGpioUnused); - ac.setRaw(decode->state, length); - *result = ac.toCommon(); - } else { - IRArgoAC ac(kGpioUnused); - switch (length) { - case kArgoStateLength: - case kArgoShortStateLength: - ac.setRaw(decode->state, length); - *result = ac.toCommon(); - break; - default: - return false; - } + case decode_type_t::ARGO: { + const uint16_t length = decode->bits / 8; + if (IRArgoAC_WREM3::isValidWrem3Message(decode->state, + decode->bits, true)) { + IRArgoAC_WREM3 ac(kGpioUnused); + ac.setRaw(decode->state, length); + *result = ac.toCommon(); + } else { + IRArgoAC ac(kGpioUnused); + switch (length) { + case kArgoStateLength: + case kArgoShortStateLength: + ac.setRaw(decode->state, length); + *result = ac.toCommon(); + break; + default: + return false; } - break; } + break; + } #endif // DECODE_ARGO #if DECODE_BOSCH144 - case decode_type_t::BOSCH144: { - IRBosch144AC ac(kGpioUnused); - ac.setRaw(decode->state); - *result = ac.toCommon(); - break; - } + case decode_type_t::BOSCH144: { + IRBosch144AC ac(kGpioUnused); + ac.setRaw(decode->state); + *result = ac.toCommon(); + break; + } #endif // DECODE_BOSCH144 #if DECODE_CARRIER_AC64 - case decode_type_t::CARRIER_AC64: { - IRCarrierAc64 ac(kGpioUnused); - ac.setRaw(decode->value); // Uses value instead of state. - *result = ac.toCommon(); - break; - } + case decode_type_t::CARRIER_AC64: { + IRCarrierAc64 ac(kGpioUnused); + ac.setRaw(decode->value); // Uses value instead of state. + *result = ac.toCommon(); + break; + } #endif // DECODE_CARRIER_AC64 #if DECODE_COOLIX - case decode_type_t::COOLIX: { - IRCoolixAC ac(kGpioUnused); - ac.setRaw(decode->value); // Uses value instead of state. - *result = ac.toCommon(prev); - break; - } + case decode_type_t::COOLIX: { + IRCoolixAC ac(kGpioUnused); + ac.setRaw(decode->value); // Uses value instead of state. + *result = ac.toCommon(prev); + break; + } #endif // DECODE_COOLIX #if DECODE_CORONA_AC - case decode_type_t::CORONA_AC: { - IRCoronaAc ac(kGpioUnused); - ac.setRaw(decode->state, decode->bits / 8); - *result = ac.toCommon(); - break; - } + case decode_type_t::CORONA_AC: { + IRCoronaAc ac(kGpioUnused); + ac.setRaw(decode->state, decode->bits / 8); + *result = ac.toCommon(); + break; + } #endif // DECODE_CARRIER_AC64 #if DECODE_DAIKIN - case decode_type_t::DAIKIN: { - IRDaikinESP ac(kGpioUnused); - ac.setRaw(decode->state); - *result = ac.toCommon(); - break; - } + case decode_type_t::DAIKIN: { + IRDaikinESP ac(kGpioUnused); + ac.setRaw(decode->state); + *result = ac.toCommon(); + break; + } #endif // DECODE_DAIKIN #if DECODE_DAIKIN128 - case decode_type_t::DAIKIN128: { - IRDaikin128 ac(kGpioUnused); - ac.setRaw(decode->state); - *result = ac.toCommon(prev); - break; - } + case decode_type_t::DAIKIN128: { + IRDaikin128 ac(kGpioUnused); + ac.setRaw(decode->state); + *result = ac.toCommon(prev); + break; + } #endif // DECODE_DAIKIN128 #if DECODE_DAIKIN152 - case decode_type_t::DAIKIN152: { - IRDaikin152 ac(kGpioUnused); - ac.setRaw(decode->state); - *result = ac.toCommon(); - break; - } + case decode_type_t::DAIKIN152: { + IRDaikin152 ac(kGpioUnused); + ac.setRaw(decode->state); + *result = ac.toCommon(); + break; + } #endif // DECODE_DAIKIN152 #if DECODE_DAIKIN160 - case decode_type_t::DAIKIN160: { - IRDaikin160 ac(kGpioUnused); - ac.setRaw(decode->state); - *result = ac.toCommon(); - break; - } + case decode_type_t::DAIKIN160: { + IRDaikin160 ac(kGpioUnused); + ac.setRaw(decode->state); + *result = ac.toCommon(); + break; + } #endif // DECODE_DAIKIN160 #if DECODE_DAIKIN176 - case decode_type_t::DAIKIN176: { - IRDaikin176 ac(kGpioUnused); - ac.setRaw(decode->state); - *result = ac.toCommon(); - break; - } + case decode_type_t::DAIKIN176: { + IRDaikin176 ac(kGpioUnused); + ac.setRaw(decode->state); + *result = ac.toCommon(); + break; + } #endif // DECODE_DAIKIN160 #if DECODE_DAIKIN2 - case decode_type_t::DAIKIN2: { - IRDaikin2 ac(kGpioUnused); - ac.setRaw(decode->state); - *result = ac.toCommon(); - break; - } + case decode_type_t::DAIKIN2: { + IRDaikin2 ac(kGpioUnused); + ac.setRaw(decode->state); + *result = ac.toCommon(); + break; + } #endif // DECODE_DAIKIN2 #if DECODE_DAIKIN216 - case decode_type_t::DAIKIN216: { - IRDaikin216 ac(kGpioUnused); - ac.setRaw(decode->state); - *result = ac.toCommon(); - break; - } + case decode_type_t::DAIKIN216: { + IRDaikin216 ac(kGpioUnused); + ac.setRaw(decode->state); + *result = ac.toCommon(); + break; + } #endif // DECODE_DAIKIN216 #if DECODE_DAIKIN64 - case decode_type_t::DAIKIN64: { - IRDaikin64 ac(kGpioUnused); - ac.setRaw(decode->value); // Uses value instead of state. - *result = ac.toCommon(prev); - break; - } + case decode_type_t::DAIKIN64: { + IRDaikin64 ac(kGpioUnused); + ac.setRaw(decode->value); // Uses value instead of state. + *result = ac.toCommon(prev); + break; + } #endif // DECODE_DAIKIN64 #if DECODE_DELONGHI_AC - case decode_type_t::DELONGHI_AC: { - IRDelonghiAc ac(kGpioUnused); - ac.setRaw(decode->value); // Uses value instead of state. - *result = ac.toCommon(); - break; - } + case decode_type_t::DELONGHI_AC: { + IRDelonghiAc ac(kGpioUnused); + ac.setRaw(decode->value); // Uses value instead of state. + *result = ac.toCommon(); + break; + } #endif // DECODE_DELONGHI_AC #if DECODE_ECOCLIM - case decode_type_t::ECOCLIM: { - if (decode->bits == kEcoclimBits) { - IREcoclimAc ac(kGpioUnused); - ac.setRaw(decode->value); // Uses value instead of state. - *result = ac.toCommon(); - } else { - return false; - } - break; + case decode_type_t::ECOCLIM: { + if (decode->bits == kEcoclimBits) { + IREcoclimAc ac(kGpioUnused); + ac.setRaw(decode->value); // Uses value instead of state. + *result = ac.toCommon(); + } else { + return false; } + break; + } #endif // DECODE_ECOCLIM #if DECODE_ELECTRA_AC - case decode_type_t::ELECTRA_AC: { - IRElectraAc ac(kGpioUnused); - ac.setRaw(decode->state); - *result = ac.toCommon(); - break; - } + case decode_type_t::ELECTRA_AC: { + IRElectraAc ac(kGpioUnused); + ac.setRaw(decode->state); + *result = ac.toCommon(); + break; + } #endif // DECODE_ELECTRA_AC #if DECODE_FUJITSU_AC - case decode_type_t::FUJITSU_AC: { - IRFujitsuAC ac(kGpioUnused); - ac.setRaw(decode->state, decode->bits / 8); - *result = ac.toCommon(prev); - break; - } + case decode_type_t::FUJITSU_AC: { + IRFujitsuAC ac(kGpioUnused); + ac.setRaw(decode->state, decode->bits / 8); + *result = ac.toCommon(prev); + break; + } #endif // DECODE_FUJITSU_AC #if DECODE_GOODWEATHER - case decode_type_t::GOODWEATHER: { - IRGoodweatherAc ac(kGpioUnused); - ac.setRaw(decode->value); // Uses value instead of state. - *result = ac.toCommon(); - break; - } + case decode_type_t::GOODWEATHER: { + IRGoodweatherAc ac(kGpioUnused); + ac.setRaw(decode->value); // Uses value instead of state. + *result = ac.toCommon(); + break; + } #endif // DECODE_GOODWEATHER #if DECODE_GREE - case decode_type_t::GREE: { - IRGreeAC ac(kGpioUnused); - ac.setRaw(decode->state); - *result = ac.toCommon(); - break; - } + case decode_type_t::GREE: { + IRGreeAC ac(kGpioUnused); + ac.setRaw(decode->state); + *result = ac.toCommon(); + break; + } #endif // DECODE_GREE #if DECODE_HAIER_AC - case decode_type_t::HAIER_AC: { - IRHaierAC ac(kGpioUnused); - ac.setRaw(decode->state); - *result = ac.toCommon(); - break; - } + case decode_type_t::HAIER_AC: { + IRHaierAC ac(kGpioUnused); + ac.setRaw(decode->state); + *result = ac.toCommon(); + break; + } #endif // DECODE_HAIER_AC #if DECODE_HAIER_AC160 - case decode_type_t::HAIER_AC160: { - IRHaierAC160 ac(kGpioUnused); - ac.setRaw(decode->state); - *result = ac.toCommon(prev); - break; - } + case decode_type_t::HAIER_AC160: { + IRHaierAC160 ac(kGpioUnused); + ac.setRaw(decode->state); + *result = ac.toCommon(prev); + break; + } #endif // DECODE_HAIER_AC160 #if DECODE_HAIER_AC176 - case decode_type_t::HAIER_AC176: { - IRHaierAC176 ac(kGpioUnused); - ac.setRaw(decode->state); - *result = ac.toCommon(); - break; - } + case decode_type_t::HAIER_AC176: { + IRHaierAC176 ac(kGpioUnused); + ac.setRaw(decode->state); + *result = ac.toCommon(); + break; + } #endif // DECODE_HAIER_AC176 #if DECODE_HAIER_AC_YRW02 - case decode_type_t::HAIER_AC_YRW02: { - IRHaierACYRW02 ac(kGpioUnused); - ac.setRaw(decode->state); - *result = ac.toCommon(); - break; - } + case decode_type_t::HAIER_AC_YRW02: { + IRHaierACYRW02 ac(kGpioUnused); + ac.setRaw(decode->state); + *result = ac.toCommon(); + break; + } #endif // DECODE_HAIER_AC_YRW02 #if (DECODE_HITACHI_AC || DECODE_HITACHI_AC2) - case decode_type_t::HITACHI_AC: { - IRHitachiAc ac(kGpioUnused); - ac.setRaw(decode->state); - *result = ac.toCommon(); - break; - } + case decode_type_t::HITACHI_AC: { + IRHitachiAc ac(kGpioUnused); + ac.setRaw(decode->state); + *result = ac.toCommon(); + break; + } #endif // (DECODE_HITACHI_AC || DECODE_HITACHI_AC2) #if DECODE_HITACHI_AC1 - case decode_type_t::HITACHI_AC1: { - IRHitachiAc1 ac(kGpioUnused); - ac.setRaw(decode->state); - *result = ac.toCommon(); - break; - } + case decode_type_t::HITACHI_AC1: { + IRHitachiAc1 ac(kGpioUnused); + ac.setRaw(decode->state); + *result = ac.toCommon(); + break; + } #endif // DECODE_HITACHI_AC1 #if DECODE_HITACHI_AC264 - case decode_type_t::HITACHI_AC264: { - IRHitachiAc264 ac(kGpioUnused); - ac.setRaw(decode->state); - *result = ac.toCommon(); - break; - } + case decode_type_t::HITACHI_AC264: { + IRHitachiAc264 ac(kGpioUnused); + ac.setRaw(decode->state); + *result = ac.toCommon(); + break; + } #endif // DECODE_HITACHI_AC264 #if DECODE_HITACHI_AC296 - case decode_type_t::HITACHI_AC296: { - IRHitachiAc296 ac(kGpioUnused); - ac.setRaw(decode->state); - *result = ac.toCommon(); - break; - } + case decode_type_t::HITACHI_AC296: { + IRHitachiAc296 ac(kGpioUnused); + ac.setRaw(decode->state); + *result = ac.toCommon(); + break; + } #endif // DECODE_HITACHI_AC296 #if DECODE_HITACHI_AC344 - case decode_type_t::HITACHI_AC344: { - IRHitachiAc344 ac(kGpioUnused); - ac.setRaw(decode->state); - *result = ac.toCommon(); - break; - } + case decode_type_t::HITACHI_AC344: { + IRHitachiAc344 ac(kGpioUnused); + ac.setRaw(decode->state); + *result = ac.toCommon(); + break; + } #endif // DECODE_HITACHI_AC344 #if DECODE_HITACHI_AC424 - case decode_type_t::HITACHI_AC424: { - IRHitachiAc424 ac(kGpioUnused); - ac.setRaw(decode->state); - *result = ac.toCommon(); - break; - } + case decode_type_t::HITACHI_AC424: { + IRHitachiAc424 ac(kGpioUnused); + ac.setRaw(decode->state); + *result = ac.toCommon(); + break; + } #endif // DECODE_HITACHI_AC424 #if DECODE_KELON - case decode_type_t::KELON: { - IRKelonAc ac(kGpioUnused); - ac.setRaw(decode->value); - *result = ac.toCommon(prev); - break; - } + case decode_type_t::KELON: { + IRKelonAc ac(kGpioUnused); + ac.setRaw(decode->value); + *result = ac.toCommon(prev); + break; + } #endif // DECODE_KELON #if DECODE_KELVINATOR - case decode_type_t::KELVINATOR: { - IRKelvinatorAC ac(kGpioUnused); - ac.setRaw(decode->state); - *result = ac.toCommon(); - break; - } + case decode_type_t::KELVINATOR: { + IRKelvinatorAC ac(kGpioUnused); + ac.setRaw(decode->state); + *result = ac.toCommon(); + break; + } #endif // DECODE_KELVINATOR #if DECODE_LG - case decode_type_t::LG: - case decode_type_t::LG2: { - IRLgAc ac(kGpioUnused); - ac.setRaw(decode->value, decode->decode_type); // Use value, not state. - if (!ac.isValidLgAc()) return false; - *result = ac.toCommon(prev); - break; - } + case decode_type_t::LG: + case decode_type_t::LG2: { + IRLgAc ac(kGpioUnused); + ac.setRaw(decode->value, decode->decode_type); // Use value, not state. + if (!ac.isValidLgAc()) return false; + *result = ac.toCommon(prev); + break; + } #endif // DECODE_LG #if DECODE_MIDEA - case decode_type_t::MIDEA: { - IRMideaAC ac(kGpioUnused); - ac.setRaw(decode->value); // Uses value instead of state. - *result = ac.toCommon(prev); - break; - } + case decode_type_t::MIDEA: { + IRMideaAC ac(kGpioUnused); + ac.setRaw(decode->value); // Uses value instead of state. + *result = ac.toCommon(prev); + break; + } #endif // DECODE_MIDEA #if DECODE_MIRAGE - case decode_type_t::MIRAGE: { - IRMirageAc ac(kGpioUnused); - ac.setRaw(decode->state); - *result = ac.toCommon(); - break; - } + case decode_type_t::MIRAGE: { + IRMirageAc ac(kGpioUnused); + ac.setRaw(decode->state); + *result = ac.toCommon(); + break; + } #endif // DECODE_MIRAGE #if DECODE_MITSUBISHI_AC - case decode_type_t::MITSUBISHI_AC: { - IRMitsubishiAC ac(kGpioUnused); - ac.setRaw(decode->state); - *result = ac.toCommon(); - break; - } + case decode_type_t::MITSUBISHI_AC: { + IRMitsubishiAC ac(kGpioUnused); + ac.setRaw(decode->state); + *result = ac.toCommon(); + break; + } #endif // DECODE_MITSUBISHI_AC #if DECODE_MITSUBISHI112 - case decode_type_t::MITSUBISHI112: { - IRMitsubishi112 ac(kGpioUnused); - ac.setRaw(decode->state); - *result = ac.toCommon(); - break; - } + case decode_type_t::MITSUBISHI112: { + IRMitsubishi112 ac(kGpioUnused); + ac.setRaw(decode->state); + *result = ac.toCommon(); + break; + } #endif // DECODE_MITSUBISHI112 #if DECODE_MITSUBISHI136 - case decode_type_t::MITSUBISHI136: { - IRMitsubishi136 ac(kGpioUnused); - ac.setRaw(decode->state); - *result = ac.toCommon(); - break; - } + case decode_type_t::MITSUBISHI136: { + IRMitsubishi136 ac(kGpioUnused); + ac.setRaw(decode->state); + *result = ac.toCommon(); + break; + } #endif // DECODE_MITSUBISHI136 #if DECODE_MITSUBISHIHEAVY - case decode_type_t::MITSUBISHI_HEAVY_88: { - IRMitsubishiHeavy88Ac ac(kGpioUnused); - ac.setRaw(decode->state); - *result = ac.toCommon(); - break; - } - case decode_type_t::MITSUBISHI_HEAVY_152: { - IRMitsubishiHeavy152Ac ac(kGpioUnused); - ac.setRaw(decode->state); - *result = ac.toCommon(); - break; - } + case decode_type_t::MITSUBISHI_HEAVY_88: { + IRMitsubishiHeavy88Ac ac(kGpioUnused); + ac.setRaw(decode->state); + *result = ac.toCommon(); + break; + } + case decode_type_t::MITSUBISHI_HEAVY_152: { + IRMitsubishiHeavy152Ac ac(kGpioUnused); + ac.setRaw(decode->state); + *result = ac.toCommon(); + break; + } #endif // DECODE_MITSUBISHIHEAVY #if DECODE_NEOCLIMA - case decode_type_t::NEOCLIMA: { - IRNeoclimaAc ac(kGpioUnused); - ac.setRaw(decode->state); - *result = ac.toCommon(); - break; - } + case decode_type_t::NEOCLIMA: { + IRNeoclimaAc ac(kGpioUnused); + ac.setRaw(decode->state); + *result = ac.toCommon(); + break; + } #endif // DECODE_NEOCLIMA #if DECODE_PANASONIC_AC - case decode_type_t::PANASONIC_AC: { - IRPanasonicAc ac(kGpioUnused); - ac.setRaw(decode->state); - *result = ac.toCommon(); - break; - } + case decode_type_t::PANASONIC_AC: { + IRPanasonicAc ac(kGpioUnused); + ac.setRaw(decode->state); + *result = ac.toCommon(); + break; + } #endif // DECODE_PANASONIC_AC #if DECODE_PANASONIC_AC32 - case decode_type_t::PANASONIC_AC32: { - IRPanasonicAc32 ac(kGpioUnused); - if (decode->bits >= kPanasonicAc32Bits) { - ac.setRaw(decode->value); // Uses value instead of state. - *result = ac.toCommon(prev); - } else { - return false; - } - break; + case decode_type_t::PANASONIC_AC32: { + IRPanasonicAc32 ac(kGpioUnused); + if (decode->bits >= kPanasonicAc32Bits) { + ac.setRaw(decode->value); // Uses value instead of state. + *result = ac.toCommon(prev); + } else { + return false; } + break; + } #endif // DECODE_PANASONIC_AC32 #if DECODE_RHOSS - case decode_type_t::RHOSS: { - IRRhossAc ac(kGpioUnused); - ac.setRaw(decode->state); - *result = ac.toCommon(); - break; - } + case decode_type_t::RHOSS: { + IRRhossAc ac(kGpioUnused); + ac.setRaw(decode->state); + *result = ac.toCommon(); + break; + } #endif // DECODE_RHOSS #if DECODE_SAMSUNG_AC - case decode_type_t::SAMSUNG_AC: { - IRSamsungAc ac(kGpioUnused); - ac.setRaw(decode->state, decode->bits / 8); - *result = ac.toCommon(); - break; - } + case decode_type_t::SAMSUNG_AC: { + IRSamsungAc ac(kGpioUnused); + ac.setRaw(decode->state, decode->bits / 8); + *result = ac.toCommon(); + break; + } #endif // DECODE_SAMSUNG_AC #if DECODE_SANYO_AC - case decode_type_t::SANYO_AC: { - IRSanyoAc ac(kGpioUnused); - ac.setRaw(decode->state); - *result = ac.toCommon(); - break; - } + case decode_type_t::SANYO_AC: { + IRSanyoAc ac(kGpioUnused); + ac.setRaw(decode->state); + *result = ac.toCommon(); + break; + } #endif // DECODE_SANYO_AC #if DECODE_SANYO_AC88 - case decode_type_t::SANYO_AC88: { - IRSanyoAc88 ac(kGpioUnused); - ac.setRaw(decode->state); - *result = ac.toCommon(); - break; - } + case decode_type_t::SANYO_AC88: { + IRSanyoAc88 ac(kGpioUnused); + ac.setRaw(decode->state); + *result = ac.toCommon(); + break; + } #endif // DECODE_SANYO_AC88 #if DECODE_SHARP_AC - case decode_type_t::SHARP_AC: { - IRSharpAc ac(kGpioUnused); - ac.setRaw(decode->state); - *result = ac.toCommon(prev); - break; - } + case decode_type_t::SHARP_AC: { + IRSharpAc ac(kGpioUnused); + ac.setRaw(decode->state); + *result = ac.toCommon(prev); + break; + } #endif // DECODE_SHARP_AC #if (DECODE_TCL112AC || DECODE_TEKNOPOINT) - case decode_type_t::TCL112AC: - case decode_type_t::TEKNOPOINT: { - IRTcl112Ac ac(kGpioUnused); - ac.setRaw(decode->state); - *result = ac.toCommon(prev); - // Teknopoint uses the TCL protocol, but with a different model number. - // Just keep the original protocol type ... for now. - result->protocol = decode->decode_type; - break; - } + case decode_type_t::TCL112AC: + case decode_type_t::TEKNOPOINT: { + IRTcl112Ac ac(kGpioUnused); + ac.setRaw(decode->state); + *result = ac.toCommon(prev); + // Teknopoint uses the TCL protocol, but with a different model number. + // Just keep the original protocol type ... for now. + result->protocol = decode->decode_type; + break; + } #endif // (DECODE_TCL112AC || DECODE_TEKNOPOINT) #if DECODE_TECHNIBEL_AC - case decode_type_t::TECHNIBEL_AC: { - IRTechnibelAc ac(kGpioUnused); - ac.setRaw(decode->value); // Uses value instead of state. - *result = ac.toCommon(); - break; - } + case decode_type_t::TECHNIBEL_AC: { + IRTechnibelAc ac(kGpioUnused); + ac.setRaw(decode->value); // Uses value instead of state. + *result = ac.toCommon(); + break; + } #endif // DECODE_TECHNIBEL_AC #if DECODE_TECO - case decode_type_t::TECO: { - IRTecoAc ac(kGpioUnused); - ac.setRaw(decode->value); // Uses value instead of state. - *result = ac.toCommon(); - break; - } + case decode_type_t::TECO: { + IRTecoAc ac(kGpioUnused); + ac.setRaw(decode->value); // Uses value instead of state. + *result = ac.toCommon(); + break; + } #endif // DECODE_TECO #if DECODE_TOSHIBA_AC - case decode_type_t::TOSHIBA_AC: { - IRToshibaAC ac(kGpioUnused); - ac.setRaw(decode->state, decode->bits / 8); - *result = ac.toCommon(prev); - break; - } + case decode_type_t::TOSHIBA_AC: { + IRToshibaAC ac(kGpioUnused); + ac.setRaw(decode->state, decode->bits / 8); + *result = ac.toCommon(prev); + break; + } #endif // DECODE_TOSHIBA_AC #if DECODE_TRANSCOLD - case decode_type_t::TRANSCOLD: { - IRTranscoldAc ac(kGpioUnused); - ac.setRaw(decode->value); // TRANSCOLD Uses value instead of state. - *result = ac.toCommon(prev); - break; - } + case decode_type_t::TRANSCOLD: { + IRTranscoldAc ac(kGpioUnused); + ac.setRaw(decode->value); // TRANSCOLD Uses value instead of state. + *result = ac.toCommon(prev); + break; + } #endif // DECODE_TRANSCOLD #if DECODE_TROTEC - case decode_type_t::TROTEC: { - IRTrotecESP ac(kGpioUnused); - ac.setRaw(decode->state); - *result = ac.toCommon(); - break; - } + case decode_type_t::TROTEC: { + IRTrotecESP ac(kGpioUnused); + ac.setRaw(decode->state); + *result = ac.toCommon(); + break; + } #endif // DECODE_TROTEC #if DECODE_TROTEC_3550 - case decode_type_t::TROTEC_3550: { - IRTrotec3550 ac(kGpioUnused); - ac.setRaw(decode->state); - *result = ac.toCommon(); - break; - } + case decode_type_t::TROTEC_3550: { + IRTrotec3550 ac(kGpioUnused); + ac.setRaw(decode->state); + *result = ac.toCommon(); + break; + } #endif // DECODE_TROTEC_3550 #if DECODE_TRUMA - case decode_type_t::TRUMA: { - IRTrumaAc ac(kGpioUnused); - ac.setRaw(decode->value); // Uses value instead of state. - *result = ac.toCommon(); - break; - } + case decode_type_t::TRUMA: { + IRTrumaAc ac(kGpioUnused); + ac.setRaw(decode->value); // Uses value instead of state. + *result = ac.toCommon(); + break; + } #endif // DECODE_TRUMA #if DECODE_VESTEL_AC - case decode_type_t::VESTEL_AC: { - IRVestelAc ac(kGpioUnused); - ac.setRaw(decode->value); // Uses value instead of state. - *result = ac.toCommon(); - break; - } + case decode_type_t::VESTEL_AC: { + IRVestelAc ac(kGpioUnused); + ac.setRaw(decode->value); // Uses value instead of state. + *result = ac.toCommon(); + break; + } #endif // DECODE_VESTEL_AC #if DECODE_VOLTAS - case decode_type_t::VOLTAS: { - IRVoltas ac(kGpioUnused); - ac.setRaw(decode->state); - *result = ac.toCommon(prev); - break; - } + case decode_type_t::VOLTAS: { + IRVoltas ac(kGpioUnused); + ac.setRaw(decode->state); + *result = ac.toCommon(prev); + break; + } #endif // DECODE_VOLTAS #if DECODE_WHIRLPOOL_AC - case decode_type_t::WHIRLPOOL_AC: { - IRWhirlpoolAc ac(kGpioUnused); - ac.setRaw(decode->state); - *result = ac.toCommon(prev); - break; - } + case decode_type_t::WHIRLPOOL_AC: { + IRWhirlpoolAc ac(kGpioUnused); + ac.setRaw(decode->state); + *result = ac.toCommon(prev); + break; + } #endif // DECODE_WHIRLPOOL_AC #if DECODE_YORK - case decode_type_t::YORK: { - IRYorkAc ac(kGpioUnused); - ac.setRaw(decode->state); - *result = ac.toCommon(prev); - break; - } -#endif // DECODE_YORK - default: - return false; + case decode_type_t::YORK: { + IRYorkAc ac(kGpioUnused); + ac.setRaw(decode->state); + *result = ac.toCommon(prev); + break; } - return true; +#endif // DECODE_YORK + default: + return false; } + return true; +} } // namespace IRAcUtils diff --git a/src/IRac.h b/src/IRac.h index e3c261d0d..ae78b8ce3 100644 --- a/src/IRac.h +++ b/src/IRac.h @@ -574,8 +574,8 @@ static stdAc::state_t handleToggles(const stdAc::state_t desired, /// Common functions for use with all A/Cs supported by the IRac class. namespace IRAcUtils { - String resultAcToString(const decode_results * const results); - bool decodeToState(const decode_results *decode, stdAc::state_t *result, - const stdAc::state_t *prev = NULL); +String resultAcToString(const decode_results * const results); +bool decodeToState(const decode_results *decode, stdAc::state_t *result, + const stdAc::state_t *prev = NULL); } // namespace IRAcUtils #endif // IRAC_H_ diff --git a/src/IRrecv.cpp b/src/IRrecv.cpp index 316dfc149..3cd88b377 100644 --- a/src/IRrecv.cpp +++ b/src/IRrecv.cpp @@ -233,8 +233,8 @@ static void USE_IRAM_ATTR gpio_intr() { // USE_IRAM_ATTR in this ISR. // @see https://github.com/crankyoldgit/IRremoteESP8266/issues/1350 // @see https://github.com/espressif/arduino-esp32/blob/6b0114366baf986c155e8173ab7c22bc0c5fcedc/cores/esp32/esp32-hal-timer.c#L106-L110 - timer->dev->load_high = (uint32_t) 0; - timer->dev->load_low = (uint32_t) 0; + timer->dev->load_high = static_cast(0); + timer->dev->load_low = static_cast(0); timer->dev->reload = 1; // The next line is the same, but instead replaces: // `timerAlarmEnable(timer);` @@ -1219,9 +1219,10 @@ uint8_t IRrecv::_validTolerance(const uint8_t percentage) { uint32_t IRrecv::ticksLow(const uint32_t usecs, const uint8_t tolerance, const uint16_t delta) { // max() used to ensure the result can't drop below 0 before the cast. - return ((uint32_t)std::max( - (int32_t)(usecs * (1.0 - _validTolerance(tolerance) / 100.0) - delta), - (int32_t)0)); + return (static_cast(std::max( + static_cast(usecs * (1.0 - _validTolerance(tolerance) / 100.0) - + delta), + static_cast(0)))); } /// Calculate the upper bound of the nr. of ticks. @@ -1231,8 +1232,8 @@ uint32_t IRrecv::ticksLow(const uint32_t usecs, const uint8_t tolerance, /// @return Nr. of ticks. uint32_t IRrecv::ticksHigh(const uint32_t usecs, const uint8_t tolerance, const uint16_t delta) { - return ((uint32_t)(usecs * (1.0 + _validTolerance(tolerance) / 100.0)) + 1 + - delta); + return (static_cast(usecs * (1.0 + _validTolerance(tolerance) / + 100.0)) + 1 + delta); } /// Check if we match a pulse(measured) with the desired within @@ -1283,7 +1284,8 @@ bool IRrecv::matchAtLeast(uint32_t measured, uint32_t desired, DPRINT(". Matching: "); DPRINT(measured); DPRINT(" >= "); - DPRINT(ticksLow(std::min(desired, (uint32_t)MS_TO_USEC(params.timeout)), + DPRINT(ticksLow(std::min(desired, + static_cast(MS_TO_USEC(params.timeout))), tolerance, delta)); DPRINT(" [min("); DPRINT(ticksLow(desired, tolerance, delta)); @@ -1304,9 +1306,9 @@ bool IRrecv::matchAtLeast(uint32_t measured, uint32_t desired, // We really should never get a value of 0, except as the last value // in the buffer. If that is the case, then assume infinity and return true. if (measured == 0) return true; - return measured >= ticksLow(std::min(desired, - (uint32_t)MS_TO_USEC(params.timeout)), - tolerance, delta); + return measured >= ticksLow(std::min( + desired, static_cast(MS_TO_USEC(params.timeout))), tolerance, + delta); } /// Check if we match a mark signal(measured) with the desired within diff --git a/src/IRremoteESP8266.h b/src/IRremoteESP8266.h index b5daffaf8..4a0e60bf2 100644 --- a/src/IRremoteESP8266.h +++ b/src/IRremoteESP8266.h @@ -1507,12 +1507,24 @@ const uint16_t kYorkStateLength = 17; #ifdef DEBUG #ifdef UNIT_TEST -#define DPRINT(x) do { std::cout << x; } while (0) -#define DPRINTLN(x) do { std::cout << x << std::endl; } while (0) +#define DPRINT(x) do { \ + std::cout << x; \ + } \ + while (0) +#define DPRINTLN(x) do { \ + std::cout << x << std::endl; \ + } \ + while (0) #endif // UNIT_TEST #ifdef ARDUINO -#define DPRINT(x) do { Serial.print(x); } while (0) -#define DPRINTLN(x) do { Serial.println(x); } while (0) +#define DPRINT(x) do { \ + Serial.print(x); \ + } \ + while (0) +#define DPRINTLN(x) do { \ + Serial.println(x); \ + } \ + while (0) #endif // ARDUINO #else // DEBUG #define DPRINT(x) diff --git a/src/IRsend.cpp b/src/IRsend.cpp index 1864ee2a3..8b2309b8f 100644 --- a/src/IRsend.cpp +++ b/src/IRsend.cpp @@ -74,9 +74,9 @@ uint32_t IRsend::calcUSecPeriod(uint32_t hz, bool use_offset) { (1000000UL + hz / 2) / hz; // The equiv of round(1000000/hz). // Apply the offset and ensure we don't result in a <= 0 value. if (use_offset) - return std::max((uint32_t)1, period + periodOffset); + return std::max(static_cast(1), period + periodOffset); else - return std::max((uint32_t)1, period); + return std::max(static_cast(1), period); } /// Set the output frequency modulation and duty cycle. @@ -174,14 +174,16 @@ uint16_t IRsend::mark(uint16_t usec) { ledOn(); // Calculate how long we should pulse on for. // e.g. Are we to close to the end of our requested mark time (usec)? - _delayMicroseconds(std::min((uint32_t)onTimePeriod, usec - elapsed)); + _delayMicroseconds(std::min(static_cast(onTimePeriod), + usec - elapsed)); ledOff(); counter++; if (elapsed + onTimePeriod >= usec) return counter; // LED is now off & we've passed our allotted time. // Wait for the lesser of the rest of the duty cycle, or the time remaining. _delayMicroseconds( - std::min(usec - elapsed - onTimePeriod, (uint32_t)offTimePeriod)); + std::min(usec - elapsed - onTimePeriod, + static_cast(offTimePeriod))); elapsed = usecTimer.elapsed(); // Update & recache the actual elapsed time. } return counter; @@ -214,7 +216,7 @@ int8_t IRsend::calibrate(uint16_t hz) { uint32_t timeTaken = usecTimer.elapsed(); // Record the time it took. // While it shouldn't be necessary, assume at least 1 pulse, to avoid a // divide by 0 situation. - pulses = std::max(pulses, (uint16_t)1U); + pulses = std::max(pulses, static_cast(1U)); uint32_t calcPeriod = calcUSecPeriod(hz); // e.g. @38kHz it should be 26us. // Assuming 38kHz for the example calculations: // In a 65535us pulse, we should have 2520.5769 pulses @ 26us periods. diff --git a/src/IRsend.h b/src/IRsend.h index cf97521c4..80e5d65d5 100644 --- a/src/IRsend.h +++ b/src/IRsend.h @@ -631,7 +631,8 @@ class IRsend { void sendHaierAC(const unsigned char data[], const uint16_t nbytes = kHaierACStateLength, const uint16_t repeat = kHaierAcDefaultRepeat); -#endif // (SEND_HAIER_AC || SEND_HAIER_AC_YRW02 || SEND_HAIER_AC160 || SEND_HAIER_AC176) +#endif // (SEND_HAIER_AC || SEND_HAIER_AC_YRW02 || SEND_HAIER_AC160 || + // SEND_HAIER_AC176) #if SEND_HAIER_AC_YRW02 void sendHaierACYRW02(const unsigned char data[], const uint16_t nbytes = kHaierACYRW02StateLength, diff --git a/src/IRutils.cpp b/src/IRutils.cpp index d8cabaff4..299545484 100644 --- a/src/IRutils.cpp +++ b/src/IRutils.cpp @@ -46,7 +46,7 @@ uint64_t reverseBits(uint64_t input, uint16_t nbits) { if (nbits <= 1) return input; // Reversing <= 1 bits makes no change at all. // Cap the nr. of bits to rotate to the max nr. of bits in the input. - nbits = std::min(nbits, (uint16_t)(sizeof(input) * 8)); + nbits = std::min(nbits, static_cast((sizeof(input) * 8))); uint64_t output = 0; for (uint16_t i = 0; i < nbits; i++) { output <<= 1; @@ -528,921 +528,922 @@ float celsiusToFahrenheit(const float deg) { return (deg * 9.0) / 5.0 + 32.0; } float fahrenheitToCelsius(const float deg) { return (deg - 32.0) * 5.0 / 9.0; } namespace irutils { - /// Create a String with a colon separated "label: value" pair suitable for - /// Humans. - /// @param[in] value The value to come after the label. - /// @param[in] label The label to precede the value. - /// @param[in] precomma Should the output string start with ", " or not? - /// @return The resulting String. - String addLabeledString(const String value, const String label, - const bool precomma) { - String result = ""; - // ", " + ": " = 4 chars - result.reserve(4 + value.length() + label.length()); - if (precomma) result += kCommaSpaceStr; - result += label; - result += kColonSpaceStr; - return result + value; - } +/// Create a String with a colon separated "label: value" pair suitable for +/// Humans. +/// @param[in] value The value to come after the label. +/// @param[in] label The label to precede the value. +/// @param[in] precomma Should the output string start with ", " or not? +/// @return The resulting String. +String addLabeledString(const String value, const String label, + const bool precomma) { + String result = ""; + // ", " + ": " = 4 chars + result.reserve(4 + value.length() + label.length()); + if (precomma) result += kCommaSpaceStr; + result += label; + result += kColonSpaceStr; + return result + value; +} - /// Create a String with a colon separated flag suitable for Humans. - /// e.g. "Power: On" - /// @param[in] value The value to come after the label. - /// @param[in] label The label to precede the value. - /// @param[in] precomma Should the output string start with ", " or not? - /// @return The resulting String. - String addBoolToString(const bool value, const String label, - const bool precomma) { - return addLabeledString(value ? kOnStr : kOffStr, label, precomma); - } +/// Create a String with a colon separated flag suitable for Humans. +/// e.g. "Power: On" +/// @param[in] value The value to come after the label. +/// @param[in] label The label to precede the value. +/// @param[in] precomma Should the output string start with ", " or not? +/// @return The resulting String. +String addBoolToString(const bool value, const String label, + const bool precomma) { + return addLabeledString(value ? kOnStr : kOffStr, label, precomma); +} - /// Create a String with a colon separated toggle flag suitable for Humans. - /// e.g. "Light: Toggle", "Light: -" - /// @param[in] toggle The value of the toggle to come after the label. - /// @param[in] label The label to precede the value. - /// @param[in] precomma Should the output string start with ", " or not? - /// @return The resulting String. - String addToggleToString(const bool toggle, const String label, - const bool precomma) { - return addLabeledString(toggle ? kToggleStr : kDashStr, label, precomma); - } +/// Create a String with a colon separated toggle flag suitable for Humans. +/// e.g. "Light: Toggle", "Light: -" +/// @param[in] toggle The value of the toggle to come after the label. +/// @param[in] label The label to precede the value. +/// @param[in] precomma Should the output string start with ", " or not? +/// @return The resulting String. +String addToggleToString(const bool toggle, const String label, + const bool precomma) { + return addLabeledString(toggle ? kToggleStr : kDashStr, label, precomma); +} - /// Create a String with a colon separated labeled Integer suitable for - /// Humans. - /// e.g. "Foo: 23" - /// @param[in] value The value to come after the label. - /// @param[in] label The label to precede the value. - /// @param[in] precomma Should the output string start with ", " or not? - /// @return The resulting String. - String addIntToString(const uint16_t value, const String label, - const bool precomma) { - return addLabeledString(uint64ToString(value), label, precomma); - } +/// Create a String with a colon separated labeled Integer suitable for +/// Humans. +/// e.g. "Foo: 23" +/// @param[in] value The value to come after the label. +/// @param[in] label The label to precede the value. +/// @param[in] precomma Should the output string start with ", " or not? +/// @return The resulting String. +String addIntToString(const uint16_t value, const String label, + const bool precomma) { + return addLabeledString(uint64ToString(value), label, precomma); +} - /// Create a String with a colon separated labeled Integer suitable for - /// Humans. - /// e.g. "Foo: 23" - /// @param[in] value The value to come after the label. - /// @param[in] label The label to precede the value. - /// @param[in] precomma Should the output string start with ", " or not? - /// @return The resulting String. - String addSignedIntToString(const int16_t value, const String label, - const bool precomma) { - return addLabeledString(int64ToString(value), label, precomma); - } +/// Create a String with a colon separated labeled Integer suitable for +/// Humans. +/// e.g. "Foo: 23" +/// @param[in] value The value to come after the label. +/// @param[in] label The label to precede the value. +/// @param[in] precomma Should the output string start with ", " or not? +/// @return The resulting String. +String addSignedIntToString(const int16_t value, const String label, + const bool precomma) { + return addLabeledString(int64ToString(value), label, precomma); +} - /// Generate the model string for a given Protocol/Model pair. - /// @param[in] protocol The IR protocol. - /// @param[in] model The model number for that protocol. - /// @return The resulting String. - /// @note After adding a new model you should update IRac::strToModel() too. - String modelToStr(const decode_type_t protocol, const int16_t model) { - switch (protocol) { - case decode_type_t::FUJITSU_AC: - switch (model) { - case fujitsu_ac_remote_model_t::ARRAH2E: return kArrah2eStr; - case fujitsu_ac_remote_model_t::ARDB1: return kArdb1Str; - case fujitsu_ac_remote_model_t::ARREB1E: return kArreb1eStr; - case fujitsu_ac_remote_model_t::ARJW2: return kArjw2Str; - case fujitsu_ac_remote_model_t::ARRY4: return kArry4Str; - case fujitsu_ac_remote_model_t::ARREW4E: return kArrew4eStr; - default: return kUnknownStr; - } - break; - case decode_type_t::GREE: - switch (model) { - case gree_ac_remote_model_t::YAW1F: return kYaw1fStr; - case gree_ac_remote_model_t::YBOFB: return kYbofbStr; - case gree_ac_remote_model_t::YX1FSF: return kYx1fsfStr; - default: return kUnknownStr; - } - break; - case decode_type_t::HAIER_AC176: - switch (model) { - case haier_ac176_remote_model_t::V9014557_A: - return kV9014557AStr; - case haier_ac176_remote_model_t::V9014557_B: - return kV9014557BStr; - default: - return kUnknownStr; - } - break; - case decode_type_t::HITACHI_AC1: - switch (model) { - case hitachi_ac1_remote_model_t::R_LT0541_HTA_A: - return kRlt0541htaaStr; - case hitachi_ac1_remote_model_t::R_LT0541_HTA_B: - return kRlt0541htabStr; - default: - return kUnknownStr; - } - break; - case decode_type_t::LG: - case decode_type_t::LG2: - switch (model) { - case lg_ac_remote_model_t::GE6711AR2853M: return kGe6711ar2853mStr; - case lg_ac_remote_model_t::AKB75215403: return kAkb75215403Str; - case lg_ac_remote_model_t::AKB74955603: return kAkb74955603Str; - case lg_ac_remote_model_t::AKB73757604: return kAkb73757604Str; - case lg_ac_remote_model_t::LG6711A20083V: return kLg6711a20083vStr; - default: return kUnknownStr; - } - break; - case decode_type_t::MIRAGE: - switch (model) { - case mirage_ac_remote_model_t::KKG9AC1: return kKkg9ac1Str; - case mirage_ac_remote_model_t::KKG29AC1: return kKkg29ac1Str; - default: return kUnknownStr; - } - break; - case decode_type_t::PANASONIC_AC: - switch (model) { - case panasonic_ac_remote_model_t::kPanasonicLke: return kLkeStr; - case panasonic_ac_remote_model_t::kPanasonicNke: return kNkeStr; - case panasonic_ac_remote_model_t::kPanasonicDke: return kDkeStr; - case panasonic_ac_remote_model_t::kPanasonicJke: return kJkeStr; - case panasonic_ac_remote_model_t::kPanasonicCkp: return kCkpStr; - case panasonic_ac_remote_model_t::kPanasonicRkr: return kRkrStr; - default: return kUnknownStr; - } - break; - case decode_type_t::SHARP_AC: - switch (model) { - case sharp_ac_remote_model_t::A907: return kA907Str; - case sharp_ac_remote_model_t::A705: return kA705Str; - case sharp_ac_remote_model_t::A903: return kA903Str; - default: return kUnknownStr; - } - break; - case decode_type_t::TCL112AC: - switch (model) { - case tcl_ac_remote_model_t::TAC09CHSD: return kTac09chsdStr; - case tcl_ac_remote_model_t::GZ055BE1: return kGz055be1Str; - default: return kUnknownStr; - } - break; - case decode_type_t::VOLTAS: - switch (model) { - case voltas_ac_remote_model_t::kVoltas122LZF: return k122lzfStr; - default: return kUnknownStr; - } - break; - case decode_type_t::WHIRLPOOL_AC: - switch (model) { - case whirlpool_ac_remote_model_t::DG11J13A: return kDg11j13aStr; - case whirlpool_ac_remote_model_t::DG11J191: return kDg11j191Str; - default: return kUnknownStr; - } - break; - case decode_type_t::ARGO: - switch (model) { - case argo_ac_remote_model_t::SAC_WREM2: return kArgoWrem2Str; - case argo_ac_remote_model_t::SAC_WREM3: return kArgoWrem3Str; - default: return kUnknownStr; - } - break; - case decode_type_t::TOSHIBA_AC: - switch (model) { - case toshiba_ac_remote_model_t::kToshibaGenericRemote_A: - return kToshibaGenericRemoteAStr; - case toshiba_ac_remote_model_t::kToshibaGenericRemote_B: - return kToshibaGenericRemoteBStr; - default: - return kUnknownStr; - } - default: return kUnknownStr; - } +/// Generate the model string for a given Protocol/Model pair. +/// @param[in] protocol The IR protocol. +/// @param[in] model The model number for that protocol. +/// @return The resulting String. +/// @note After adding a new model you should update IRac::strToModel() too. +String modelToStr(const decode_type_t protocol, const int16_t model) { + switch (protocol) { + case decode_type_t::FUJITSU_AC: + switch (model) { + case fujitsu_ac_remote_model_t::ARRAH2E: return kArrah2eStr; + case fujitsu_ac_remote_model_t::ARDB1: return kArdb1Str; + case fujitsu_ac_remote_model_t::ARREB1E: return kArreb1eStr; + case fujitsu_ac_remote_model_t::ARJW2: return kArjw2Str; + case fujitsu_ac_remote_model_t::ARRY4: return kArry4Str; + case fujitsu_ac_remote_model_t::ARREW4E: return kArrew4eStr; + default: return kUnknownStr; + } + break; + case decode_type_t::GREE: + switch (model) { + case gree_ac_remote_model_t::YAW1F: return kYaw1fStr; + case gree_ac_remote_model_t::YBOFB: return kYbofbStr; + case gree_ac_remote_model_t::YX1FSF: return kYx1fsfStr; + default: return kUnknownStr; + } + break; + case decode_type_t::HAIER_AC176: + switch (model) { + case haier_ac176_remote_model_t::V9014557_A: + return kV9014557AStr; + case haier_ac176_remote_model_t::V9014557_B: + return kV9014557BStr; + default: + return kUnknownStr; + } + break; + case decode_type_t::HITACHI_AC1: + switch (model) { + case hitachi_ac1_remote_model_t::R_LT0541_HTA_A: + return kRlt0541htaaStr; + case hitachi_ac1_remote_model_t::R_LT0541_HTA_B: + return kRlt0541htabStr; + default: + return kUnknownStr; + } + break; + case decode_type_t::LG: + case decode_type_t::LG2: + switch (model) { + case lg_ac_remote_model_t::GE6711AR2853M: return kGe6711ar2853mStr; + case lg_ac_remote_model_t::AKB75215403: return kAkb75215403Str; + case lg_ac_remote_model_t::AKB74955603: return kAkb74955603Str; + case lg_ac_remote_model_t::AKB73757604: return kAkb73757604Str; + case lg_ac_remote_model_t::LG6711A20083V: return kLg6711a20083vStr; + default: return kUnknownStr; + } + break; + case decode_type_t::MIRAGE: + switch (model) { + case mirage_ac_remote_model_t::KKG9AC1: return kKkg9ac1Str; + case mirage_ac_remote_model_t::KKG29AC1: return kKkg29ac1Str; + default: return kUnknownStr; + } + break; + case decode_type_t::PANASONIC_AC: + switch (model) { + case panasonic_ac_remote_model_t::kPanasonicLke: return kLkeStr; + case panasonic_ac_remote_model_t::kPanasonicNke: return kNkeStr; + case panasonic_ac_remote_model_t::kPanasonicDke: return kDkeStr; + case panasonic_ac_remote_model_t::kPanasonicJke: return kJkeStr; + case panasonic_ac_remote_model_t::kPanasonicCkp: return kCkpStr; + case panasonic_ac_remote_model_t::kPanasonicRkr: return kRkrStr; + default: return kUnknownStr; + } + break; + case decode_type_t::SHARP_AC: + switch (model) { + case sharp_ac_remote_model_t::A907: return kA907Str; + case sharp_ac_remote_model_t::A705: return kA705Str; + case sharp_ac_remote_model_t::A903: return kA903Str; + default: return kUnknownStr; + } + break; + case decode_type_t::TCL112AC: + switch (model) { + case tcl_ac_remote_model_t::TAC09CHSD: return kTac09chsdStr; + case tcl_ac_remote_model_t::GZ055BE1: return kGz055be1Str; + default: return kUnknownStr; + } + break; + case decode_type_t::VOLTAS: + switch (model) { + case voltas_ac_remote_model_t::kVoltas122LZF: return k122lzfStr; + default: return kUnknownStr; + } + break; + case decode_type_t::WHIRLPOOL_AC: + switch (model) { + case whirlpool_ac_remote_model_t::DG11J13A: return kDg11j13aStr; + case whirlpool_ac_remote_model_t::DG11J191: return kDg11j191Str; + default: return kUnknownStr; + } + break; + case decode_type_t::ARGO: + switch (model) { + case argo_ac_remote_model_t::SAC_WREM2: return kArgoWrem2Str; + case argo_ac_remote_model_t::SAC_WREM3: return kArgoWrem3Str; + default: return kUnknownStr; + } + break; + case decode_type_t::TOSHIBA_AC: + switch (model) { + case toshiba_ac_remote_model_t::kToshibaGenericRemote_A: + return kToshibaGenericRemoteAStr; + case toshiba_ac_remote_model_t::kToshibaGenericRemote_B: + return kToshibaGenericRemoteBStr; + default: + return kUnknownStr; + } + default: return kUnknownStr; } +} - /// Create a String of human output for a given protocol model number. - /// e.g. "Model: JKE" - /// @param[in] protocol The IR protocol. - /// @param[in] model The model number for that protocol. - /// @param[in] precomma Should the output string start with ", " or not? - /// @return The resulting String. - String addModelToString(const decode_type_t protocol, const int16_t model, - const bool precomma) { - String result = ""; - // ", Model: NNN (BlahBlahEtc)" = ~40 chars for longest model name. - result.reserve(40); - result += addIntToString(model, kModelStr, precomma); - result += kSpaceLBraceStr; - result += modelToStr(protocol, model); - return result + ')'; - } +/// Create a String of human output for a given protocol model number. +/// e.g. "Model: JKE" +/// @param[in] protocol The IR protocol. +/// @param[in] model The model number for that protocol. +/// @param[in] precomma Should the output string start with ", " or not? +/// @return The resulting String. +String addModelToString(const decode_type_t protocol, const int16_t model, + const bool precomma) { + String result = ""; + // ", Model: NNN (BlahBlahEtc)" = ~40 chars for longest model name. + result.reserve(40); + result += addIntToString(model, kModelStr, precomma); + result += kSpaceLBraceStr; + result += modelToStr(protocol, model); + return result + ')'; +} - /// Create a String of human output for a given temperature. - /// e.g. "Temp: 25C" - /// @param[in] degrees The temperature in degrees. - /// @param[in] celsius Is the temp Celsius or Fahrenheit. - /// true is C, false is F - /// @param[in] precomma Should the output string start with ", " or not? - /// @param[in] isSensorTemp Is the value a room (ambient) temp. or target? - /// @return The resulting String. - String addTempToString(const uint16_t degrees, const bool celsius, - const bool precomma, const bool isSensorTemp) { - String result = addIntToString(degrees, (isSensorTemp)? - kSensorTempStr : kTempStr, precomma); - result += celsius ? 'C' : 'F'; - return result; - } +/// Create a String of human output for a given temperature. +/// e.g. "Temp: 25C" +/// @param[in] degrees The temperature in degrees. +/// @param[in] celsius Is the temp Celsius or Fahrenheit. +/// true is C, false is F +/// @param[in] precomma Should the output string start with ", " or not? +/// @param[in] isSensorTemp Is the value a room (ambient) temp. or target? +/// @return The resulting String. +String addTempToString(const uint16_t degrees, const bool celsius, + const bool precomma, const bool isSensorTemp) { + String result = addIntToString(degrees, (isSensorTemp)? + kSensorTempStr : kTempStr, precomma); + result += celsius ? 'C' : 'F'; + return result; +} - /// Create a String of human output for a given temperature. - /// e.g. "Temp: 25.5C" - /// @param[in] degrees The temperature in degrees. - /// @param[in] celsius Is the temp Celsius or Fahrenheit. - /// true is C, false is F - /// @param[in] precomma Should the output string start with ", " or not? - /// @param[in] isSensorTemp Is the value a room (ambient) temp. or target? - /// @return The resulting String. - String addTempFloatToString(const float degrees, const bool celsius, - const bool precomma, const bool isSensorTemp) { - String result = ""; - result.reserve(21); // Assuming ", Sensor Temp: XXX.5F" is the largest. - result += addIntToString(degrees, (isSensorTemp)? - kSensorTempStr : kTempStr, precomma); - // Is it a half degree? - if (((uint16_t)(2 * degrees)) & 1) result += F(".5"); - result += celsius ? 'C' : 'F'; - return result; - } +/// Create a String of human output for a given temperature. +/// e.g. "Temp: 25.5C" +/// @param[in] degrees The temperature in degrees. +/// @param[in] celsius Is the temp Celsius or Fahrenheit. +/// true is C, false is F +/// @param[in] precomma Should the output string start with ", " or not? +/// @param[in] isSensorTemp Is the value a room (ambient) temp. or target? +/// @return The resulting String. +String addTempFloatToString(const float degrees, const bool celsius, + const bool precomma, const bool isSensorTemp) { + String result = ""; + result.reserve(21); // Assuming ", Sensor Temp: XXX.5F" is the largest. + result += addIntToString(degrees, (isSensorTemp)? + kSensorTempStr : kTempStr, precomma); + // Is it a half degree? + if (static_cast(2 * degrees) & 1) + result += F(".5"); + result += celsius ? 'C' : 'F'; + return result; +} - /// Create a String of human output for the given operating mode. - /// e.g. "Mode: 1 (Cool)" - /// @param[in] mode The operating mode to display. - /// @param[in] automatic The numeric value for Auto mode. - /// @param[in] cool The numeric value for Cool mode. - /// @param[in] heat The numeric value for Heat mode. - /// @param[in] dry The numeric value for Dry mode. - /// @param[in] fan The numeric value for Fan mode. - /// @return The resulting String. - String addModeToString(const uint8_t mode, const uint8_t automatic, - const uint8_t cool, const uint8_t heat, - const uint8_t dry, const uint8_t fan) { - String result = ""; - result.reserve(22); // ", Mode: NNN (UNKNOWN)" - result += addIntToString(mode, kModeStr); - result += kSpaceLBraceStr; - if (mode == automatic) result += kAutoStr; - else if (mode == cool) result += kCoolStr; - else if (mode == heat) result += kHeatStr; - else if (mode == dry) result += kDryStr; - else if (mode == fan) result += kFanStr; - else - result += kUnknownStr; - return result + ')'; - } +/// Create a String of human output for the given operating mode. +/// e.g. "Mode: 1 (Cool)" +/// @param[in] mode The operating mode to display. +/// @param[in] automatic The numeric value for Auto mode. +/// @param[in] cool The numeric value for Cool mode. +/// @param[in] heat The numeric value for Heat mode. +/// @param[in] dry The numeric value for Dry mode. +/// @param[in] fan The numeric value for Fan mode. +/// @return The resulting String. +String addModeToString(const uint8_t mode, const uint8_t automatic, + const uint8_t cool, const uint8_t heat, + const uint8_t dry, const uint8_t fan) { + String result = ""; + result.reserve(22); // ", Mode: NNN (UNKNOWN)" + result += addIntToString(mode, kModeStr); + result += kSpaceLBraceStr; + if (mode == automatic) result += kAutoStr; + else if (mode == cool) result += kCoolStr; + else if (mode == heat) result += kHeatStr; + else if (mode == dry) result += kDryStr; + else if (mode == fan) result += kFanStr; + else + result += kUnknownStr; + return result + ')'; +} - /// Create a String of the 3-letter day of the week from a numerical day of - /// the week. e.g. "Day: 1 (Mon)" - /// @param[in] day_of_week A numerical version of the sequential day of the - /// week. e.g. Saturday = 7 etc. - /// @param[in] offset Days to offset by. - /// e.g. For different day starting the week. - /// @param[in] precomma Should the output string start with ", " or not? - /// @return The resulting String. - String addDayToString(const uint8_t day_of_week, const int8_t offset, - const bool precomma) { - String result = ""; - result.reserve(19); // ", Day: N (UNKNOWN)" - result += addIntToString(day_of_week, kDayStr, precomma); - result += kSpaceLBraceStr; - result += dayToString(day_of_week, offset); - return result + ')'; - } +/// Create a String of the 3-letter day of the week from a numerical day of +/// the week. e.g. "Day: 1 (Mon)" +/// @param[in] day_of_week A numerical version of the sequential day of the +/// week. e.g. Saturday = 7 etc. +/// @param[in] offset Days to offset by. +/// e.g. For different day starting the week. +/// @param[in] precomma Should the output string start with ", " or not? +/// @return The resulting String. +String addDayToString(const uint8_t day_of_week, const int8_t offset, + const bool precomma) { + String result = ""; + result.reserve(19); // ", Day: N (UNKNOWN)" + result += addIntToString(day_of_week, kDayStr, precomma); + result += kSpaceLBraceStr; + result += dayToString(day_of_week, offset); + return result + ')'; +} - /// Create a String of the 3-letter day of the week from a numerical day of - /// the week. e.g. "Mon" - /// @param[in] day_of_week A numerical version of the sequential day of the - /// week. e.g. Sunday = 1, Monday = 2, ..., Saturday = 7 - /// @param[in] offset Days to offset by. - /// e.g. For different day starting the week. - /// @return The resulting String. - String dayToString(const uint8_t day_of_week, const int8_t offset) { - if ((uint8_t)(day_of_week + offset) < 7) +/// Create a String of the 3-letter day of the week from a numerical day of +/// the week. e.g. "Mon" +/// @param[in] day_of_week A numerical version of the sequential day of the +/// week. e.g. Sunday = 1, Monday = 2, ..., Saturday = 7 +/// @param[in] offset Days to offset by. +/// e.g. For different day starting the week. +/// @return The resulting String. +String dayToString(const uint8_t day_of_week, const int8_t offset) { + if ((uint8_t)(day_of_week + offset) < 7) #if UNIT_TEST - return String(kThreeLetterDayOfWeekStr).substr( - (day_of_week + offset) * 3, 3); + return String(kThreeLetterDayOfWeekStr).substr( + (day_of_week + offset) * 3, 3); #else // UNIT_TEST - return String(kThreeLetterDayOfWeekStr).substring( - (day_of_week + offset) * 3, (day_of_week + offset) * 3 + 3); + return String(kThreeLetterDayOfWeekStr).substring( + (day_of_week + offset) * 3, (day_of_week + offset) * 3 + 3); #endif // UNIT_TEST - else - return kUnknownStr; - } + else + return kUnknownStr; +} - /// Create a String of human output for the given fan speed. - /// e.g. "Fan: 0 (Auto)" - /// @param[in] speed The numeric speed of the fan to display. - /// @param[in] high The numeric value for High speed. (second highest) - /// @param[in] low The numeric value for Low speed. - /// @param[in] automatic The numeric value for Auto speed. - /// @param[in] quiet The numeric value for Quiet speed. - /// @param[in] medium The numeric value for Medium speed. - /// @param[in] maximum The numeric value for Highest speed. (if > high) - /// @param[in] medium_high The numeric value for third-highest speed. - /// (if > medium) - /// @return The resulting String. - String addFanToString(const uint8_t speed, const uint8_t high, - const uint8_t low, const uint8_t automatic, - const uint8_t quiet, const uint8_t medium, - const uint8_t maximum, const uint8_t medium_high) { - String result = ""; - result.reserve(21); // ", Fan: NNN (UNKNOWN)" - result += addIntToString(speed, kFanStr); - result += kSpaceLBraceStr; - if (speed == high) result += kHighStr; - else if (speed == low) result += kLowStr; - else if (speed == automatic) result += kAutoStr; - else if (speed == quiet) result += kQuietStr; - else if (speed == medium) result += kMediumStr; - else if (speed == maximum) result += kMaximumStr; - else if (speed == medium_high) result += kMedHighStr; - else - result += kUnknownStr; - return result + ')'; - } +/// Create a String of human output for the given fan speed. +/// e.g. "Fan: 0 (Auto)" +/// @param[in] speed The numeric speed of the fan to display. +/// @param[in] high The numeric value for High speed. (second highest) +/// @param[in] low The numeric value for Low speed. +/// @param[in] automatic The numeric value for Auto speed. +/// @param[in] quiet The numeric value for Quiet speed. +/// @param[in] medium The numeric value for Medium speed. +/// @param[in] maximum The numeric value for Highest speed. (if > high) +/// @param[in] medium_high The numeric value for third-highest speed. +/// (if > medium) +/// @return The resulting String. +String addFanToString(const uint8_t speed, const uint8_t high, + const uint8_t low, const uint8_t automatic, + const uint8_t quiet, const uint8_t medium, + const uint8_t maximum, const uint8_t medium_high) { + String result = ""; + result.reserve(21); // ", Fan: NNN (UNKNOWN)" + result += addIntToString(speed, kFanStr); + result += kSpaceLBraceStr; + if (speed == high) result += kHighStr; + else if (speed == low) result += kLowStr; + else if (speed == automatic) result += kAutoStr; + else if (speed == quiet) result += kQuietStr; + else if (speed == medium) result += kMediumStr; + else if (speed == maximum) result += kMaximumStr; + else if (speed == medium_high) result += kMedHighStr; + else + result += kUnknownStr; + return result + ')'; +} - /// Create a String of human output for the given horizontal swing setting. - /// e.g. "Swing(H): 0 (Auto)" - /// @param[in] position The numeric position of the swing to display. - /// @param[in] automatic The numeric value for Auto position. - /// @param[in] maxleft The numeric value for most left position. - /// @param[in] left The numeric value for Left position. - /// @param[in] middle The numeric value for Middle position. - /// @param[in] right The numeric value for Right position. - /// @param[in] maxright The numeric value for most right position. - /// @param[in] off The numeric value for Off position. - /// @param[in] leftright The numeric value for "left right" position. - /// @param[in] rightleft The numeric value for "right left" position. - /// @param[in] threed The numeric value for 3D setting. - /// @param[in] wide The numeric value for Wide position. - /// @return The resulting String. - String addSwingHToString(const uint8_t position, const uint8_t automatic, - const uint8_t maxleft, const uint8_t left, - const uint8_t middle, - const uint8_t right, const uint8_t maxright, - const uint8_t off, - const uint8_t leftright, const uint8_t rightleft, - const uint8_t threed, const uint8_t wide) { - String result = ""; - result.reserve(30); // ", Swing(H): NNN (Left Right)" - result += addIntToString(position, kSwingHStr); - result += kSpaceLBraceStr; - if (position == automatic) { - result += kAutoStr; - } else if (position == left) { - result += kLeftStr; - } else if (position == middle) { - result += kMiddleStr; - } else if (position == right) { - result += kRightStr; - } else if (position == maxleft) { - result += kMaxLeftStr; - } else if (position == maxright) { - result += kMaxRightStr; - } else if (position == off) { - result += kOffStr; - } else if (position == leftright) { - result += kLeftStr; - result += ' '; - result += kRightStr; - } else if (position == rightleft) { - result += kRightStr; - result += ' '; - result += kLeftStr; - } else if (position == threed) { - result += k3DStr; - } else if (position == wide) { - result += kWideStr; - } else { - result += kUnknownStr; - } - return result + ')'; +/// Create a String of human output for the given horizontal swing setting. +/// e.g. "Swing(H): 0 (Auto)" +/// @param[in] position The numeric position of the swing to display. +/// @param[in] automatic The numeric value for Auto position. +/// @param[in] maxleft The numeric value for most left position. +/// @param[in] left The numeric value for Left position. +/// @param[in] middle The numeric value for Middle position. +/// @param[in] right The numeric value for Right position. +/// @param[in] maxright The numeric value for most right position. +/// @param[in] off The numeric value for Off position. +/// @param[in] leftright The numeric value for "left right" position. +/// @param[in] rightleft The numeric value for "right left" position. +/// @param[in] threed The numeric value for 3D setting. +/// @param[in] wide The numeric value for Wide position. +/// @return The resulting String. +String addSwingHToString(const uint8_t position, const uint8_t automatic, + const uint8_t maxleft, const uint8_t left, + const uint8_t middle, + const uint8_t right, const uint8_t maxright, + const uint8_t off, + const uint8_t leftright, const uint8_t rightleft, + const uint8_t threed, const uint8_t wide) { + String result = ""; + result.reserve(30); // ", Swing(H): NNN (Left Right)" + result += addIntToString(position, kSwingHStr); + result += kSpaceLBraceStr; + if (position == automatic) { + result += kAutoStr; + } else if (position == left) { + result += kLeftStr; + } else if (position == middle) { + result += kMiddleStr; + } else if (position == right) { + result += kRightStr; + } else if (position == maxleft) { + result += kMaxLeftStr; + } else if (position == maxright) { + result += kMaxRightStr; + } else if (position == off) { + result += kOffStr; + } else if (position == leftright) { + result += kLeftStr; + result += ' '; + result += kRightStr; + } else if (position == rightleft) { + result += kRightStr; + result += ' '; + result += kLeftStr; + } else if (position == threed) { + result += k3DStr; + } else if (position == wide) { + result += kWideStr; + } else { + result += kUnknownStr; } + return result + ')'; +} - /// Create a String of human output for the given vertical swing setting. - /// e.g. "Swing(V): 0 (Auto)" - /// @param[in] position The numeric position of the swing to display. - /// @param[in] automatic The numeric value for Auto position. - /// @param[in] highest The numeric value for Highest position. - /// @param[in] high The numeric value for High position. - /// @param[in] uppermiddle The numeric value for Upper Middle position. - /// @param[in] middle The numeric value for Middle position. - /// @param[in] lowermiddle The numeric value for Lower Middle position. - /// @param[in] low The numeric value for Low position. - /// @param[in] lowest The numeric value for Low position. - /// @param[in] off The numeric value for Off position. - /// @param[in] swing The numeric value for Swing setting. - /// @param[in] breeze The numeric value for Breeze setting. - /// @param[in] circulate The numeric value for Circulate setting. - /// @return The resulting String. - String addSwingVToString(const uint8_t position, const uint8_t automatic, - const uint8_t highest, const uint8_t high, - const uint8_t uppermiddle, - const uint8_t middle, - const uint8_t lowermiddle, - const uint8_t low, const uint8_t lowest, - const uint8_t off, const uint8_t swing, - const uint8_t breeze, const uint8_t circulate) { - String result = ""; - result.reserve(31); // ", Swing(V): NNN (Upper Middle)" - result += addIntToString(position, kSwingVStr); - result += kSpaceLBraceStr; - if (position == automatic) { - result += kAutoStr; - } else if (position == highest) { - result += kHighestStr; - } else if (position == high) { - result += kHighStr; - } else if (position == middle) { - result += kMiddleStr; - } else if (position == low) { - result += kLowStr; - } else if (position == lowest) { - result += kLowestStr; - } else if (position == off) { - result += kOffStr; - } else if (position == uppermiddle) { - result += kUpperStr; - result += ' '; - result += kMiddleStr; - } else if (position == lowermiddle) { - result += kLowerStr; - result += ' '; - result += kMiddleStr; - } else if (position == swing) { - result += kSwingStr; - } else if (position == breeze) { - result += kBreezeStr; - } else if (position == circulate) { - result += kCirculateStr; - } else { - result += kUnknownStr; - } - return result + ')'; +/// Create a String of human output for the given vertical swing setting. +/// e.g. "Swing(V): 0 (Auto)" +/// @param[in] position The numeric position of the swing to display. +/// @param[in] automatic The numeric value for Auto position. +/// @param[in] highest The numeric value for Highest position. +/// @param[in] high The numeric value for High position. +/// @param[in] uppermiddle The numeric value for Upper Middle position. +/// @param[in] middle The numeric value for Middle position. +/// @param[in] lowermiddle The numeric value for Lower Middle position. +/// @param[in] low The numeric value for Low position. +/// @param[in] lowest The numeric value for Low position. +/// @param[in] off The numeric value for Off position. +/// @param[in] swing The numeric value for Swing setting. +/// @param[in] breeze The numeric value for Breeze setting. +/// @param[in] circulate The numeric value for Circulate setting. +/// @return The resulting String. +String addSwingVToString(const uint8_t position, const uint8_t automatic, + const uint8_t highest, const uint8_t high, + const uint8_t uppermiddle, + const uint8_t middle, + const uint8_t lowermiddle, + const uint8_t low, const uint8_t lowest, + const uint8_t off, const uint8_t swing, + const uint8_t breeze, const uint8_t circulate) { + String result = ""; + result.reserve(31); // ", Swing(V): NNN (Upper Middle)" + result += addIntToString(position, kSwingVStr); + result += kSpaceLBraceStr; + if (position == automatic) { + result += kAutoStr; + } else if (position == highest) { + result += kHighestStr; + } else if (position == high) { + result += kHighStr; + } else if (position == middle) { + result += kMiddleStr; + } else if (position == low) { + result += kLowStr; + } else if (position == lowest) { + result += kLowestStr; + } else if (position == off) { + result += kOffStr; + } else if (position == uppermiddle) { + result += kUpperStr; + result += ' '; + result += kMiddleStr; + } else if (position == lowermiddle) { + result += kLowerStr; + result += ' '; + result += kMiddleStr; + } else if (position == swing) { + result += kSwingStr; + } else if (position == breeze) { + result += kBreezeStr; + } else if (position == circulate) { + result += kCirculateStr; + } else { + result += kUnknownStr; } + return result + ')'; +} - /// @brief Create a String of human output for the given timer setting. - /// e.g. "Timer Mode: 2 (Schedule 1)" - /// @param[in] timerMode The numeric value of the timer mode to display. - /// @param[in] noTimer The numeric value for no timer (off) - /// @param[in] delayTimer The numeric value for delay (sleep) timer - /// @param[in] schedule1 The numeric value for schedule timer #1 - /// @param[in] schedule2 The numeric value for schedule timer #2 - /// @param[in] schedule3 The numeric value for schedule timer #3 - /// @param[in] precomma Should the output string start with ", " or not? - /// @return String representation - String addTimerModeToString(const uint8_t timerMode, const uint8_t noTimer, - const uint8_t delayTimer, const uint8_t schedule1, - const uint8_t schedule2, const uint8_t schedule3, - const bool precomma) { - String result = ""; - result.reserve(28); // ", Timer Mode: 2 (Schedule 1)" - result += addIntToString(timerMode, kTimerModeStr, precomma); - result += kSpaceLBraceStr; - if (timerMode == noTimer) { - result += kOffStr; - } else if (timerMode == delayTimer) { - result += kSleepTimerStr; - } else if (timerMode == schedule1) { - result += kScheduleStr; - result += '1'; - } else if (timerMode == schedule2) { - result += kScheduleStr; - result += '2'; - } else if (timerMode == schedule3) { - result += kScheduleStr; - result += '3'; - } else { - result += kUnknownStr; - } - return result + ')'; +/// @brief Create a String of human output for the given timer setting. +/// e.g. "Timer Mode: 2 (Schedule 1)" +/// @param[in] timerMode The numeric value of the timer mode to display. +/// @param[in] noTimer The numeric value for no timer (off) +/// @param[in] delayTimer The numeric value for delay (sleep) timer +/// @param[in] schedule1 The numeric value for schedule timer #1 +/// @param[in] schedule2 The numeric value for schedule timer #2 +/// @param[in] schedule3 The numeric value for schedule timer #3 +/// @param[in] precomma Should the output string start with ", " or not? +/// @return String representation +String addTimerModeToString(const uint8_t timerMode, const uint8_t noTimer, + const uint8_t delayTimer, const uint8_t schedule1, + const uint8_t schedule2, const uint8_t schedule3, + const bool precomma) { + String result = ""; + result.reserve(28); // ", Timer Mode: 2 (Schedule 1)" + result += addIntToString(timerMode, kTimerModeStr, precomma); + result += kSpaceLBraceStr; + if (timerMode == noTimer) { + result += kOffStr; + } else if (timerMode == delayTimer) { + result += kSleepTimerStr; + } else if (timerMode == schedule1) { + result += kScheduleStr; + result += '1'; + } else if (timerMode == schedule2) { + result += kScheduleStr; + result += '2'; + } else if (timerMode == schedule3) { + result += kScheduleStr; + result += '3'; + } else { + result += kUnknownStr; } + return result + ')'; +} - /// @brief Create a String of human output for the given channel - /// e.g. "[CH#0]" - /// @param channel The numeric value of the channel to display. - /// @return String representation - String channelToString(const uint8_t channel) { - String result = ""; - result.reserve(6); // "[CH#4]" - result += "["; - result += kChStr; - result += uint64ToString(channel); - result += "]"; - return result; - } +/// @brief Create a String of human output for the given channel +/// e.g. "[CH#0]" +/// @param channel The numeric value of the channel to display. +/// @return String representation +String channelToString(const uint8_t channel) { + String result = ""; + result.reserve(6); // "[CH#4]" + result += "["; + result += kChStr; + result += uint64ToString(channel); + result += "]"; + return result; +} - /// @brief Create a String of human output for the given command type - /// e.g. "IFeel Report" - /// @param irCommandType The numeric value of the command type to display. - /// @param acControlCmd The numeric value of the "control" (default) command - /// @param iFeelReportCmd The numeric value of the sensor temperature command - /// @param timerCmd The numeric value of the timer config IR command - /// @param configCmd The numeric value of the config param set IR command - /// @return String representation - String irCommandTypeToString(uint8_t irCommandType, uint8_t acControlCmd, - uint8_t iFeelReportCmd, uint8_t timerCmd, - uint8_t configCmd) { - String result = ""; - result.reserve(12); // "IFeel Report" - if (irCommandType == acControlCmd) { - result += kCommandStr; - } else if (irCommandType == iFeelReportCmd) { - result += kIFeelReportStr; - } else if (irCommandType == timerCmd) { - result += kTimerStr; - } else if (irCommandType == configCmd) { - result += kConfigCommandStr; - } else { - result += kUnknownStr; - } - return result; +/// @brief Create a String of human output for the given command type +/// e.g. "IFeel Report" +/// @param irCommandType The numeric value of the command type to display. +/// @param acControlCmd The numeric value of the "control" (default) command +/// @param iFeelReportCmd The numeric value of the sensor temperature command +/// @param timerCmd The numeric value of the timer config IR command +/// @param configCmd The numeric value of the config param set IR command +/// @return String representation +String irCommandTypeToString(uint8_t irCommandType, uint8_t acControlCmd, + uint8_t iFeelReportCmd, uint8_t timerCmd, + uint8_t configCmd) { + String result = ""; + result.reserve(12); // "IFeel Report" + if (irCommandType == acControlCmd) { + result += kCommandStr; + } else if (irCommandType == iFeelReportCmd) { + result += kIFeelReportStr; + } else if (irCommandType == timerCmd) { + result += kTimerStr; + } else if (irCommandType == configCmd) { + result += kConfigCommandStr; + } else { + result += kUnknownStr; } + return result; +} - /// @brief Create a String of the 3-letter day of the week bitmap - // e.g. 0b0000101 is "Sun | Tue" - /// @param[in] daysBitmap The bitmap representing days of week to represent - /// e.g bit[0]=Sunday, bit[1]=Monday, ... - /// @param[in] offset Days to offset by. - /// e.g. For different day starting the week. - /// @return String representation. - String daysBitmaskToString(uint8_t daysBitmap, uint8_t offset) { - String result = ""; - result.reserve(27); // Sun|Mon|Tue|Wed|Thu|Fri|Sat - - for (uint8_t i = 0; i < 7; ++i) { - if (((daysBitmap >> i) & 0b1) == 0b1) { - if (result.length() > 0) { - result += "|"; - } - result += irutils::dayToString(i, offset); - } - } - return result; - } +/// @brief Create a String of the 3-letter day of the week bitmap +// e.g. 0b0000101 is "Sun | Tue" +/// @param[in] daysBitmap The bitmap representing days of week to represent +/// e.g bit[0]=Sunday, bit[1]=Monday, ... +/// @param[in] offset Days to offset by. +/// e.g. For different day starting the week. +/// @return String representation. +String daysBitmaskToString(uint8_t daysBitmap, uint8_t offset) { + String result = ""; + result.reserve(27); // Sun|Mon|Tue|Wed|Thu|Fri|Sat - /// Escape any special HTML (unsafe) characters in a string. e.g. anti-XSS. - /// @param[in] unescaped A String containing text to make HTML safe. - /// @return A string that is HTML safe. - String htmlEscape(const String unescaped) { - String result = ""; - uint16_t ulen = unescaped.length(); - result.reserve(ulen); // The result will be at least the size of input. - for (size_t i = 0; i < ulen; i++) { - char c = unescaped[i]; - switch (c) { - // ';!-"<>=&#{}() are all unsafe. - case '\'': result += F("'"); break; - case ';': result += F(";"); break; - case '!': result += F("!"); break; - case '-': result += F("‐"); break; - case '\"': result += F("""); break; - case '<': result += F("<"); break; - case '>': result += F(">"); break; - case '=': result += F("&#equals;"); break; - case '&': result += F("&"); break; - case '#': result += F("#"); break; - case '{': result += F("{"); break; - case '}': result += F("}"); break; - case '(': result += F("("); break; - case ')': result += F(")"); break; - default: result += c; + for (uint8_t i = 0; i < 7; ++i) { + if (((daysBitmap >> i) & 0b1) == 0b1) { + if (result.length() > 0) { + result += "|"; } + result += irutils::dayToString(i, offset); } - return result; } + return result; +} - /// Convert a nr. of milliSeconds into a Human-readable string. - /// e.g. "1 Day 6 Hours 34 Minutes 17 Seconds" - /// @param[in] msecs Nr. of milliSeconds (ms). - /// @return A human readable string. - String msToString(uint32_t const msecs) { - uint32_t totalseconds = msecs / 1000; - if (totalseconds == 0) return kNowStr; - - // Note: uint32_t can only hold up to 45 days, so uint8_t is safe. - uint8_t days = totalseconds / (60 * 60 * 24); - uint8_t hours = (totalseconds / (60 * 60)) % 24; - uint8_t minutes = (totalseconds / 60) % 60; - uint8_t seconds = totalseconds % 60; - - String result = ""; - result.reserve(42); // "99 Days, 23 Hours, 59 Minutes, 59 Seconds" - if (days) - result += uint64ToString(days) + ' ' + String((days > 1) ? kDaysStr - : kDayStr); - if (hours) { - if (result.length()) result += ' '; - result += uint64ToString(hours) + ' ' + String((hours > 1) ? kHoursStr - : kHourStr); - } - if (minutes) { - if (result.length()) result += ' '; - result += uint64ToString(minutes) + ' ' + String( - (minutes > 1) ? kMinutesStr : kMinuteStr); - } - if (seconds) { - if (result.length()) result += ' '; - result += uint64ToString(seconds) + ' ' + String( - (seconds > 1) ? kSecondsStr : kSecondStr); +/// Escape any special HTML (unsafe) characters in a string. e.g. anti-XSS. +/// @param[in] unescaped A String containing text to make HTML safe. +/// @return A string that is HTML safe. +String htmlEscape(const String unescaped) { + String result = ""; + uint16_t ulen = unescaped.length(); + result.reserve(ulen); // The result will be at least the size of input. + for (size_t i = 0; i < ulen; i++) { + char c = unescaped[i]; + switch (c) { + // ';!-"<>=&#{}() are all unsafe. + case '\'': result += F("'"); break; + case ';': result += F(";"); break; + case '!': result += F("!"); break; + case '-': result += F("‐"); break; + case '\"': result += F("""); break; + case '<': result += F("<"); break; + case '>': result += F(">"); break; + case '=': result += F("&#equals;"); break; + case '&': result += F("&"); break; + case '#': result += F("#"); break; + case '{': result += F("{"); break; + case '}': result += F("}"); break; + case '(': result += F("("); break; + case ')': result += F(")"); break; + default: result += c; } - return result; } + return result; +} - /// Convert a nr. of minutes into a 24h clock format Human-readable string. - /// e.g. "23:59" - /// @param[in] mins Nr. of Minutes. - /// @return A human readable string. - String minsToString(const uint16_t mins) { - String result = ""; - result.reserve(5); // 23:59 is the typical worst case. - if (mins / 60 < 10) result += '0'; // Zero pad the hours - result += uint64ToString(mins / 60) + kTimeSep; - if (mins % 60 < 10) result += '0'; // Zero pad the minutes. - result += uint64ToString(mins % 60); - return result; - } +/// Convert a nr. of milliSeconds into a Human-readable string. +/// e.g. "1 Day 6 Hours 34 Minutes 17 Seconds" +/// @param[in] msecs Nr. of milliSeconds (ms). +/// @return A human readable string. +String msToString(uint32_t const msecs) { + uint32_t totalseconds = msecs / 1000; + if (totalseconds == 0) return kNowStr; - /// Sum all the nibbles together in a series of bytes. - /// @param[in] start A ptr to the start of the byte array to calculate over. - /// @param[in] length How many bytes to use in the calculation. - /// @param[in] init Starting value of the calculation to use. (Default is 0) - /// @return The 8-bit calculated result of all the bytes and init value. - uint8_t sumNibbles(const uint8_t * const start, const uint16_t length, - const uint8_t init) { - uint8_t sum = init; - const uint8_t *ptr; - for (ptr = start; ptr - start < length; ptr++) - sum += (*ptr >> 4) + (*ptr & 0xF); - return sum; - } + // Note: uint32_t can only hold up to 45 days, so uint8_t is safe. + uint8_t days = totalseconds / (60 * 60 * 24); + uint8_t hours = (totalseconds / (60 * 60)) % 24; + uint8_t minutes = (totalseconds / 60) % 60; + uint8_t seconds = totalseconds % 60; - /// Sum all the nibbles together in an integer. - /// @param[in] data The integer to be summed. - /// @param[in] count The number of nibbles to sum. Starts from LSB. Max of 16. - /// @param[in] init Starting value of the calculation to use. (Default is 0) - /// @param[in] nibbleonly true, the result is 4 bits. false, it's 8 bits. - /// @return The 4/8-bit calculated result of all the nibbles and init value. - uint8_t sumNibbles(const uint64_t data, const uint8_t count, - const uint8_t init, const bool nibbleonly) { - uint8_t sum = init; - uint64_t copy = data; - const uint8_t nrofnibbles = (count < 16) ? count : (64 / 4); - for (uint8_t i = 0; i < nrofnibbles; i++, copy >>= 4) sum += copy & 0xF; - return nibbleonly ? sum & 0xF : sum; + String result = ""; + result.reserve(42); // "99 Days, 23 Hours, 59 Minutes, 59 Seconds" + if (days) + result += uint64ToString(days) + ' ' + String((days > 1) ? kDaysStr + : kDayStr); + if (hours) { + if (result.length()) result += ' '; + result += uint64ToString(hours) + ' ' + String((hours > 1) ? kHoursStr + : kHourStr); } - - /// Sum all the bytes together in an integer. - /// @param[in] data The integer to be summed. - /// @param[in] count The number of bytes to sum. Starts from LSB. Max of 8. - /// @param[in] init Starting value of the calculation to use. (Default is 0) - /// @param[in] byteonly true, the result is 8 bits. false, it's 16 bits. - /// @return The 8/16-bit calculated result of all the bytes and init value. - uint16_t sumBytes(const uint64_t data, const uint8_t count, - const uint8_t init, const bool byteonly) { - uint16_t sum = init; - uint64_t copy = data; - const uint8_t nrofbytes = (count < 8) ? count : (64 / 8); - for (uint8_t i = 0; i < nrofbytes; i++, copy >>= 8) sum += (copy & 0xFF); - return byteonly ? sum & 0xFF : sum; + if (minutes) { + if (result.length()) result += ' '; + result += uint64ToString(minutes) + ' ' + String( + (minutes > 1) ? kMinutesStr : kMinuteStr); } - - /// Convert a byte of Binary Coded Decimal(BCD) into an Integer. - /// @param[in] bcd The BCD value. - /// @return A normal Integer value. - uint8_t bcdToUint8(const uint8_t bcd) { - if (bcd > 0x99) return 255; // Too big. - return (bcd >> 4) * 10 + (bcd & 0xF); + if (seconds) { + if (result.length()) result += ' '; + result += uint64ToString(seconds) + ' ' + String( + (seconds > 1) ? kSecondsStr : kSecondStr); } + return result; +} - /// Convert an Integer into a byte of Binary Coded Decimal(BCD). - /// @param[in] integer The number to convert. - /// @return An 8-bit BCD value. - uint8_t uint8ToBcd(const uint8_t integer) { - if (integer > 99) return 255; // Too big. - return ((integer / 10) << 4) + (integer % 10); - } +/// Convert a nr. of minutes into a 24h clock format Human-readable string. +/// e.g. "23:59" +/// @param[in] mins Nr. of Minutes. +/// @return A human readable string. +String minsToString(const uint16_t mins) { + String result = ""; + result.reserve(5); // 23:59 is the typical worst case. + if (mins / 60 < 10) result += '0'; // Zero pad the hours + result += uint64ToString(mins / 60) + kTimeSep; + if (mins % 60 < 10) result += '0'; // Zero pad the minutes. + result += uint64ToString(mins % 60); + return result; +} - /// Return the value of `position`th bit of an Integer. - /// @param[in] data Value to be examined. - /// @param[in] position Nr. of the Nth bit to be examined. `0` is the LSB. - /// @param[in] size Nr. of bits in data. - /// @return The bit's value. - bool getBit(const uint64_t data, const uint8_t position, const uint8_t size) { - if (position >= size) return false; // Outside of range. - return data & (1ULL << position); - } +/// Sum all the nibbles together in a series of bytes. +/// @param[in] start A ptr to the start of the byte array to calculate over. +/// @param[in] length How many bytes to use in the calculation. +/// @param[in] init Starting value of the calculation to use. (Default is 0) +/// @return The 8-bit calculated result of all the bytes and init value. +uint8_t sumNibbles(const uint8_t * const start, const uint16_t length, + const uint8_t init) { + uint8_t sum = init; + const uint8_t *ptr; + for (ptr = start; ptr - start < length; ptr++) + sum += (*ptr >> 4) + (*ptr & 0xF); + return sum; +} - /// Return the value of `position`th bit of an Integer. - /// @param[in] data Value to be examined. - /// @param[in] position Nr. of the Nth bit to be examined. `0` is the LSB. - /// @return The bit's value. - bool getBit(const uint8_t data, const uint8_t position) { - if (position >= 8) return false; // Outside of range. - return data & (1 << position); - } +/// Sum all the nibbles together in an integer. +/// @param[in] data The integer to be summed. +/// @param[in] count The number of nibbles to sum. Starts from LSB. Max of 16. +/// @param[in] init Starting value of the calculation to use. (Default is 0) +/// @param[in] nibbleonly true, the result is 4 bits. false, it's 8 bits. +/// @return The 4/8-bit calculated result of all the nibbles and init value. +uint8_t sumNibbles(const uint64_t data, const uint8_t count, + const uint8_t init, const bool nibbleonly) { + uint8_t sum = init; + uint64_t copy = data; + const uint8_t nrofnibbles = (count < 16) ? count : (64 / 4); + for (uint8_t i = 0; i < nrofnibbles; i++, copy >>= 4) sum += copy & 0xF; + return nibbleonly ? sum & 0xF : sum; +} - /// Return the value of an Integer with the `position`th bit changed. - /// @param[in] data Value to be changed. - /// @param[in] position Nr. of the bit to be changed. `0` is the LSB. - /// @param[in] on Value to set the position'th bit to. - /// @param[in] size Nr. of bits in data. - /// @return A suitably modified integer. - uint64_t setBit(const uint64_t data, const uint8_t position, const bool on, - const uint8_t size) { - if (position >= size) return data; // Outside of range. - uint64_t mask = 1ULL << position; - if (on) - return data | mask; - else - return data & ~mask; - } +/// Sum all the bytes together in an integer. +/// @param[in] data The integer to be summed. +/// @param[in] count The number of bytes to sum. Starts from LSB. Max of 8. +/// @param[in] init Starting value of the calculation to use. (Default is 0) +/// @param[in] byteonly true, the result is 8 bits. false, it's 16 bits. +/// @return The 8/16-bit calculated result of all the bytes and init value. +uint16_t sumBytes(const uint64_t data, const uint8_t count, + const uint8_t init, const bool byteonly) { + uint16_t sum = init; + uint64_t copy = data; + const uint8_t nrofbytes = (count < 8) ? count : (64 / 8); + for (uint8_t i = 0; i < nrofbytes; i++, copy >>= 8) sum += (copy & 0xFF); + return byteonly ? sum & 0xFF : sum; +} - /// Return the value of an Integer with the `position`th bit changed. - /// @param[in] data Value to be changed. - /// @param[in] position Nr. of the bit to be changed. `0` is the LSB. - /// @param[in] on Value to set the position'th bit to. - /// @return A suitably modified integer. - uint8_t setBit(const uint8_t data, const uint8_t position, const bool on) { - if (position >= 8) return data; // Outside of range. - uint8_t mask = 1 << position; - if (on) - return data | mask; - else - return data & ~mask; - } +/// Convert a byte of Binary Coded Decimal(BCD) into an Integer. +/// @param[in] bcd The BCD value. +/// @return A normal Integer value. +uint8_t bcdToUint8(const uint8_t bcd) { + if (bcd > 0x99) return 255; // Too big. + return (bcd >> 4) * 10 + (bcd & 0xF); +} - /// Alter the value of an Integer with the `position`th bit changed. - /// @param[in,out] data A pointer to the 8-bit integer to be changed. - /// @param[in] position Nr. of the bit to be changed. `0` is the LSB. - /// @param[in] on Value to set the position'th bit to. - void setBit(uint8_t * const data, const uint8_t position, const bool on) { - uint8_t mask = 1 << position; - if (on) - *data |= mask; - else - *data &= ~mask; - } +/// Convert an Integer into a byte of Binary Coded Decimal(BCD). +/// @param[in] integer The number to convert. +/// @return An 8-bit BCD value. +uint8_t uint8ToBcd(const uint8_t integer) { + if (integer > 99) return 255; // Too big. + return ((integer / 10) << 4) + (integer % 10); +} - /// Alter the value of an Integer with the `position`th bit changed. - /// @param[in,out] data A pointer to the 32-bit integer to be changed. - /// @param[in] position Nr. of the bit to be changed. `0` is the LSB. - /// @param[in] on Value to set the position'th bit to. - void setBit(uint32_t * const data, const uint8_t position, const bool on) { - uint32_t mask = (uint32_t)1 << position; - if (on) - *data |= mask; - else - *data &= ~mask; - } +/// Return the value of `position`th bit of an Integer. +/// @param[in] data Value to be examined. +/// @param[in] position Nr. of the Nth bit to be examined. `0` is the LSB. +/// @param[in] size Nr. of bits in data. +/// @return The bit's value. +bool getBit(const uint64_t data, const uint8_t position, const uint8_t size) { + if (position >= size) return false; // Outside of range. + return data & (1ULL << position); +} - /// Alter the value of an Integer with the `position`th bit changed. - /// @param[in,out] data A pointer to the 64-bit integer to be changed. - /// @param[in] position Nr. of the bit to be changed. `0` is the LSB. - /// @param[in] on Value to set the position'th bit to. - void setBit(uint64_t * const data, const uint8_t position, const bool on) { - uint64_t mask = (uint64_t)1 << position; - if (on) - *data |= mask; - else - *data &= ~mask; - } +/// Return the value of `position`th bit of an Integer. +/// @param[in] data Value to be examined. +/// @param[in] position Nr. of the Nth bit to be examined. `0` is the LSB. +/// @return The bit's value. +bool getBit(const uint8_t data, const uint8_t position) { + if (position >= 8) return false; // Outside of range. + return data & (1 << position); +} - /// Alter an uint8_t value by overwriting an arbitrary given number of bits. - /// @param[in,out] dst A pointer to the value to be changed. - /// @param[in] offset Nr. of bits from the Least Significant Bit to be ignored - /// @param[in] nbits Nr of bits of data to be placed into the destination. - /// @param[in] data The value to be placed. - void setBits(uint8_t * const dst, const uint8_t offset, const uint8_t nbits, - const uint8_t data) { - if (offset >= 8 || !nbits) return; // Short circuit as it won't change. - // Calculate the mask for the supplied value. - uint8_t mask = UINT8_MAX >> (8 - ((nbits > 8) ? 8 : nbits)); - // Calculate the mask & clear the space for the data. - // Clear the destination bits. - *dst &= ~(uint8_t)(mask << offset); - // Merge in the data. - *dst |= ((data & mask) << offset); - } +/// Return the value of an Integer with the `position`th bit changed. +/// @param[in] data Value to be changed. +/// @param[in] position Nr. of the bit to be changed. `0` is the LSB. +/// @param[in] on Value to set the position'th bit to. +/// @param[in] size Nr. of bits in data. +/// @return A suitably modified integer. +uint64_t setBit(const uint64_t data, const uint8_t position, const bool on, + const uint8_t size) { + if (position >= size) return data; // Outside of range. + uint64_t mask = 1ULL << position; + if (on) + return data | mask; + else + return data & ~mask; +} - /// Alter an uint32_t value by overwriting an arbitrary given number of bits. - /// @param[in,out] dst A pointer to the value to be changed. - /// @param[in] offset Nr. of bits from the Least Significant Bit to be ignored - /// @param[in] nbits Nr of bits of data to be placed into the destination. - /// @param[in] data The value to be placed. - void setBits(uint32_t * const dst, const uint8_t offset, const uint8_t nbits, - const uint32_t data) { - if (offset >= 32 || !nbits) return; // Short circuit as it won't change. - // Calculate the mask for the supplied value. - uint32_t mask = UINT32_MAX >> (32 - ((nbits > 32) ? 32 : nbits)); - // Calculate the mask & clear the space for the data. - // Clear the destination bits. - *dst &= ~(mask << offset); - // Merge in the data. - *dst |= ((data & mask) << offset); - } +/// Return the value of an Integer with the `position`th bit changed. +/// @param[in] data Value to be changed. +/// @param[in] position Nr. of the bit to be changed. `0` is the LSB. +/// @param[in] on Value to set the position'th bit to. +/// @return A suitably modified integer. +uint8_t setBit(const uint8_t data, const uint8_t position, const bool on) { + if (position >= 8) return data; // Outside of range. + uint8_t mask = 1 << position; + if (on) + return data | mask; + else + return data & ~mask; +} - /// Alter an uint64_t value by overwriting an arbitrary given number of bits. - /// @param[in,out] dst A pointer to the value to be changed. - /// @param[in] offset Nr. of bits from the Least Significant Bit to be ignored - /// @param[in] nbits Nr of bits of data to be placed into the destination. - /// @param[in] data The value to be placed. - void setBits(uint64_t * const dst, const uint8_t offset, const uint8_t nbits, - const uint64_t data) { - if (offset >= 64 || !nbits) return; // Short circuit as it won't change. - // Calculate the mask for the supplied value. - uint64_t mask = UINT64_MAX >> (64 - ((nbits > 64) ? 64 : nbits)); - // Calculate the mask & clear the space for the data. - // Clear the destination bits. - *dst &= ~(mask << offset); - // Merge in the data. - *dst |= ((data & mask) << offset); - } +/// Alter the value of an Integer with the `position`th bit changed. +/// @param[in,out] data A pointer to the 8-bit integer to be changed. +/// @param[in] position Nr. of the bit to be changed. `0` is the LSB. +/// @param[in] on Value to set the position'th bit to. +void setBit(uint8_t * const data, const uint8_t position, const bool on) { + uint8_t mask = 1 << position; + if (on) + *data |= mask; + else + *data &= ~mask; +} - /// Create byte pairs where the second byte of the pair is a bit - /// inverted/flipped copy of the first/previous byte of the pair. - /// @param[in,out] ptr A pointer to the start of array to modify. - /// @param[in] length The byte size of the array. - /// @note A length of `<= 1` will do nothing. - /// @return A ptr to the modified array. - uint8_t * invertBytePairs(uint8_t *ptr, const uint16_t length) { - for (uint16_t i = 1; i < length; i += 2) { - // Code done this way to avoid a compiler warning bug. - uint8_t inv = ~*(ptr + i - 1); - *(ptr + i) = inv; - } - return ptr; +/// Alter the value of an Integer with the `position`th bit changed. +/// @param[in,out] data A pointer to the 32-bit integer to be changed. +/// @param[in] position Nr. of the bit to be changed. `0` is the LSB. +/// @param[in] on Value to set the position'th bit to. +void setBit(uint32_t * const data, const uint8_t position, const bool on) { + uint32_t mask = static_cast(1) << position; + if (on) + *data |= mask; + else + *data &= ~mask; +} + +/// Alter the value of an Integer with the `position`th bit changed. +/// @param[in,out] data A pointer to the 64-bit integer to be changed. +/// @param[in] position Nr. of the bit to be changed. `0` is the LSB. +/// @param[in] on Value to set the position'th bit to. +void setBit(uint64_t * const data, const uint8_t position, const bool on) { + uint64_t mask = static_cast(1) << position; + if (on) + *data |= mask; + else + *data &= ~mask; +} + +/// Alter an uint8_t value by overwriting an arbitrary given number of bits. +/// @param[in,out] dst A pointer to the value to be changed. +/// @param[in] offset Nr. of bits from the Least Significant Bit to be ignored +/// @param[in] nbits Nr of bits of data to be placed into the destination. +/// @param[in] data The value to be placed. +void setBits(uint8_t * const dst, const uint8_t offset, const uint8_t nbits, + const uint8_t data) { + if (offset >= 8 || !nbits) return; // Short circuit as it won't change. + // Calculate the mask for the supplied value. + uint8_t mask = UINT8_MAX >> (8 - ((nbits > 8) ? 8 : nbits)); + // Calculate the mask & clear the space for the data. + // Clear the destination bits. + *dst &= ~(uint8_t)(mask << offset); + // Merge in the data. + *dst |= ((data & mask) << offset); +} + +/// Alter an uint32_t value by overwriting an arbitrary given number of bits. +/// @param[in,out] dst A pointer to the value to be changed. +/// @param[in] offset Nr. of bits from the Least Significant Bit to be ignored +/// @param[in] nbits Nr of bits of data to be placed into the destination. +/// @param[in] data The value to be placed. +void setBits(uint32_t * const dst, const uint8_t offset, const uint8_t nbits, + const uint32_t data) { + if (offset >= 32 || !nbits) return; // Short circuit as it won't change. + // Calculate the mask for the supplied value. + uint32_t mask = UINT32_MAX >> (32 - ((nbits > 32) ? 32 : nbits)); + // Calculate the mask & clear the space for the data. + // Clear the destination bits. + *dst &= ~(mask << offset); + // Merge in the data. + *dst |= ((data & mask) << offset); +} + +/// Alter an uint64_t value by overwriting an arbitrary given number of bits. +/// @param[in,out] dst A pointer to the value to be changed. +/// @param[in] offset Nr. of bits from the Least Significant Bit to be ignored +/// @param[in] nbits Nr of bits of data to be placed into the destination. +/// @param[in] data The value to be placed. +void setBits(uint64_t * const dst, const uint8_t offset, const uint8_t nbits, + const uint64_t data) { + if (offset >= 64 || !nbits) return; // Short circuit as it won't change. + // Calculate the mask for the supplied value. + uint64_t mask = UINT64_MAX >> (64 - ((nbits > 64) ? 64 : nbits)); + // Calculate the mask & clear the space for the data. + // Clear the destination bits. + *dst &= ~(mask << offset); + // Merge in the data. + *dst |= ((data & mask) << offset); +} + +/// Create byte pairs where the second byte of the pair is a bit +/// inverted/flipped copy of the first/previous byte of the pair. +/// @param[in,out] ptr A pointer to the start of array to modify. +/// @param[in] length The byte size of the array. +/// @note A length of `<= 1` will do nothing. +/// @return A ptr to the modified array. +uint8_t * invertBytePairs(uint8_t *ptr, const uint16_t length) { + for (uint16_t i = 1; i < length; i += 2) { + // Code done this way to avoid a compiler warning bug. + uint8_t inv = ~*(ptr + i - 1); + *(ptr + i) = inv; } + return ptr; +} - /// Check an array to see if every second byte of a pair is a bit - /// inverted/flipped copy of the first/previous byte of the pair. - /// @param[in] ptr A pointer to the start of array to check. - /// @param[in] length The byte size of the array. - /// @note A length of `<= 1` will always return true. - /// @return true, if every second byte is inverted. Otherwise false. - bool checkInvertedBytePairs(const uint8_t * const ptr, - const uint16_t length) { - for (uint16_t i = 1; i < length; i += 2) { - // Code done this way to avoid a compiler warning bug. - uint8_t inv = ~*(ptr + i - 1); - if (*(ptr + i) != inv) return false; - } - return true; +/// Check an array to see if every second byte of a pair is a bit +/// inverted/flipped copy of the first/previous byte of the pair. +/// @param[in] ptr A pointer to the start of array to check. +/// @param[in] length The byte size of the array. +/// @note A length of `<= 1` will always return true. +/// @return true, if every second byte is inverted. Otherwise false. +bool checkInvertedBytePairs(const uint8_t * const ptr, + const uint16_t length) { + for (uint16_t i = 1; i < length; i += 2) { + // Code done this way to avoid a compiler warning bug. + uint8_t inv = ~*(ptr + i - 1); + if (*(ptr + i) != inv) return false; } + return true; +} - /// Perform a low level bit manipulation sanity check for the given cpu - /// architecture and the compiler operation. Calls to this should return - /// 0 if everything is as expected, anything else means the library won't work - /// as expected. - /// @return A bit mask value of potential issues. - /// 0: (e.g. 0b00000000) Everything appears okay. - /// 0th bit set: (0b1) Unexpected bit field/packing encountered. - /// Try a different compiler. - /// 1st bit set: (0b10) Unexpected Endianness. Try a different compiler flag - /// or use a CPU different architecture. - /// e.g. A result of 3 (0b11) would mean both a bit field and an Endianness - /// issue has been found. - uint8_t lowLevelSanityCheck(void) { - const uint64_t kExpectedBitFieldResult = 0x8000012340000039ULL; - volatile uint32_t EndianTest = 0x12345678; - const uint8_t kBitFieldError = 0b01; - const uint8_t kEndiannessError = 0b10; - uint8_t result = 0; - union bitpackdata { - struct { - uint64_t lowestbit:1; // 0th bit - uint64_t next7bits:7; // 1-7th bits - uint64_t _unused_1:20; // 8-27th bits - // Cross the 32 bit boundary. - uint64_t crossbits:16; // 28-43rd bits - uint64_t _usused_2:18; // 44-61st bits - uint64_t highest2bits:2; // 62-63rd bits - }; - uint64_t all; +/// Perform a low level bit manipulation sanity check for the given cpu +/// architecture and the compiler operation. Calls to this should return +/// 0 if everything is as expected, anything else means the library won't work +/// as expected. +/// @return A bit mask value of potential issues. +/// 0: (e.g. 0b00000000) Everything appears okay. +/// 0th bit set: (0b1) Unexpected bit field/packing encountered. +/// Try a different compiler. +/// 1st bit set: (0b10) Unexpected Endianness. Try a different compiler flag +/// or use a CPU different architecture. +/// e.g. A result of 3 (0b11) would mean both a bit field and an Endianness +/// issue has been found. +uint8_t lowLevelSanityCheck(void) { + const uint64_t kExpectedBitFieldResult = 0x8000012340000039ULL; + volatile uint32_t EndianTest = 0x12345678; + const uint8_t kBitFieldError = 0b01; + const uint8_t kEndiannessError = 0b10; + uint8_t result = 0; + union bitpackdata { + struct { + uint64_t lowestbit:1; // 0th bit + uint64_t next7bits:7; // 1-7th bits + uint64_t _unused_1:20; // 8-27th bits + // Cross the 32 bit boundary. + uint64_t crossbits:16; // 28-43rd bits + uint64_t _usused_2:18; // 44-61st bits + uint64_t highest2bits:2; // 62-63rd bits }; - - bitpackdata data; - data.lowestbit = true; - data.next7bits = 0b0011100; // 0x1C - data._unused_1 = 0; - data.crossbits = 0x1234; - data._usused_2 = 0; - data.highest2bits = 0b10; // 2 - - if (data.all != kExpectedBitFieldResult) result |= kBitFieldError; - // Check that we are using Little Endian for integers + uint64_t all; + }; + + bitpackdata data; + data.lowestbit = true; + data.next7bits = 0b0011100; // 0x1C + data._unused_1 = 0; + data.crossbits = 0x1234; + data._usused_2 = 0; + data.highest2bits = 0b10; // 2 + + if (data.all != kExpectedBitFieldResult) result |= kBitFieldError; + // Check that we are using Little Endian for integers #if defined(BYTE_ORDER) && defined(LITTLE_ENDIAN) - if (BYTE_ORDER != LITTLE_ENDIAN) result |= kEndiannessError; + if (BYTE_ORDER != LITTLE_ENDIAN) result |= kEndiannessError; #endif #if defined(__IEEE_BIG_ENDIAN) || defined(__IEEE_BYTES_BIG_ENDIAN) - result |= kEndiannessError; + result |= kEndiannessError; #endif - // Brute force check for little endian. - if (*((uint8_t*)(&EndianTest)) != 0x78) // NOLINT(readability/casting) - result |= kEndiannessError; - return result; - } + // Brute force check for little endian. + if (*((uint8_t*)(&EndianTest)) != 0x78) // NOLINT(readability/casting) + result |= kEndiannessError; + return result; +} } // namespace irutils diff --git a/src/IRutils.h b/src/IRutils.h index 8c94df228..65a9b4dea 100644 --- a/src/IRutils.h +++ b/src/IRutils.h @@ -46,110 +46,111 @@ float fahrenheitToCelsius(const float deg); /// Namespace for covering common functions & procedures for advancd protocol /// handlers namespace irutils { - String addBoolToString(const bool value, const String label, +String addBoolToString(const bool value, const String label, + const bool precomma = true); +String addToggleToString(const bool toggle, const String label, const bool precomma = true); - String addToggleToString(const bool toggle, const String label, - const bool precomma = true); - String addIntToString(const uint16_t value, const String label, +String addIntToString(const uint16_t value, const String label, + const bool precomma = true); +String addSignedIntToString(const int16_t value, const String label, + const bool precomma = true); +String modelToStr(const decode_type_t protocol, const int16_t model); +String addModelToString(const decode_type_t protocol, const int16_t model, const bool precomma = true); - String addSignedIntToString(const int16_t value, const String label, - const bool precomma = true); - String modelToStr(const decode_type_t protocol, const int16_t model); - String addModelToString(const decode_type_t protocol, const int16_t model, - const bool precomma = true); - String addLabeledString(const String value, const String label, - const bool precomma = true); - String addTempToString(const uint16_t degrees, const bool celsius = true, - const bool precomma = true, - const bool isSensorTemp = false); - String addTempFloatToString(const float degrees, const bool celsius = true, - const bool precomma = true, - const bool isSensorTemp = false); - String addModeToString(const uint8_t mode, const uint8_t automatic, - const uint8_t cool, const uint8_t heat, - const uint8_t dry, const uint8_t fan); - String addFanToString(const uint8_t speed, const uint8_t high, - const uint8_t low, const uint8_t automatic, - const uint8_t quiet, const uint8_t medium, - const uint8_t maximum = 0xFF, - const uint8_t medium_high = 0xFF); - String addSwingHToString(const uint8_t position, const uint8_t automatic, - const uint8_t maxleft, const uint8_t left, - const uint8_t middle, - const uint8_t right, const uint8_t maxright, - const uint8_t off, - const uint8_t leftright, const uint8_t rightleft, - const uint8_t threed, const uint8_t wide); - String addSwingVToString(const uint8_t position, const uint8_t automatic, - const uint8_t highest, const uint8_t high, - const uint8_t uppermiddle, - const uint8_t middle, - const uint8_t lowermiddle, - const uint8_t low, const uint8_t lowest, - const uint8_t off, const uint8_t swing, - const uint8_t breeze, const uint8_t circulate); - String addDayToString(const uint8_t day_of_week, const int8_t offset = 0, +String addLabeledString(const String value, const String label, const bool precomma = true); - String addTimerModeToString(const uint8_t timerType, const uint8_t noTimer, - const uint8_t delayTimer, - const uint8_t schedule1 = 0xFF, - const uint8_t schedule2 = 0xFF, - const uint8_t schedule3 = 0xFF, - const bool precomma = true); - String irCommandTypeToString(uint8_t commandType, uint8_t acControlCmd, - uint8_t iFeelReportCmd = 0xFF, - uint8_t timerCmd = 0xFF, - uint8_t configCmd = 0xFF); - String dayToString(const uint8_t day_of_week, const int8_t offset = 0); - String daysBitmaskToString(uint8_t daysBitmap, uint8_t offset = 0); - String channelToString(const uint8_t channel); - String htmlEscape(const String unescaped); - String msToString(uint32_t const msecs); - String minsToString(const uint16_t mins); - uint8_t sumNibbles(const uint8_t * const start, const uint16_t length, - const uint8_t init = 0); - uint8_t sumNibbles(const uint64_t data, const uint8_t count = 16, - const uint8_t init = 0, const bool nibbleonly = true); - uint16_t sumBytes(const uint64_t data, const uint8_t count = 8, - const uint8_t init = 0, const bool byteonly = true); - uint8_t bcdToUint8(const uint8_t bcd); - uint8_t uint8ToBcd(const uint8_t integer); - bool getBit(const uint64_t data, const uint8_t position, - const uint8_t size = 64); - bool getBit(const uint8_t data, const uint8_t position); -#define GETBIT8(a, b) ((a) & ((uint8_t)1 << (b))) -#define GETBIT16(a, b) ((a) & ((uint16_t)1 << (b))) -#define GETBIT32(a, b) ((a) & ((uint32_t)1 << (b))) -#define GETBIT64(a, b) ((a) & ((uint64_t)1 << (b))) +String addTempToString(const uint16_t degrees, const bool celsius = true, + const bool precomma = true, + const bool isSensorTemp = false); +String addTempFloatToString(const float degrees, const bool celsius = true, + const bool precomma = true, + const bool isSensorTemp = false); +String addModeToString(const uint8_t mode, const uint8_t automatic, + const uint8_t cool, const uint8_t heat, + const uint8_t dry, const uint8_t fan); +String addFanToString(const uint8_t speed, const uint8_t high, + const uint8_t low, const uint8_t automatic, + const uint8_t quiet, const uint8_t medium, + const uint8_t maximum = 0xFF, + const uint8_t medium_high = 0xFF); +String addSwingHToString(const uint8_t position, const uint8_t automatic, + const uint8_t maxleft, const uint8_t left, + const uint8_t middle, + const uint8_t right, const uint8_t maxright, + const uint8_t off, + const uint8_t leftright, const uint8_t rightleft, + const uint8_t threed, const uint8_t wide); +String addSwingVToString(const uint8_t position, const uint8_t automatic, + const uint8_t highest, const uint8_t high, + const uint8_t uppermiddle, + const uint8_t middle, + const uint8_t lowermiddle, + const uint8_t low, const uint8_t lowest, + const uint8_t off, const uint8_t swing, + const uint8_t breeze, const uint8_t circulate); +String addDayToString(const uint8_t day_of_week, const int8_t offset = 0, + const bool precomma = true); +String addTimerModeToString(const uint8_t timerType, const uint8_t noTimer, + const uint8_t delayTimer, + const uint8_t schedule1 = 0xFF, + const uint8_t schedule2 = 0xFF, + const uint8_t schedule3 = 0xFF, + const bool precomma = true); +String irCommandTypeToString(uint8_t commandType, uint8_t acControlCmd, + uint8_t iFeelReportCmd = 0xFF, + uint8_t timerCmd = 0xFF, + uint8_t configCmd = 0xFF); +String dayToString(const uint8_t day_of_week, const int8_t offset = 0); +String daysBitmaskToString(uint8_t daysBitmap, uint8_t offset = 0); +String channelToString(const uint8_t channel); +String htmlEscape(const String unescaped); +String msToString(uint32_t const msecs); +String minsToString(const uint16_t mins); +uint8_t sumNibbles(const uint8_t * const start, const uint16_t length, + const uint8_t init = 0); +uint8_t sumNibbles(const uint64_t data, const uint8_t count = 16, + const uint8_t init = 0, const bool nibbleonly = true); +uint16_t sumBytes(const uint64_t data, const uint8_t count = 8, + const uint8_t init = 0, const bool byteonly = true); +uint8_t bcdToUint8(const uint8_t bcd); +uint8_t uint8ToBcd(const uint8_t integer); +bool getBit(const uint64_t data, const uint8_t position, + const uint8_t size = 64); +bool getBit(const uint8_t data, const uint8_t position); +#define GETBIT8(a, b) ((a) & (static_cast(1) << (b))) +#define GETBIT16(a, b) ((a) & (static_cast(1) << (b))) +#define GETBIT32(a, b) ((a) & (static_cast(1) << (b))) +#define GETBIT64(a, b) ((a) & (static_cast(1) << (b))) #define GETBITS8(data, offset, size) \ - (((data) & (((uint8_t)UINT8_MAX >> (8 - (size))) << (offset))) >> (offset)) + (((data) & ((static_cast(UINT8_MAX) >> (8 - (size))) << \ + (offset))) >> (offset)) #define GETBITS16(data, offset, size) \ - (((data) & (((uint16_t)UINT16_MAX >> (16 - (size))) << (offset))) >> \ - (offset)) + (((data) & ((static_cast(UINT16_MAX) >> (16 - (size))) << \ + (offset))) >> (offset)) #define GETBITS32(data, offset, size) \ - (((data) & (((uint32_t)UINT32_MAX >> (32 - (size))) << (offset))) >> \ - (offset)) + (((data) & ((static_cast(UINT32_MAX) >> (32 - (size))) << \ + (offset))) >> (offset)) #define GETBITS64(data, offset, size) \ - (((data) & (((uint64_t)UINT64_MAX >> (64 - (size))) << (offset))) >> \ - (offset)) - uint64_t setBit(const uint64_t data, const uint8_t position, - const bool on = true, const uint8_t size = 64); - uint8_t setBit(const uint8_t data, const uint8_t position, - const bool on = true); - void setBit(uint8_t * const data, const uint8_t position, - const bool on = true); - void setBit(uint32_t * const data, const uint8_t position, - const bool on = true); - void setBit(uint64_t * const data, const uint8_t position, - const bool on = true); - void setBits(uint8_t * const dst, const uint8_t offset, const uint8_t nbits, - const uint8_t data); - void setBits(uint32_t * const dst, const uint8_t offset, const uint8_t nbits, - const uint32_t data); - void setBits(uint64_t * const dst, const uint8_t offset, const uint8_t nbits, - const uint64_t data); - uint8_t * invertBytePairs(uint8_t *ptr, const uint16_t length); - bool checkInvertedBytePairs(const uint8_t * const ptr, const uint16_t length); - uint8_t lowLevelSanityCheck(void); + (((data) & ((static_cast(UINT64_MAX) >> (64 - (size))) << \ + (offset))) >> (offset)) +uint64_t setBit(const uint64_t data, const uint8_t position, + const bool on = true, const uint8_t size = 64); +uint8_t setBit(const uint8_t data, const uint8_t position, + const bool on = true); +void setBit(uint8_t * const data, const uint8_t position, + const bool on = true); +void setBit(uint32_t * const data, const uint8_t position, + const bool on = true); +void setBit(uint64_t * const data, const uint8_t position, + const bool on = true); +void setBits(uint8_t * const dst, const uint8_t offset, const uint8_t nbits, + const uint8_t data); +void setBits(uint32_t * const dst, const uint8_t offset, const uint8_t nbits, + const uint32_t data); +void setBits(uint64_t * const dst, const uint8_t offset, const uint8_t nbits, + const uint64_t data); +uint8_t * invertBytePairs(uint8_t *ptr, const uint16_t length); +bool checkInvertedBytePairs(const uint8_t * const ptr, const uint16_t length); +uint8_t lowLevelSanityCheck(void); } // namespace irutils #endif // IRUTILS_H_ diff --git a/src/ir_Argo.cpp b/src/ir_Argo.cpp index 2f5ce4ea6..ba72764a9 100644 --- a/src/ir_Argo.cpp +++ b/src/ir_Argo.cpp @@ -12,6 +12,8 @@ #include #include #include +#include +#include #ifndef UNIT_TEST #include #endif // UNIT_TEST @@ -1311,14 +1313,14 @@ stdAc::state_t IRArgoAC_WREM3::toCommon(void) const { namespace { - /// @brief Short-hand for casting enum to its underlying storage type - /// @tparam E The type of enum - /// @param e Enum value - /// @return Type of underlying value - template - constexpr typename std::underlying_type::type to_underlying(E e) noexcept { - return static_cast::type>(e); - } +/// @brief Short-hand for casting enum to its underlying storage type +/// @tparam E The type of enum +/// @param e Enum value +/// @return Type of underlying value +template +constexpr typename std::underlying_type::type to_underlying(E e) noexcept { + return static_cast::type>(e); +} } /// Convert the current internal state into a human readable string (WREM2). @@ -1556,16 +1558,16 @@ argo_ac_remote_model_t IRArgoAC_WREM3::getModel() const { } namespace { - String commandTypeToString(argoIrMessageType_t type, uint8_t channel) { - String result = irutils::irCommandTypeToString(to_underlying(type), - to_underlying(argoIrMessageType_t::AC_CONTROL), - to_underlying(argoIrMessageType_t::IFEEL_TEMP_REPORT), - to_underlying(argoIrMessageType_t::TIMER_COMMAND), - to_underlying(argoIrMessageType_t::CONFIG_PARAM_SET)); - result += irutils::channelToString(channel); - result += kColonSpaceStr; - return result; - } +String commandTypeToString(argoIrMessageType_t type, uint8_t channel) { + String result = irutils::irCommandTypeToString(to_underlying(type), + to_underlying(argoIrMessageType_t::AC_CONTROL), + to_underlying(argoIrMessageType_t::IFEEL_TEMP_REPORT), + to_underlying(argoIrMessageType_t::TIMER_COMMAND), + to_underlying(argoIrMessageType_t::CONFIG_PARAM_SET)); + result += irutils::channelToString(channel); + result += kColonSpaceStr; + return result; +} } // namespace /// Convert the current internal state into a human readable string (WREM3). @@ -1791,16 +1793,20 @@ bool IRArgoAC_WREM3::isValidWrem3Message(const uint8_t state[], switch (messageType) { case argoIrMessageType_t::AC_CONTROL : - if (stateLengthBytes != kArgo3AcControlStateLength) { return false; } + if (stateLengthBytes != kArgo3AcControlStateLength) + return false; break; - case argoIrMessageType_t::CONFIG_PARAM_SET: - if (stateLengthBytes != kArgo3ConfigStateLength) { return false; } + case argoIrMessageType_t::CONFIG_PARAM_SET: + if (stateLengthBytes != kArgo3ConfigStateLength) + return false; break; - case argoIrMessageType_t::TIMER_COMMAND: - if (stateLengthBytes != kArgo3TimerStateLength) { return false; } + case argoIrMessageType_t::TIMER_COMMAND: + if (stateLengthBytes != kArgo3TimerStateLength) + return false; break; case argoIrMessageType_t::IFEEL_TEMP_REPORT: - if (stateLengthBytes != kArgo3iFeelReportStateLength) { return false; } + if (stateLengthBytes != kArgo3iFeelReportStateLength) + return false; break; default: return false; diff --git a/src/ir_Bosch.cpp b/src/ir_Bosch.cpp index 56e9d2b99..c18dddf38 100644 --- a/src/ir_Bosch.cpp +++ b/src/ir_Bosch.cpp @@ -5,6 +5,7 @@ /// @see https://github.com/crankyoldgit/IRremoteESP8266/issues/1787 #include "ir_Bosch.h" +#include #if SEND_BOSCH144 /// Send a Bosch 144-bit / 18-byte message (96-bit message are also possible) diff --git a/src/ir_Daikin.cpp b/src/ir_Daikin.cpp index 114d38989..fc93ef52a 100644 --- a/src/ir_Daikin.cpp +++ b/src/ir_Daikin.cpp @@ -74,7 +74,8 @@ void IRsend::sendDaikin(const unsigned char data[], const uint16_t nbytes, sendGeneric(0, 0, // No header for the header kDaikinBitMark, kDaikinOneSpace, kDaikinBitMark, kDaikinZeroSpace, kDaikinBitMark, kDaikinZeroSpace + kDaikinGap, - (uint64_t)0b00000, kDaikinHeaderLength, 38, false, 0, 50); + static_cast(0b00000), kDaikinHeaderLength, 38, false, + 0, 50); // Data #1 if (nbytes < kDaikinStateLength) { // Are we using the legacy size? // Do this as a constant to save RAM and keep in flash memory @@ -675,7 +676,7 @@ void IRsend::sendDaikin2(const unsigned char data[], const uint16_t nbytes, for (uint16_t r = 0; r <= repeat; r++) { // Leader sendGeneric(kDaikin2LeaderMark, kDaikin2LeaderSpace, - 0, 0, 0, 0, 0, 0, (uint64_t) 0, // No data payload. + 0, 0, 0, 0, 0, 0, static_cast(0), // No data payload. 0, kDaikin2Freq, false, 0, 50); // Section #1 sendGeneric(kDaikin2HdrMark, kDaikin2HdrSpace, kDaikin2BitMark, @@ -2937,7 +2938,8 @@ bool IRrecv::decodeDaikin128(decode_results *results, uint16_t offset, kDaikinTolerance, kDaikinMarkExcess)) return false; } const uint16_t ksectionSize[kDaikin128Sections] = { - kDaikin128SectionLength, (uint16_t)(nbits / 8 - kDaikin128SectionLength)}; + kDaikin128SectionLength, + static_cast(nbits / 8 - kDaikin128SectionLength)}; // Data Sections uint16_t pos = 0; for (uint8_t section = 0; section < kDaikin128Sections; section++) { @@ -2987,7 +2989,7 @@ void IRsend::sendDaikin152(const unsigned char data[], const uint16_t nbytes, sendGeneric(0, 0, kDaikin152BitMark, kDaikin152OneSpace, kDaikin152BitMark, kDaikin152ZeroSpace, kDaikin152BitMark, kDaikin152Gap, - (uint64_t)0, kDaikin152LeaderBits, + static_cast(0), kDaikin152LeaderBits, kDaikin152Freq, false, 0, kDutyDefault); // Header + Data + Footer sendGeneric(kDaikin152HdrMark, kDaikin152HdrSpace, kDaikin152BitMark, @@ -3839,7 +3841,7 @@ void IRsend::sendDaikin312(const unsigned char data[], const uint16_t nbytes, kDaikin312BitMark, kDaikin312OneSpace, kDaikin312BitMark, kDaikin312ZeroSpace, kDaikin312BitMark, kDaikin312HdrGap, - (uint64_t)0b00000, kDaikinHeaderLength, + static_cast(0b00000), kDaikinHeaderLength, kDaikin2Freq, false, 0, kDutyDefault); // Section #1 sendGeneric(kDaikin312HdrMark, kDaikin312HdrSpace, kDaikin312BitMark, diff --git a/src/ir_Ecoclim.cpp b/src/ir_Ecoclim.cpp index e24559b5f..4aa320a4f 100644 --- a/src/ir_Ecoclim.cpp +++ b/src/ir_Ecoclim.cpp @@ -282,7 +282,7 @@ uint16_t IREcoclimAc::getClock(void) const { return _.Clock; } /// Set the clock time on the A/C unit. /// @param[in] nr_of_mins Nr. of minutes past midnight. void IREcoclimAc::setClock(const uint16_t nr_of_mins) { - _.Clock = std::min(nr_of_mins, (uint16_t)(24 * 60 - 1)); + _.Clock = std::min(nr_of_mins, static_cast(24 * 60 - 1)); } /// Get the Unit type/DIP switch settings of the remote. diff --git a/src/ir_GlobalCache.cpp b/src/ir_GlobalCache.cpp index e8ebac4af..4fbc34050 100644 --- a/src/ir_GlobalCache.cpp +++ b/src/ir_GlobalCache.cpp @@ -37,7 +37,8 @@ void IRsend::sendGC(uint16_t buf[], uint16_t len) { enableIROut(hz); uint32_t periodic_time = calcUSecPeriod(hz, false); uint8_t emits = - std::min(buf[kGlobalCacheRptIndex], (uint16_t)kGlobalCacheMaxRepeat); + std::min(buf[kGlobalCacheRptIndex], + static_cast(kGlobalCacheMaxRepeat)); // Repeat for (uint8_t repeat = 0; repeat < emits; repeat++) { // First time through, start at the beginning (kGlobalCacheStartIndex), diff --git a/src/ir_Goodweather.cpp b/src/ir_Goodweather.cpp index c3d9d62c8..3eb07c859 100644 --- a/src/ir_Goodweather.cpp +++ b/src/ir_Goodweather.cpp @@ -471,7 +471,7 @@ bool IRrecv::decodeGoodweather(decode_results* results, uint16_t offset, DPRINT("DEBUG: inverted = "); DPRINTLN((uint16_t)inverted); if (data != (inverted ^ 0xFF)) return false; // Data integrity failed. - dataSoFar |= (uint64_t)data << dataBitsSoFar; + dataSoFar |= static_cast(data) << dataBitsSoFar; } // Footer. diff --git a/src/ir_Haier.cpp b/src/ir_Haier.cpp index a60828282..c18846942 100644 --- a/src/ir_Haier.cpp +++ b/src/ir_Haier.cpp @@ -723,8 +723,10 @@ void IRHaierAC176::setTemp(const uint8_t degree, const bool fahrenheit) { temp = kHaierAcYrw02MinTempF; else if (temp > kHaierAcYrw02MaxTempF) temp = kHaierAcYrw02MaxTempF; - if (degree >= 77) { temp++; } - if (degree >= 79) { temp++; } + if (degree >= 77) + temp++; + if (degree >= 79) + temp++; // See at IRHaierAC176::getTemp() comments for clarification _.ExtraDegreeF = temp % 2; _.Temp = (temp - kHaierAcYrw02MinTempF -_.ExtraDegreeF) >> 1; @@ -741,7 +743,8 @@ void IRHaierAC176::setTemp(const uint8_t degree, const bool fahrenheit) { /// The unit of temperature is specified by UseFahrenheit value. /// @return The current setting for temperature. uint8_t IRHaierAC176::getTemp(void) const { - if (!_.UseFahrenheit) { return _.Temp + kHaierAcYrw02MinTempC; } + if (!_.UseFahrenheit) + return _.Temp + kHaierAcYrw02MinTempC; uint8_t degree = _.Temp*2 + kHaierAcYrw02MinTempF + _.ExtraDegreeF; // The way of coding the temperature in degree Fahrenheit is // kHaierAcYrw02MinTempF + Temp*2 + ExtraDegreeF, for example @@ -778,8 +781,10 @@ uint8_t IRHaierAC176::getTemp(void) const { // | 84F | 0b1101 | 0b0 | // | 86F | 0b1110 | 0b0 | // | 85F | 0b1101 | 0b1 | - if (degree >= 77) { degree--; } - if (degree >= 79) { degree--; } + if (degree >= 77) + degree--; + if (degree >= 79) + degree--; return degree; } @@ -958,7 +963,7 @@ uint8_t IRHaierAC176::getTimerMode(void) const { return _.TimerMode; } /// Set the number of minutes of the On Timer setting. /// @param[in] mins Nr. of Minutes for the Timer. `0` means disable the timer. void IRHaierAC176::setOnTimer(const uint16_t mins) { - const uint16_t nr_mins = std::min((uint16_t)(23 * 60 + 59), mins); + const uint16_t nr_mins = std::min(static_cast(23 * 60 + 59), mins); _.OnTimerHrs = nr_mins / 60; _.OnTimerMins = nr_mins % 60; @@ -988,7 +993,7 @@ uint16_t IRHaierAC176::getOnTimer(void) const { /// Set the number of minutes of the Off Timer setting. /// @param[in] mins Nr. of Minutes for the Timer. `0` means disable the timer. void IRHaierAC176::setOffTimer(const uint16_t mins) { - const uint16_t nr_mins = std::min((uint16_t)(23 * 60 + 59), mins); + const uint16_t nr_mins = std::min(static_cast(23 * 60 + 59), mins); _.OffTimerHrs = nr_mins / 60; _.OffTimerMins = nr_mins % 60; @@ -1617,8 +1622,10 @@ void IRHaierAC160::setTemp(const uint8_t degree, const bool fahrenheit) { temp = kHaierAcYrw02MinTempF; else if (temp > kHaierAcYrw02MaxTempF) temp = kHaierAcYrw02MaxTempF; - if (degree >= 77) { temp++; } - if (degree >= 79) { temp++; } + if (degree >= 77) + temp++; + if (degree >= 79) + temp++; // See at IRHaierAC160::getTemp() comments for clarification _.ExtraDegreeF = temp % 2; _.Temp = (temp - kHaierAcYrw02MinTempF -_.ExtraDegreeF) >> 1; @@ -1635,7 +1642,8 @@ void IRHaierAC160::setTemp(const uint8_t degree, const bool fahrenheit) { /// The unit of temperature is specified by UseFahrenheit value. /// @return The current setting for temperature. uint8_t IRHaierAC160::getTemp(void) const { - if (!_.UseFahrenheit) { return _.Temp + kHaierAcYrw02MinTempC; } + if (!_.UseFahrenheit) + return _.Temp + kHaierAcYrw02MinTempC; uint8_t degree = _.Temp*2 + kHaierAcYrw02MinTempF + _.ExtraDegreeF; // The way of coding the temperature in degree Fahrenheit is // kHaierAcYrw02MinTempF + Temp*2 + ExtraDegreeF, for example @@ -1672,8 +1680,10 @@ uint8_t IRHaierAC160::getTemp(void) const { // | 84F | 0b1101 | 0b0 | // | 86F | 0b1110 | 0b0 | // | 85F | 0b1101 | 0b1 | - if (degree >= 77) { degree--; } - if (degree >= 79) { degree--; } + if (degree >= 77) + degree--; + if (degree >= 79) + degree--; return degree; } @@ -1854,7 +1864,7 @@ uint8_t IRHaierAC160::getTimerMode(void) const { return _.TimerMode; } /// Set the number of minutes of the On Timer setting. /// @param[in] mins Nr. of Minutes for the Timer. `0` means disable the timer. void IRHaierAC160::setOnTimer(const uint16_t mins) { - const uint16_t nr_mins = std::min((uint16_t)(23 * 60 + 59), mins); + const uint16_t nr_mins = std::min(static_cast(23 * 60 + 59), mins); _.OnTimerHrs = nr_mins / 60; _.OnTimerMins = nr_mins % 60; @@ -1884,7 +1894,7 @@ uint16_t IRHaierAC160::getOnTimer(void) const { /// Set the number of minutes of the Off Timer setting. /// @param[in] mins Nr. of Minutes for the Timer. `0` means disable the timer. void IRHaierAC160::setOffTimer(const uint16_t mins) { - const uint16_t nr_mins = std::min((uint16_t)(23 * 60 + 59), mins); + const uint16_t nr_mins = std::min(static_cast(23 * 60 + 59), mins); _.OffTimerHrs = nr_mins / 60; _.OffTimerMins = nr_mins % 60; diff --git a/src/ir_Kelon.cpp b/src/ir_Kelon.cpp index bb8f16093..c891b738f 100644 --- a/src/ir_Kelon.cpp +++ b/src/ir_Kelon.cpp @@ -318,8 +318,9 @@ void IRKelonAc::setTimer(uint16_t mins) { /// @return The timer set minutes uint16_t IRKelonAc::getTimer() const { if (_.TimerHours >= 10) - return ((uint16_t) ((_.TimerHours << 1) | _.TimerHalfHour) - 10) * 60; - return (((uint16_t) _.TimerHours) * 60) + (_.TimerHalfHour ? 30 : 0); + return (static_cast((_.TimerHours << 1) | _.TimerHalfHour) - + 10) * 60; + return static_cast(_.TimerHours) * 60 + (_.TimerHalfHour ? 30 : 0); } /// Enable or disable the timer. Note that in order to enable the timer the diff --git a/src/ir_Lego.cpp b/src/ir_Lego.cpp index 3b7144768..6470bb547 100644 --- a/src/ir_Lego.cpp +++ b/src/ir_Lego.cpp @@ -38,7 +38,7 @@ void IRsend::sendLegoPf(const uint64_t data, const uint16_t nbits, // Spec says a pause before transmittion. if (channelid < 4) space((4 - channelid) * kLegoPfMinCommandLength); // Spec says there are a minimum of 5 message repeats. - for (uint16_t r = 0; r < std::max(repeat, (uint16_t)5); r++) { + for (uint16_t r = 0; r < std::max(repeat, static_cast(5)); r++) { // Lego has a special repeat mode which repeats a message with varying // start to start times. sendGeneric(kLegoPfBitMark, kLegoPfHdrSpace, diff --git a/src/ir_Lutron.cpp b/src/ir_Lutron.cpp index 5d0424784..11e4c0ae7 100644 --- a/src/ir_Lutron.cpp +++ b/src/ir_Lutron.cpp @@ -96,7 +96,7 @@ bool IRrecv::decodeLutron(decode_results *results, uint16_t offset, break; // We've likely reached the end of a message. } // Remove a bit length from the current entry. - entry = std::max(entry, (uint16_t)(kLutronTick / kRawTick)) - + entry = std::max(entry, static_cast(kLutronTick / kRawTick)) - kLutronTick / kRawTick; } if (offset % 2 && !match(entry, kLutronDelta, 0, kLutronDelta)) { diff --git a/src/ir_Midea.cpp b/src/ir_Midea.cpp index 80acfcda3..c8cd610a3 100644 --- a/src/ir_Midea.cpp +++ b/src/ir_Midea.cpp @@ -566,7 +566,7 @@ uint16_t IRMideaAC::getOnTimer(void) const { /// Setting it will disable that mode/settings. void IRMideaAC::setOnTimer(const uint16_t mins) { setEnableSensorTemp(false); - uint8_t halfhours = std::min((uint16_t)(24 * 60), mins) / 30; + uint8_t halfhours = std::min(static_cast(24 * 60), mins) / 30; if (halfhours) _.SensorTemp = ((halfhours - 1) << 1) | 1; else @@ -589,7 +589,7 @@ uint16_t IRMideaAC::getOffTimer(void) const { return _.OffTimer * 30 + 30; } /// of the actual device/protocol. /// @note A value of less than 30 will disable the Timer. void IRMideaAC::setOffTimer(const uint16_t mins) { - uint8_t halfhours = std::min((uint16_t)(24 * 60), mins) / 30; + uint8_t halfhours = std::min(static_cast(24 * 60), mins) / 30; if (halfhours) _.OffTimer = halfhours - 1; else diff --git a/src/ir_Mirage.cpp b/src/ir_Mirage.cpp index b7d6ce42d..caa72375a 100644 --- a/src/ir_Mirage.cpp +++ b/src/ir_Mirage.cpp @@ -389,8 +389,9 @@ void IRMirageAc::setClock(const uint32_t nr_of_seconds) { _.Minutes = _.Seconds = 0; // No clock setting. Clear it just in case. break; default: + // Limit to 23:59:59 uint32_t remaining = std::min( - nr_of_seconds, (uint32_t)(24 * 60 * 60 - 1)); // Limit to 23:59:59. + nr_of_seconds, static_cast(24 * 60 * 60 - 1)); _.Seconds = uint8ToBcd(remaining % 60); remaining /= 60; _.Minutes = uint8ToBcd(remaining % 60); @@ -586,7 +587,7 @@ uint16_t IRMirageAc::getOnTimer(void) const { /// Set the number of minutes for the On Timer. /// @param[in] nr_of_mins How long to set the timer for. 0 disables the timer. void IRMirageAc::setOnTimer(const uint16_t nr_of_mins) { - uint16_t mins = std::min(nr_of_mins, (uint16_t)(24 * 60)); + uint16_t mins = std::min(nr_of_mins, static_cast(24 * 60)); switch (_model) { case mirage_ac_remote_model_t::KKG29AC1: _.OnTimerEnable = (mins > 0); @@ -612,7 +613,7 @@ uint16_t IRMirageAc::getOffTimer(void) const { /// Set the number of minutes for the Off Timer. /// @param[in] nr_of_mins How long to set the timer for. 0 disables the timer. void IRMirageAc::setOffTimer(const uint16_t nr_of_mins) { - uint16_t mins = std::min(nr_of_mins, (uint16_t)(24 * 60)); + uint16_t mins = std::min(nr_of_mins, static_cast(24 * 60)); switch (_model) { case mirage_ac_remote_model_t::KKG29AC1: _.OffTimerEnable = (mins > 0); diff --git a/src/ir_Panasonic.cpp b/src/ir_Panasonic.cpp index 82acaac71..37241570c 100644 --- a/src/ir_Panasonic.cpp +++ b/src/ir_Panasonic.cpp @@ -88,7 +88,8 @@ void IRsend::sendPanasonic64(const uint64_t data, const uint16_t nbits, /// @note This protocol is a modified version of Kaseikyo. void IRsend::sendPanasonic(const uint16_t address, const uint32_t data, const uint16_t nbits, const uint16_t repeat) { - sendPanasonic64(((uint64_t)address << 32) | (uint64_t)data, nbits, repeat); + sendPanasonic64(static_cast(address) << 32 | + static_cast(data), nbits, repeat); } /// Calculate the raw Panasonic data based on device, subdevice, & function. @@ -105,8 +106,10 @@ uint64_t IRsend::encodePanasonic(const uint16_t manufacturer, const uint8_t subdevice, const uint8_t function) { uint8_t checksum = device ^ subdevice ^ function; - return (((uint64_t)manufacturer << 32) | ((uint64_t)device << 24) | - ((uint64_t)subdevice << 16) | ((uint64_t)function << 8) | checksum); + return ((static_cast(manufacturer) << 32) | + (static_cast(device) << 24) | + (static_cast(subdevice) << 16) | + (static_cast(function) << 8) | checksum); } #endif // (SEND_PANASONIC || SEND_DENON) diff --git a/src/ir_Pioneer.cpp b/src/ir_Pioneer.cpp index 6efe15c0a..98f4420f1 100644 --- a/src/ir_Pioneer.cpp +++ b/src/ir_Pioneer.cpp @@ -80,7 +80,7 @@ void IRsend::sendPioneer(const uint64_t data, const uint16_t nbits, /// `irsend.sendPioneer(irsend.encodePioneer(0xAA1C, 0xAA1C), 64, 0);` /// @see https://github.com/crankyoldgit/IRremoteESP8266/issues/1749#issuecomment-1028122645 uint64_t IRsend::encodePioneer(const uint16_t address, const uint16_t command) { - return (((uint64_t)encodeNEC(address >> 8, address & 0xFF)) << 32) | + return static_cast(encodeNEC(address >> 8, address & 0xFF)) << 32 | encodeNEC(command >> 8, command & 0xFF); } #endif // SEND_PIONEER diff --git a/src/ir_Pronto.cpp b/src/ir_Pronto.cpp index 2d4ffa759..dcd513d10 100644 --- a/src/ir_Pronto.cpp +++ b/src/ir_Pronto.cpp @@ -62,7 +62,8 @@ void IRsend::sendPronto(uint16_t data[], uint16_t len, uint16_t repeat) { // Pronto frequency is in Hz. uint16_t hz = - (uint16_t)(1000000U / (data[kProntoFreqOffset] * kProntoFreqFactor)); + static_cast(1000000U / (data[kProntoFreqOffset] * + kProntoFreqFactor)); enableIROut(hz); // Grab the length of the two sequences. diff --git a/src/ir_RC5_RC6.cpp b/src/ir_RC5_RC6.cpp index 1e0c75b3f..c47303aa2 100644 --- a/src/ir_RC5_RC6.cpp +++ b/src/ir_RC5_RC6.cpp @@ -129,7 +129,7 @@ uint16_t IRsend::encodeRC5X(const uint8_t address, const uint8_t command, // The 2nd start/field bit (MSB of the return value) is the value of the 7th // command bit. bool s2 = (command >> 6) & 1; - return ((uint16_t)s2 << (kRC5XBits - 1)) | + return (static_cast(s2) << (kRC5XBits - 1)) | encodeRC5(address, command, key_released); } @@ -174,7 +174,8 @@ uint64_t IRsend::encodeRC6(const uint32_t address, const uint8_t command, case kRC6Mode0Bits: return ((address & 0xFFF) << 8) | (command & 0xFF); case kRC6_36Bits: - return ((uint64_t)(address & 0xFFFFFFF) << 8) | (command & 0xFF); + return (static_cast(address & 0xFFFFFFF) << 8) | + (command & 0xFF); default: return 0; } @@ -360,7 +361,7 @@ bool IRrecv::decodeRC5(decode_results *results, uint16_t offset, results->repeat = false; if (is_rc5x) { results->decode_type = RC5X; - results->command |= ((uint32_t)is_rc5x) << 6; + results->command |= (static_cast(is_rc5x)) << 6; } else { results->decode_type = RC5; actual_bits--; // RC5 doesn't count the field bit as data. diff --git a/src/ir_RCMM.cpp b/src/ir_RCMM.cpp index 00cc58f02..36cbbd51a 100644 --- a/src/ir_RCMM.cpp +++ b/src/ir_RCMM.cpp @@ -101,13 +101,15 @@ bool IRrecv::decodeRCMM(decode_results *results, uint16_t offset, // Calc the maximum size in bits, the message can be, or that we can accept. int16_t maxBitSize = - std::min((uint16_t)results->rawlen - 5, (uint16_t)sizeof(data) * 8); + std::min(static_cast(results->rawlen) - 5, + static_cast(sizeof(data)) * 8); // Compliance if (strict) { // Technically the spec says bit sizes should be 12 xor 24. however // 32 bits has been seen from a device. We are going to assume // 12 <= bits <= 32 is the 'required' bit length for the spec. - if (maxBitSize < 12 || maxBitSize > 32) return false; + if (maxBitSize < 12 || maxBitSize > 32) + return false; if (maxBitSize < nbits) return false; // Short cut, we can never reach the expected nr. of bits. } diff --git a/src/ir_Samsung.cpp b/src/ir_Samsung.cpp index 958f2665b..fc5cbfcc7 100644 --- a/src/ir_Samsung.cpp +++ b/src/ir_Samsung.cpp @@ -775,7 +775,7 @@ uint16_t IRSamsungAc::getSleepTimer(void) const { } #define TIMER_RESOLUTION(mins) \ - (((std::min((mins), (uint16_t)(24 * 60))) / 10) * 10) + (((std::min((mins), static_cast(24 * 60))) / 10) * 10) /// Set the On Timer value of the A/C. /// @param[in] nr_of_mins The number of minutes the timer should be. diff --git a/src/ir_Sanyo.cpp b/src/ir_Sanyo.cpp index 4b99d0492..6c939e18d 100644 --- a/src/ir_Sanyo.cpp +++ b/src/ir_Sanyo.cpp @@ -892,7 +892,8 @@ uint16_t IRSanyoAc88::getClock(void) const { /// Set the current clock time. /// @param[in] mins_since_midnight The time as nr. of minutes past midnight. void IRSanyoAc88::setClock(const uint16_t mins_since_midnight) { - uint16_t mins = std::min(mins_since_midnight, (uint16_t)(23 * 60 + 59)); + uint16_t mins = std::min(mins_since_midnight, + static_cast(23 * 60 + 59)); _.ClockMins = mins % 60; _.ClockHrs = mins / 60; _.ClockSecs = 0; diff --git a/src/ir_Sharp.cpp b/src/ir_Sharp.cpp index d184c9301..984551ee0 100644 --- a/src/ir_Sharp.cpp +++ b/src/ir_Sharp.cpp @@ -35,9 +35,11 @@ const uint16_t kSharpGapTicks = 1677; const uint16_t kSharpGap = kSharpGapTicks * kSharpTick; // Address(5) + Command(8) + Expansion(1) + Check(1) const uint64_t kSharpToggleMask = - ((uint64_t)1 << (kSharpBits - kSharpAddressBits)) - 1; -const uint64_t kSharpAddressMask = ((uint64_t)1 << kSharpAddressBits) - 1; -const uint64_t kSharpCommandMask = ((uint64_t)1 << kSharpCommandBits) - 1; + (static_cast(1) << (kSharpBits - kSharpAddressBits)) - 1; +const uint64_t kSharpAddressMask = (static_cast(1) << + kSharpAddressBits) - 1; +const uint64_t kSharpCommandMask = (static_cast(1) << + kSharpCommandBits) - 1; using irutils::addBoolToString; using irutils::addFanToString; diff --git a/src/ir_Sherwood.cpp b/src/ir_Sherwood.cpp index 76ffc35ff..e3a7eb506 100644 --- a/src/ir_Sherwood.cpp +++ b/src/ir_Sherwood.cpp @@ -19,6 +19,7 @@ /// @note Sherwood remote codes appear to be NEC codes with a mandatory repeat /// code. i.e. repeat should be >= kSherwoodMinRepeat (1). void IRsend::sendSherwood(uint64_t data, uint16_t nbits, uint16_t repeat) { - sendNEC(data, nbits, std::max((uint16_t)kSherwoodMinRepeat, repeat)); + sendNEC(data, nbits, + std::max(static_cast(kSherwoodMinRepeat), repeat)); } #endif // SEND_SHERWOOD diff --git a/src/ir_Teco.cpp b/src/ir_Teco.cpp index 289e15d52..a8845fb05 100644 --- a/src/ir_Teco.cpp +++ b/src/ir_Teco.cpp @@ -231,7 +231,8 @@ uint16_t IRTecoAc::getTimer(void) const { /// `0` will clear the timer. Max is 24 hrs. /// @note Time is stored internally in increments of 30 mins. void IRTecoAc::setTimer(const uint16_t nr_mins) { - uint16_t mins = std::min(nr_mins, (uint16_t)(24 * 60)); // Limit to 24 hrs. + // Limit to 24 hrs + uint16_t mins = std::min(nr_mins, static_cast(24 * 60)); uint8_t hours = mins / 60; _.TimerOn = mins > 0; // Set the timer flag. _.HalfHour = (mins % 60) >= 30; diff --git a/src/ir_Toshiba.cpp b/src/ir_Toshiba.cpp index 68ca47d74..53eff99d1 100644 --- a/src/ir_Toshiba.cpp +++ b/src/ir_Toshiba.cpp @@ -106,7 +106,7 @@ uint16_t IRToshibaAC::getInternalStateLength(const uint8_t state[], const uint16_t size) { if (size < kToshibaAcLengthByte) return 0; // Fix: Extract the last 4 bits instead - return std::min((uint16_t)((state[kToshibaAcLengthByte] & 0xF) + return std::min(static_cast((state[kToshibaAcLengthByte] & 0xF) + kToshibaAcMinLength), kToshibaACStateLengthLong); } diff --git a/src/ir_Voltas.cpp b/src/ir_Voltas.cpp index 9837e0605..71eceb6c7 100644 --- a/src/ir_Voltas.cpp +++ b/src/ir_Voltas.cpp @@ -422,7 +422,7 @@ uint16_t IRVoltas::getOnTime(void) const { /// 0 disables the timer. Max is 23 hrs & 59 mins (1439 mins) void IRVoltas::setOnTime(const uint16_t nr_of_mins) { // Cap the total number of mins. - uint16_t mins = std::min(nr_of_mins, (uint16_t)(23 * 60 + 59)); + uint16_t mins = std::min(nr_of_mins, static_cast(23 * 60 + 59)); uint16_t hrs = (mins / 60) + 1; _.OnTimerMins = mins % 60; _.OnTimer12Hr = hrs / 12; @@ -442,7 +442,7 @@ uint16_t IRVoltas::getOffTime(void) const { /// 0 disables the timer. Max is 23 hrs & 59 mins (1439 mins) void IRVoltas::setOffTime(const uint16_t nr_of_mins) { // Cap the total number of mins. - uint16_t mins = std::min(nr_of_mins, (uint16_t)(23 * 60 + 59)); + uint16_t mins = std::min(nr_of_mins, static_cast(23 * 60 + 59)); uint16_t hrs = (mins / 60) + 1; _.OffTimerMins = mins % 60; _.OffTimer12Hr = hrs / 12; diff --git a/src/ir_Xmp.cpp b/src/ir_Xmp.cpp index 5d9da4c52..a60bcdbbb 100644 --- a/src/ir_Xmp.cpp +++ b/src/ir_Xmp.cpp @@ -30,81 +30,81 @@ const uint8_t kXmpRepeatCodeAlt = 0b1001; using irutils::setBits; namespace IRXmpUtils { - /// Get the current checksum value from an XMP data section. - /// @param[in] data The value of the data section. - /// @param[in] nbits The number of data bits in the section. - /// @return The value of the stored checksum. - /// @warning Returns 0 if we can't obtain a valid checksum. - uint8_t getSectionChecksum(const uint32_t data, const uint16_t nbits) { - // The checksum is the 2nd most significant nibble of a section. - return (nbits < 2 * kNibbleSize) ? 0 : GETBITS32(data, - nbits - (2 * kNibbleSize), - kNibbleSize); - } +/// Get the current checksum value from an XMP data section. +/// @param[in] data The value of the data section. +/// @param[in] nbits The number of data bits in the section. +/// @return The value of the stored checksum. +/// @warning Returns 0 if we can't obtain a valid checksum. +uint8_t getSectionChecksum(const uint32_t data, const uint16_t nbits) { + // The checksum is the 2nd most significant nibble of a section. + return (nbits < 2 * kNibbleSize) ? 0 : GETBITS32(data, + nbits - (2 * kNibbleSize), + kNibbleSize); +} - /// Calculate the correct checksum value for an XMP data section. - /// @param[in] data The value of the data section. - /// @param[in] nbits The number of data bits in the section. - /// @return The value of the correct checksum. - uint8_t calcSectionChecksum(const uint32_t data, const uint16_t nbits) { - return (0xF & ~(irutils::sumNibbles(data, nbits / kNibbleSize, 0xF, false) - - getSectionChecksum(data, nbits))); - } +/// Calculate the correct checksum value for an XMP data section. +/// @param[in] data The value of the data section. +/// @param[in] nbits The number of data bits in the section. +/// @return The value of the correct checksum. +uint8_t calcSectionChecksum(const uint32_t data, const uint16_t nbits) { + return (0xF & ~(irutils::sumNibbles(data, nbits / kNibbleSize, 0xF, false) - + getSectionChecksum(data, nbits))); +} - /// Recalculate a XMP message code ensuring it has the checksums valid. - /// @param[in] data The value of the XMP message code. - /// @param[in] nbits The number of data bits in the entire message code. - /// @return The corrected XMP message with valid checksum sections. - uint64_t updateChecksums(const uint64_t data, const uint16_t nbits) { - const uint16_t sectionbits = nbits / kXmpSections; - uint64_t result = data; - for (uint16_t sectionOffset = 0; sectionOffset < nbits; - sectionOffset += sectionbits) { - const uint16_t checksumOffset = sectionOffset + sectionbits - - (2 * kNibbleSize); - setBits(&result, checksumOffset, kNibbleSize, - calcSectionChecksum(GETBITS64(data, sectionOffset, sectionbits), - sectionbits)); - } - return result; +/// Recalculate a XMP message code ensuring it has the checksums valid. +/// @param[in] data The value of the XMP message code. +/// @param[in] nbits The number of data bits in the entire message code. +/// @return The corrected XMP message with valid checksum sections. +uint64_t updateChecksums(const uint64_t data, const uint16_t nbits) { + const uint16_t sectionbits = nbits / kXmpSections; + uint64_t result = data; + for (uint16_t sectionOffset = 0; sectionOffset < nbits; + sectionOffset += sectionbits) { + const uint16_t checksumOffset = sectionOffset + sectionbits - + (2 * kNibbleSize); + setBits(&result, checksumOffset, kNibbleSize, + calcSectionChecksum(GETBITS64(data, sectionOffset, sectionbits), + sectionbits)); } + return result; +} - /// Calculate the bit offset the repeat nibble in an XMP code. - /// @param[in] nbits The number of data bits in the entire message code. - /// @return The offset to the start of the XMP repeat nibble. - uint16_t calcRepeatOffset(const uint16_t nbits) { - return (nbits < 3 * kNibbleSize) ? 0 - : (nbits / kXmpSections) - - (3 * kNibbleSize); - } +/// Calculate the bit offset the repeat nibble in an XMP code. +/// @param[in] nbits The number of data bits in the entire message code. +/// @return The offset to the start of the XMP repeat nibble. +uint16_t calcRepeatOffset(const uint16_t nbits) { + return (nbits < 3 * kNibbleSize) ? 0 + : (nbits / kXmpSections) - + (3 * kNibbleSize); +} - /// Test if an XMP message code is a repeat or not. - /// @param[in] data The value of the XMP message code. - /// @param[in] nbits The number of data bits in the entire message code. - /// @return true, if it looks like a repeat, false if not. - bool isRepeat(const uint64_t data, const uint16_t nbits) { - switch (GETBITS64(data, calcRepeatOffset(nbits), kNibbleSize)) { - case kXmpRepeatCode: - case kXmpRepeatCodeAlt: - return true; - default: - return false; - } +/// Test if an XMP message code is a repeat or not. +/// @param[in] data The value of the XMP message code. +/// @param[in] nbits The number of data bits in the entire message code. +/// @return true, if it looks like a repeat, false if not. +bool isRepeat(const uint64_t data, const uint16_t nbits) { + switch (GETBITS64(data, calcRepeatOffset(nbits), kNibbleSize)) { + case kXmpRepeatCode: + case kXmpRepeatCodeAlt: + return true; + default: + return false; } +} - /// Adjust an XMP message code to make it a valid repeat or non-repeat code. - /// @param[in] data The value of the XMP message code. - /// @param[in] nbits The number of data bits in the entire message code. - /// @param[in] repeat_code The value of the XMP repeat nibble to use. - /// A value of `8` is the normal value for a repeat. `9` has also been seen. - /// A value of `0` will convert the code to a non-repeat code. - /// @return The valud of the modified XMP code. - uint64_t adjustRepeat(const uint64_t data, const uint16_t nbits, - const uint8_t repeat_code) { - uint64_t result = data; - setBits(&result, calcRepeatOffset(nbits), kNibbleSize, repeat_code); - return updateChecksums(result, nbits); - } +/// Adjust an XMP message code to make it a valid repeat or non-repeat code. +/// @param[in] data The value of the XMP message code. +/// @param[in] nbits The number of data bits in the entire message code. +/// @param[in] repeat_code The value of the XMP repeat nibble to use. +/// A value of `8` is the normal value for a repeat. `9` has also been seen. +/// A value of `0` will convert the code to a non-repeat code. +/// @return The valud of the modified XMP code. +uint64_t adjustRepeat(const uint64_t data, const uint16_t nbits, + const uint8_t repeat_code) { + uint64_t result = data; + setBits(&result, calcRepeatOffset(nbits), kNibbleSize, repeat_code); + return updateChecksums(result, nbits); +} } // namespace IRXmpUtils using IRXmpUtils::calcSectionChecksum; @@ -126,7 +126,8 @@ void IRsend::sendXmp(const uint64_t data, const uint16_t nbits, uint64_t send_data = data; for (uint16_t r = 0; r <= repeat; r++) { uint16_t bits_so_far = kXmpWordSize; - for (uint64_t mask = ((uint64_t)kXmpMaxWordValue) << (nbits - kXmpWordSize); + for (uint64_t mask = static_cast(kXmpMaxWordValue) << + (nbits - kXmpWordSize); mask; mask >>= kXmpWordSize) { uint8_t word = (send_data & mask) >> (nbits - bits_so_far); diff --git a/test/IRsend_test.cpp b/test/IRsend_test.cpp index 51fae7499..e1cb78f4e 100644 --- a/test/IRsend_test.cpp +++ b/test/IRsend_test.cpp @@ -674,16 +674,16 @@ TEST(TestSend, GenericSimpleSendMethodFailure) { for (int i = 0; i <= kLastDecodeType; i++) { if (hasACState((decode_type_t)i) && i != GREE) { // Gree is an exception. // Check it fails. - ASSERT_FALSE(irsend.send((decode_type_t)i, (uint64_t)0, 0)); + ASSERT_FALSE(irsend.send((decode_type_t)i, static_cast(0), 0)); } } // Test some other special cases. - ASSERT_FALSE(irsend.send(UNKNOWN, (uint64_t)0, 0)); - ASSERT_FALSE(irsend.send(UNUSED, (uint64_t)0, 0)); - ASSERT_FALSE(irsend.send(RAW, (uint64_t)0, 0)); - ASSERT_FALSE(irsend.send(PRONTO, (uint64_t)0, 0)); - ASSERT_FALSE(irsend.send(GLOBALCACHE, (uint64_t)0, 0)); + ASSERT_FALSE(irsend.send(UNKNOWN, static_cast(0), 0)); + ASSERT_FALSE(irsend.send(UNUSED, static_cast(0), 0)); + ASSERT_FALSE(irsend.send(RAW, static_cast(0), 0)); + ASSERT_FALSE(irsend.send(PRONTO, static_cast(0), 0)); + ASSERT_FALSE(irsend.send(GLOBALCACHE, static_cast(0), 0)); } // Test expected to work/produce a message for complex irsend:send() diff --git a/test/IRsend_test.h b/test/IRsend_test.h index f43409433..60787988e 100644 --- a/test/IRsend_test.h +++ b/test/IRsend_test.h @@ -72,7 +72,7 @@ class IRsendTest : public IRsend { capture.decode_type = UNKNOWN; capture.bits = 0; capture.rawlen = last + 2 - offset; - capture.overflow = (last - offset >= (int16_t)RAW_BUF); + capture.overflow = (last - offset >= static_cast(RAW_BUF)); capture.repeat = false; capture.address = 0; capture.command = 0; diff --git a/test/IRutils_test.cpp b/test/IRutils_test.cpp index c5a6d1339..d0d15c896 100644 --- a/test/IRutils_test.cpp +++ b/test/IRutils_test.cpp @@ -582,12 +582,12 @@ TEST(TestUtils, getBit) { EXPECT_FALSE(GETBIT8((uint8_t)0b01111111, 7)); EXPECT_TRUE(GETBIT8((uint8_t)0b10000000, 7)); // uint64_t method. - EXPECT_FALSE(irutils::getBit((uint64_t)0, 0)); - EXPECT_TRUE(irutils::getBit((uint64_t)1, 0)); - EXPECT_FALSE(irutils::getBit((uint64_t)0b01, 1)); - EXPECT_TRUE(irutils::getBit((uint64_t)0b10, 1)); - EXPECT_FALSE(irutils::getBit((uint64_t)0b01111111, 7)); - EXPECT_TRUE(irutils::getBit((uint64_t)0b10000000, 7)); + EXPECT_FALSE(irutils::getBit(static_cast(0), 0)); + EXPECT_TRUE(irutils::getBit(static_cast(1), 0)); + EXPECT_FALSE(irutils::getBit(static_cast(0b01), 1)); + EXPECT_TRUE(irutils::getBit(static_cast(0b10), 1)); + EXPECT_FALSE(irutils::getBit(static_cast(0b01111111), 7)); + EXPECT_TRUE(irutils::getBit(static_cast(0b10000000), 7)); } TEST(TestUtils, setBit) { @@ -603,16 +603,17 @@ TEST(TestUtils, setBit) { EXPECT_EQ(0b11111111, irutils::setBit((uint8_t)0b01111111, 7, true)); EXPECT_EQ(0, irutils::setBit((uint8_t)0b10000000, 7, false)); // uint64_t method. - EXPECT_EQ(0, irutils::setBit((uint64_t)0, 0, false)); - EXPECT_EQ(0, irutils::setBit((uint64_t)1, 0, false)); - EXPECT_EQ(1, irutils::setBit((uint64_t)0, 0, true)); - EXPECT_EQ(1, irutils::setBit((uint64_t)1, 0, true)); - EXPECT_EQ(0b101, irutils::setBit((uint64_t)0b101, 1, false)); - EXPECT_EQ(0b100, irutils::setBit((uint64_t)0b110, 1, false)); - EXPECT_EQ(0b111, irutils::setBit((uint64_t)0b101, 1, true)); - EXPECT_EQ(0b110, irutils::setBit((uint64_t)0b110, 1, true)); - EXPECT_EQ(0b11111111, irutils::setBit((uint64_t)0b01111111, 7, true)); - EXPECT_EQ(0, irutils::setBit((uint64_t)0b10000000, 7, false)); + EXPECT_EQ(0, irutils::setBit(static_cast(0), 0, false)); + EXPECT_EQ(0, irutils::setBit(static_cast(1), 0, false)); + EXPECT_EQ(1, irutils::setBit(static_cast(0), 0, true)); + EXPECT_EQ(1, irutils::setBit(static_cast(1), 0, true)); + EXPECT_EQ(0b101, irutils::setBit(static_cast(0b101), 1, false)); + EXPECT_EQ(0b100, irutils::setBit(static_cast(0b110), 1, false)); + EXPECT_EQ(0b111, irutils::setBit(static_cast(0b101), 1, true)); + EXPECT_EQ(0b110, irutils::setBit(static_cast(0b110), 1, true)); + EXPECT_EQ(0b11111111, + irutils::setBit(static_cast(0b01111111), 7, true)); + EXPECT_EQ(0, irutils::setBit(static_cast(0b10000000), 7, false)); // uint8_t Pointer method. uint8_t data = 0; irutils::setBit(&data, 0, false); diff --git a/test/ir_Argo_test.cpp b/test/ir_Argo_test.cpp index 817272a17..0a83ef50e 100644 --- a/test/ir_Argo_test.cpp +++ b/test/ir_Argo_test.cpp @@ -2,7 +2,13 @@ // Copyright 2022 Mateusz Bronk (mbronk) #include #include +#include #include +#include +#include +#include +#include +#include #include "ir_Argo.h" #include "IRac.h" #include "IRrecv.h" diff --git a/test/ir_Gorenje_test.cpp b/test/ir_Gorenje_test.cpp index 245b29b98..dc803ffdd 100644 --- a/test/ir_Gorenje_test.cpp +++ b/test/ir_Gorenje_test.cpp @@ -1,5 +1,7 @@ // Copyright 2022 Mateusz Bronk (mbronk) +#include +#include #include "IRac.h" #include "IRsend.h" #include "IRsend_test.h" diff --git a/test/ir_Gree_test.cpp b/test/ir_Gree_test.cpp index d2d8354ed..a5e77c529 100644 --- a/test/ir_Gree_test.cpp +++ b/test/ir_Gree_test.cpp @@ -202,7 +202,7 @@ TEST(TestSendGree, CompareUint64ToCharResults) { irsend_chars.reset(); irsend_uint64.reset(); irsend_chars.sendGree(gree_zero_code); - irsend_uint64.sendGree((uint64_t)0x0); + irsend_uint64.sendGree(static_cast(0x0)); ASSERT_EQ(irsend_chars.outputStr(), irsend_uint64.outputStr()); } diff --git a/tools/code_to_raw.cpp b/tools/code_to_raw.cpp index 7358f16da..49838d634 100644 --- a/tools/code_to_raw.cpp +++ b/tools/code_to_raw.cpp @@ -5,6 +5,7 @@ #include #include #include +#include #include #include "IRac.h" #include "IRsend.h" diff --git a/tools/gc_decode.cpp b/tools/gc_decode.cpp index f1c374bbe..d1a543867 100644 --- a/tools/gc_decode.cpp +++ b/tools/gc_decode.cpp @@ -6,6 +6,8 @@ #include #include #include +#include +#include #include #include "IRac.h" #include "IRsend.h" @@ -21,7 +23,7 @@ void str_to_uint16(char *str, uint16_t *res, uint8_t base) { if (errno == ERANGE || val < 0 || val > UINT16_MAX || end == str || *end != '\0') return; - *res = (uint16_t)val; + *res = static_cast(val); } void usage_error(char *name) { diff --git a/tools/mode2_decode.cpp b/tools/mode2_decode.cpp index 63dfa6221..e81df390b 100644 --- a/tools/mode2_decode.cpp +++ b/tools/mode2_decode.cpp @@ -21,6 +21,7 @@ space 500000 #include #include #include +#include #include #include #include @@ -37,7 +38,7 @@ void str_to_uint16(char *str, uint16_t *res, uint8_t base) { if (errno == ERANGE || val < 0 || val > UINT16_MAX || end == str || *end != '\0') return; - *res = (uint16_t)val; + *res = static_cast(val); } void usage_error(char *name) {