Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: pappersverk/oled
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v0.3.1
Choose a base ref
...
head repository: pappersverk/oled
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref

Commits on Dec 5, 2019

  1. Add CI integration

    luisgabrielroldan committed Dec 5, 2019
    Copy the full SHA
    84586d0 View commit details
  2. Update README.md

    luisgabrielroldan authored Dec 5, 2019
    Copy the full SHA
    c240bb2 View commit details

Commits on Dec 21, 2019

  1. Simplify rendering

    luisgabrielroldan committed Dec 21, 2019
    Copy the full SHA
    e1a8dc8 View commit details
  2. Copy the full SHA
    a28c5ae View commit details
  3. Copy the full SHA
    3ee0d85 View commit details
  4. Removing warnings

    luisgabrielroldan committed Dec 21, 2019
    Copy the full SHA
    594c94e View commit details
  5. Merge pull request #1 from pappersverk/development

    Add extra primitives
    luisgabrielroldan authored Dec 21, 2019
    Copy the full SHA
    5afe5af View commit details

Commits on Feb 6, 2020

  1. Remove memory cmd

    luisgabrielroldan committed Feb 6, 2020
    Copy the full SHA
    e60aaad View commit details
  2. Fix normal mode

    luisgabrielroldan committed Feb 6, 2020
    Copy the full SHA
    f065581 View commit details

Commits on Mar 4, 2020

  1. Copy the full SHA
    5cda2f7 View commit details
  2. Merge pull request #3 from pappersverk/issue-2-vertical-lines

    Fix aritmetic error on vertical lines using line/5
    luisgabrielroldan authored Mar 4, 2020
    Copy the full SHA
    62a6782 View commit details
  3. Release 0.3.4

    luisgabrielroldan committed Mar 4, 2020
    Copy the full SHA
    4771f44 View commit details

Commits on Mar 6, 2020

  1. Copy the full SHA
    5f889e7 View commit details
  2. Merge pull request #5 from pappersverk/fix-error-propagation

    Fix error propagation on display initialization
    luisgabrielroldan authored Mar 6, 2020
    Copy the full SHA
    01f11cb View commit details

Commits on Dec 23, 2021

  1. Copy the full SHA
    79d74b6 View commit details

Commits on Dec 26, 2021

  1. Merge pull request #10 from pappersverk/add-gh-actions-tests

    Replace circle-ci with github actions
    luisgabrielroldan authored Dec 26, 2021
    Copy the full SHA
    cb4fab3 View commit details
  2. Copy the full SHA
    6a6e25b View commit details
  3. Copy the full SHA
    fee1c09 View commit details
  4. Copy the full SHA
    bd0f71d View commit details
  5. Copy the full SHA
    1b98bc8 View commit details
  6. Copy the full SHA
    ace02f9 View commit details

Commits on Dec 28, 2021

  1. Merge pull request #9 from pappersverk/change-display-frame

    Add `display_raw_frame/2`, `put_buffer/1` and `get_buffer/0`
    luisgabrielroldan authored Dec 28, 2021
    Copy the full SHA
    f7d0921 View commit details

Commits on Dec 30, 2021

  1. Bump version

    luisgabrielroldan committed Dec 30, 2021
    Copy the full SHA
    8a05e84 View commit details
  2. Copy the full SHA
    7f0c054 View commit details

Commits on Jan 19, 2022

  1. Copy the full SHA
    3dbe03b View commit details
  2. Merge pull request #12 from pappersverk/update-beam-installation-duri…

    …ng-ci
    
    Update setup-elixir to setup-beam
    PhillippOhlandt authored Jan 19, 2022
    Copy the full SHA
    bae0907 View commit details

Commits on Sep 21, 2022

  1. Update dependencies

    ringvold committed Sep 21, 2022
    Copy the full SHA
    e77bfdd View commit details

Commits on Oct 18, 2022

  1. Merge pull request #16 from ringvold/update-dependencies

    Update dependencies
    luisgabrielroldan authored Oct 18, 2022
    Copy the full SHA
    b9f1cbe View commit details
  2. Bump version

    luisgabrielroldan committed Oct 18, 2022
    Copy the full SHA
    ba80d17 View commit details
52 changes: 52 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
name: Tests

on:
push:
branches: [ master ]
pull_request:
branches: [ '*' ]

jobs:
build:

name: Build and test
runs-on: ubuntu-latest

strategy:
fail-fast: false
matrix:
elixir: [ '1.7', '1.8', '1.9', '1.10', '1.11', '1.12', '1.13' ]
otp: [ '22', '23', '24' ]
exclude:
- elixir: '1.7'
otp: '23'
- elixir: '1.7'
otp: '24'
- elixir: '1.8'
otp: '23'
- elixir: '1.8'
otp: '24'
- elixir: '1.9'
otp: '23'
- elixir: '1.9'
otp: '24'
- elixir: '1.10'
otp: '24'

