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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
use joystick::SDL_Joystick;
#[cfg(feature = "no_std")]
use core::prelude::*;
use libc::{c_int, c_uint, c_char, c_float, c_void, int16_t, int32_t, uint8_t, uint16_t, uint32_t};

pub const SDL_HAPTIC_CONSTANT: uint16_t = 1 << 0;
pub const SDL_HAPTIC_SINE: uint16_t = 1 << 1;
pub const SDL_HAPTIC_LEFTRIGHT: uint16_t = 1 << 2;
pub const SDL_HAPTIC_TRIANGLE: uint16_t = 1 << 3;
pub const SDL_HAPTIC_SAWTOOTHUP: uint16_t = 1 << 4;
pub const SDL_HAPTIC_SAWTOOTHDOWN: uint16_t = 1 << 5;
pub const SDL_HAPTIC_RAMP: uint16_t = 1 << 6;
pub const SDL_HAPTIC_SPRING: uint16_t = 1 << 7;
pub const SDL_HAPTIC_DAMPER: uint16_t = 1 << 8;
pub const SDL_HAPTIC_INERTIA: uint16_t = 1 << 9;
pub const SDL_HAPTIC_FRICTION: uint16_t = 1 << 10;
pub const SDL_HAPTIC_CUSTOM: uint16_t = 1 << 11;
pub const SDL_HAPTIC_GAIN: uint16_t = 1 << 12;
pub const SDL_HAPTIC_AUTOCENTER: uint16_t = 1 << 13;
pub const SDL_HAPTIC_STATUS: uint16_t = 1 << 14;
pub const SDL_HAPTIC_PAUSE: uint16_t = 1 << 15;

pub type SDL_Haptic = c_void;

