Skip to content

Commit c751a3e

Browse files
bithiumfhunleth
authored andcommitted
Fix I2CServer.send_message/1 with SimpleI2CDevice
This commit fixes the issue where the `I2CServer.send_message/1` function only worked with `I2CDevice` devices and not with `SimpleI2CDevice` devices. The problem was that the handling of the `:send_message` was not being specialized for `SimpleI2CDevice` devices.
1 parent 3c28259 commit c751a3e

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

lib/circuits_sim/i2c/i2c_server.ex

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ defmodule CircuitsSim.I2C.I2CServer do
126126
end
127127

128128
def handle_call({:send_message, message}, _from, state) do
129-
{result, new_device} = I2CDevice.handle_message(state.device, message)
129+
{result, new_device} = do_send_message(state, message)
130130
{:reply, result, %{state | device: new_device}}
131131
end
132132

@@ -165,6 +165,14 @@ defmodule CircuitsSim.I2C.I2CServer do
165165
SimpleI2CDevice.render(state.device)
166166
end
167167

168+
defp do_send_message(%{protocol: I2CDevice} = state, message) do
169+
I2CDevice.handle_message(state.device, message)
170+
end
171+
172+
defp do_send_message(%{protocol: SimpleI2CDevice} = state, message) do
173+
SimpleI2CDevice.handle_message(state.device, message)
174+
end
175+
168176
defp simple_read(state, 0, acc) do
169177
result = acc |> Enum.reverse() |> :binary.list_to_bin()
170178
{result, state}

0 commit comments

Comments
 (0)