From f1eebd327b4841e49e1d0c1329901c443a51f77b Mon Sep 17 00:00:00 2001 From: kirill9617 Date: Fri, 25 Nov 2016 00:14:10 +0300 Subject: [PATCH 1/3] fix negative time =) --- RFControl.cpp | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/RFControl.cpp b/RFControl.cpp index 2bb46e4..781f10b 100644 --- a/RFControl.cpp +++ b/RFControl.cpp @@ -11,10 +11,11 @@ #define STATUS_RECORDING_3 4 #define STATUS_RECORDING_END 5 -#define PULSE_LENGTH_DIVIDER 4 +#define PULSE_LENGTH_DIVIDER 1 -#define MIN_FOOTER_LENGTH (3500 / PULSE_LENGTH_DIVIDER) +#define MIN_FOOTER_LENGTH (3000 / PULSE_LENGTH_DIVIDER) #define MIN_PULSE_LENGTH (100 / PULSE_LENGTH_DIVIDER) +#define MAX_PULSE_LENGTH (4000000 / PULSE_LENGTH_DIVIDER) unsigned int footer_length; unsigned int timings[MAX_RECORDINGS]; @@ -104,11 +105,11 @@ bool RFControl::existNewDuration(){ } bool probablyFooter(unsigned int duration) { - return duration >= MIN_FOOTER_LENGTH; + return duration >= MIN_FOOTER_LENGTH && ((int)duration >0); } bool matchesFooter(unsigned int duration) { - unsigned int footer_delta = footer_length/4; + unsigned int footer_delta = footer_length/3; return (footer_length - footer_delta < duration && duration < footer_length + footer_delta); } @@ -117,6 +118,9 @@ void startRecording(unsigned int duration) { printf(" => start recoding"); #endif footer_length = duration; + #ifdef RF_CONTROL_SIMULATE_ARDUINO + printf(" footer = %u",duration); + #endif data_end[0] = 0; data_end[1] = 0; data_end[2] = 0; @@ -164,7 +168,14 @@ void recording(unsigned int duration, int package) { else if (duration < 100000) printf(" duration=%i", duration); #endif - if (matchesFooter(duration)) //test for footer (+-25%). + if ((int)duration < 0){ + +#ifdef RF_CONTROL_SIMULATE_ARDUINO + printf("invalid duration=%i", duration); +#endif + RFControl::startReceiving(interruptPin); + + }else if (matchesFooter(duration)) //test for footer (+-25%). { //Package is complete!!!! timings[data_end[package]] = duration; @@ -285,7 +296,7 @@ void verification(int package) { } void handleInterrupt() { - //hw_digitalWrite(9, HIGH); + hw_digitalWrite(9, HIGH); unsigned long currentTime = hw_micros(); duration = (currentTime - lastTime) / PULSE_LENGTH_DIVIDER; //lastTime = currentTime; @@ -322,7 +333,7 @@ void handleInterrupt() { } else skip = true; - //hw_digitalWrite(9, LOW); + hw_digitalWrite(9, LOW); #ifdef RF_CONTROL_SIMULATE_ARDUINO printf("\n"); #endif From cb68bf3de230274f8043dda6cd89a07e0fc6de84 Mon Sep 17 00:00:00 2001 From: kirill9617 Date: Fri, 25 Nov 2016 00:14:10 +0300 Subject: [PATCH 2/3] fix negative time =) --- RFControl.cpp | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/RFControl.cpp b/RFControl.cpp index 781f10b..377a8cc 100644 --- a/RFControl.cpp +++ b/RFControl.cpp @@ -13,9 +13,8 @@ #define PULSE_LENGTH_DIVIDER 1 -#define MIN_FOOTER_LENGTH (3000 / PULSE_LENGTH_DIVIDER) +#define MIN_FOOTER_LENGTH (3500 / PULSE_LENGTH_DIVIDER) #define MIN_PULSE_LENGTH (100 / PULSE_LENGTH_DIVIDER) -#define MAX_PULSE_LENGTH (4000000 / PULSE_LENGTH_DIVIDER) unsigned int footer_length; unsigned int timings[MAX_RECORDINGS]; @@ -296,7 +295,7 @@ void verification(int package) { } void handleInterrupt() { - hw_digitalWrite(9, HIGH); + //hw_digitalWrite(9, HIGH); unsigned long currentTime = hw_micros(); duration = (currentTime - lastTime) / PULSE_LENGTH_DIVIDER; //lastTime = currentTime; @@ -333,7 +332,7 @@ void handleInterrupt() { } else skip = true; - hw_digitalWrite(9, LOW); + //hw_digitalWrite(9, LOW); #ifdef RF_CONTROL_SIMULATE_ARDUINO printf("\n"); #endif From ba65f8c70ee6d92b3a0eafd14b8e5dc1e6db2549 Mon Sep 17 00:00:00 2001 From: kirill9617 Date: Fri, 25 Nov 2016 00:14:10 +0300 Subject: [PATCH 3/3] fix negative time =) --- RFControl.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/RFControl.cpp b/RFControl.cpp index 377a8cc..49badb0 100644 --- a/RFControl.cpp +++ b/RFControl.cpp @@ -11,7 +11,7 @@ #define STATUS_RECORDING_3 4 #define STATUS_RECORDING_END 5 -#define PULSE_LENGTH_DIVIDER 1 +#define PULSE_LENGTH_DIVIDER 4 #define MIN_FOOTER_LENGTH (3500 / PULSE_LENGTH_DIVIDER) #define MIN_PULSE_LENGTH (100 / PULSE_LENGTH_DIVIDER) @@ -108,7 +108,7 @@ bool probablyFooter(unsigned int duration) { } bool matchesFooter(unsigned int duration) { - unsigned int footer_delta = footer_length/3; + unsigned int footer_delta = footer_length/4; return (footer_length - footer_delta < duration && duration < footer_length + footer_delta); }