CircuitsSim.GPIO.GPIODevice protocol (circuits_sim v0.1.2)

View Source

A protocol for GPIO devices

Summary

Types

t()

All the types that implement this protocol.

Functions

Handle a message sent to the GenServer running the device

Handle an user message

Read state

Return the internal state as ASCII art

Write state

Types

t()

@type t() :: term()

All the types that implement this protocol.

Functions

handle_info(dev, message)

@spec handle_info(t(), any()) :: t()

Handle a message sent to the GenServer running the device

These are used for timeouts or other events

handle_message(dev, message)

@spec handle_message(t(), any()) :: {any(), t()}

Handle an user message

User messages are used to modify the state of the simulated device outside of I2C. This can be used to simulate real world changes like temperature changes affecting a simulated temperature sensor. Another use is as a hook for getting internal state.

read(dev)

@spec read(t()) :: Circuits.GPIO.value() | :hi_z

Read state

This is only called when the GPIO is an input. If the GPIO is an output, the most recently written value is returned without making this call.

If the wire is not being driven (i.e., high impedance state or disconnected), return :hi_z.

render(dev)

@spec render(t()) :: IO.ANSI.ansidata()

Return the internal state as ASCII art

write(dev, value)

@spec write(t(), Circuits.GPIO.value()) :: t()

Write state

This is only called when the GPIO is set as an output.