Derive the release protocol.

This commit is contained in:
James Harton 2020-01-12 16:57:41 +13:00
parent f3309948e5
commit c94812cfab
4 changed files with 7 additions and 29 deletions

View file

@ -1,5 +1,5 @@
defmodule INA219 do
@derive [Wafer.Chip, Wafer.DeviceID]
@derive [Wafer.Chip, Wafer.DeviceID, Wafer.Release]
defstruct ~w[conn current_divisor power_divisor]a
@behaviour Wafer.Conn
alias Wafer.Conn
@ -54,14 +54,6 @@ defmodule INA219 do
end
end
@doc """
Release the connection to the device.
"""
@spec release(t) :: :ok
@impl Wafer.Conn
def release(%INA219{conn: %{__struct__: mod} = inner} = _conn),
do: apply(mod, :release, [inner])
@doc """
Power-on-reset the device,
"""

10
mix.exs
View file

@ -34,13 +34,13 @@ defmodule INA219.MixProject do
# Run "mix help deps" to learn about dependencies.
defp deps do
[
{:ex_doc, ">= 0.0.0", only: [:dev, :test]},
{:earmark, ">= 0.0.0", only: [:dev, :test]},
{:mimic, "~> 1.1", only: :test},
{:circuits_i2c, "~> 0.3", optional: true},
{:credo, "~> 1.1", only: [:dev, :test], runtime: false},
{:wafer, git: "https://gitlab.com/jimsy/wafer"},
{:earmark, ">= 0.0.0", only: [:dev, :test]},
{:elixir_ale, "~> 1.2", optional: true},
{:circuits_i2c, "~> 0.3", optional: true}
{:ex_doc, ">= 0.0.0", only: [:dev, :test]},
{:mimic, "~> 1.1", only: :test},
{:wafer, "~> 0.1"}
]
end
end

View file

@ -11,5 +11,5 @@
"makeup_elixir": {:hex, :makeup_elixir, "0.14.0", "cf8b7c66ad1cff4c14679698d532f0b5d45a3968ffbcbfd590339cb57742f1ae", [:mix], [{:makeup, "~> 1.0", [hex: :makeup, repo: "hexpm", optional: false]}], "hexpm"},
"mimic": {:hex, :mimic, "1.1.3", "3bad83d5271b4faa7bbfef587417a6605cbbc802a353395d446a1e5f46fe7115", [:mix], [], "hexpm"},
"nimble_parsec": {:hex, :nimble_parsec, "0.5.1", "c90796ecee0289dbb5ad16d3ad06f957b0cd1199769641c961cfe0b97db190e0", [:mix], [], "hexpm"},
"wafer": {:git, "https://gitlab.com/jimsy/wafer", "b5181189ef664831d0403e5d80312f5cbae10f0c", []},
"wafer": {:hex, :wafer, "0.1.0", "8ca31024770f77ff1457a5ae413ae0158e9a713bd8c65aeeb0d7426ca36439e2", [:mix], [{:circuits_gpio, "~> 0.4", [hex: :circuits_gpio, repo: "hexpm", optional: true]}, {:circuits_i2c, "~> 0.3", [hex: :circuits_i2c, repo: "hexpm", optional: true]}, {:circuits_spi, "~> 0.1", [hex: :circuits_spi, repo: "hexpm", optional: true]}, {:elixir_ale, "~> 1.2", [hex: :elixir_ale, repo: "hexpm", optional: true]}], "hexpm"},
}

View file

@ -19,20 +19,6 @@ defmodule INA219Test do
end
end
describe "release/1" do
test "calls `release/1` on the upstream driver" do
conn = conn()
Fake
|> expect(:release, 1, fn driver ->
assert driver == conn.conn
:ok
end)
assert :ok = INA219.release(conn)
end
end
describe "reset/1" do
test "sets the MSB to 1" do
INA219.Registers