Code cleanup

Wed, 14 May 2014 23:40:38 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Wed, 14 May 2014 23:40:38 +0200
changeset 37
2e9b7c1be9a6
parent 36
8701b4dab77b
child 38
19422d958768

Code cleanup

lib/rc-switch.c file | annotate | diff | comparison | revisions
--- a/lib/rc-switch.c	Tue May 13 16:46:36 2014 +0200
+++ b/lib/rc-switch.c	Wed May 14 23:40:38 2014 +0200
@@ -134,9 +134,7 @@
 void sendT1(void);
 void sendTF(void);
 void sendSync(void);
-bool receiveProtocol1(unsigned int);
-bool receiveProtocol2(unsigned int);
-bool receiveProtocol3(unsigned int);
+bool receiveProtocol(int, unsigned int);
 void handleInterrupt(void);
 char *dec2binWcharfill(unsigned long, unsigned int, char);
 
@@ -863,93 +861,6 @@
 
 
 
-bool receiveProtocol2(unsigned int changeCount)
-{
-    unsigned long	code = 0;
-    unsigned long	ldelay = timings[0] / 10;
-    unsigned long	delayTolerance = ldelay * rcReceiveTolerance * 0.01;    
-    int			i;
-
-    for (i = 1; i<changeCount ; i=i+2) {
-	if (timings[i] > ldelay-delayTolerance &&
-	    timings[i] < ldelay+delayTolerance &&
-	    timings[i+1] > ldelay*2-delayTolerance &&
-	    timings[i+1] < ldelay*2+delayTolerance) {
-            code = code << 1;
-        } else if (timings[i] > ldelay*2-delayTolerance &&
-		   timings[i] < ldelay*2+delayTolerance &&
-		   timings[i+1] > ldelay-delayTolerance &&
-		   timings[i+1] < ldelay+delayTolerance) {
-	    code+=1;
-	    code = code << 1;
-	} else {
-            // Failed
-            i = changeCount;
-            code = 0;
-	}
-    }      
-    code = code >> 1;
-    
-    if (changeCount > 6) {    // ignore < 4bit values as there are no devices sending 4bit values => noise
-	rcReceivedValue = code;
-	rcReceivedBitlength = changeCount / 2;
-	rcReceivedDelay = ldelay;
-	rcReceivedProtocol = 2;
-    }
-
-    if (code == 0) {
-	return false;
-    } 
-    return true;
-}
-
-
-
-/*
- * Protocol 3 is used by BL35P02.
- */
-bool receiveProtocol3(unsigned int changeCount)
-{
-    unsigned long	code = 0;
-    unsigned long	ldelay = timings[0] / PROTOCOL3_SYNC_FACTOR;
-    unsigned long	delayTolerance = ldelay * rcReceiveTolerance * 0.01;    
-    int			i;
-
-    for (i = 1; i<changeCount ; i=i+2) {
-      
-	if (timings[i]   > ldelay*PROTOCOL3_0_HIGH_CYCLES - delayTolerance &&
-            timings[i]   < ldelay*PROTOCOL3_0_HIGH_CYCLES + delayTolerance &&
-            timings[i+1] > ldelay*PROTOCOL3_0_LOW_CYCLES  - delayTolerance &&
-            timings[i+1] < ldelay*PROTOCOL3_0_LOW_CYCLES  + delayTolerance) {
-            code = code << 1;
-        } else if (timings[i]   > ldelay*PROTOCOL3_1_HIGH_CYCLES - delayTolerance &&
-                   timings[i]   < ldelay*PROTOCOL3_1_HIGH_CYCLES + delayTolerance &&
-                   timings[i+1] > ldelay*PROTOCOL3_1_LOW_CYCLES  - delayTolerance &&
-                   timings[i+1] < ldelay*PROTOCOL3_1_LOW_CYCLES  + delayTolerance) {
-            code+=1;
-            code = code << 1;
-        } else {
-            // Failed
-            i = changeCount;
-            code = 0;
-	}
-    }      
-    code = code >> 1;
-    if (changeCount > 6) {    // ignore < 4bit values as there are no devices sending 4bit values => noise
-        rcReceivedValue = code;
-        rcReceivedBitlength = changeCount / 2;
-        rcReceivedDelay = ldelay;
-        rcReceivedProtocol = 3;
-    }
-
-    if (code == 0) {
-    	return false;
-    } 
-    return true;
-}
-
-
-
 void handleInterrupt() {
 
   static unsigned int duration;
@@ -965,10 +876,12 @@
     repeatCount++;
     changeCount--;
     if (repeatCount == 2) {
-      if (receiveProtocol(TYPE_A, changeCount) == false){
-        if (receiveProtocol(TYPE_B, changeCount) == false){
-	  if (receiveProtocol(TYPE_C, changeCount) == false){
-            //failed
+      if (receiveProtocol(TYPE_A, changeCount) == false) {
+        if (receiveProtocol(TYPE_B, changeCount) == false) {
+	  if (receiveProtocol(TYPE_C, changeCount) == false) {
+	    if (receiveProtocol(TYPE_D, changeCount) == false) {
+              //failed
+	    }
 	  }
         }
       }

mercurial