timex_datalink/protocol_3/
sound_options.rs

1//! Sound Options implementation for Protocol 3
2//!
3//! This module handles various sound options for Timex Datalink watches.
4
5use crate::PacketGenerator;
6use crate::helpers::crc_packets_wrapper;
7
8/// Sound Options structure for Protocol 3
9///
10/// This controls watch sounds like hourly chimes and button beeps.
11pub struct SoundOptions {
12    /// Whether the watch chimes on the hour
13    pub hourly_chime: bool,
14    
15    /// Whether buttons make a beep sound when pressed
16    pub button_beep: bool,
17}
18
19impl PacketGenerator for SoundOptions {
20    fn packets(&self) -> Vec<Vec<u8>> {
21        // Define constants from Ruby implementation
22        const CPACKET_BEEPS: u8 = 0x71;
23
24        // Create the raw packet
25        let mut raw_packet = Vec::with_capacity(3);
26        raw_packet.push(CPACKET_BEEPS);
27        raw_packet.push(if self.hourly_chime { 1 } else { 0 });
28        raw_packet.push(if self.button_beep { 1 } else { 0 });
29        
30        // Apply CRC wrapping
31        crc_packets_wrapper::wrap_packets_with_crc(vec![raw_packet])
32    }
33}
34
35#[cfg(test)]
36mod tests {
37    use super::*;
38
39    #[test]
40    fn test_sound_options() {
41        let sound_options = SoundOptions {
42            hourly_chime: true,
43            button_beep: false,
44        };
45
46        // From golden fixture: sound_options.jsonl
47        let expected = vec![vec![6, 113, 1, 0, 3, 81]];
48
49        assert_eq!(sound_options.packets(), expected);
50    }
51}