steps:
- uses: actions/checkout@v2
- name: Set up Elixir
uses: erlef/setup-beam@v1
with:
elixir-version: ${{ matrix.elixir }}
otp-version: ${{ matrix.otp }}
- name: Restore dependencies cache
uses: actions/cache@v2
with:
path: deps
key: ${{ runner.os }}-${{ matrix.elixir }}-${{ matrix.otp }}-mix-${{ hashFiles('**/mix.lock') }}
restore-keys: ${{ runner.os }}-${{ matrix.elixir }}-${{ matrix.otp }}-mix-
- name: Install dependencies
run: mix deps.get
- name: Run tests
run: mix test
11 changes: 6 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# OLED

![Test Status](https://github.com/pappersverk/oled/actions/workflows/tests.yml/badge.svg)
[![Hex version](https://img.shields.io/hexpm/v/oled.svg "Hex version")](https://hex.pm/packages/oled)


@@ -17,12 +18,12 @@ Graphic primitives
- [x] Points
- [x] Lines
- [x] Rects
- [ ] Circles
- [ ] Polygons
- [ ] Filled Rects
- [x] Filled Rects
- [x] Circles
- [ ] Filled Circles
- [ ] Polygons
- [ ] Filled Polygons
- [ ] Text rendering
- [ ] Text rendering (Try [Chisel](https://github.com/luisgabrielroldan/chisel))



@@ -44,7 +45,7 @@ Graphic primitives
```elixir
def deps do
[
{:oled, "~> 0.1.0"}
{:oled, "~> 0.3"}
]
end
```
66 changes: 65 additions & 1 deletion lib/oled/display.ex
Original file line number Diff line number Diff line change
@@ -79,12 +79,21 @@ defmodule OLED.Display do
def display_frame(data, opts \\ []),
do: Server.display_frame(@me, data, opts)

def display_raw_frame(data, opts \\ []),
do: Server.display_raw_frame(@me, data, opts)

def clear(),
do: Server.clear(@me)

def clear(pixel_state),
do: Server.clear(@me, pixel_state)

def put_buffer(data),
do: Server.put_buffer(@me, data)

def get_buffer(),
do: Server.get_buffer(@me)

def put_pixel(x, y, opts \\ []),
do: Server.put_pixel(@me, x, y, opts)

@@ -100,6 +109,12 @@ defmodule OLED.Display do
def rect(x, y, width, height, opts \\ []),
do: Server.rect(@me, x, y, width, height, opts)

def circle(x0, y0, r, opts \\ []),
do: Server.circle(@me, x0, y0, r, opts)

def fill_rect(x, y, width, height, opts \\ []),
do: Server.fill_rect(@me, x, y, width, height, opts)

def get_dimensions(),
do: Server.get_dimensions(@me)
end
@@ -112,10 +127,21 @@ defmodule OLED.Display do
@callback display() :: :ok

@doc """
Transfer a data frame to the display buffer.
Transfer a data frame to the screen. The data frame format is equal to the display buffer
that gets altered via the drawing commands.
Calling this function transfers the data frame directly to the screen and does not alter the display buffer.
"""
@callback display_frame(data :: binary(), opts :: Server.display_frame_opts()) :: :ok

@doc """
Transfer a raw data frame to the screen.
A raw data frame is in a different format than the display buffer.
To transform a display buffer to a raw data frame, `OLED.Display.Impl.SSD1306.translate_buffer/3` can be used.
"""
@callback display_raw_frame(data :: binary(), opts :: Server.display_frame_opts()) :: :ok

@doc """
Clear the buffer.
"""
@@ -126,6 +152,21 @@ defmodule OLED.Display do
"""
@callback clear(pixel_state :: Server.pixel_state()) :: :ok

@doc """
Override the current buffer which is the internal data structure that is sent to the screen with `c:display/0`.
A possible use-case is to draw some content, get the buffer via `c:get_buffer/0`
and set it again at a later time to save calls to the draw functions.
"""
@callback put_buffer(data :: binary()) :: :ok | {:error, term()}

@doc """
Get the current buffer which is the internal data structure that is changed by the draw methods
and sent to the screen with `c:display/0`.
"""
@callback get_buffer() :: {:ok, binary()}


@doc """
Put a pixel on the buffer. The pixel can be on or off and be drawed in xor mode (if the pixel is already on is turned off).
"""
@@ -178,6 +219,29 @@ defmodule OLED.Display do
opts :: Server.pixel_opts()
) :: :ok

@doc """
Draw a circle
Origin `(x0, y0)` with radius `r`.
"""
@callback circle(
x0 :: integer(),
y0 :: integer(),
r :: integer(),
opts :: Server.pixel_opts()
) :: :ok

@doc """
Draw a filled rect
"""
@callback fill_rect(
x :: integer(),
y :: integer(),
width :: integer(),
height :: integer(),
opts :: Server.pixel_opts()
) :: :ok

@doc """
Get display dimensions
"""
75 changes: 58 additions & 17 deletions lib/oled/display/impl/ssd_1306.ex
Original file line number Diff line number Diff line change
@@ -36,11 +36,6 @@ defmodule OLED.Display.Impl.SSD1306 do
@ssd1306_deactivate_scroll 0x2E
# @ssd1306_activate_scroll 0x2F

# Full width of SSD1306 controller memory
@lcd_total_width 128
# Full height of SSD1306 controller memory
@lcd_total_height 64

@default_config [
width: 128,
height: 64,
@@ -62,10 +57,12 @@ defmodule OLED.Display.Impl.SSD1306 do
external_vcc: nil

defdelegate put_pixel(state, x, y, opts), to: Draw
defdelegate circle(state, x0, y0, r, opts), to: Draw
defdelegate rect(state, x, y, width, height, opts), to: Draw
defdelegate line(state, x1, y1, x2, y2, opts), to: Draw
defdelegate line_h(state, x, y, width, opts), to: Draw
defdelegate line_v(state, x, y, height, opts), to: Draw
defdelegate fill_rect(state, x, y, width, height, opts), to: Draw

def init_dev(config) do
case Keyword.get(config, :type) do
@@ -124,28 +121,58 @@ defmodule OLED.Display.Impl.SSD1306 do
|> command([@ssd1306_displayon])
end

def display(%__MODULE__{} = state, opts \\ []) do
def display(state, opts \\ [])

def display(%__MODULE__{} = state, opts) do
%{buffer: buffer, width: width} = state
opts = Keyword.merge(@display_opts, opts)

memory_mode = get_memory_mode(opts[:memory_mode] || :horizontal)
buffer = translate_buffer(buffer, width, opts[:memory_mode])

state
|> command([@ssd1306_memorymode, memory_mode])
|> command([@ssd1306_pageaddr, 0, trunc(state.height / 8 - 1)])
|> command([@ssd1306_columnaddr, 0, state.width - 1])
|> transfer(state.buffer)
|> command([@ssd1306_memorymode, 0])
display_raw_frame(state, buffer, opts)
end

def display_frame(%__MODULE__{} = state, data, opts) do
def display(error, _opts),
do: error

def display_frame(%__MODULE__{width: width} = state, data, opts) do
opts = Keyword.merge(@display_opts, opts)

buffer = translate_buffer(data, width, opts[:memory_mode])

display_raw_frame(state, buffer, opts)
end

def display_raw_frame(%__MODULE__{} = state, data, opts) do
memory_mode = get_memory_mode(opts[:memory_mode] || :horizontal)

if byte_size(data) == state.width * state.height / 8 do
display(%{state | buffer: data}, opts)
state
|> command([@ssd1306_memorymode, memory_mode])
|> command([@ssd1306_pageaddr, 0, trunc(state.height / 8 - 1)])
|> command([@ssd1306_columnaddr, 0, state.width - 1])
|> transfer(data)
else
{:error, :invalid_data_size}
end
end

def clear_buffer(%__MODULE__{} = state, pixel_state)
def translate_buffer(buffer, width, :horizontal) do
transformation =
for x <- 0..(width - 1), y <- 0..7 do
(7 - y) * width + x
end

for <<page::binary-size(width) <- buffer>>, into: <<>> do
for source <- transformation, into: <<>> do
rest = width * 8 - source - 1
<<_::size(source)-unit(1), b::1, _::size(rest)-unit(1)>> = page
<<b::1>>
end
end
end

def clear_buffer(%__MODULE__{width: w, height: h} = state, pixel_state)
when pixel_state in [:on, :off] do
value =
case pixel_state do
@@ -157,13 +184,27 @@ defmodule OLED.Display.Impl.SSD1306 do
end

buffer =
for _ <- 1..trunc(@lcd_total_width * @lcd_total_height / 8), into: <<>> do
for _ <- 1..trunc(w * h / 8), into: <<>> do
value
end

%{state | buffer: buffer}
end

def clear_buffer(error, _pixel_state),
do: error

def put_buffer(%__MODULE__{} = state, data) do
if byte_size(data) == state.width * state.height / 8 do
%{state | buffer: data}
else
{:error, :invalid_data_size}
end
end

def get_buffer(%__MODULE__{buffer: buffer}),
do: {:ok, buffer}

def get_dimensions(%__MODULE__{width: width, height: height}),
do: {:ok, width, height}

Loading