vex_sdk/
device.rs

1//! V5 Smart Devices
2
3use core::ffi::{c_double, c_int};
4
5/// The max number of internal port indicies that could theoretically exist in VEXos.
6///
7/// This serves as the upper limit for the number of internal ports that will be added
8/// to VEXos and is thus a somewhatsafe value to set as a buffer length for functions
9/// such as [`vexDeviceGetStatus`].
10pub const V5_MAX_DEVICE_PORTS: usize = 32;
11
12/// Handle to an opaque [`V5_Device`].
13#[allow(non_camel_case_types)]
14pub type V5_DeviceT = *mut V5_Device;
15
16/// A device plugged into a smart port.
17pub type V5_Device = *mut core::ffi::c_void;
18
19#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
20#[repr(transparent)]
21pub struct V5_DeviceType(pub core::ffi::c_uchar);
22
23impl V5_DeviceType {
24    /// No device connected
25    pub const kDeviceTypeNoSensor: Self = Self(0);
26
27    /// V5 Smart Motor
28    pub const kDeviceTypeMotorSensor: Self = Self(2);
29
30    /// Unknown use (possibly unreleased hardware)
31    pub const kDeviceTypeLedSensor: Self = Self(3);
32
33    /// Rotation Sensor
34    pub const kDeviceTypeAbsEncSensor: Self = Self(4);
35
36    /// V5 Motor CR (unknown use)
37    pub const kDeviceTypeCrMotorSensor: Self = Self(5);
38
39    /// Inertial Sensor
40    pub const kDeviceTypeImuSensor: Self = Self(6);
41
42    /// Distance Sensor
43    pub const kDeviceTypeDistanceSensor: Self = Self(7);
44
45    /// Radio
46    pub const kDeviceTypeRadioSensor: Self = Self(8);
47
48    /// Master Controller
49    pub const kDeviceTypeTetherSensor: Self = Self(9);
50
51    /// Brain
52    pub const kDeviceTypeBrainSensor: Self = Self(10);
53
54    /// Vision Sensor
55    pub const kDeviceTypeVisionSensor: Self = Self(11);
56
57    /// ADI
58    pub const kDeviceTypeAdiSensor: Self = Self(12);
59
60    /// Partner Controller
61    pub const kDeviceTypeRes1Sensor: Self = Self(13);
62
63    /// Battery
64    pub const kDeviceTypeRes2Sensor: Self = Self(14);
65
66    /// Solenoid (unknown use)
67    pub const kDeviceTypeRes3Sensor: Self = Self(15);
68
69    /// Optical Sensor
70    pub const kDeviceTypeOpticalSensor: Self = Self(16);
71
72    /// Electromagnet
73    pub const kDeviceTypeMagnetSensor: Self = Self(17);
74
75    /// GPS
76    pub const kDeviceTypeGpsSensor: Self = Self(20);
77
78    /// AI Stereo Camera
79    pub const kDeviceTypeAicameraSensor: Self = Self(26);
80
81    /// CTE Workcell Light Tower
82    pub const kDeviceTypeLightTowerSensor: Self = Self(27);
83
84    /// CTE Workcell Arm
85    pub const kDeviceTypeArmDevice: Self = Self(28);
86
87    /// AI Vision Sensor
88    pub const kDeviceTypeAiVisionSensor: Self = Self(29);
89
90    /// CTE Workcell Pneumatics
91    pub const kDeviceTypePneumaticSensor: Self = Self(30);
92
93    // All of these are probably just unreleased or beta hardware...
94    pub const kDeviceTypeBumperSensor: Self = Self(0x40);
95    pub const kDeviceTypeGyroSensor: Self = Self(0x46);
96    pub const kDeviceTypeSonarSensor: Self = Self(0x47);
97    pub const kDeviceTypeGenericSensor: Self = Self(128);
98
99    /// Generic Serial
100    pub const kDeviceTypeGenericSerial: Self = Self(129);
101
102    /// Unknown use
103    pub const kDeviceTypeUndefinedSensor: Self = Self(255);
104}
105
106unsafe extern "system" {
107    pub fn vexDevicesGetNumber() -> u32;
108    pub fn vexDevicesGetNumberByType(device_type: V5_DeviceType) -> u32;
109    pub fn vexDevicesGet() -> V5_DeviceT;
110    pub fn vexDeviceGetByIndex(index: u32) -> V5_DeviceT;
111    pub fn vexDeviceGetStatus(devices: *mut V5_DeviceType) -> i32;
112    pub fn vexDeviceGetTimestamp(device: V5_DeviceT) -> u32;
113    pub fn vexDeviceGenericValueGet(device: V5_DeviceT) -> c_double;
114    pub fn vexDeviceButtonStateGet() -> c_int;
115}