From 32efb41613abc7931721a7015228b662181054e2 Mon Sep 17 00:00:00 2001 From: Ahmet Inan Date: Sun, 7 Dec 2014 18:14:37 +0100 Subject: [PATCH] added "gray" area between data and control signal to improve sync detection --- app/src/main/rs/calibration_detector.rsh | 7 +++---- app/src/main/rs/decoder.rs | 11 ++++++----- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/app/src/main/rs/calibration_detector.rsh b/app/src/main/rs/calibration_detector.rsh index e4eed55..b600f09 100644 --- a/app/src/main/rs/calibration_detector.rsh +++ b/app/src/main/rs/calibration_detector.rsh @@ -20,12 +20,11 @@ limitations under the License. #include "constants.rsh" #include "state.rsh" -static int calibration_detected(float dat_value, int cnt_active, int cnt_quantized) +static int calibration_detected(float dat_value, int dat_active, int cnt_active, int cnt_quantized) { static int progress, countdown; static int leader_counter, break_counter; - int dat_active = !cnt_active; progress = countdown ? progress : 0; countdown -= !!countdown; @@ -99,9 +98,9 @@ static int calibration_detected(float dat_value, int cnt_active, int cnt_quantiz return -1; } -static int calibration_detector(float dat_value, int cnt_active, int cnt_quantized) +static int calibration_detector(float dat_value, int dat_active, int cnt_active, int cnt_quantized) { - switch (calibration_detected(dat_value, cnt_active, cnt_quantized)) { + switch (calibration_detected(dat_value, dat_active, cnt_active, cnt_quantized)) { case 0x88: return mode_robot36; case 0x0c: diff --git a/app/src/main/rs/decoder.rs b/app/src/main/rs/decoder.rs index f11a3eb..2e951b0 100644 --- a/app/src/main/rs/decoder.rs +++ b/app/src/main/rs/decoder.rs @@ -130,10 +130,11 @@ void decode(int samples) { float cnt_value = demodulate(&cnt_fmd, cnt_baseband); float dat_value = demodulate(&dat_fmd, dat_baseband); - int cnt_active = cabs(dat_baseband) < cabs(cnt_baseband); - uchar cnt_level = save_cnt ? 127.5f - 127.5f * cnt_value : 0.0f; - uchar dat_level = save_dat ? 127.5f + 127.5f * dat_value : 0.0f; - value_buffer[hpos + even_hpos] = cnt_active ? cnt_level : dat_level; + int cnt_active = cabs(dat_baseband) < 4.0f * cabs(cnt_baseband); + int dat_active = cabs(cnt_baseband) < 4.0f * cabs(dat_baseband); + uchar cnt_level = save_cnt && cnt_active ? 127.5f - 127.5f * cnt_value : 0.0f; + uchar dat_level = save_dat && dat_active ? 127.5f + 127.5f * dat_value : 0.0f; + value_buffer[hpos + even_hpos] = cnt_level | dat_level; int cnt_quantized = round(cnt_value); int dat_quantized = round(dat_value); @@ -143,7 +144,7 @@ void decode(int samples) { sync_counter = sync_level ? sync_counter + 1 : 0; if (*current_mode != mode_raw) { - int detected_mode = calibration_detector(dat_value, cnt_active, cnt_quantized); + int detected_mode = calibration_detector(dat_value, dat_active, cnt_active, cnt_quantized); if (detected_mode >= 0) reset(); switch_mode(detected_mode);