Skip to content

pappersverk/oled_virtual

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OLEDVirtual

OLEDVirtual is a virtual version of the oled library.

Its main purpose it to reduce the roundtrip time during development by fully virtualizing the oled display.

It also comes with a MultiDisplay module to use both hardware and virtual display at the same time.

Demo: Showing the virtual LiveView powered version on the web interface and the real screen on the device

Installation

The package can be installed by adding oled_virtual to your list of dependencies in mix.exs:

def deps do
  [
    {:oled_virtual, "~> 1.0"}
  ]
end

Quickstart

  1. Define the display module
defmodule MyApp.OledVirtual do
  use OLEDVirtual.Display, app: :my_app

  def on_display(data, dimensions) do
    # React to new frames
    payload = %{
      data: data,
      dimensions: dimensions
    }
    Phoenix.PubSub.broadcast(MyApp.PubSub, "oled-virtual", %{event: "on_display", payload: payload})
  end
end
  1. Define the dimensions of the display
config :my_app, MyApp.OledVirtual,
   width: 128,
   height: 64
  1. Add the virtual display to your supervision tree.
defmodule MyApp.Application do
  use Application

  @impl true
  def start(_type, _args) do
    children = [
      # Add this line
      MyApp.OledVirtual
    ]

    opts = [strategy: :one_for_one, name: MyApp.Supervisor]
    Supervisor.start_link(children, opts)
  end
end
  1. Use it
# Draw something
MyApp.OledVirtual.rect(0, 0, 127, 63)
MyApp.OledVirtual.line(0, 0, 127, 63)
MyApp.OledVirtual.line(0, 63, 127, 0)

# Display it!
MyApp.OledVirtual.display()

The whole documentation can be found at https://hexdocs.pm/oled_virtual.