CircuitsSim.I2C.SimpleI2CDevice protocol (circuits_sim v0.1.2)

View Source

A protocol that makes register-based I2C devices easier to simulate

Summary

Types

t()

All the types that implement this protocol.

Functions

Handle an user message

Read a register

Return a pretty printable view the the state

Write a value to a register

Types

t()

@type t() :: term()

All the types that implement this protocol.

Functions

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_register(dev, reg)

@spec read_register(t(), non_neg_integer()) :: {non_neg_integer(), t()}

Read a register

render(dev)

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

Return a pretty printable view the the state

write_register(dev, reg, value)

@spec write_register(t(), non_neg_integer(), non_neg_integer()) :: t()

Write a value to a register