View Source Fledex.Leds (fledex v0.3.0)

This module allows to define a sequence of Leds. You first create the new sequence of leds by calling one of the leds functions.

Note: usually the leds function would rather be called new but when importing the Leds module, it becomes more natural to say

  leds(10) |> light(:red)`

To keep the classical semantics some delegates are defined, so you can use new as well.

Summary

Functions

Helper function to convert a list of colors to the correct map structure

This function checks how many leds are defined in the led sequence.

Retrieve the color of an led at a specific position

Defines the leds through a gradient function.

Create a new led sequence of length 0.

Creates a new led sequence with a set number of leds

Create a new led sequence with a set number of leds and some options.

Create a new led sequence with a set number of leds, some set leds and options.

Creates a led sequence with a set number of leds, some set leds, some options and some meta information.

Defines the color(s) of the next led

Defines the color of an led at position (one indexed)

Defines the color of an led at position and repeats it repeat times.

Defines a rainbow over the leds. The options that can be specified are

repeat teh existing sequence amount times

Convenience function to send the led sequence to an Fledex.LedStrip.

This function sets the count of leds of the led sequence.

Define the server_name and the namespace

Convert the sequence of leds to a binary sequence of Fledex.Color.Types.colorint colors.

Convert the sequence of leds into an list of Fledex.Color.Types.colorint colors.

Convert the sequence of leds to a markdown representation.

Types

@type t() :: %Fledex.Leds{
  count: integer(),
  leds: %{required(pos_integer()) => Fledex.Color.Types.colorint()},
  meta: %{required(atom()) => any()},
  opts: %{required(atom()) => any()}
}

Functions

Link to this function

convert_to_leds_structure(rgbs, offset \\ 0)

View Source
@spec convert_to_leds_structure([Fledex.Color.Types.color()], integer()) :: map()

Helper function to convert a list of colors to the correct map structure

@spec count(t()) :: pos_integer()

This function checks how many leds are defined in the led sequence.

Note: The color of an led outside that range can be defined, but it won't be send to the Fledex.LedStrip when the send/2 function is called. See also set_count/2 for information.

@spec get_light(t(), pos_integer()) :: Fledex.Color.Types.colorint()

Retrieve the color of an led at a specific position

Link to this function

gradient(leds, start_color, end_color, opts \\ [])

View Source
@spec gradient(t(), Fledex.Color.Types.color(), Fledex.Color.Types.color(), keyword()) ::
  t()

Defines the leds through a gradient function.

The gradient function will create a smoot transition from a start_color to an end_color. The options that can be specified are the following:

  • "num_leds: Over how many leds the transition should happen. (default: all)
  • :offset: The offset where to start the gardient at (default: 0)
@spec leds() :: t()

Create a new led sequence of length 0.

This is rarely useful. Use the leds/1 function instead (or change the count by using set_count/2)

@spec leds(integer()) :: t()

Creates a new led sequence with a set number of leds

@spec leds(integer(), map()) :: t()

Create a new led sequence with a set number of leds and some options.

Currently two options are available:

  • :server_name and
  • :namespace.

Those are important when you want to send your led sequence to an Fledex.LedStrip. You should prefer to use the set_driver_info/3 function instead.

@spec leds(
  integer(),
  [Fledex.Color.Types.color()]
  | %{required(integer()) => Fledex.Color.Types.color()},
  map()
) :: t()

Create a new led sequence with a set number of leds, some set leds and options.

This function is similar to leds/2, but you an specify some leds (between the count and the opts) through a map or a list.

If a map is used the key of the map (an integer) is the index (one-indexed) of the led and the value is the color. If a list is used each entry in the list defines a color. Internally it will be converted to a map.

Leds that are outside the count can be specified, but will be ignored when sent to an Fledex.LedStrip through the send/2 function.

Link to this function

leds(count, leds, opts, meta)

View Source
@spec leds(
  integer(),
  [Fledex.Color.Types.color()]
  | %{required(integer()) => Fledex.Color.Types.color()},
  map(),
  map()
) :: t()

Creates a led sequence with a set number of leds, some set leds, some options and some meta information.

This function is similar to the leds/3 function, but some additional meta information can be specified. Currently the only meta information is to keep track of an index that specfies which led will be set when using the light/2 function, i.e. without an offset. This way it's possible to have a sequence of updates like the following to specify the colors:

leds(10) |> light(:red) |> light(:blue)
@spec light(t(), Fledex.Color.Types.color() | t()) :: t()

Defines the color(s) of the next led

If there are no more leds, this function will virtually continue and define leds outside the scope, see also the note on set_count/2.

Note: it is possible to use a sub sequence of leds and they all will be added to the sequence.

Link to this function

light(leds, led, offset)

View Source
@spec light(t(), Fledex.Color.Types.color() | t(), pos_integer()) :: t()

Defines the color of an led at position (one indexed)

The offset needs to be > 0 if it's bigger than the count then the led will be stored, but ignored (but see the description of set_count/2). The same note as for light/2 applies.

Link to this function

light(leds, led, offset, repeat)

View Source
@spec light(t(), Fledex.Color.Types.color() | t(), pos_integer(), pos_integer()) ::
  t()

Defines the color of an led at position and repeats it repeat times.

THe repeat needs to be more than 1, otherwise it wouldn't make sense. In adition the same note as for light/2 applies.

See Fledex.Leds.leds/0.

See Fledex.Leds.leds/1.

See Fledex.Leds.leds/2.

See Fledex.Leds.leds/3.

Link to this function

new(count, leds, opts, meta)

View Source

See Fledex.Leds.leds/4.

Link to this function

rainbow(leds, opts \\ %{})

View Source
@spec rainbow(t(), map()) :: t()

Defines a rainbow over the leds. The options that can be specified are:

  • :num_leds: how many leds should be part of the rainbow (by default all leds)
  • :offset: as from which led we want to start the rainbow (default: 0, no offset)
  • :reversed: The rainbow can go from red (start color) to blue (end color) or the other way around.
  • :initial_hue: The starting color in degree (0..360). (default: 0)

Note: any led that has been defined before calling this function will be overwritten with the rainbow value.

@spec repeat(t(), integer()) :: t()

repeat teh existing sequence amount times

This way you can easily create a repetitive pattern

Note: this will change the led sequence count (amount times the initial count)

@spec send(t(), map()) :: :ok | {:error, String}

Convenience function to send the led sequence to an Fledex.LedStrip.

In order for the function to succeed either set_driver_info/3 needs to be called or the information needs to be passed as part of the opts. The opts can be the following:

  • :offset: Move the led sequence to the side (see Note below)
  • :rotate_left: whether the offset should be appiled toward the right or the left
  • :server_name: The name of the server_name to which the led sequence should be send to (default: Fledex.LedStrip)
  • :namespace: The name of the namespace within the LedStrip (default: :default)

Note: the led sequence will always be applied in it's entirety, and will wrap around. Through the :offset it is possible to create simple animations by simply counting up up the counter.

Note2: If no server_name and/or no namespace are defined, then they will be defined (and started). A warning will be emitted to the concole.

@spec set_count(t(), pos_integer()) :: t()

This function sets the count of leds of the led sequence.

Note: Be careful if you redefine the count when some leds have been defined outside of the previous range; they might suddenly become visible.

Link to this function

set_driver_info(leds, namespace, server_name \\ Fledex.LedStrip)

View Source
@spec set_driver_info(t(), namespace :: atom(), server_name :: atom()) :: t()

Define the server_name and the namespace

This is used when the led sequence is sent to the Fledex.LedStrip when the send/2 function is called.

@spec to_binary(t()) :: binary()

Convert the sequence of leds to a binary sequence of Fledex.Color.Types.colorint colors.

Note: Only the leds that are inside the count will be emitted into the binary sequence.

@spec to_list(t()) :: [Fledex.Color.Types.colorint()]

Convert the sequence of leds into an list of Fledex.Color.Types.colorint colors.

Note: Only the leds that are inside the count will be added to the list.

Link to this function

to_markdown(leds, opts \\ %{})

View Source
@spec to_markdown(t(), map()) :: String.t()

Convert the sequence of leds to a markdown representation.

The █ will be used to represent the leds and they will be colored in the appropriate color. It then looks something like this:

The opts are currently not used, but are planned to be used for potential color correction (similar to Fledex.Driver.Impl.Kino)