From 3d6f915b75b1c8c0bf53abeef3e29fc36da7ea40 Mon Sep 17 00:00:00 2001 From: Ahmet Inan Date: Sat, 13 Dec 2014 20:31:06 +0100 Subject: [PATCH] improved calibration header detection "gray" area doesn't work very well with the calibration detection code --- app/src/main/rs/calibration_detector.rsh | 9 ++++++--- app/src/main/rs/decoder.rs | 9 ++++++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/app/src/main/rs/calibration_detector.rsh b/app/src/main/rs/calibration_detector.rsh index 9b926e5..87045bb 100644 --- a/app/src/main/rs/calibration_detector.rsh +++ b/app/src/main/rs/calibration_detector.rsh @@ -20,7 +20,7 @@ limitations under the License. #include "constants.rsh" #include "state.rsh" -static int calibration_detected(float dat_value, int dat_active, int cnt_active, int cnt_quantized) +static int calibration_detected(float dat_value, float dat_amp, float cnt_amp, int cnt_quantized) { static int progress, countdown; static int leader_counter, break_counter; @@ -28,6 +28,9 @@ static int calibration_detected(float dat_value, int dat_active, int cnt_active, progress = countdown ? progress : 0; countdown -= !!countdown; + int cnt_active = dat_amp < cnt_amp; + int dat_active = !cnt_active; + int leader_quantized = round(filter(&leader_lowpass, dat_value)); int leader_level = dat_active && leader_quantized == 0; int leader_pulse = !leader_level && leader_counter >= leader_length; @@ -98,9 +101,9 @@ static int calibration_detected(float dat_value, int dat_active, int cnt_active, return -1; } -static int calibration_detector(float dat_value, int dat_active, int cnt_active, int cnt_quantized) +static int calibration_detector(float dat_value, float dat_amp, float cnt_amp, int cnt_quantized) { - switch (calibration_detected(dat_value, dat_active, cnt_active, cnt_quantized)) { + switch (calibration_detected(dat_value, dat_amp, cnt_amp, 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 6c3411a..eef1e7d 100644 --- a/app/src/main/rs/decoder.rs +++ b/app/src/main/rs/decoder.rs @@ -177,8 +177,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) < 4.0f * cabs(cnt_baseband); - int dat_active = cabs(cnt_baseband) < 4.0f * cabs(dat_baseband); + float cnt_amp = cabs(cnt_baseband); + float dat_amp = cabs(dat_baseband); + + int cnt_active = dat_amp < 4.0f * cnt_amp; + int dat_active = cnt_amp < 4.0f * dat_amp; 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 + prev_hpos] = cnt_level | dat_level; @@ -191,7 +194,7 @@ void decode(int samples) { sync_counter = sync_level ? sync_counter + 1 : 0; if (*current_mode != mode_debug) { - int detected_mode = calibration_detector(dat_value, dat_active, cnt_active, cnt_quantized); + int detected_mode = calibration_detector(dat_value, dat_amp, cnt_amp, cnt_quantized); if (detected_mode >= 0) { free_running = 0; reset_buffer();