fix: update 0x02 protocol to use byte offset instead of LED position offset

This commit is contained in:
2025-07-09 14:26:25 +08:00
parent 5f5824721e
commit 142332730f
3 changed files with 40 additions and 17 deletions

View File

@ -430,10 +430,12 @@ impl LedColorsPublisher {
}
}
let offset = group.start.min(group.end);
// Calculate byte offset based on LED position and LED type
let led_offset = group.start.min(group.end);
let byte_offset = led_offset * bytes_per_led;
let mut tx_buffer = vec![2];
tx_buffer.push((offset >> 8) as u8);
tx_buffer.push((offset & 0xff) as u8);
tx_buffer.push((byte_offset >> 8) as u8);
tx_buffer.push((byte_offset & 0xff) as u8);
tx_buffer.append(&mut buffer);
udp_rpc.send_to_all(&tx_buffer).await?;

View File

@ -182,8 +182,8 @@ async fn send_test_colors_to_board(board_address: String, offset: u16, buffer: V
})?;
let mut packet = vec![0x02]; // Header
packet.push((offset >> 8) as u8); // Offset high
packet.push((offset & 0xff) as u8); // Offset low
packet.push((offset >> 8) as u8); // Byte offset high
packet.push((offset & 0xff) as u8); // Byte offset low
packet.extend_from_slice(&buffer); // Color data
socket.send_to(&packet, &board_address).await.map_err(|e| {
@ -351,8 +351,8 @@ async fn send_test_colors_to_board_internal(board_address: &str, offset: u16, bu
let socket = UdpSocket::bind("0.0.0.0:0").await?;
let mut packet = vec![0x02]; // Header
packet.push((offset >> 8) as u8); // Offset high
packet.push((offset & 0xff) as u8); // Offset low
packet.push((offset >> 8) as u8); // Byte offset high
packet.push((offset & 0xff) as u8); // Byte offset low
packet.extend_from_slice(&buffer); // Color data
socket.send_to(&packet, board_address).await?;