vex_sdk/
vision.rs

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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
//! V5 Vision Sensor

#[cfg(any(target_env = "v5", target_env = "exp"))]
use crate::{map_jump_table, V5_DeviceT};

#[repr(transparent)]
#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
pub struct V5VisionMode(pub core::ffi::c_uchar);

impl V5VisionMode {
    pub const kVisionModeNormal: Self = Self(0);
    pub const kVisionModeMixed: Self = Self(1);
    pub const kVisionModeLineDetect: Self = Self(2);
    pub const kVisionTypeTest: Self = Self(3);
}

#[repr(transparent)]
#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
pub struct V5VisionBlockType(pub core::ffi::c_uchar);

impl V5VisionBlockType {
    pub const kVisionTypeNormal: Self = Self(0);
    pub const kVisionTypeColorCode: Self = Self(1);
    pub const kVisionTypeLineDetect: Self = Self(2);
}

#[repr(C, packed)]
#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
pub struct V5_DeviceVisionObject {
    /// block signature
    pub signature: u16,
    /// block type
    pub r#type: V5VisionBlockType,
    /// left side of block
    pub xoffset: u16,
    /// top of block
    pub yoffset: u16,
    /// width of block
    pub width: u16,
    /// height of block
    pub height: u16,
    /// angle of CC block in 0.1 deg units
    pub angle: u16,
}

#[repr(C, packed)]
#[derive(Default, Debug, Copy, Clone, PartialEq)]
pub struct V5_DeviceVisionSignature {
    pub id: u8,
    pub flags: u8,
    pub pad: [u8; 2],
    pub range: f32,
    pub uMin: i32,
    pub uMax: i32,
    pub uMean: i32,
    pub vMin: i32,
    pub vMax: i32,
    pub vMean: i32,
    pub mRgb: u32,
    pub mType: u32,
}

#[repr(transparent)]
#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
pub struct V5VisionWBMode(pub core::ffi::c_uchar);

impl V5VisionWBMode {
    pub const kVisionWBNormal: Self = Self(0);
    pub const kVisionWBStart: Self = Self(1);
    pub const kVisionWBManual: Self = Self(2);
}

#[repr(C, packed)]
#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
pub struct V5_DeviceVisionRgb {
    pub red: u8,
    pub green: u8,
    pub blue: u8,
    pub brightness: u8,
}

#[repr(transparent)]
#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
pub struct V5VisionLedMode(pub core::ffi::c_uchar);

impl V5VisionLedMode {
    pub const kVisionLedModeAuto: Self = Self(0);
    pub const kVisionLedModeManual: Self = Self(1);
}

#[repr(transparent)]
#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
pub struct V5VisionWifiMode(pub core::ffi::c_uchar);

impl V5VisionWifiMode {
    pub const kVisionWifiModeOff: Self = Self(0);
    pub const kVisionWifiModeOn: Self = Self(1);
}

#[cfg(any(target_env = "v5", target_env = "exp"))]
map_jump_table! {
    0x398 => pub fn vexDeviceVisionModeSet(device: V5_DeviceT, mode: V5VisionMode),
    0x39c => pub fn vexDeviceVisionModeGet(device: V5_DeviceT) -> V5VisionMode,
    0x3a0 => pub fn vexDeviceVisionObjectCountGet(device: V5_DeviceT) -> i32,
    0x3a4 => pub fn vexDeviceVisionObjectGet(device: V5_DeviceT, index: u32, object: *mut V5_DeviceVisionObject) -> i32,
    0x3a8 => pub fn vexDeviceVisionSignatureSet(device: V5_DeviceT, signature: *mut V5_DeviceVisionSignature),
    0x3ac => pub fn vexDeviceVisionSignatureGet(device: V5_DeviceT, id: u32, signature: *mut V5_DeviceVisionSignature) -> bool,
    0x3c0 => pub fn vexDeviceVisionBrightnessSet(device: V5_DeviceT, percent: u8),
    0x3c4 => pub fn vexDeviceVisionBrightnessGet(device: V5_DeviceT) -> u8,
    0x3c8 => pub fn vexDeviceVisionWhiteBalanceModeSet(device: V5_DeviceT, mode: V5VisionWBMode),
    0x3cc => pub fn vexDeviceVisionWhiteBalanceModeGet(device: V5_DeviceT) -> V5VisionWBMode,
    0x3c0 => pub fn vexDeviceVisionWhiteBalanceSet(device: V5_DeviceT, color: V5_DeviceVisionRgb),
    0x3c4 => pub fn vexDeviceVisionWhiteBalanceGet(device: V5_DeviceT) -> V5_DeviceVisionRgb,
    0x3c8 => pub fn vexDeviceVisionLedModeSet(device: V5_DeviceT, mode: V5VisionLedMode),
    0x3cc => pub fn vexDeviceVisionLedModeGet(device: V5_DeviceT) -> V5VisionLedMode,
    0x3d0 => pub fn vexDeviceVisionLedBrigntnessSet(device: V5_DeviceT, percent: u8),
    0x3d4 => pub fn vexDeviceVisionLedBrigntnessGet(device: V5_DeviceT) -> u8,
    0x3d8 => pub fn vexDeviceVisionLedColorSet(device: V5_DeviceT, color: V5_DeviceVisionRgb),
    0x3dc => pub fn vexDeviceVisionLedColorGet(device: V5_DeviceT) -> V5_DeviceVisionRgb,
    0x3e0 => pub fn vexDeviceVisionWifiModeSet(device: V5_DeviceT, mode: V5VisionWifiMode),
    0x3e4 => pub fn vexDeviceVisionWifiModeGet(device: V5_DeviceT) -> V5VisionWifiMode,
}