Skip to main content

Vibro

Struct Vibro 

Source
pub struct Vibro<I2C> { /* private fields */ }
Expand description

Driver for the Modulino Vibro module.

§Example

use modulino::{Vibro, PowerLevel};

let mut vibro = Vibro::new(i2c)?;

// Vibrate at medium power for 500ms
vibro.on(500, PowerLevel::Medium)?;

// Vibrate with custom power level
vibro.on_with_power(1000, 50)?;

// Stop vibration
vibro.off()?;

Implementations§

Source§

impl<I2C, E> Vibro<I2C>
where I2C: I2c<Error = E>,

Source

pub const DEFAULT_FREQUENCY: u32 = 1000

Default vibration frequency in Hz.

Source

pub fn new(i2c: I2C) -> Result<Self, E>

Create a new Vibro instance with the default address.

Source

pub fn new_with_address(i2c: I2C, address: u8) -> Result<Self, E>

Create a new Vibro instance with a custom address.

Source

pub fn address(&self) -> u8

Get the I2C address.

Source

pub fn frequency(&self) -> u32

Get the current frequency setting.

Source

pub fn set_frequency(&mut self, frequency: u32)

Set the vibration frequency.

Source

pub fn on(&mut self, duration_ms: u16, power: PowerLevel) -> Result<(), E>

Turn on the vibration motor.

§Arguments
  • duration_ms - Duration in milliseconds (0xFFFF for indefinite)
  • power - Power level
Source

pub fn on_with_power(&mut self, duration_ms: u16, power: u8) -> Result<(), E>

Turn on the vibration motor with a custom power level.

§Arguments
  • duration_ms - Duration in milliseconds (0xFFFF for indefinite)
  • power - Power level (0-100)
Source

pub fn on_continuous(&mut self, power: PowerLevel) -> Result<(), E>

Turn on the vibration motor indefinitely.

Source

pub fn off(&mut self) -> Result<(), E>

Turn off the vibration motor.

Source

pub fn stop(&mut self) -> Result<(), E>

Alias for off().

Source

pub fn pulse(&mut self, on_ms: u16, power: PowerLevel) -> Result<(), E>

Vibrate in a pattern (pulse).

§Arguments
  • on_ms - Vibration duration in milliseconds
  • power - Power level
Source

pub fn release(self) -> I2C

Release the I2C bus.

Auto Trait Implementations§

§

impl<I2C> Freeze for Vibro<I2C>
where I2C: Freeze,

§

impl<I2C> RefUnwindSafe for Vibro<I2C>
where I2C: RefUnwindSafe,

§

impl<I2C> Send for Vibro<I2C>
where I2C: Send,

§

impl<I2C> Sync for Vibro<I2C>
where I2C: Sync,

§

impl<I2C> Unpin for Vibro<I2C>
where I2C: Unpin,

§

impl<I2C> UnwindSafe for Vibro<I2C>
where I2C: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.