pub struct HapticPattern { /* private fields */ }Expand description
A vibration waveform: alternating durations with a target amplitude each.
This is Android’s VibrationEffect.createWaveform(long[], int[], int) in
framework terms. Index 0 is an off period by convention (its amplitude is
usually 0), then on, then off — but nothing enforces that, so an app is
free to shape a ramp out of consecutive non-zero amplitudes.
Amplitudes run 0 (off) to 255 (the device’s strongest). Devices without
amplitude control treat any non-zero amplitude as full strength; check
Haptics::has_amplitude_control before designing around subtle levels.
Implementations§
Source§impl HapticPattern
impl HapticPattern
Sourcepub const MAX_STEPS: usize = 512
pub const MAX_STEPS: usize = 512
The longest waveform the framework passes to a platform vibrator. Android’s own limit is device-defined and far lower in practice; this bound keeps a malformed pattern from reaching JNI at all.
Sourcepub fn new(
timings_ms: &[u32],
amplitudes: &[u8],
) -> Result<HapticPattern, HapticError>
pub fn new( timings_ms: &[u32], amplitudes: &[u8], ) -> Result<HapticPattern, HapticError>
Builds a one-shot waveform.
Fails when the two slices differ in length, when there are no steps, or when every timing is zero.
Sourcepub fn repeating(
timings_ms: &[u32],
amplitudes: &[u8],
repeat_index: usize,
) -> Result<HapticPattern, HapticError>
pub fn repeating( timings_ms: &[u32], amplitudes: &[u8], repeat_index: usize, ) -> Result<HapticPattern, HapticError>
Builds a waveform that loops back to repeat_index until
Haptics::cancel stops it.
Sourcepub fn timings_ms(&self) -> &[u32]
pub fn timings_ms(&self) -> &[u32]
The per-step durations in milliseconds.
Sourcepub fn amplitudes(&self) -> &[u8] ⓘ
pub fn amplitudes(&self) -> &[u8] ⓘ
The per-step amplitudes, 0 to 255.
Sourcepub fn total_duration_ms(&self) -> u32
pub fn total_duration_ms(&self) -> u32
One pass through the waveform, in milliseconds.
Sourcepub fn peak_amplitude(&self) -> u8
pub fn peak_amplitude(&self) -> u8
The strongest amplitude in the waveform, which is what a backend without waveform support falls back on.
Sourcepub fn closest_feedback(&self) -> HapticFeedback
pub fn closest_feedback(&self) -> HapticFeedback
The closest HapticFeedback constant for this pattern, derived from
its strength and length. Backends without waveform support use it.