Pwmx.Backend (Pwmx v0.1.0)

Copy Markdown View Source

Backend GenServer, dispatching PWM calls either to the real sysfs interface (Pwmx.Backend.Sysfs) on a Linux host that exposes /sys/class, or to an in-memory simulation (Pwmx.Backend.Virtual) elsewhere.

A default, application-supervised instance is registered under the name Pwmx.Backend. Every public function takes the backend server as its first argument (a pid or a registered name), so additional, isolated instances can be started, this is what lets tests run against a private virtual board:

{:ok, backend} = Pwmx.Backend.start_link(name: :my_board, mode: :virtual)
Pwmx.Backend.list_chips(backend)

Options

  • :name : the name to register the instance under. Defaults to Pwmx.Backend.
  • :mode : :auto (default), :virtual or :real. :auto uses the sysfs backend when /sys/class exists (and always the virtual one under MIX_ENV=test).
  • :virtual_chips : a map of chip_name => output_count describing the board the virtual backend simulates. Defaults to the :pwmx, :virtual_chips application environment, or %{"virtualchip0" => 4}.

Summary

Functions

already_exported?(server \\ Pwmx.Backend, chip, output)

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

disable(server \\ Pwmx.Backend, chip, output)

enable(server \\ Pwmx.Backend, chip, output)

enabled?(server \\ Pwmx.Backend, chip, output)

enumerate_outputs(server \\ Pwmx.Backend, chip)

export(server \\ Pwmx.Backend, chip, output)

get_duty_cycle(server \\ Pwmx.Backend, chip, output)

get_period(server \\ Pwmx.Backend, chip, output)

init(opts)

Callback implementation for GenServer.init/1.

list_chips(server \\ Pwmx.Backend)

@spec list_chips(GenServer.server()) :: {:ok, [binary()]} | {:error, any()}

set_duty_cycle_absolute(server \\ Pwmx.Backend, chip, output, value, unit)

set_duty_cycle_normalized(server \\ Pwmx.Backend, chip, output, value)

set_period(server \\ Pwmx.Backend, chip, output, value, unit)

set_polarity(server \\ Pwmx.Backend, chip, output, direction)

start_link(opts \\ [])

unexport(server \\ Pwmx.Backend, chip, output)