#[derive(Copy, Clone)]
#[repr(C)]
pub struct SDL_HapticDirection {
    pub type_: uint8_t,
    pub dir: [int32_t; 3],
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct SDL_HapticConstant {
    pub type_: uint16_t,
    pub direction: SDL_HapticDirection,
    pub length: uint32_t,
    pub delay: uint16_t,
    pub button: uint16_t,
    pub interval: uint16_t,
    pub level: int16_t,
    pub attack_length: uint16_t,
    pub attack_level: uint16_t,
    pub fade_length: uint16_t,
    pub fade_level: uint16_t,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct SDL_HapticPeriodic {
    pub type_: uint16_t,
    pub direction: SDL_HapticDirection,
    pub length: uint32_t,
    pub delay: uint16_t,
    pub button: uint16_t,
    pub interval: uint16_t,
    pub period: uint16_t,
    pub magnitude: int16_t,
    pub offset: int16_t,
    pub phase: uint16_t,
    pub attack_length: uint16_t,
    pub attack_level: uint16_t,
    pub fade_length: uint16_t,
    pub fade_level: uint16_t,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct SDL_HapticCondition {
    pub type_: uint16_t,
    pub direction: SDL_HapticDirection,
    pub length: uint32_t,
    pub delay: uint16_t,
    pub button: uint16_t,
    pub interval: uint16_t,
    pub right_sat: [uint16_t; 3],
    pub left_sat: [uint16_t; 3],
    pub right_coeff: [int16_t; 3],
    pub left_coeff: [int16_t; 3],
    pub deadband: [uint16_t; 3],
    pub center: [int16_t; 3],
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct SDL_HapticRamp {
    pub type_: uint16_t,
    pub length: uint32_t,
    pub delay: uint16_t,
    pub button: uint16_t,
    pub interval: uint16_t,
    pub start: int16_t,
    pub end: int16_t,
    pub attack_length: uint16_t,
    pub attack_level: uint16_t,
    pub fade_length: uint16_t,
    pub fade_level: uint16_t,
}

#[derive(Copy, Clone)]
#[repr(C)]
pub struct SDL_HapticLeftRight {
    pub type_: uint16_t,
    pub length: uint32_t,
    pub large_magnitude: uint16_t,
    pub small_magnitude: uint16_t,
}

#[allow(missing_copy_implementations)]
#[repr(C)]
pub struct SDL_HapticCustom {
    pub type_: uint16_t,
    pub direction: SDL_HapticDirection,
    pub length: uint32_t,
    pub delay: uint16_t,
    pub button: uint16_t,
    pub interval: uint16_t,
    pub channels: uint8_t,
    pub period: uint16_t,
    pub samples: uint16_t,
    pub data: *const uint16_t,
    pub attack_length: uint16_t,
    pub attack_level: uint16_t,
    pub fade_length: uint16_t,
    pub fade_level: uint16_t,
}

#[allow(missing_copy_implementations)]
#[repr(C)]
pub struct SDL_HapticEffect {
    pub data: [uint8_t; 72],
}

impl SDL_HapticEffect {
    pub fn type_(&mut self) -> *mut uint16_t {
        self.data.as_mut_ptr() as *mut _
    }

    pub fn constant(&mut self) -> *mut SDL_HapticConstant {
        self.data.as_mut_ptr() as *mut _
    }

    pub fn periodic(&mut self) -> *mut SDL_HapticPeriodic {
        self.data.as_mut_ptr() as *mut _
    }

    pub fn condition(&mut self) -> *mut SDL_HapticCondition {
        self.data.as_mut_ptr() as *mut _
    }

    pub fn ramp(&mut self) -> *mut SDL_HapticRamp {
        self.data.as_mut_ptr() as *mut _
    }

    pub fn left_right(&mut self) -> *mut SDL_HapticLeftRight {
        self.data.as_mut_ptr() as *mut _
    }

    pub fn custom(&mut self) -> *mut SDL_HapticCustom {
        self.data.as_mut_ptr() as *mut _
    }
}

extern "C" {
    pub fn SDL_NumHaptics() -> c_int;
    pub fn SDL_HapticName(device_index: c_int) -> *const c_char;
    pub fn SDL_HapticOpen(device_index: c_int) -> *mut SDL_Haptic;
    pub fn SDL_HapticOpened(device_index: c_int) -> c_int;
    pub fn SDL_HapticIndex(haptic: *mut SDL_Haptic) -> c_int;
    pub fn SDL_MouseIsHaptic() -> c_int;
    pub fn SDL_HapticOpenFromMouse() -> *mut SDL_Haptic;
    pub fn SDL_JoystickIsHaptic(joystick: *mut SDL_Joystick) -> c_int;
    pub fn SDL_HapticOpenFromJoystick(joystick: *mut SDL_Joystick) -> *mut SDL_Haptic;
    pub fn SDL_HapticClose(haptic: *mut SDL_Haptic);
    pub fn SDL_HapticNumEffects(haptic: *mut SDL_Haptic) -> c_int;
    pub fn SDL_HapticNumEffectsPlaying(haptic: *mut SDL_Haptic) -> c_int;
    pub fn SDL_HapticQuery(haptic: *mut SDL_Haptic) -> c_uint;
    pub fn SDL_HapticNumAxes(haptic: *mut SDL_Haptic) -> c_int;
    pub fn SDL_HapticEffectSupported(haptic: *mut SDL_Haptic, effect: *mut SDL_HapticEffect) -> c_int;
    pub fn SDL_HapticNewEffect(haptic: *mut SDL_Haptic, effect: *mut SDL_HapticEffect) -> c_int;
    pub fn SDL_HapticUpdateEffect(haptic: *mut SDL_Haptic, effect: *mut SDL_HapticEffect) -> c_int;
    pub fn SDL_HapticRunEffect(haptic: *mut SDL_Haptic, effect: c_int, iterations: uint32_t) -> c_int;
    pub fn SDL_HapticStopEffect(haptic: *mut SDL_Haptic, effect: c_int) -> c_int;
    pub fn SDL_HapticDestroyEffect(haptic: *mut SDL_Haptic, effect: c_int);
    pub fn SDL_HapticGetEffectStatus(haptic: *mut SDL_Haptic, effect: c_int) -> c_int;
    pub fn SDL_HapticSetGain(haptic: *mut SDL_Haptic, gain: c_int) -> c_int;
    pub fn SDL_HapticSetAutocenter(haptic: *mut SDL_Haptic, autocenter: c_int) -> c_int;
    pub fn SDL_HapticPause(haptic: *mut SDL_Haptic) -> c_int;
    pub fn SDL_HapticUnpause(haptic: *mut SDL_Haptic) -> c_int;
    pub fn SDL_HapticStopAll(haptic: *mut SDL_Haptic) -> c_int;
    pub fn SDL_HapticRumbleSupported(haptic: *mut SDL_Haptic) -> c_int;
    pub fn SDL_HapticRumbleInit(haptic: *mut SDL_Haptic) -> c_int;
    pub fn SDL_HapticRumblePlay(haptic: *mut SDL_Haptic, strength: c_float, length: uint32_t) -> c_int;
    pub fn SDL_HapticRumbleStop(haptic: *mut SDL_Haptic) -> c_int;
}