fake

package
v0.48.0-rc0 Latest Latest
Warning

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

Go to latest
Published: Oct 28, 2024 License: AGPL-3.0 Imports: 14 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
	// contains filtered or unexported fields
}

An Analog reads back the same set value.

func (*Analog) Read

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

func (*Analog) Set

func (a *Analog) Set(value int)

Set is used to set the value of an Analog.

func (*Analog) Write added in v0.26.0

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

type Board

type Board struct {
	resource.Named

	Analogs  map[string]*Analog
	Digitals map[string]*DigitalInterrupt
	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 NewBoard

func NewBoard(ctx context.Context, conf resource.Config, logger logging.Logger) (*Board, error)

NewBoard returns a new fake board.

func (*Board) AnalogByName added in v0.26.0

func (b *Board) AnalogByName(name string) (board.Analog, error)

AnalogByName returns the analog pin by the given name if it exists.

func (*Board) AnalogNames added in v0.26.0

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

AnalogNames returns the names of all known analog pins.

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, error)

DigitalInterruptByName returns the interrupt by the given name if it exists.

func (*Board) DigitalInterruptNames

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

DigitalInterruptNames returns the names 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) 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

func (b *Board) SetPowerMode(ctx context.Context, mode pb.PowerMode, duration *time.Duration) error

SetPowerMode sets the board to the given power mode. If provided, the board will exit the given power mode after the specified duration.

func (*Board) StreamTicks added in v0.24.0

func (b *Board) StreamTicks(ctx context.Context, interrupts []board.DigitalInterrupt, ch chan board.Tick,
	extra map[string]interface{},
) error

StreamTicks starts a stream of digital interrupt ticks.

type Config

type Config struct {
	AnalogReaders     []board.AnalogReaderConfig     `json:"analogs,omitempty"`
	DigitalInterrupts []board.DigitalInterruptConfig `json:"digital_interrupts,omitempty"`
	FailNew           bool                           `json:"fail_new"`
}

A Config describes the configuration of a fake board and all of its connected parts.

func (*Config) Validate

func (conf *Config) Validate(path string) ([]string, error)

Validate ensures all parts of the config are valid.

type DigitalInterrupt added in v0.27.0

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

DigitalInterrupt is a fake digital interrupt.

func NewDigitalInterrupt added in v0.27.0

func NewDigitalInterrupt(conf board.DigitalInterruptConfig) (*DigitalInterrupt, error)

NewDigitalInterrupt returns a new fake digital interrupt.

func (*DigitalInterrupt) Name added in v0.27.0

func (s *DigitalInterrupt) Name() string

Name returns the name of the digital interrupt.

func (*DigitalInterrupt) Value added in v0.27.0

func (s *DigitalInterrupt) Value(ctx context.Context, extra map[string]interface{}) (int64, error)

Value returns the current value of the interrupt which is based on the type of interrupt.

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.

Jump to

Keyboard shortcuts

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