iotest

package
v0.0.0-...-9eb3501 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 30, 2020 License: MPL-2.0 Imports: 1 Imported by: 0

Documentation

Overview

Package iotest contains some test helpers for code relying on golang.org/x/exp/io/i2c.

 func TestMCP4725(t *testing.T)  {
	data := make(chan []byte, 2)
	c := iotest.NewI2CConn()

	// Set the TxFunc.
	c.TxFunc(func(w, _ []byte) error {
		data <- w
		return nil
	})

	conn, _ := i2c.Open(iotest.NewI2CDriver(c), 0x1)
	dac, _  := microchip.NewMCP4725(conn, 5.5)

        // Under the hood SetInputCode calls c.Tx which in turn calls TxFunc defined earlier.
	dac.SetInputCode(0x539, 1)

	assert.Equal(t, []byte{0x5, 0x39}, <-data)
}

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type I2CConn

type I2CConn struct {
	// contains filtered or unexported fields
}

I2CConn implements the driver.Conn interface.

func NewI2CConn

func NewI2CConn() I2CConn

NewI2CConn creates a new I2CConn.

func (I2CConn) Close

func (c I2CConn) Close() error

Close calls the CloseFunc.

func (*I2CConn) CloseFunc

func (c *I2CConn) CloseFunc(f func() error)

CloseFunc sets the CloseFunc. CloseFunc is called when Close is called.

func (I2CConn) Tx

func (c I2CConn) Tx(w, r []byte) error

Tx calls the TxFunc.

func (*I2CConn) TxFunc

func (c *I2CConn) TxFunc(f func(w, r []byte) error)

TxFunc sets TxFunc which is called when Tx is called.

type I2CDriver

type I2CDriver struct {
	// contains filtered or unexported fields
}

I2CDriver implements the i2c.Device interface.

func NewI2CDriver

func NewI2CDriver(c I2CConn) *I2CDriver

NewI2CDriver creates a new I2CDriver.

func (I2CDriver) Open

func (d I2CDriver) Open(_ int, _ bool) (driver.Conn, error)

Open returns a type that implements the driver.Conn interface.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL