Struct syact::device::SoftwarePWM

source ·
pub struct SoftwarePWM<P: OutputPin + Send> { /* private fields */ }
Expand description

A simple software-made PWM-signal

Implementations§

source§

impl<P: OutputPin + Send + 'static> SoftwarePWM<P>

source

pub fn new(pin: P) -> Self

Create a new software PWM-signal at the given pin. Make sure the pin is not already in use!

§Setup

Once the setup function is called, the thread and the pin will be crated

source

pub fn with_freq(self, freq: Frequency) -> Self

Sets the frequency of the PWM-Signal inline

source

pub fn with_period_time(self, time: Time) -> Self

Sets the period time of the signal inline

source

pub fn pulse(pin: &mut P, t_ac: Time, t_in: Time) -> Result<(), P::Error>

Does a single pulse with the active time t_ac and inactive time t_in

source

pub fn get_times(&self) -> [Time; 2]

Get the current signal times (t_ac, t_in)

source

pub fn set_times(&mut self, t_ac: Time, t_in: Time)

Sets the signal times (t_ac, t_in)

source

pub fn get_period(&self) -> [Time; 2]

Get the signal times in period style (t_ac, t_per)

source

pub fn set_period(&mut self, t_ac: Time, t_per: Time)

Set the signal times in period style

  • t_ac is the active time
  • t_per is the full period time
§Panics

The function panics if the given active time t_ac is bigger than the period time t_per

source

pub fn get_freq(&self) -> (Velocity, f32)

Get the signal times in frequency style (freq, factor)

  • freq is the freqency of the signal, meaning how many pulses there are per second
  • factor represents how much of the pulse is active time (values 0.0 to 1.0)
source

pub fn set_freq(&mut self, freq: Frequency, factor: f32)

Set the signal times in frequency style

  • freq is the freqency of the signal, meaning how many pulses there are per second
  • factor represents how much of the pulse is active time (values 0.0 to 1.0)
§Panics

The function panics if the given factor is out of range

source

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

Stops the PWM-Signal and deletes the thread, can be started again if desired with start()

Trait Implementations§

source§

impl<P: Debug + OutputPin + Send> Debug for SoftwarePWM<P>

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl<P: OutputPin + Send + 'static> Dismantle for SoftwarePWM<P>

source§

fn dismantle(&mut self) -> Result<(), Error>

Calls all required functions to assure the component will not occupy any more resources like pins or network connections, without dropping the value
source§

fn dismantle_inline(self) -> Result<Self, Error>
where Self: Sized,

Calls dismantle() with an owned object
source§

impl<P: OutputPin + Send> ErrorType for SoftwarePWM<P>

§

type Error = ErrorKind

Error type
source§

impl<P: OutputPin + Send + 'static> SetDutyCycle for SoftwarePWM<P>

source§

fn max_duty_cycle(&self) -> u16

Get the maximum duty cycle value. Read more
source§

fn set_duty_cycle(&mut self, duty: u16) -> Result<(), Self::Error>

Set the duty cycle to duty / max_duty. Read more
source§

fn set_duty_cycle_fully_off(&mut self) -> Result<(), Self::Error>

Set the duty cycle to 0%, or always inactive.
source§

fn set_duty_cycle_fully_on(&mut self) -> Result<(), Self::Error>

Set the duty cycle to 100%, or always active.
source§

fn set_duty_cycle_fraction( &mut self, num: u16, denom: u16 ) -> Result<(), Self::Error>

Set the duty cycle to num / denom. Read more
source§

fn set_duty_cycle_percent(&mut self, percent: u8) -> Result<(), Self::Error>

Set the duty cycle to percent / 100 Read more
source§

impl<P: OutputPin + Send> Setup for SoftwarePWM<P>

source§

fn setup(&mut self) -> Result<(), Error>

Calls all required functions to assure the components functionality
source§

fn setup_inline(self) -> Result<Self, Error>
where Self: Sized,

Points to `setup``, helper function

Auto Trait Implementations§

§

impl<P> Freeze for SoftwarePWM<P>

§

impl<P> !RefUnwindSafe for SoftwarePWM<P>

§

impl<P> Send for SoftwarePWM<P>

§

impl<P> !Sync for SoftwarePWM<P>

§

impl<P> Unpin for SoftwarePWM<P>
where P: Unpin,

§

impl<P> !UnwindSafe for SoftwarePWM<P>

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>,

§

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>,

§

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.