Skip to content

Commit 7bcde6a

Browse files
committed
Minimally fix remainder of Circuits.GPIO 2.0 updates
1 parent 50e8ce2 commit 7bcde6a

6 files changed

Lines changed: 23 additions & 32 deletions

File tree

lib/circuits_sim/device/gpio_button.ex

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,11 +80,6 @@ defmodule CircuitsSim.Device.GPIOButton do
8080
"Button #{state.state} connected with #{state.connection}"
8181
end
8282

83-
@impl GPIODevice
84-
def info(state) do
85-
%{device: __MODULE__, value: state.state}
86-
end
87-
8883
@impl GPIODevice
8984
def handle_message(state, {:press, duration}) do
9085
if duration != :infinity do

lib/circuits_sim/device/gpio_led.ex

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,6 @@ defmodule CircuitsSim.Device.GPIOLED do
3939
defp led_string(0), do: "off"
4040
defp led_string(1), do: "on"
4141

42-
@impl GPIODevice
43-
def info(state) do
44-
%{device: __MODULE__, value: state.value}
45-
end
46-
4742
@impl GPIODevice
4843
def handle_message(state, _message) do
4944
{:ok, state}

lib/circuits_sim/gpio/backend.ex

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,32 @@ defmodule CircuitsSim.GPIO.Backend do
99
alias CircuitsSim.GPIO.GPIOServer
1010
alias CircuitsSim.GPIO.Handle
1111

12+
@impl Backend
13+
def enumerate(_options) do
14+
DeviceRegistry.bus_names(:gpio)
15+
end
16+
17+
@impl Backend
18+
def identifiers(gpio_spec, _options) do
19+
# Simplest possible implementation for now.
20+
{:ok, %{controller: "sim", label: "unknown", location: gpio_spec}}
21+
end
22+
23+
@impl Backend
24+
def status(_gpio_spec, _options) do
25+
{:error, :unimplemented}
26+
end
27+
1228
@doc """
1329
Open an GPIO handle
1430
"""
1531
@impl Backend
1632
def open(gpio_spec, direction, options) do
1733
with {:ok, identifiers} <- identifiers(gpio_spec, options),
18-
handle = %Handle{gpio_spec: identifiers.gpio_spec},
19-
:ok <- GPIOServer.set_direction(identifiers.gpio_spec, direction),
20-
:ok <- set_pull_mode(identifiers.gpio_spec, options[:pull_mode]),
21-
:ok <- set_initial_value(identifiers.gpio_spec, options[:initial_value]) do
34+
handle = %Handle{gpio_spec: identifiers.location},
35+
:ok <- GPIOServer.set_direction(identifiers.location, direction),
36+
:ok <- set_pull_mode(identifiers.location, options[:pull_mode]),
37+
:ok <- set_initial_value(identifiers.location, options[:initial_value]) do
2238
{:ok, handle}
2339
end
2440
end
@@ -33,7 +49,7 @@ defmodule CircuitsSim.GPIO.Backend do
3349
Return information about this backend
3450
"""
3551
@impl Backend
36-
def info() do
52+
def backend_info() do
3753
%{backend: __MODULE__}
3854
end
3955
end

lib/circuits_sim/gpio/gpio_device.ex

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,6 @@ defprotocol CircuitsSim.GPIO.GPIODevice do
2323
@spec write(t(), GPIO.value()) :: t()
2424
def write(dev, value)
2525

26-
@doc """
27-
Return info about the GPIO like Circuits.GPIO.info/1
28-
"""
29-
@spec info(t()) :: map()
30-
def info(dev)
31-
3226
@doc """
3327
Return the internal state as ASCII art
3428
"""
@@ -49,7 +43,7 @@ defprotocol CircuitsSim.GPIO.GPIODevice do
4943
@doc """
5044
Handle a message sent to the GenServer running the device
5145
52-
These are used for timeouts or
46+
These are used for timeouts or other events
5347
"""
5448
@spec handle_info(t(), any()) :: t()
5549
def handle_info(dev, message)

lib/circuits_sim/gpio/gpio_server.ex

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ defmodule CircuitsSim.GPIO.GPIOServer do
5959
GenServer.call(via_name(gpio_spec), :read)
6060
end
6161

62-
@spec set_direction(GPIO.gpio_spec(), GPIO.pin_direction()) :: :ok | {:error, atom()}
62+
@spec set_direction(GPIO.gpio_spec(), GPIO.direction()) :: :ok | {:error, atom()}
6363
def set_direction(gpio_spec, direction) do
6464
GenServer.call(via_name(gpio_spec), {:set_direction, direction})
6565
end
@@ -132,10 +132,6 @@ defmodule CircuitsSim.GPIO.GPIOServer do
132132
{:reply, GPIODevice.render(state.device), state}
133133
end
134134

135-
def handle_call(:info, _from, state) do
136-
{:reply, GPIODevice.info(state.device), state}
137-
end
138-
139135
def handle_call({:send_message, message}, _from, state) do
140136
{result, new_device} = GPIODevice.handle_message(state.device, message)
141137
state = %{state | device: new_device}

lib/circuits_sim/gpio/handle.ex

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,5 @@ defmodule CircuitsSim.GPIO.Handle do
4747

4848
@impl Handle
4949
def close(%CircuitsSim.GPIO.Handle{}), do: :ok
50-
51-
@impl Handle
52-
def info(%CircuitsSim.GPIO.Handle{} = handle) do
53-
GPIOServer.info(handle.pin_spec)
54-
end
5550
end
5651
end

0 commit comments

Comments
 (0)