1use core::ffi::c_double;
4
5use crate::device::V5_DeviceT;
6
7#[repr(transparent)]
8#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
9pub struct V5MotorBrakeMode(pub core::ffi::c_uchar);
10
11impl V5MotorBrakeMode {
12 pub const kV5MotorBrakeModeCoast: Self = Self(0);
13 pub const kV5MotorBrakeModeBrake: Self = Self(1);
14 pub const kV5MotorBrakeModeHold: Self = Self(2);
15}
16
17#[repr(transparent)]
18#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
19pub struct V5MotorControlMode(pub core::ffi::c_uchar);
20
21impl V5MotorControlMode {
22 pub const kMotorControlModeOFF: Self = Self(0);
23 pub const kMotorControlModeBRAKE: Self = Self(1);
24 pub const kMotorControlModeHOLD: Self = Self(2);
25 pub const kMotorControlModeSERVO: Self = Self(3);
26 pub const kMotorControlModePROFILE: Self = Self(4);
27 pub const kMotorControlModeVELOCITY: Self = Self(5);
28 pub const kMotorControlModeUNDEFINED: Self = Self(6);
29}
30
31#[repr(transparent)]
32#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
33pub struct V5MotorEncoderUnits(pub core::ffi::c_uchar);
34
35impl V5MotorEncoderUnits {
36 pub const kMotorEncoderDegrees: Self = Self(0);
37 pub const kMotorEncoderRotations: Self = Self(1);
38 pub const kMotorEncoderCounts: Self = Self(2);
39}
40
41#[repr(transparent)]
42#[derive(Default, Debug, Copy, Clone, Eq, PartialEq)]
43pub struct V5MotorGearset(pub core::ffi::c_uchar);
44
45impl V5MotorGearset {
46 pub const kMotorGearSet_36: Self = Self(0);
47 pub const kMotorGearSet_18: Self = Self(1);
48 pub const kMotorGearSet_06: Self = Self(2);
49}
50
51#[repr(C, packed)]
52#[derive(Default, Copy, Clone, Eq, PartialEq, Debug)]
53pub struct V5_DeviceMotorPid {
54 pub kf: u8,
55 pub kp: u8,
56 pub ki: u8,
57 pub kd: u8,
58 pub filter: u8,
59 pub pad1: u8,
60 pub limit: u16,
61 pub threshold: u8,
62 pub loopspeed: u8,
63 pub pad2: [u8; 2],
64}
65
66unsafe extern "system" {
67 pub fn vexDeviceMotorVelocitySet(device: V5_DeviceT, velocity: i32);
68 pub fn vexDeviceMotorVelocityGet(device: V5_DeviceT) -> i32;
69 pub fn vexDeviceMotorActualVelocityGet(device: V5_DeviceT) -> c_double;
70 pub fn vexDeviceMotorDirectionGet(device: V5_DeviceT) -> i32;
71 pub fn vexDeviceMotorModeSet(device: V5_DeviceT, mode: V5MotorControlMode);
72 pub fn vexDeviceMotorModeGet(device: V5_DeviceT) -> V5MotorControlMode;
73 pub fn vexDeviceMotorPwmSet(device: V5_DeviceT, pwm: i32);
74 pub fn vexDeviceMotorPwmGet(device: V5_DeviceT) -> i32;
75 pub fn vexDeviceMotorCurrentLimitSet(device: V5_DeviceT, limit: i32);
76 pub fn vexDeviceMotorCurrentLimitGet(device: V5_DeviceT) -> i32;
77 pub fn vexDeviceMotorCurrentGet(device: V5_DeviceT) -> i32;
78 pub fn vexDeviceMotorPowerGet(device: V5_DeviceT) -> c_double;
79 pub fn vexDeviceMotorTorqueGet(device: V5_DeviceT) -> c_double;
80 pub fn vexDeviceMotorEfficiencyGet(device: V5_DeviceT) -> c_double;
81 pub fn vexDeviceMotorTemperatureGet(device: V5_DeviceT) -> c_double;
82 pub fn vexDeviceMotorOverTempFlagGet(device: V5_DeviceT) -> bool;
83 pub fn vexDeviceMotorCurrentLimitFlagGet(device: V5_DeviceT) -> bool;
84 pub fn vexDeviceMotorZeroVelocityFlagGet(device: V5_DeviceT) -> bool;
85 pub fn vexDeviceMotorZeroPositionFlagGet(device: V5_DeviceT) -> bool;
86 pub fn vexDeviceMotorReverseFlagSet(device: V5_DeviceT, reverse: bool);
87 pub fn vexDeviceMotorReverseFlagGet(device: V5_DeviceT) -> bool;
88 pub fn vexDeviceMotorEncoderUnitsSet(device: V5_DeviceT, units: V5MotorEncoderUnits);
89 pub fn vexDeviceMotorEncoderUnitsGet(device: V5_DeviceT) -> V5MotorEncoderUnits;
90 pub fn vexDeviceMotorBrakeModeSet(device: V5_DeviceT, mode: V5MotorBrakeMode);
91 pub fn vexDeviceMotorBrakeModeGet(device: V5_DeviceT) -> V5MotorBrakeMode;
92 pub fn vexDeviceMotorPositionSet(device: V5_DeviceT, position: c_double);
93 pub fn vexDeviceMotorPositionGet(device: V5_DeviceT) -> c_double;
94 pub fn vexDeviceMotorPositionRawGet(device: V5_DeviceT, timestamp: *mut u32) -> i32;
95 pub fn vexDeviceMotorPositionReset(device: V5_DeviceT);
96 pub fn vexDeviceMotorTargetGet(device: V5_DeviceT) -> c_double;
97 pub fn vexDeviceMotorServoTargetSet(device: V5_DeviceT, position: c_double);
98 pub fn vexDeviceMotorAbsoluteTargetSet(device: V5_DeviceT, position: c_double, veloctiy: i32);
99 pub fn vexDeviceMotorRelativeTargetSet(device: V5_DeviceT, position: c_double, velocity: i32);
100 pub fn vexDeviceMotorFaultsGet(device: V5_DeviceT) -> u32;
101 pub fn vexDeviceMotorFlagsGet(device: V5_DeviceT) -> u32;
102 pub fn vexDeviceMotorVoltageSet(device: V5_DeviceT, voltage: i32);
103 pub fn vexDeviceMotorVoltageGet(device: V5_DeviceT) -> i32;
104 pub fn vexDeviceMotorGearingSet(device: V5_DeviceT, gearset: V5MotorGearset);
105 pub fn vexDeviceMotorGearingGet(device: V5_DeviceT) -> V5MotorGearset;
106 pub fn vexDeviceMotorVoltageLimitSet(device: V5_DeviceT, limit: i32);
107 pub fn vexDeviceMotorVoltageLimitGet(device: V5_DeviceT) -> i32;
108 pub fn vexDeviceMotorVelocityUpdate(device: V5_DeviceT, velocity: i32);
109 pub fn vexDeviceMotorPositionPidSet(device: V5_DeviceT, pid: *mut V5_DeviceMotorPid);
110 pub fn vexDeviceMotorVelocityPidSet(device: V5_DeviceT, pid: *mut V5_DeviceMotorPid);
111 pub fn vexDeviceMotorExternalProfileSet(device: V5_DeviceT, position: c_double, velocity: i32);
112}