Fledex.LedStrip (fledex v0.6.0)
View SourceThis module defines a GenServer that manages the LED strip (be it a real one with the
Fledex.Driver.Impl.Spi or a virtual one with e.g. the Fledex.Driver.Impl.Kino).
You would start an LedStrip for every led strip you have.
The Fledex.LedStrip will take several Fledex.Leds definitions and merge them
together to be displayed on a single LED strip.
The role the LedStrip plays is similar to the one a window server plays on a normal computer, except that a window server would manage several screens, whereas here each LED strip would get its own.
Note: In general you shouldn't require to start an LedStrip directly, but you should
use the Fledex DSL. In order to start an LedStrip a Registry (with name as provided by
Fledex.Supervisor.Utils.worker_registry/0) is required.
Summary
Functions
Change some aspect of a configuration for a specific strip. The configuration will be updated and the old values will be returned.
Returns a specification to start this module under a supervisor.
Define a new namespace
Drop a previously defined namespace.
Checks whether the specified namespace already exists
In some circumstances it might be necessary to reinitialize the led_strip (including the drivers). Most of the time you don't need to call this. If you do, you will surely know about it :)
Sets the leds in a specific strip and namespace.
Similar to set_leds/4 but allows to specify some options to rotate
the leds.
This starts the server controlling a specfic led strip. It is possible to install several drivers at the same time, so different hardware gets the same data at the same time (similar to mirroring a screen). If you want to send different data to different strips, you should start several instances of this server
Types
@type drivers_config_t() :: module() | Fledex.Driver.Manager.driver_t() | Fledex.Driver.Manager.drivers_t()
Functions
Change some aspect of a configuration for a specific strip. The configuration will be updated and the old values will be returned.
@spec child_spec({atom(), drivers_config_t(), keyword()}) :: Supervisor.child_spec()
Returns a specification to start this module under a supervisor.
See Supervisor.
Define a new namespace
Drop a previously defined namespace.
Checks whether the specified namespace already exists
@spec reinit(atom(), drivers_config_t(), keyword()) :: :ok
In some circumstances it might be necessary to reinitialize the led_strip (including the drivers). Most of the time you don't need to call this. If you do, you will surely know about it :)
@spec set_leds(atom(), atom(), [pos_integer()], non_neg_integer() | nil) :: :ok | {:error, String.t()}
Sets the leds in a specific strip and namespace.
The count should correspond to the length of the leds list and will be
calculated if not provided (but often this information is already available
and therefore can be provided)
Note: repeated calls of this function will result in previously set leds will be overwritten. We are passing a list of leds which means every led will be rewritten, except if we define a 'shorter" led sequence. In that case some leds might retain their previously set value.
@spec set_leds_with_rotation( atom(), atom(), [pos_integer()], non_neg_integer() | nil, keyword() ) :: :ok | {:error, String.t()}
Similar to set_leds/4 but allows to specify some options to rotate
the leds.
The recognized options are:
:offset: The amount to rotate:rotate_left: whether we want to rotate to the left (or the right). The default istrue
@spec start_link(atom(), drivers_config_t(), keyword()) :: GenServer.on_start()
This starts the server controlling a specfic led strip. It is possible to install several drivers at the same time, so different hardware gets the same data at the same time (similar to mirroring a screen). If you want to send different data to different strips, you should start several instances of this server
Because we can have several drivers (even though that is rather the exception) the confirgation is split up into several parts (not all of them need to be present):
- The name of the strip (mandatory)
- The global configuration of the strip (optional, defaults will be used if not specified)
- A driver module (that also provides a default set of configs)
- A list of detailed configs that are overlayed over the defaults. This allows
for example to reuse the
Fledex.Driver.Impl.Spidefaults, but change for example to a different spi device by setting:devtospidev0.1
Here some examples (with aliased module names) how you can start the server:
- Without real driver:
start_link(:name) - With real driver:
start_link(:name, Spi) - With some global config overlay and real driver:
start_link(:name, Spi, timer_only_dirty_update: true) - With real driver and some driver overlay:
start_link(:name, {Spi, dev: "spidev0.1"}) - With several drivers:
start_link(:name, [{Spu, []}, {Spi, dev: "spidev0.1"}]) - With several drivers and global config:
start_link(:name, [{Spi, []}, {Spi, dev: "spidev0.1"}], timer_only_dirty_update: true)