Pwmx.Utils (Pwmx v0.1.0)

Copy Markdown View Source

Utilities for type and units conversions.

Summary

Functions

Ensures you have an integer in case you were passing a binary. Can raise, since String.to_integer/1 can raise an ArgumentError

Linux's sysfs PWM interface expects to get period and duty cycle values expressed in nanoseconds.

Functions

ensure_int!(value)

@spec ensure_int!(binary() | integer()) :: integer()

Ensures you have an integer in case you were passing a binary. Can raise, since String.to_integer/1 can raise an ArgumentError

iex> Pwmx.Utils.ensure_int!(10)
10
iex> Pwmx.Utils.ensure_int!("10")
10

to_nanoseconds(value, unit)

@spec to_nanoseconds(integer(), :ms | :ns | :s | :us) :: integer()

Linux's sysfs PWM interface expects to get period and duty cycle values expressed in nanoseconds.

iex> Pwmx.Utils.to_nanoseconds(10, :ms)
10_000_000
iex> Pwmx.Utils.to_nanoseconds(10, :ns)
10