From f52dcdadd33e422760d275b51d4e57cb700f453d Mon Sep 17 00:00:00 2001 From: "Christian W. Zuckschwerdt" Date: Mon, 22 Jan 2018 12:34:51 +0100 Subject: [PATCH] change pulse_detect to use pwm_precise for sync bits --- src/pulse_detect.c | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/src/pulse_detect.c b/src/pulse_detect.c index aa0f26c2..0728b5f0 100644 --- a/src/pulse_detect.c +++ b/src/pulse_detect.c @@ -584,24 +584,24 @@ void pulse_analyzer(pulse_data_t *data, uint32_t samp_rate) device.long_limit = hist_pulses.bins[0].mean; // Bit period equal to pulse length (NRZ) device.reset_limit = hist_pulses.bins[0].mean*1024; // No limit to run of zeros... } else if(hist_pulses.bins_count == 3) { - fprintf(stderr, "Pulse Width Modulation with startbit/delimiter\n"); - device.modulation = OOK_PULSE_PWM_TERNARY; - device.short_limit = (hist_pulses.bins[0].mean + hist_pulses.bins[1].mean) / 2; // Set limit between two lowest pulse widths - device.long_limit = (hist_pulses.bins[1].mean + hist_pulses.bins[2].mean) / 2; // Set limit between two next lowest pulse widths - device.reset_limit = hist_gaps.bins[hist_gaps.bins_count-1].max +1; // Set limit above biggest gap + fprintf(stderr, "Pulse Width Modulation with sync/delimiter\n"); // Re-sort to find lowest pulse count index (is probably delimiter) histogram_sort_count(&hist_pulses); - if (hist_pulses.bins[0].mean < device.short_limit) { device.demod_arg = 0; } // Shortest pulse is delimiter - else if (hist_pulses.bins[0].mean < device.long_limit) { device.demod_arg = 1; } // Middle pulse is delimiter - else { device.demod_arg = 2; } // Longest pulse is delimiter + int p1 = hist_pulses.bins[1].mean; + int p2 = hist_pulses.bins[2].mean; + device.modulation = OOK_PULSE_PWM_PRECISE; + device.short_limit = p1 < p2 ? p1 : p2; // Set to shorter pulse width + device.long_limit = p1 < p2 ? p2 : p1; // Set to longer pulse width + device.sync_width = hist_pulses.bins[0].mean; // Set to lowest count pulse width + device.reset_limit = hist_gaps.bins[hist_gaps.bins_count-1].max +1; // Set limit above biggest gap } else { fprintf(stderr, "No clue...\n"); } // Demodulate (if detected) if(device.modulation) { - fprintf(stderr, "Attempting demodulation... short_limit: %.0f, long_limit: %.0f, reset_limit: %.0f, demod_arg: %u\n", - device.short_limit, device.long_limit, device.reset_limit, device.demod_arg); + fprintf(stderr, "Attempting demodulation... short_limit: %.0f, long_limit: %.0f, reset_limit: %.0f, sync_width: %.0f\n", + device.short_limit, device.long_limit, device.reset_limit, device.sync_width); switch(device.modulation) { case FSK_PULSE_PCM: pulse_demod_pcm(data, &device); @@ -614,9 +614,9 @@ void pulse_analyzer(pulse_data_t *data, uint32_t samp_rate) data->gap[data->num_pulses-1] = device.reset_limit + 1; // Be sure to terminate package pulse_demod_pwm(data, &device); break; - case OOK_PULSE_PWM_TERNARY: + case OOK_PULSE_PWM_PRECISE: data->gap[data->num_pulses-1] = device.reset_limit + 1; // Be sure to terminate package - pulse_demod_pwm_ternary(data, &device); + pulse_demod_pwm_precise(data, &device); break; case OOK_PULSE_MANCHESTER_ZEROBIT: data->gap[data->num_pulses-1] = device.reset_limit + 1; // Be sure to terminate package