From a0fb5247180232faea03b8f8268ea2e10be9f296 Mon Sep 17 00:00:00 2001
From: Max Horn <max@quendi.de>
Date: Tue, 5 Jan 2016 15:43:36 +0100
Subject: [PATCH] Fix warnings

---
 RCSwitch.cpp | 39 ++++++++++++---------------------------
 1 file changed, 12 insertions(+), 27 deletions(-)

diff --git a/RCSwitch.cpp b/RCSwitch.cpp
index b7ed81c..e02ccf6 100644
--- a/RCSwitch.cpp
+++ b/RCSwitch.cpp
@@ -30,7 +30,7 @@
 #include "RCSwitch.h"
 
 #if not defined( RCSwitchDisableReceiving )
-unsigned long RCSwitch::nReceivedValue = NULL;
+unsigned long RCSwitch::nReceivedValue = 0;
 unsigned int RCSwitch::nReceivedBitlength = 0;
 unsigned int RCSwitch::nReceivedDelay = 0;
 unsigned int RCSwitch::nReceivedProtocol = 0;
@@ -50,7 +50,7 @@ RCSwitch::RCSwitch() {
   #if not defined( RCSwitchDisableReceiving )
   this->nReceiverInterrupt = -1;
   this->setReceiveTolerance(60);
-  RCSwitch::nReceivedValue = NULL;
+  RCSwitch::nReceivedValue = 0;
   #endif
 }
 
@@ -622,8 +622,8 @@ void RCSwitch::enableReceive(int interrupt) {
 
 void RCSwitch::enableReceive() {
   if (this->nReceiverInterrupt != -1) {
-    RCSwitch::nReceivedValue = NULL;
-    RCSwitch::nReceivedBitlength = NULL;
+    RCSwitch::nReceivedValue = 0;
+    RCSwitch::nReceivedBitlength = 0;
     attachInterrupt(this->nReceiverInterrupt, handleInterrupt, CHANGE);
   }
 }
@@ -637,11 +637,11 @@ void RCSwitch::disableReceive() {
 }
 
 bool RCSwitch::available() {
-  return RCSwitch::nReceivedValue != NULL;
+  return RCSwitch::nReceivedValue != 0;
 }
 
 void RCSwitch::resetAvailable() {
-  RCSwitch::nReceivedValue = NULL;
+  RCSwitch::nReceivedValue = 0;
 }
 
 unsigned long RCSwitch::getReceivedValue() {
@@ -673,7 +673,7 @@ bool RCSwitch::receiveProtocol1(unsigned int changeCount){
       unsigned long delay = RCSwitch::timings[0] / 31;
       unsigned long delayTolerance = delay * RCSwitch::nReceiveTolerance * 0.01;    
 
-      for (int i = 1; i<changeCount ; i=i+2) {
+      for (unsigned int i = 1; i<changeCount ; i=i+2) {
       
           if (RCSwitch::timings[i] > delay-delayTolerance && RCSwitch::timings[i] < delay+delayTolerance && RCSwitch::timings[i+1] > delay*3-delayTolerance && RCSwitch::timings[i+1] < delay*3+delayTolerance) {
             code = code << 1;
@@ -694,13 +694,7 @@ bool RCSwitch::receiveProtocol1(unsigned int changeCount){
       RCSwitch::nReceivedProtocol = 1;
     }
 
-    if (code == 0){
-        return false;
-    }else if (code != 0){
-        return true;
-    }
-    
-
+    return code != 0;
 }
 
 bool RCSwitch::receiveProtocol2(unsigned int changeCount){
@@ -709,7 +703,7 @@ bool RCSwitch::receiveProtocol2(unsigned int changeCount){
       unsigned long delay = RCSwitch::timings[0] / 10;
       unsigned long delayTolerance = delay * RCSwitch::nReceiveTolerance * 0.01;    
 
-      for (int i = 1; i<changeCount ; i=i+2) {
+      for (unsigned int i = 1; i<changeCount ; i=i+2) {
       
           if (RCSwitch::timings[i] > delay-delayTolerance && RCSwitch::timings[i] < delay+delayTolerance && RCSwitch::timings[i+1] > delay*2-delayTolerance && RCSwitch::timings[i+1] < delay*2+delayTolerance) {
             code = code << 1;
@@ -730,12 +724,7 @@ bool RCSwitch::receiveProtocol2(unsigned int changeCount){
       RCSwitch::nReceivedProtocol = 2;
     }
 
-    if (code == 0){
-        return false;
-    }else if (code != 0){
-        return true;
-    }
-
+    return code != 0;
 }
 
 /** Protocol 3 is used by BL35P02.
@@ -747,7 +736,7 @@ bool RCSwitch::receiveProtocol3(unsigned int changeCount){
       unsigned long delay = RCSwitch::timings[0] / PROTOCOL3_SYNC_FACTOR;
       unsigned long delayTolerance = delay * RCSwitch::nReceiveTolerance * 0.01;    
 
-      for (int i = 1; i<changeCount ; i=i+2) {
+      for (unsigned int i = 1; i<changeCount ; i=i+2) {
       
           if  (RCSwitch::timings[i]   > delay*PROTOCOL3_0_HIGH_CYCLES - delayTolerance
             && RCSwitch::timings[i]   < delay*PROTOCOL3_0_HIGH_CYCLES + delayTolerance
@@ -774,11 +763,7 @@ bool RCSwitch::receiveProtocol3(unsigned int changeCount){
         RCSwitch::nReceivedProtocol = 3;
       }
 
-      if (code == 0){
-        return false;
-      }else if (code != 0){
-        return true;
-      }
+    return code != 0;
 }
 
 void RCSwitch::handleInterrupt() {
-- 
GitLab