From 7bcbb571353fcd029276825819299cb5bb582d6c Mon Sep 17 00:00:00 2001 From: Michael Walz Date: Sun, 24 Mar 2019 10:34:26 +0100 Subject: [PATCH 1/2] Solved warnings so that compilation with g++ -Werror=conversion and -Werror=switch-default is possible. --- RCSwitch.cpp | 10 +++++++--- RCSwitch.h | 4 ++-- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/RCSwitch.cpp b/RCSwitch.cpp index 1a6736e..06c7fe7 100644 --- a/RCSwitch.cpp +++ b/RCSwitch.cpp @@ -32,6 +32,7 @@ */ #include "RCSwitch.h" +#include #ifdef RaspberryPi // PROGMEM and _P functions are for AVR based microprocessors, @@ -134,7 +135,7 @@ void RCSwitch::setProtocol(int nProtocol) { /** * Sets the protocol to send with pulse length in microseconds. */ -void RCSwitch::setProtocol(int nProtocol, int nPulseLength) { +void RCSwitch::setProtocol(int nProtocol, uint16_t nPulseLength) { setProtocol(nProtocol); this->setPulseLength(nPulseLength); } @@ -143,7 +144,7 @@ void RCSwitch::setProtocol(int nProtocol, int nPulseLength) { /** * Sets pulse length in microseconds */ -void RCSwitch::setPulseLength(int nPulseLength) { +void RCSwitch::setPulseLength(uint16_t nPulseLength) { this->protocol.pulseLength = nPulseLength; } @@ -438,6 +439,7 @@ char* RCSwitch::getCodeWordD(char sGroup, int nDevice, bool bStatus) { /** * @param sCodeWord a tristate code word consisting of the letter 0, 1, F + * @note any other value than 0,1,F will be treated as 0. */ void RCSwitch::sendTriState(const char* sCodeWord) { // turn the tristate code word into the corresponding bit pattern, then send it @@ -446,6 +448,7 @@ void RCSwitch::sendTriState(const char* sCodeWord) { for (const char* p = sCodeWord; *p; p++) { code <<= 2L; switch (*p) { + default: case '0': // bit pattern 00 break; @@ -664,7 +667,8 @@ void RECEIVE_ATTR RCSwitch::handleInterrupt() { static unsigned int repeatCount = 0; const long time = micros(); - const unsigned int duration = time - lastTime; + const long duration_long = time - lastTime; + const unsigned int duration = (duration_long <= UINT_MAX) ? static_cast(duration_long) : UINT_MAX; if (duration > RCSwitch::nSeparationLimit) { // A long stretch without signal level change occurred. This could diff --git a/RCSwitch.h b/RCSwitch.h index b7755e0..8615792 100644 --- a/RCSwitch.h +++ b/RCSwitch.h @@ -96,7 +96,7 @@ class RCSwitch { void enableTransmit(int nTransmitterPin); void disableTransmit(); - void setPulseLength(int nPulseLength); + void setPulseLength(uint16_t nPulseLength); void setRepeatTransmit(int nRepeatTransmit); #if not defined( RCSwitchDisableReceiving ) void setReceiveTolerance(int nPercent); @@ -146,7 +146,7 @@ class RCSwitch { void setProtocol(Protocol protocol); void setProtocol(int nProtocol); - void setProtocol(int nProtocol, int nPulseLength); + void setProtocol(int nProtocol, uint16_t nPulseLength); private: char* getCodeWordA(const char* sGroup, const char* sDevice, bool bStatus); From caff923cbbece323e58c3e0a03b8a896f527d988 Mon Sep 17 00:00:00 2001 From: Michael Walz Date: Sun, 24 Mar 2019 11:22:56 +0100 Subject: [PATCH 2/2] Removed warning -Werror=sign-compare which appears with g++ on raspberry pi --- RCSwitch.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/RCSwitch.cpp b/RCSwitch.cpp index 06c7fe7..007aa88 100644 --- a/RCSwitch.cpp +++ b/RCSwitch.cpp @@ -668,7 +668,7 @@ void RECEIVE_ATTR RCSwitch::handleInterrupt() { const long time = micros(); const long duration_long = time - lastTime; - const unsigned int duration = (duration_long <= UINT_MAX) ? static_cast(duration_long) : UINT_MAX; + const unsigned int duration = (duration_long <= INT_MAX) ? static_cast(duration_long) : INT_MAX; if (duration > RCSwitch::nSeparationLimit) { // A long stretch without signal level change occurred. This could