diff --git a/main.cpp b/main.cpp index 4839a9e..d08c26c 100644 --- a/main.cpp +++ b/main.cpp @@ -3061,13 +3061,16 @@ int run(const Config& cfg) { !tty_do1_pair_state.pending_ch1_di8_high && !di8_level; if (pair_di1_matches && pair_di2_matches) { - if (both_di8_high) { - tty_di8_state.add_sample(0U, tty_do1_pair_state.pending_ch1_raw); - tty_di8_state.add_sample(1U, adc_raw_value); - ++packet_di8_samples_accumulated; - ++packet_di8_both_high; - } else if (both_di8_normal) { - ++packet_di8_both_normal; + if (!both_di8_high && !both_di8_normal) { + ++packet_di8_mixed; // mixed DI8 pair -- discard + } else { + if (both_di8_high) { + ++packet_di8_both_high; + } else { + ++packet_di8_both_normal; + } + + // DO1 transition detection (ALL non-mixed pairs). if (!tty_do1_pair_state.run_initialized) { tty_do1_pair_state.start_run(di1_level); } else if (tty_do1_pair_state.run_di1_high != di1_level) { @@ -3076,11 +3079,20 @@ int run(const Config& cfg) { tty_do1_pair_state.start_run(di1_level); } + // DI8=HIGH accumulation AFTER transition check so emitted + // di8_ref_step belongs to the completed run, not the new one. + if (both_di8_high) { + tty_di8_state.add_sample(0U, tty_do1_pair_state.pending_ch1_raw); + tty_di8_state.add_sample(1U, adc_raw_value); + ++packet_di8_samples_accumulated; + } + + // Pair subtraction includes ALL non-mixed pairs (both + // DI8=HIGH and DI8=LOW) so DO1 transitions stay visible + // even when DO8 and DO1 phases are perfectly aligned. tty_do1_pair_state.add_pair_sample(di2_level, tty_do1_pair_state.pending_ch1_raw, adc_raw_value); - } else { - ++packet_di8_mixed; // mixed DI8 pair -- discard } } } diff --git a/run_do8_freq_ref.sh b/run_do8_freq_ref.sh index e03ef2d..e53a291 100755 --- a/run_do8_freq_ref.sh +++ b/run_do8_freq_ref.sh @@ -30,6 +30,6 @@ exec "$BIN" \ do1_toggle_per_frame \ do1_pair_subtract_avg \ do8_freq_ref \ - do8_cycle_period:8 \ + do8_cycle_period:4 \ "tty:${TTY_PATH}" \ "$@"