From 804dc66a4b7ff255c72145d952f40649edeee214 Mon Sep 17 00:00:00 2001 From: Priec Date: Sun, 23 Nov 2025 22:16:36 +0100 Subject: [PATCH] sampling only in the middle --- .../software_uart/src/uart_emulation.rs | 20 ++----------------- 1 file changed, 2 insertions(+), 18 deletions(-) diff --git a/semestralka_1_final_crate/software_uart/src/uart_emulation.rs b/semestralka_1_final_crate/software_uart/src/uart_emulation.rs index 5c65314..7875b38 100644 --- a/semestralka_1_final_crate/software_uart/src/uart_emulation.rs +++ b/semestralka_1_final_crate/software_uart/src/uart_emulation.rs @@ -116,25 +116,9 @@ pub fn decode_uart_samples( let frame_bits = 1 + nbits + parity_bits + stop_bits_count; let frame_len = frame_bits * ovs; - // Majority vote over 3 samples centered at `i` + // Get sample in the middle of the bit let get_bit = |i: usize| -> u8 { - let mut votes = 0; - // Check i-1, i, i+1. Saturating sub/add handles boundaries roughly. - if i > 0 && samples.get(i - 1).map_or(true, |&x| x != 0) { - votes += 1; - } - if samples.get(i).map_or(true, |&x| x != 0) { - votes += 1; - } - if samples.get(i + 1).map_or(true, |&x| x != 0) { - votes += 1; - } - - if votes >= 2 { - 1 - } else { - 0 - } + if samples[i] != 0 { 1 } else { 0 } }; // Decode while remaining samples for a full frame