Skip to content

Commit 69d1926

Browse files
author
shimmy-void
committed
Fixed code lints and decodeFujitsuAC264
1 parent 3c6c741 commit 69d1926

File tree

4 files changed

+137
-97
lines changed

4 files changed

+137
-97
lines changed

src/IRrecv.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,10 @@ bool IRrecv::decode(decode_results *results, irparams_t *save,
698698
// Fujitsu A/C needs to precede Panasonic and Denon as it has a short
699699
// message which looks exactly the same as a Panasonic/Denon message.
700700
DPRINTLN("Attempting Fujitsu A/C264 decode");
701-
if (decodeFujitsuAC264(results, offset)) return true;
701+
if (decodeFujitsuAC264(results, offset, kFujitsuAc264Bits) ||
702+
decodeFujitsuAC264(results, offset, kFujitsuAc264BitsMiddle) ||
703+
decodeFujitsuAC264(results, offset, kFujitsuAc264BitsShort))
704+
return true;
702705
#endif
703706
#if DECODE_DENON
704707
// Denon needs to precede Panasonic as it is a special case of Panasonic.

src/ir_Fujitsu.cpp

+66-42
Original file line numberDiff line numberDiff line change
@@ -1202,21 +1202,28 @@ bool IRFujitsuAC264::setRaw(const uint8_t newState[], const uint16_t length) {
12021202
}
12031203
switch (length) {
12041204
case kFujitsuAc264StateLengthShort:
1205-
if (std::memcmp(_.raw, kFujitsuAc264StatesTurnOff, kFujitsuAc264StateLengthShort) == 0)
1205+
if (std::memcmp(_.raw, kFujitsuAc264StatesTurnOff,
1206+
kFujitsuAc264StateLengthShort) == 0)
12061207
_cmd = kFujitsuAc264SpCmdTurnOff;
1207-
if (std::memcmp(_.raw, kFujitsuAc264StatesTogglePowerful, kFujitsuAc264StateLengthShort) == 0)
1208+
if (std::memcmp(_.raw, kFujitsuAc264StatesTogglePowerful,
1209+
kFujitsuAc264StateLengthShort) == 0)
12081210
_cmd = kFujitsuAc264SpCmdTogglePowerful;
1209-
if (std::memcmp(_.raw, kFujitsuAc264StatesEcoFanOff, kFujitsuAc264StateLengthShort) == 0)
1211+
if (std::memcmp(_.raw, kFujitsuAc264StatesEcoFanOff,
1212+
kFujitsuAc264StateLengthShort) == 0)
12101213
_cmd = kFujitsuAc264SpCmdEcoFanOff;
1211-
if (std::memcmp(_.raw, kFujitsuAc264StatesEcoFanOn, kFujitsuAc264StateLengthShort) == 0)
1214+
if (std::memcmp(_.raw, kFujitsuAc264StatesEcoFanOn,
1215+
kFujitsuAc264StateLengthShort) == 0)
12121216
_cmd = kFujitsuAc264SpCmdEcoFanOn;
12131217
break;
12141218
case kFujitsuAc264StateLengthMiddle:
1215-
if (std::memcmp(_.raw, kFujitsuAc264StatesOutsideQuietOff, kFujitsuAc264StateLengthMiddle) == 0)
1219+
if (std::memcmp(_.raw, kFujitsuAc264StatesOutsideQuietOff,
1220+
kFujitsuAc264StateLengthMiddle) == 0)
12161221
_cmd = kFujitsuAc264SpCmdOutsideQuietOff;
1217-
if (std::memcmp(_.raw, kFujitsuAc264StatesOutsideQuietOn, kFujitsuAc264StateLengthMiddle) == 0)
1222+
if (std::memcmp(_.raw, kFujitsuAc264StatesOutsideQuietOn,
1223+
kFujitsuAc264StateLengthMiddle) == 0)
12181224
_cmd = kFujitsuAc264SpCmdOutsideQuietOn;
1219-
if (std::memcmp(_.raw, kFujitsuAc264StatesToggleSterilization, kFujitsuAc264StateLengthMiddle) == 0)
1225+
if (std::memcmp(_.raw, kFujitsuAc264StatesToggleSterilization,
1226+
kFujitsuAc264StateLengthMiddle) == 0)
12201227
_cmd = kFujitsuAc264SpCmdToggleSterilization;
12211228
break;
12221229
case kFujitsuAc264StateLength:
@@ -1246,7 +1253,8 @@ bool IRFujitsuAC264::validChecksum(uint8_t state[], const uint16_t length) {
12461253
checksum = state[kFujitsuAc264StateLengthMiddle - 1];
12471254
sum = sumBytes(state, kFujitsuAc264StateLengthMiddle - 1);
12481255
sum_complement = 0x9E;
1249-
} else if (length == kFujitsuAc264StateLength){ // The current command is normal
1256+
// The current command is normal
1257+
} else if (length == kFujitsuAc264StateLength) {
12501258
checksum = state[kFujitsuAc264StateLength - 1];
12511259
sum = sumBytes(state, kFujitsuAc264StateLength - 1);
12521260
sum_complement = 0xAF;
@@ -1271,7 +1279,7 @@ void IRFujitsuAC264::checkSum(void) {
12711279
_.raw[25] = 0x00;
12721280
_.raw[26] = 0x00;
12731281
_.raw[27] = 0x00;
1274-
_.raw[28] |= 0xF0;
1282+
_.raw[28] |= 0xF0;
12751283
_.raw[29] = 0xFF;
12761284
_.raw[30] = 0xFF;
12771285

@@ -1284,7 +1292,8 @@ void IRFujitsuAC264::checkSum(void) {
12841292
}
12851293

12861294
/// Is the current command a special command?
1287-
/// @return True, if special command (kFujitsuAc264SpCmd*); false, if normal command (kFujitsuAc264Cmd*).
1295+
/// @return True, if special command (kFujitsuAc264SpCmd*);
1296+
/// false, if normal command (kFujitsuAc264Cmd*).
12881297
bool IRFujitsuAC264::isSpecialCommand(void) const {
12891298
return (_cmd & 0xF0) == 0xF0;
12901299
}
@@ -1328,7 +1337,8 @@ void IRFujitsuAC264::setPower(const bool on) {
13281337
_cmd = kFujitsuAc264CmdCool;
13291338
} else {
13301339
_cmd = kFujitsuAc264SpCmdTurnOff;
1331-
std::memcpy(_.raw, kFujitsuAc264StatesTurnOff, kFujitsuAc264StateLengthShort);
1340+
std::memcpy(_.raw, kFujitsuAc264StatesTurnOff,
1341+
kFujitsuAc264StateLengthShort);
13321342
}
13331343
}
13341344

@@ -1338,7 +1348,7 @@ bool IRFujitsuAC264::getPower(void) const { return _ispoweredon; }
13381348

13391349
/// Check if the temperature setting is changed.
13401350
/// @return True if the temperature is not changed.
1341-
bool IRFujitsuAC264::isTempStayed(void) const { return _settemp == _.Temp; };
1351+
bool IRFujitsuAC264::isTempStayed(void) const { return _settemp == _.Temp; }
13421352

13431353
/// Set the temperature.
13441354
/// @param[in] temp The temperature in degrees Celcius.
@@ -1363,7 +1373,7 @@ void IRFujitsuAC264::setTemp(const float temp) {
13631373
/// Get the current temperature setting.
13641374
/// @return The current setting for temperature in degrees Celcius.
13651375
float IRFujitsuAC264::getTemp(void) const {
1366-
return (float)(_.Temp / 2.0) + (kFujitsuAc264TempOffsetC / 2);
1376+
return static_cast<float>(_.Temp / 2.0) + (kFujitsuAc264TempOffsetC / 2);
13671377
}
13681378

13691379
/// Set the temperature in auto mode.
@@ -1386,7 +1396,7 @@ void IRFujitsuAC264::setTempAuto(const float temp) {
13861396
/// Get the current temperature in auto mode setting.
13871397
/// @return The current setting for temp in auto mode in degrees Celcius.
13881398
float IRFujitsuAC264::getTempAuto(void) const {
1389-
return (float) ((int8_t) (_.TempAuto) / 10.0);
1399+
return static_cast<float>(static_cast<int8_t>(_.TempAuto) / 10.0);
13901400
}
13911401

13921402
/// Set the operating mode of the A/C.
@@ -1429,18 +1439,19 @@ uint8_t IRFujitsuAC264::getMode(void) const { return _.Mode; }
14291439

14301440
/// Get the weak dry mode setting of the A/C.
14311441
/// @return The weak dry mode setting.
1432-
bool IRFujitsuAC264::isWeakDry(void) const { return _.WeakDry; };
1442+
bool IRFujitsuAC264::isWeakDry(void) const { return _.WeakDry; }
14331443

14341444
/// Set the speed of the fan.
14351445
/// @param[in] fanSpeed The desired setting.
14361446
void IRFujitsuAC264::setFanSpeed(const uint8_t fanSpeed) {
1447+
// Set the fan to auto if out of range.
14371448
if ((fanSpeed == kFujitsuAc264FanSpeedQuiet) ||
14381449
(fanSpeed == kFujitsuAc264FanSpeedLow) ||
14391450
(fanSpeed == kFujitsuAc264FanSpeedMed) ||
14401451
(fanSpeed == kFujitsuAc264FanSpeedHigh))
14411452
_.FanSpeed = fanSpeed;
14421453
else
1443-
_.FanSpeed = kFujitsuAc264FanSpeedAuto; // Set the fan to auto if out of range.
1454+
_.FanSpeed = kFujitsuAc264FanSpeedAuto;
14441455
_cmd = _.Cmd = kFujitsuAc264CmdFanSpeed;
14451456
_.SubCmd = 0;
14461457
}
@@ -1452,9 +1463,10 @@ uint8_t IRFujitsuAC264::getFanSpeed(void) const { return _.FanSpeed; }
14521463
/// Set the angle of the fan.
14531464
/// @param[in] fanAngle The desired setting.
14541465
void IRFujitsuAC264::setFanAngle(const uint8_t fanAngle) {
1466+
// Set the fan to stay if out of range.
14551467
if ((fanAngle > kFujitsuAc264FanAngle7) ||
14561468
(fanAngle < kFujitsuAc264FanAngle1)) {
1457-
_.FanAngle = kFujitsuAc264FanAngleStay; // Set the fan to stay if out of range.
1469+
_.FanAngle = kFujitsuAc264FanAngleStay;
14581470
} else {
14591471
_.FanAngle = fanAngle;
14601472
}
@@ -1509,7 +1521,8 @@ void IRFujitsuAC264::toggleSterilization(void) {
15091521
if (getPower())
15101522
return;
15111523
_cmd = kFujitsuAc264SpCmdToggleSterilization;
1512-
std::memcpy(_.raw, kFujitsuAc264StatesToggleSterilization, kFujitsuAc264StateLengthMiddle);
1524+
std::memcpy(_.raw, kFujitsuAc264StatesToggleSterilization,
1525+
kFujitsuAc264StateLengthMiddle);
15131526
}
15141527

15151528
/// Set weather outside quiet mode is enabled or not.
@@ -1520,10 +1533,12 @@ void IRFujitsuAC264::setOutsideQuiet(const bool on) {
15201533
return;
15211534
if (on) {
15221535
_cmd = kFujitsuAc264SpCmdOutsideQuietOn;
1523-
std::memcpy(_.raw, kFujitsuAc264StatesOutsideQuietOn, kFujitsuAc264StateLengthMiddle);
1536+
std::memcpy(_.raw, kFujitsuAc264StatesOutsideQuietOn,
1537+
kFujitsuAc264StateLengthMiddle);
15241538
} else {
15251539
_cmd = kFujitsuAc264SpCmdOutsideQuietOff;
1526-
std::memcpy(_.raw, kFujitsuAc264StatesOutsideQuietOff, kFujitsuAc264StateLengthMiddle);
1540+
std::memcpy(_.raw, kFujitsuAc264StatesOutsideQuietOff,
1541+
kFujitsuAc264StateLengthMiddle);
15271542
}
15281543
}
15291544

@@ -1539,10 +1554,12 @@ void IRFujitsuAC264::setEcoFan(const bool on) {
15391554
return;
15401555
if (on) {
15411556
_cmd = kFujitsuAc264SpCmdEcoFanOn;
1542-
std::memcpy(_.raw, kFujitsuAc264StatesEcoFanOn, kFujitsuAc264StateLengthShort);
1557+
std::memcpy(_.raw, kFujitsuAc264StatesEcoFanOn,
1558+
kFujitsuAc264StateLengthShort);
15431559
} else {
15441560
_cmd = kFujitsuAc264SpCmdEcoFanOff;
1545-
std::memcpy(_.raw, kFujitsuAc264StatesEcoFanOff, kFujitsuAc264StateLengthShort);
1561+
std::memcpy(_.raw, kFujitsuAc264StatesEcoFanOff,
1562+
kFujitsuAc264StateLengthShort);
15461563
}
15471564
}
15481565

@@ -1556,7 +1573,8 @@ void IRFujitsuAC264::togglePowerful(void) {
15561573
if (!getPower())
15571574
return;
15581575
_cmd = kFujitsuAc264SpCmdTogglePowerful;
1559-
std::memcpy(_.raw, kFujitsuAc264StatesTogglePowerful, kFujitsuAc264StateLengthShort);
1576+
std::memcpy(_.raw, kFujitsuAc264StatesTogglePowerful,
1577+
kFujitsuAc264StateLengthShort);
15601578
}
15611579

15621580
/// Set the clock on the A/C unit.
@@ -1633,30 +1651,35 @@ void IRFujitsuAC264::setTimerEnable(const uint8_t timer_enable) {
16331651
uint8_t IRFujitsuAC264::getTimerEnable(void) const { return _.TimerEnable; }
16341652

16351653
/// Set the on timer setting of the A/C.
1636-
/// @param[in] mins10 Time in 10 minutes unit, when the A/C will turn on. 0 means 0:00 AM, 1 means 0:10 AM.
1654+
/// @param[in] mins10 Time in 10 minutes unit, when the A/C will turn on.
1655+
/// 0 means 0:00 AM, 1 means 0:10 AM.
16371656
void IRFujitsuAC264::setOnTimer(const uint8_t mins10) {
16381657
if (mins10 <= kFujitsuAc26OnOffTimerMax)
16391658
_.OnTimer = mins10;
16401659
}
16411660

16421661
/// Get the on timer setting of the A/C.
1643-
/// @return Time in 10 minutes unit, when the A/C will turn on. 0 means 0:00 AM, 1 means 0:10 AM.
1662+
/// @return Time in 10 minutes unit, when the A/C will turn on.
1663+
/// 0 means 0:00 AM, 1 means 0:10 AM.
16441664
uint8_t IRFujitsuAC264::getOnTimer(void) const { return _.OnTimer; }
16451665

16461666
/// Set the off timer setting of the A/C.
1647-
/// @param[in] mins10 Time in 10 minutes unit, when the A/C will turn off. 0 means 0:00 AM, 1 means 0:10 AM.
1667+
/// @param[in] mins10 Time in 10 minutes unit, when the A/C will turn off.
1668+
/// 0 means 0:00 AM, 1 means 0:10 AM.
16481669
void IRFujitsuAC264::setOffTimer(const uint8_t mins10) {
16491670
if (mins10 <= kFujitsuAc26OnOffTimerMax)
16501671
_.OffTimer = mins10;
16511672
}
16521673

16531674
/// Get the off timer setting of the A/C.
1654-
/// @return Time in 10 minutes unit, when the A/C will turn off. 0 means 0:00 AM, 1 means 0:10 AM.
1675+
/// @return Time in 10 minutes unit, when the A/C will turn off.
1676+
/// 0 means 0:00 AM, 1 means 0:10 AM.
16551677
uint8_t IRFujitsuAC264::getOffTimer(void) const { return _.OffTimer; }
16561678

16571679
/// Set the requested (normal) command part for the A/C message.
16581680
/// @param[in] cmd Command to be set.
1659-
/// @note Only normal commands (=!isSpecialCommand()) can be set with this function.
1681+
/// @note Only normal commands (=!isSpecialCommand()) can be set
1682+
/// with this function.
16601683
void IRFujitsuAC264::setCmd(const uint8_t cmd) {
16611684
switch (cmd) {
16621685
case kFujitsuAc264CmdCool:
@@ -1754,8 +1777,8 @@ stdAc::state_t IRFujitsuAC264::toCommon(const stdAc::state_t *prev) {
17541777
result.protocol = decode_type_t::FUJITSU_AC264;
17551778
checkSum();
17561779
result.power = _cmd != kFujitsuAc264SpCmdTurnOff;
1757-
// Only update these settings if it is not a special command message, or we have no previous
1758-
// state info for those settings.
1780+
// Only update these settings if it is not a special command message,
1781+
// or we have no previous state info for those settings.
17591782
if (!isSpecialCommand() || prev == NULL) {
17601783
result.mode = toCommonMode(_.Mode);
17611784
result.celsius = true;
@@ -1819,23 +1842,23 @@ String IRFujitsuAC264::toString(void) const {
18191842
} else { // Normal commands
18201843
result += addBoolToString(true, kPowerStr, false);
18211844
// Mode
1822-
result += addModeToString(_.Mode, kFujitsuAc264ModeAuto, kFujitsuAc264ModeCool,
1823-
kFujitsuAc264ModeHeat, kFujitsuAc264ModeDry,
1824-
kFujitsuAc264ModeFan);
1845+
result += addModeToString(_.Mode, kFujitsuAc264ModeAuto,
1846+
kFujitsuAc264ModeCool, kFujitsuAc264ModeHeat,
1847+
kFujitsuAc264ModeDry, kFujitsuAc264ModeFan);
18251848
// Temp
18261849
float degrees = getTemp();
18271850
result += addTempFloatToString(getTemp());
18281851
// Temp in Auto
18291852
degrees = getTempAuto();
1830-
String degrees_str = (degrees >= 0)? uint64ToString(degrees):
1831-
String(kDashStr) + uint64ToString(-degrees);
1853+
String degrees_str = (degrees >= 0)? uint64ToString(degrees):
1854+
String(kDashStr) + uint64ToString(-degrees);
18321855
result += addLabeledString(degrees_str, "Temp (Auto)");
18331856
if (((uint16_t)(2 * degrees)) & 1) result += F(".5");
18341857
result += 'C';
18351858
// Fan Speed
1836-
result += addFanToString(_.FanSpeed, kFujitsuAc264FanSpeedHigh, kFujitsuAc264FanSpeedLow,
1837-
kFujitsuAc264FanSpeedAuto, kFujitsuAc264FanSpeedQuiet,
1838-
kFujitsuAc264FanSpeedMed);
1859+
result += addFanToString(_.FanSpeed, kFujitsuAc264FanSpeedHigh,
1860+
kFujitsuAc264FanSpeedLow, kFujitsuAc264FanSpeedAuto,
1861+
kFujitsuAc264FanSpeedQuiet, kFujitsuAc264FanSpeedMed);
18391862
// Fan Angle
18401863
result += addIntToString(_.FanAngle, "Fan Angle");
18411864
result += kSpaceLBraceStr;
@@ -2005,12 +2028,13 @@ bool IRrecv::decodeFujitsuAC264(decode_results* results, uint16_t offset,
20052028
results->state[2] != 0x00 || results->state[3] != 0x10 ||
20062029
results->state[4] != 0x10)
20072030
return false;
2008-
2031+
20092032
// Identify which command it is
20102033
switch (results->state[5]) {
20112034
case 0xFE: // Command length is normal or middle
20122035
restLength = results->state[6];
2013-
if ((restLength != 0x1A) && (restLength != 0x09)) // check the rest length
2036+
// check the rest length
2037+
if ((restLength != 0x1A) && (restLength != 0x09))
20142038
return false;
20152039
break;
20162040
case 0x51: // Command length is short
@@ -2031,8 +2055,8 @@ bool IRrecv::decodeFujitsuAC264(decode_results* results, uint16_t offset,
20312055
// Keep reading bytes until we either run out of message or state to fill.
20322056
match_result_t data_result;
20332057
for (uint16_t i = kFujitsuAc264StateLengthShort;
2034-
offset <= results->rawlen - 16 && i < kFujitsuAc264StateLengthShort + restLength;
2035-
i++, dataBitsSoFar += 8, offset += data_result.used) {
2058+
offset <= results->rawlen - 16 && i < kFujitsuAc264StateLengthShort +
2059+
restLength; i++, dataBitsSoFar += 8, offset += data_result.used) {
20362060
data_result = matchData(
20372061
&(results->rawbuf[offset]), 8, kFujitsuAcBitMark, kFujitsuAcOneSpace,
20382062
kFujitsuAcBitMark, kFujitsuAcZeroSpace,

src/ir_Fujitsu.h

+20-10
Original file line numberDiff line numberDiff line change
@@ -301,30 +301,40 @@ const uint8_t kFujitsuAc264OnOffTimerEnable = 0x3; // 0b0011
301301
const uint16_t kFujitsuAc26OnOffTimerMax = 24 * 6 - 1; ///< 10 Minutes.
302302

303303
/// Special command for Power Off
304-
const uint8_t kFujitsuAc264StatesTurnOff[kFujitsuAc264StateLengthShort] = {
304+
const uint8_t kFujitsuAc264StatesTurnOff
305+
[kFujitsuAc264StateLengthShort] = {
305306
0x14, 0x63, 0x00, 0x10, 0x10, 0x02, 0xFD};
306307
/// Special command for Toggle Powerful
307-
const uint8_t kFujitsuAc264StatesTogglePowerful[kFujitsuAc264StateLengthShort] = {
308+
const uint8_t kFujitsuAc264StatesTogglePowerful
309+
[kFujitsuAc264StateLengthShort] = {
308310
0x14, 0x63, 0x00, 0x10, 0x10, 0x39, 0xC6};
309311
/// Special command for Eco Fan Off
310-
const uint8_t kFujitsuAc264StatesEcoFanOff[kFujitsuAc264StateLengthShort] = {
312+
const uint8_t kFujitsuAc264StatesEcoFanOff
313+
[kFujitsuAc264StateLengthShort] = {
311314
0x14, 0x63, 0x00, 0x10, 0x10, 0x51, 0xAE};
312315
/// Special command for Eco Fan On
313-
const uint8_t kFujitsuAc264StatesEcoFanOn[kFujitsuAc264StateLengthShort] = {
316+
const uint8_t kFujitsuAc264StatesEcoFanOn
317+
[kFujitsuAc264StateLengthShort] = {
314318
0x14, 0x63, 0x00, 0x10, 0x10, 0x50, 0xAF};
315319
/// Special command for Outside Quiet Off
316-
/// @note This command uses the same protocol with FujitsuAC's ARRAH2E, but has different meaning.
317-
const uint8_t kFujitsuAc264StatesOutsideQuietOff[kFujitsuAc264StateLengthMiddle] = {
320+
/// @note This command uses the same protocol with FujitsuAC's ARRAH2E,
321+
/// but has different meaning.
322+
const uint8_t kFujitsuAc264StatesOutsideQuietOff
323+
[kFujitsuAc264StateLengthMiddle] = {
318324
0x14, 0x63, 0x00, 0x10, 0x10, 0xFE, 0x09, 0xC1,
319325
0x40, 0x01, 0x00, 0x00, 0xFE, 0xBF, 0x00, 0x41};
320326
/// Special command for Outside Quiet Off
321-
/// @note This command uses the same protocol with FujitsuAC's ARRAH2E, but has different meaning.
322-
const uint8_t kFujitsuAc264StatesOutsideQuietOn[kFujitsuAc264StateLengthMiddle] = {
327+
/// @note This command uses the same protocol with FujitsuAC's ARRAH2E,
328+
/// but has different meaning.
329+
const uint8_t kFujitsuAc264StatesOutsideQuietOn
330+
[kFujitsuAc264StateLengthMiddle] = {
323331
0x14, 0x63, 0x00, 0x10, 0x10, 0xFE, 0x09, 0xC1,
324332
0x40, 0x00, 0x00, 0x00, 0xFF, 0xBF, 0x00, 0x41};
325333
/// Special command for Toggle Sterilization
326-
/// @note This command uses the same protocol with FujitsuAC's ARRAH2E, but has different meaning.
327-
const uint8_t kFujitsuAc264StatesToggleSterilization[kFujitsuAc264StateLengthMiddle] = {
334+
/// @note This command uses the same protocol with FujitsuAC's ARRAH2E,
335+
/// but has different meaning.
336+
const uint8_t kFujitsuAc264StatesToggleSterilization
337+
[kFujitsuAc264StateLengthMiddle] = {
328338
0x14, 0x63, 0x00, 0x10, 0x10, 0xFE, 0x09, 0xC1,
329339
0x60, 0x03, 0x00, 0x00, 0xFC, 0x9F, 0x00, 0x41};
330340

0 commit comments

Comments
 (0)