Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solved warnings so that compilation with g++ -Werror=conversion and -Werror=switch-default is possible. #282

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions RCSwitch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
*/

#include "RCSwitch.h"
#include <limits.h>

#ifdef RaspberryPi
// PROGMEM and _P functions are for AVR based microprocessors,
Expand Down Expand Up @@ -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);
}
Expand All @@ -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;
}

Expand Down Expand Up @@ -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
Expand All @@ -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;
Expand Down Expand Up @@ -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 <= INT_MAX) ? static_cast<unsigned int>(duration_long) : INT_MAX;

if (duration > RCSwitch::nSeparationLimit) {
// A long stretch without signal level change occurred. This could
Expand Down
4 changes: 2 additions & 2 deletions RCSwitch.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down