fake

package
v0.2.10 Latest Latest
Warning

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

Go to latest
Published: Dec 30, 2022 License: AGPL-3.0 Imports: 13 Imported by: 0

Documentation

Overview

Package fake implements a fake board.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Analog

type Analog struct {
	Value      int
	CloseCount int
	Mu         sync.RWMutex
}

A Analog reads back the same set value.

func (*Analog) Close

func (a *Analog) Close()

Close does nothing.

func (*Analog) Read

func (a *Analog) Read(ctx context.Context, extra map[string]interface{}) (int, error)

func (*Analog) Set

func (a *Analog) Set(value int)

Set is used during testing.

type Board

type Board struct {
	generic.Echo
	Name     string
	SPIs     map[string]*SPI
	I2Cs     map[string]*I2C
	Analogs  map[string]*Analog
	Digitals map[string]board.DigitalInterrupt
	GPIOPins map[string]*GPIOPin

	CloseCount int
}

A Board provides dummy data from fake parts in order to implement a Board.

func NewBoard

func NewBoard(ctx context.Context, config config.Component, logger golog.Logger) (*Board, error)

NewBoard returns a new fake 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

func (b *Board) AnalogReaderNames() []string

AnalogReaderNames returns the name of all known analog readers.

func (*Board) Close

func (b *Board) Close(ctx context.Context) error

Close attempts to cleanly close each part of the board.

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

func (b *Board) DigitalInterruptNames() []string

DigitalInterruptNames returns the name of all known digital interrupts.

func (*Board) GPIOPinByName

func (b *Board) GPIOPinByName(name string) (board.GPIOPin, error)

GPIOPinByName returns the GPIO pin by the given name if it exists.

func (*Board) GPIOPinNames

func (b *Board) GPIOPinNames() []string

GPIOPinNames returns the name of all known digital interrupts.

func (*Board) I2CByName

func (b *Board) I2CByName(name string) (board.I2C, bool)

I2CByName returns the i2c by the given name if it exists.

func (*Board) I2CNames

func (b *Board) I2CNames() []string

I2CNames returns the name of all known I2Cs.

func (*Board) ModelAttributes

func (b *Board) ModelAttributes() board.ModelAttributes

ModelAttributes returns attributes related to the model of this board.

func (*Board) SPIByName

func (b *Board) SPIByName(name string) (board.SPI, bool)

SPIByName returns the SPI by the given name if it exists.

func (*Board) SPINames

func (b *Board) SPINames() []string

SPINames returns the name of all known SPIs.

func (*Board) Status

func (b *Board) Status(ctx context.Context, extra map[string]interface{}) (*commonpb.BoardStatus, error)

Status returns the current status of the board.

func (*Board) UpdateAction

func (b *Board) UpdateAction(c *config.Component) config.UpdateActionType

UpdateAction helps hinting the reconfiguration process on what strategy to use given a modified config. See config.UpdateActionType for more information.

type Config

type Config struct {
	I2Cs              []board.I2CConfig              `json:"i2cs,omitempty"`
	SPIs              []board.SPIConfig              `json:"spis,omitempty"`
	Analogs           []board.AnalogConfig           `json:"analogs,omitempty"`
	DigitalInterrupts []board.DigitalInterruptConfig `json:"digital_interrupts,omitempty"`
	Attributes        config.AttributeMap            `json:"attributes,omitempty"`
	FailNew           bool                           `json:"fail_new"`
}

A Config describes the configuration of an arduino board and all of its connected parts.

func (*Config) Validate

func (config *Config) Validate(path string) error

Validate ensures all parts of the config are valid.

type GPIOPin

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

A GPIOPin reads back the same set values.

func (*GPIOPin) Get

func (gp *GPIOPin) Get(ctx context.Context, extra map[string]interface{}) (bool, error)

Get gets the high/low state of the pin.

func (*GPIOPin) PWM

func (gp *GPIOPin) PWM(ctx context.Context, extra map[string]interface{}) (float64, error)

PWM gets the pin's given duty cycle.

func (*GPIOPin) PWMFreq

func (gp *GPIOPin) PWMFreq(ctx context.Context, extra map[string]interface{}) (uint, error)

PWMFreq gets the PWM frequency of the pin.

func (*GPIOPin) Set

func (gp *GPIOPin) Set(ctx context.Context, high bool, extra map[string]interface{}) error

Set sets the pin to either low or high.

func (*GPIOPin) SetPWM

func (gp *GPIOPin) SetPWM(ctx context.Context, dutyCyclePct float64, extra map[string]interface{}) error

SetPWM sets the pin to the given duty cycle.

func (*GPIOPin) SetPWMFreq

func (gp *GPIOPin) SetPWMFreq(ctx context.Context, freqHz uint, extra map[string]interface{}) error

SetPWMFreq sets the given pin to the given PWM frequency. 0 will use the board's default PWM frequency.

type I2C

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

A I2C allows opening an I2CHandle.

func (*I2C) OpenHandle

func (s *I2C) OpenHandle(addr byte) (board.I2CHandle, error)

OpenHandle opens a handle to perform I2C transfers that must be later closed to release access to the bus.

type I2CHandle

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

A I2CHandle allows read/write and Close.

func (*I2CHandle) Close

func (h *I2CHandle) Close() error

Close releases access to the bus.

func (*I2CHandle) Read

func (h *I2CHandle) Read(ctx context.Context, count int) ([]byte, error)

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

func (h *I2CHandle) ReadByteData(ctx context.Context, register byte) (byte, error)

ReadByteData reads a byte from the i2c channel.

func (*I2CHandle) ReadWordData

func (h *I2CHandle) ReadWordData(ctx context.Context, register byte) (uint16, error)

ReadWordData reads a word from the i2c channel.

func (*I2CHandle) Write

func (h *I2CHandle) Write(ctx context.Context, tx []byte) error

func (*I2CHandle) WriteBlockData added in v0.2.0

func (h *I2CHandle) WriteBlockData(ctx context.Context, register byte, numBytes uint8, data []byte) error

WriteBlockData writes the given bytes to the i2c channel.

func (*I2CHandle) WriteByteData

func (h *I2CHandle) WriteByteData(ctx context.Context, register, data byte) error

WriteByteData writes a byte to the i2c channel.

func (*I2CHandle) WriteWordData

func (h *I2CHandle) WriteWordData(ctx context.Context, register byte, data uint16) error

WriteWordData writes a word to the i2c channel.

type SPI

type SPI struct {
	FIFO chan []byte
	// contains filtered or unexported fields
}

A SPI allows opening an SPIHandle.

func (*SPI) OpenHandle

func (s *SPI) OpenHandle() (board.SPIHandle, error)

OpenHandle opens a handle to perform SPI transfers that must be later closed to release access to the bus.

type SPIHandle

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

A SPIHandle allows Xfer and Close.

func (*SPIHandle) Close

func (h *SPIHandle) Close() error

Close releases access to the bus.

func (*SPIHandle) Xfer

func (h *SPIHandle) Xfer(ctx context.Context, baud uint, chipSelect string, mode uint, tx []byte) ([]byte, error)

Xfer transfers the given data.

Jump to

Keyboard shortcuts

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