Skip to main content

helios_dac/
frame.rs

1use bitflags::bitflags;
2
3#[derive(Debug, Clone, PartialEq)]
4pub struct Frame {
5    /// Rate of output in points per second
6    pub pps: u32,
7    /// default is 0
8    pub flags: WriteFrameFlags,
9    pub points: Vec<Point>,
10}
11
12impl Frame {
13    pub fn new(pps: u32, points: Vec<Point>) -> Self {
14        Frame {
15            pps,
16            points,
17            flags: WriteFrameFlags::empty(),
18        }
19    }
20
21    pub fn new_with_flags(pps: u32, points: Vec<Point>, flags: WriteFrameFlags) -> Self {
22        Frame {
23            pps,
24            points,
25            flags
26        }
27    }
28}
29
30#[derive(Debug, Clone, Copy, PartialEq)]
31pub struct Point {
32    pub coordinate: Coordinate,
33    pub color: Color,
34    pub intensity: u8,
35}
36
37/// Coordinates (x, y)
38///
39/// 12 bit (from 0 to 0xFFF)
40#[derive(Debug, Clone, Copy, PartialEq)]
41pub struct Coordinate {
42    pub x: u16,
43    pub y: u16
44}
45
46impl From<(u16, u16)> for Coordinate {
47    fn from((x, y): (u16, u16)) -> Self {
48        Coordinate { x, y }
49    }
50}
51
52#[derive(Debug, Clone, Copy, PartialEq)]
53pub struct Color {
54    /// Red channel
55    pub r: u8,
56    /// Green channel
57    pub g: u8,
58    /// Blue channel
59    pub b: u8,
60}
61
62impl Color {
63    pub fn new(r: u8, g: u8, b: u8) -> Self {
64        Color {
65            r,
66            g,
67            b
68        }
69    }
70}
71
72bitflags! {
73    pub struct WriteFrameFlags: u8 {
74        /// Bit 0 (LSB) = if 1, start output immediately, instead of waiting for current frame (if there is one) to finish playing
75        const START_IMMEDIATELY  = 0b0000_0001;
76        /// Bit 1 = if 1, play frame only once, instead of repeating until another frame is written
77        const SINGLE_MODE        = 0b0000_0010;
78        /// Bit 2 = if 1, don't let WriteFrame() block execution while waiting for the transfer to finish
79        const DONT_BLOCK         = 0b0000_0100;
80    }
81}
82