1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#[derive(Default, Debug, Clone, Copy)]
pub struct Rtc {
    pub seconds: u8,
    pub minutes: u8,
    pub hours: u8,
    pub days_low: u8,
    pub days_high: u8,
}

impl Rtc {
    pub fn new() -> Rtc {
        Default::default()
    }

    pub fn from_bytes(bytes: &[u8]) -> Rtc {
        Rtc {
            seconds: bytes[0],
            minutes: bytes[1],
            hours: bytes[2],
            days_low: bytes[3],
            days_high: bytes[4],
        }
    }

    pub fn to_bytes(self) -> [u8; 5] {
        [
            self.seconds,
            self.minutes,
            self.hours,
            self.days_low,
            self.days_high,
        ]
    }
}