Skip to content

Commit

Permalink
Even more lint fixes.
Browse files Browse the repository at this point in the history
  • Loading branch information
crankyoldgit committed Jan 7, 2025
1 parent 978fe28 commit 3cae482
Show file tree
Hide file tree
Showing 21 changed files with 78 additions and 47 deletions.
10 changes: 6 additions & 4 deletions examples/IRMQTTServer/IRMQTTServer.ino
Original file line number Diff line number Diff line change
Expand Up @@ -1659,7 +1659,8 @@ 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,
static_cast<uint16_t>(kFujitsuAcStateLengthShort - 1));
static_cast<uint16_t>(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.
Expand Down Expand Up @@ -1703,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, static_cast<uint16_t>(kSamsungAcStateLength));
stateSize = std::max(stateSize,
static_cast<uint16_t>(kSamsungAcStateLength));
// If we think it isn't a "normal" message.
if (stateSize > kSamsungAcStateLength)
// Then it probably the extended size.
stateSize = std::max(stateSize,
static_cast<uint16_t>(kSamsungAcExtendedStateLength));
stateSize = std::max(
stateSize, static_cast<uint16_t>(kSamsungAcExtendedStateLength));
// Lastly, it should never exceed the maximum "extended" size.
stateSize = std::min(stateSize, kSamsungAcExtendedStateLength);
break;
Expand Down
6 changes: 3 additions & 3 deletions src/IRac.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_
10 changes: 6 additions & 4 deletions src/IRrecv.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1231,8 +1231,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<uint32_t>(usecs * (1.0 + _validTolerance(tolerance) /
100.0)) + 1 + delta);
}

/// Check if we match a pulse(measured) with the desired within
Expand Down Expand Up @@ -1283,7 +1283,8 @@ bool IRrecv::matchAtLeast(uint32_t measured, uint32_t desired,
DPRINT(". Matching: ");
DPRINT(measured);
DPRINT(" >= ");
DPRINT(ticksLow(std::min(desired, static_cast<uint32_t>(MS_TO_USEC(params.timeout))),
DPRINT(ticksLow(std::min(desired,
static_cast<uint32_t>(MS_TO_USEC(params.timeout))),
tolerance, delta));
DPRINT(" [min(");
DPRINT(ticksLow(desired, tolerance, delta));
Expand All @@ -1305,7 +1306,8 @@ bool IRrecv::matchAtLeast(uint32_t measured, uint32_t desired,
// 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, static_cast<uint32_t>(MS_TO_USEC(params.timeout))), tolerance, delta);
desired, static_cast<uint32_t>(MS_TO_USEC(params.timeout))), tolerance,
delta);
}

/// Check if we match a mark signal(measured) with the desired within
Expand Down
20 changes: 16 additions & 4 deletions src/IRremoteESP8266.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
12 changes: 7 additions & 5 deletions src/IRsend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint32_t>(1), period + periodOffset);
else
return std::max((uint32_t)1, period);
return std::max(static_cast<uint32_t>(1), period);
}

/// Set the output frequency modulation and duty cycle.
Expand Down Expand Up @@ -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<uint32_t>(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<uint32_t>(offTimePeriod)));
elapsed = usecTimer.elapsed(); // Update & recache the actual elapsed time.
}
return counter;
Expand Down Expand Up @@ -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<uint16_t>(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.
Expand Down
2 changes: 1 addition & 1 deletion src/IRutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1422,7 +1422,7 @@ uint8_t lowLevelSanityCheck(void) {
uint64_t _usused_2:18; // 44-61st bits
uint64_t highest2bits:2; // 62-63rd bits
};
uint64_t all;
uint64_t all;
};

