sampling only in the middle

This commit is contained in:
Priec
2025-11-23 22:16:36 +01:00
parent 9451bc5ae9
commit 804dc66a4b

View File

@@ -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