Documentation ¶
Overview ¶
Package tester contains mock structs to make it easier to test I2C devices.
TODO: info on how to use this.
Index ¶
- Constants
- type Failer
- type I2CBus
- func (bus *I2CBus) AddDevice(d *I2CDevice)
- func (bus *I2CBus) FindDevice(addr uint8) *I2CDevice
- func (bus *I2CBus) NewDevice(addr uint8) *I2CDevice
- func (bus *I2CBus) ReadRegister(addr uint8, r uint8, buf []byte) error
- func (bus *I2CBus) Tx(addr uint16, w, r []byte) error
- func (bus *I2CBus) WriteRegister(addr uint8, r uint8, buf []byte) error
- type I2CDevice
Constants ¶
const MaxRegisters = 200
MaxRegisters is the maximum number of registers supported for a Device.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Failer ¶
type Failer interface { // Fatalf prints the Printf-formatted message and exits the current // goroutine. Fatalf(f string, a ...interface{}) }
Failer is used by the I2CDevice type to abort when it's used in unexpected ways, such as reading an out-of-range register.
type I2CBus ¶
type I2CBus struct {
// contains filtered or unexported fields
}
I2CBus implements the I2C interface in memory for testing.
func NewI2CBus ¶
NewI2CBus returns an I2CBus mock I2C instance that uses c to flag errors if they happen. After creating a I2C instance, add devices to it with addDevice before using NewI2CBus interface.
func (*I2CBus) AddDevice ¶
AddDevice adds a new mock device to the mock I2C bus. It panics if a device with the same address is added more than once.
func (*I2CBus) FindDevice ¶
FindDevice returns the device with the given address.
func (*I2CBus) NewDevice ¶ added in v0.15.1
NewDevice creates a new device with the given address and adds it to the mock I2C bus.
func (*I2CBus) ReadRegister ¶
ReadRegister implements I2C.ReadRegister.
type I2CDevice ¶
type I2CDevice struct { // Registers holds the device registers. It can be inspected // or changed as desired for testing. Registers [MaxRegisters]uint8 // If Err is non-nil, it will be returned as the error from the // I2C methods. Err error // contains filtered or unexported fields }
I2CDevice represents a mock I2C device on a mock I2C bus.
func NewI2CDevice ¶
NewI2CDevice returns a new mock I2C device.
func (*I2CDevice) ReadRegister ¶
ReadRegister implements I2C.ReadRegister.