bitpackdata data;
Expand Down
16 changes: 8 additions & 8 deletions src/IRutils.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,17 +122,17 @@ bool getBit(const uint8_t data, const uint8_t position);
#define GETBIT32(a, b) ((a) & (static_cast<uint32_t>(1) << (b)))
#define GETBIT64(a, b) ((a) & (static_cast<uint64_t>(1) << (b)))
#define GETBITS8(data, offset, size) \
(((data) & ((static_cast<uint8_t>(UINT8_MAX) >> (8 - (size))) << (offset))) >> \
(offset))
(((data) & ((static_cast<uint8_t>(UINT8_MAX) >> (8 - (size))) << \
(offset))) >> (offset))
#define GETBITS16(data, offset, size) \
(((data) & ((static_cast<uint16_t>(UINT16_MAX) >> (16 - (size))) << (offset))) >> \
(offset))
(((data) & ((static_cast<uint16_t>(UINT16_MAX) >> (16 - (size))) << \
(offset))) >> (offset))
#define GETBITS32(data, offset, size) \
(((data) & ((static_cast<uint32_t>(UINT32_MAX) >> (32 - (size))) << (offset))) >> \
(offset))
(((data) & ((static_cast<uint32_t>(UINT32_MAX) >> (32 - (size))) << \
(offset))) >> (offset))
#define GETBITS64(data, offset, size) \
(((data) & ((static_cast<uint64_t>(UINT64_MAX) >> (64 - (size))) << (offset))) >> \
(offset))
(((data) & ((static_cast<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,
Expand Down
2 changes: 2 additions & 0 deletions src/ir_Argo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
#include <algorithm>
#include <cmath>
#include <cstring>
#include <set>
#include <utility>
#ifndef UNIT_TEST
#include <Arduino.h>
#endif // UNIT_TEST
Expand Down
3 changes: 2 additions & 1 deletion src/ir_Daikin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
static_cast<uint64_t>(0b00000), kDaikinHeaderLength, 38, false, 0, 50);
static_cast<uint64_t>(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
Expand Down
3 changes: 2 additions & 1 deletion src/ir_GlobalCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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], static_cast<uint16_t>(kGlobalCacheMaxRepeat));
std::min(buf[kGlobalCacheRptIndex],
static_cast<uint16_t>(kGlobalCacheMaxRepeat));
// Repeat
for (uint8_t repeat = 0; repeat < emits; repeat++) {
// First time through, start at the beginning (kGlobalCacheStartIndex),
Expand Down
5 changes: 3 additions & 2 deletions src/ir_Kelon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -318,8 +318,9 @@ void IRKelonAc::setTimer(uint16_t mins) {
/// @return The timer set minutes
uint16_t IRKelonAc::getTimer() const {
if (_.TimerHours >= 10)
return (static_cast<uint16_t>((_.TimerHours << 1) | _.TimerHalfHour) - 10) * 60;
return (static_cast<uint16_t>(_.TimerHours) * 60) + (_.TimerHalfHour ? 30 : 0);
return (static_cast<uint16_t>((_.TimerHours << 1) | _.TimerHalfHour) -
10) * 60;
return static_cast<uint16_t>(_.TimerHours) * 60 + (_.TimerHalfHour ? 30 : 0);
}

/// Enable or disable the timer. Note that in order to enable the timer the
Expand Down
5 changes: 3 additions & 2 deletions src/ir_Mirage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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, static_cast<uint32_t>(24 * 60 * 60 - 1)); // Limit to 23:59:59
nr_of_seconds, static_cast<uint32_t>(24 * 60 * 60 - 1));
_.Seconds = uint8ToBcd(remaining % 60);
remaining /= 60;
_.Minutes = uint8ToBcd(remaining % 60);
Expand Down Expand Up @@ -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<uint16_t>(24 * 60));
switch (_model) {
case mirage_ac_remote_model_t::KKG29AC1:
_.OnTimerEnable = (mins > 0);
Expand Down
7 changes: 4 additions & 3 deletions src/ir_Panasonic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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((static_cast<uint64_t>(address) << 32) | static_cast<uint64_t>(data),
sendPanasonic64(static_cast<uint64_t>(address) << 32 |
static_cast<uint64_t>(data),
nbits, repeat);
}

Expand All @@ -107,9 +108,9 @@ uint64_t IRsend::encodePanasonic(const uint16_t manufacturer,
const uint8_t function) {
uint8_t checksum = device ^ subdevice ^ function;
return ((static_cast<uint64_t>(manufacturer) << 32) |
(static_cast<uint64_t>(device) << 24) |
(static_cast<uint64_t>(device) << 24) |
(static_cast<uint64_t>(subdevice) << 16) |
(static_cast<uint64_t>(function) << 8) | checksum);
(static_cast<uint64_t>(function) << 8) | checksum);
}
#endif // (SEND_PANASONIC || SEND_DENON)

Expand Down
2 changes: 1 addition & 1 deletion src/ir_Pioneer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 (static_cast<uint64_t>(encodeNEC(address >> 8, address & 0xFF)) << 32) |
return static_cast<uint64_t>(encodeNEC(address >> 8, address & 0xFF)) << 32 |
encodeNEC(command >> 8, command & 0xFF);
}
#endif // SEND_PIONEER
Expand Down
3 changes: 2 additions & 1 deletion src/ir_Pronto.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ void IRsend::sendPronto(uint16_t data[], uint16_t len, uint16_t repeat) {

// Pronto frequency is in Hz.
uint16_t hz =
static_cast<uint16_t>(1000000U / (data[kProntoFreqOffset] * kProntoFreqFactor));
static_cast<uint16_t>(1000000U / (data[kProntoFreqOffset] *
kProntoFreqFactor));
enableIROut(hz);

// Grab the length of the two sequences.
Expand Down
6 changes: 4 additions & 2 deletions src/ir_RCMM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(static_cast<uint16_t>(results->rawlen) - 5, (uint16_t)sizeof(data) * 8);
std::min(static_cast<uint16_t>(results->rawlen) - 5,
static_cast<uint16_t>(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.
}
Expand Down
3 changes: 2 additions & 1 deletion src/ir_Sherwood.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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(static_cast<uint16_t>(kSherwoodMinRepeat), repeat));
sendNEC(data, nbits,
std::max(static_cast<uint16_t>(kSherwoodMinRepeat), repeat));
}
#endif // SEND_SHERWOOD
3 changes: 2 additions & 1 deletion src/ir_Teco.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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, static_cast<uint16_t>(24 * 60)); // Limit to 24 hrs
// Limit to 24 hrs
uint16_t mins = std::min(nr_mins, static_cast<uint16_t>(24 * 60));
uint8_t hours = mins / 60;
_.TimerOn = mins > 0; // Set the timer flag.
_.HalfHour = (mins % 60) >= 30;
Expand Down
3 changes: 2 additions & 1 deletion test/IRutils_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -611,7 +611,8 @@ TEST(TestUtils, setBit) {
EXPECT_EQ(0b100, irutils::setBit(static_cast<uint64_t>(0b110), 1, false));
EXPECT_EQ(0b111, irutils::setBit(static_cast<uint64_t>(0b101), 1, true));
EXPECT_EQ(0b110, irutils::setBit(static_cast<uint64_t>(0b110), 1, true));
EXPECT_EQ(0b11111111, irutils::setBit(static_cast<uint64_t>(0b01111111), 7, true));
EXPECT_EQ(0b11111111,
irutils::setBit(static_cast<uint64_t>(0b01111111), 7, true));
EXPECT_EQ(0, irutils::setBit(static_cast<uint64_t>(0b10000000), 7, false));
// uint8_t Pointer method.
uint8_t data = 0;
Expand Down
2 changes: 1 addition & 1 deletion tools/gc_decode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#include <errno.h>
#include <inttypes.h>
#include <stdio.h>
#include <cstdio.h>
#include <string.h>
#include <cstdio>
#include <iostream>
#include <string>
#include "IRac.h"
Expand Down
2 changes: 1 addition & 1 deletion tools/mode2_decode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ space 500000
#include <errno.h>
#include <inttypes.h>
#include <stdio.h>
#include <cstdio.h>
#include <string.h>
#include <cstdio>
#include <iostream>
#include <sstream>
#include <string>
Expand Down

0 comments on commit 3cae482

Please sign in to comment.