eye_hal/control.rs
1use bitflags::bitflags;
2
3#[derive(Debug, Clone)]
4/// Device control
5pub struct Descriptor {
6 /// Unique identifier
7 pub id: u32,
8 /// Name
9 pub name: String,
10 /// State type
11 pub typ: Type,
12 /// State flags
13 pub flags: Flags,
14}
15
16impl Descriptor {
17 /// Returns true if the control value can be read
18 pub fn readable(&self) -> bool {
19 self.flags & Flags::READ == Flags::READ
20 }
21
22 /// Returns true if the control value can be written
23 pub fn writable(&self) -> bool {
24 self.flags & Flags::WRITE == Flags::WRITE
25 }
26}
27
28#[derive(Debug, Clone)]
29/// Device control type
30pub enum Type {
31 /// Stateless controls
32 Stateless,
33 /// On/Off switch
34 Boolean,
35 /// Numerical control
36 Number {
37 /// Valid value range (inclusive on both ends)
38 range: (f64, f64),
39 /// Valid range step size
40 step: f32,
41 },
42 /// String control
43 String,
44 /// Bit field
45 Bitmask,
46 /// Menu containing an arbitrary number of items
47 Menu(Vec<MenuItem>),
48}
49
50#[derive(Debug, Clone)]
51/// Device control menu item
52pub enum MenuItem {
53 /// String value
54 String(String),
55 /// Numerical value
56 Number(f64),
57}
58
59bitflags! {
60 /// Control state flags
61 pub struct Flags: u32 {
62 /// No flags are set
63 const NONE = 0x000;
64 /// Value can be read
65 const READ = 0x001;
66 /// Value can be written
67 const WRITE = 0x002;
68 }
69}
70
71#[derive(Debug, Clone)]
72/// Device control state
73pub enum State {
74 /* Stateless controls */
75 None,
76
77 /* Single value controls */
78 String(String),
79 Boolean(bool),
80 Number(f64),
81}