Documentation ¶
Overview ¶
Package fake implements a fake board.
Index ¶
- type AnalogReader
- type Board
- func (b *Board) AnalogReaderByName(name string) (board.AnalogReader, bool)
- func (b *Board) AnalogReaderNames() []string
- func (b *Board) Close(ctx context.Context) error
- func (b *Board) DigitalInterruptByName(name string) (board.DigitalInterrupt, bool)
- func (b *Board) DigitalInterruptNames() []string
- func (b *Board) GPIOPinByName(name string) (board.GPIOPin, error)
- func (b *Board) GPIOPinNames() []string
- func (b *Board) I2CByName(name string) (board.I2C, bool)
- func (b *Board) I2CNames() []string
- func (b *Board) ModelAttributes() board.ModelAttributes
- func (b *Board) Reconfigure(ctx context.Context, deps resource.Dependencies, conf resource.Config) error
- func (b *Board) SPIByName(name string) (board.SPI, bool)
- func (b *Board) SPINames() []string
- func (b *Board) SetPowerMode(ctx context.Context, mode pb.PowerMode, duration *time.Duration) error
- func (b *Board) Status(ctx context.Context, extra map[string]interface{}) (*commonpb.BoardStatus, error)
- func (b *Board) WriteAnalog(ctx context.Context, pin string, value int32, extra map[string]interface{}) error
- type Config
- type DigitalInterruptWrapper
- func (s *DigitalInterruptWrapper) AddCallback(c chan board.Tick)
- func (s *DigitalInterruptWrapper) AddPostProcessor(pp board.PostProcessor)
- func (s *DigitalInterruptWrapper) Close(ctx context.Context) error
- func (s *DigitalInterruptWrapper) RemoveCallback(c chan board.Tick)
- func (s *DigitalInterruptWrapper) Tick(ctx context.Context, high bool, nanoseconds uint64) error
- func (s *DigitalInterruptWrapper) Value(ctx context.Context, extra map[string]interface{}) (int64, error)
- type GPIOPin
- func (gp *GPIOPin) Get(ctx context.Context, extra map[string]interface{}) (bool, error)
- func (gp *GPIOPin) PWM(ctx context.Context, extra map[string]interface{}) (float64, error)
- func (gp *GPIOPin) PWMFreq(ctx context.Context, extra map[string]interface{}) (uint, error)
- func (gp *GPIOPin) Set(ctx context.Context, high bool, extra map[string]interface{}) error
- func (gp *GPIOPin) SetPWM(ctx context.Context, dutyCyclePct float64, extra map[string]interface{}) error
- func (gp *GPIOPin) SetPWMFreq(ctx context.Context, freqHz uint, extra map[string]interface{}) error
- type I2C
- type I2CHandle
- func (h *I2CHandle) Close() error
- func (h *I2CHandle) Read(ctx context.Context, count int) ([]byte, error)
- func (h *I2CHandle) ReadBlockData(ctx context.Context, register byte, numBytes uint8) ([]byte, error)
- func (h *I2CHandle) ReadByteData(ctx context.Context, register byte) (byte, error)
- func (h *I2CHandle) Write(ctx context.Context, tx []byte) error
- func (h *I2CHandle) WriteBlockData(ctx context.Context, register byte, data []byte) error
- func (h *I2CHandle) WriteByteData(ctx context.Context, register, data byte) error
- type SPI
- type SPIHandle
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type AnalogReader ¶ added in v0.11.0
type AnalogReader struct { Value int CloseCount int Mu sync.RWMutex // contains filtered or unexported fields }
An AnalogReader reads back the same set value.
func (*AnalogReader) Close ¶ added in v0.11.0
func (a *AnalogReader) Close(ctx context.Context) error
Close does nothing.
func (*AnalogReader) Set ¶ added in v0.11.0
func (a *AnalogReader) Set(value int)
Set is used during testing.
type Board ¶
type Board struct { resource.Named SPIs map[string]*SPI I2Cs map[string]*I2C AnalogReaders map[string]*AnalogReader Digitals map[string]*DigitalInterruptWrapper GPIOPins map[string]*GPIOPin CloseCount int // contains filtered or unexported fields }
A Board provides dummy data from fake parts in order to implement a Board.
func (*Board) AnalogReaderByName ¶
func (b *Board) AnalogReaderByName(name string) (board.AnalogReader, bool)
AnalogReaderByName returns the analog reader by the given name if it exists.
func (*Board) AnalogReaderNames ¶
AnalogReaderNames returns the names of all known analog readers.
func (*Board) DigitalInterruptByName ¶
func (b *Board) DigitalInterruptByName(name string) (board.DigitalInterrupt, bool)
DigitalInterruptByName returns the interrupt by the given name if it exists.
func (*Board) DigitalInterruptNames ¶
DigitalInterruptNames returns the names of all known digital interrupts.
func (*Board) GPIOPinByName ¶
GPIOPinByName returns the GPIO pin by the given name if it exists.
func (*Board) GPIOPinNames ¶
GPIOPinNames returns the names of all known GPIO pins.
func (*Board) ModelAttributes ¶
func (b *Board) ModelAttributes() board.ModelAttributes
ModelAttributes returns attributes related to the model of this board.
func (*Board) Reconfigure ¶ added in v0.2.36
func (b *Board) Reconfigure(ctx context.Context, deps resource.Dependencies, conf resource.Config) error
Reconfigure atomically reconfigures this board© in place based on the new config.
func (*Board) SetPowerMode ¶ added in v0.2.28
SetPowerMode sets the board to the given power mode. If provided, the board will exit the given power mode after the specified duration.
type Config ¶
type Config struct { I2Cs []board.I2CConfig `json:"i2cs,omitempty"` SPIs []board.SPIConfig `json:"spis,omitempty"` AnalogReaders []board.AnalogReaderConfig `json:"analogs,omitempty"` DigitalInterrupts []board.DigitalInterruptConfig `json:"digital_interrupts,omitempty"` Attributes rdkutils.AttributeMap `json:"attributes,omitempty"` FailNew bool `json:"fail_new"` }
A Config describes the configuration of a fake board and all of its connected parts.
type DigitalInterruptWrapper ¶ added in v0.2.36
type DigitalInterruptWrapper struct {
// contains filtered or unexported fields
}
DigitalInterruptWrapper is a wrapper around a digital interrupt for testing fake boards.
func NewDigitalInterruptWrapper ¶ added in v0.2.36
func NewDigitalInterruptWrapper(conf board.DigitalInterruptConfig) (*DigitalInterruptWrapper, error)
NewDigitalInterruptWrapper returns a new digital interrupt to be used for testing.
func (*DigitalInterruptWrapper) AddCallback ¶ added in v0.2.36
func (s *DigitalInterruptWrapper) AddCallback(c chan board.Tick)
AddCallback adds a callback to be sent a low/high value to when a tick happens.
func (*DigitalInterruptWrapper) AddPostProcessor ¶ added in v0.2.36
func (s *DigitalInterruptWrapper) AddPostProcessor(pp board.PostProcessor)
AddPostProcessor adds a post processor that should be used to modify what is returned by Value.
func (*DigitalInterruptWrapper) Close ¶ added in v0.2.36
func (s *DigitalInterruptWrapper) Close(ctx context.Context) error
Close does nothing.
func (*DigitalInterruptWrapper) RemoveCallback ¶ added in v0.2.36
func (s *DigitalInterruptWrapper) RemoveCallback(c chan board.Tick)
RemoveCallback removes a listener for interrupts.
type GPIOPin ¶
type GPIOPin struct {
// contains filtered or unexported fields
}
A GPIOPin reads back the same set values.
type I2C ¶
type I2C struct {
// contains filtered or unexported fields
}
A I2C allows opening an I2CHandle.
type I2CHandle ¶
type I2CHandle struct {
// contains filtered or unexported fields
}
A I2CHandle allows read/write and Close.
func (*I2CHandle) ReadBlockData ¶ added in v0.2.0
func (h *I2CHandle) ReadBlockData(ctx context.Context, register byte, numBytes uint8) ([]byte, error)
ReadBlockData reads the given number of bytes from the i2c channel.
func (*I2CHandle) ReadByteData ¶
ReadByteData reads a byte from the i2c channel.
func (*I2CHandle) WriteBlockData ¶ added in v0.2.0
WriteBlockData writes the given bytes to the i2c channel.
type SPI ¶
type SPI struct { FIFO chan []byte // contains filtered or unexported fields }
A SPI allows opening an SPIHandle.