View Source OLEDVirtual.Display behaviour (OLEDVirtual v1.0.0)

Virtual oled display.

When used, the display expects an :app as option. The :app should be the app that has the configuration.

example

Example

defmodule MyApp.MyDisplay do
  use OLEDVirtual.Display, app: :my_app
end

Could be configured with:

config :my_app, MyApp.MyDisplay,
  width: 128,
  height: 64

It needs to be added to the supervision tree:

defmodule MyApp.Application do
  use Application

  @impl true
  def start(_type, _args) do
    children = [
      ...
      MyApp.MyDisplay
    ]

    opts = [strategy: :one_for_one, name: MyApp.Supervisor]
    Supervisor.start_link(children, opts)
  end
end

And then used like this:

MyApp.MyDisplay.rect(0, 0, 127, 63)
MyApp.MyDisplay.display()

See OLED.Display for all draw and display functions.

callbacks

Callbacks

The virtual display module supports optional callbacks to get notified about buffer or frame changes. They can be used to further process the frame, e.g. broadcasting it via Phoenix.PubSub.

defmodule MyApp.MyDisplay do
  use OLEDVirtual.Display, app: :my_app

  def on_display(data, dimensions) do
    # Called after MyApp.MyDisplay.display/0 and MyApp.MyDisplay.display_frame/2
  end

  def on_buffer_update(data, dimensions) do
    # Called after any changes to the buffer of the next frame
  end
end

Link to this section Summary

Callbacks

Called after any changes to the buffer of the next frame

Called after display/0 and display_frame/2 got invoked.

Link to this section Callbacks

Link to this callback

on_buffer_update(data, dimensions)

View Source
@callback on_buffer_update(
  data :: binary(),
  dimensions :: %{width: integer(), height: integer()}
) :: any()

Called after any changes to the buffer of the next frame

Link to this callback

on_display(data, dimensions)

View Source
@callback on_display(
  data :: binary(),
  dimensions :: %{width: integer(), height: integer()}
) :: any()

Called after display/0 and display_frame/2 got invoked.