From e3960a0a32dc03892900d449174235159efec437 Mon Sep 17 00:00:00 2001 From: Max Horn <max@quendi.de> Date: Wed, 6 Jan 2016 12:57:59 +0100 Subject: [PATCH] switch receive code to ints instead of long This results in much smaller and more efficient machine code. It should not affect correctness, either: Indeed, the delay value is computed from dividing an int by another int, so it fits into an int. The delayTolerance is a fraction of that int, so it also fits. Intermediate results like delay * pro.zero.high are ints because they are equal to timings[0] * pro.zero.high / pro.syncFactor.low but syncfactor.low is always larger (at least in all current protocols) than any other high/low value. --- RCSwitch.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/RCSwitch.cpp b/RCSwitch.cpp index f3b078a..d5b7f42 100644 --- a/RCSwitch.cpp +++ b/RCSwitch.cpp @@ -627,7 +627,7 @@ unsigned int* RCSwitch::getReceivedRawdata() { } /* helper function for the various receiveProtocol methods */ -static inline unsigned long diff(long A, long B) { +static inline unsigned int diff(int A, int B) { return abs(A - B); } @@ -640,8 +640,8 @@ bool RCSwitch::receiveProtocol(const int p, unsigned int changeCount) { memcpy_P(&pro, &proto[p-1], sizeof(Protocol)); unsigned long code = 0; - const unsigned long delay = RCSwitch::timings[0] / pro.syncFactor.low; - const unsigned long delayTolerance = delay * RCSwitch::nReceiveTolerance / 100; + const unsigned int delay = RCSwitch::timings[0] / pro.syncFactor.low; + const unsigned int delayTolerance = delay * RCSwitch::nReceiveTolerance / 100; for (unsigned int i = 1; i < changeCount; i += 2) { code <<= 1; -- GitLab