mcp3008helper

package
v0.51.2 Latest Latest
Warning

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

Go to latest
Published: Nov 21, 2024 License: AGPL-3.0 Imports: 6 Imported by: 1

Documentation

Overview

Package mcp3008helper is shared code for hooking an MCP3008 ADC up to a board. It is used in both the pi and genericlinux board implementations, but does not implement a board directly.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type MCP3008AnalogConfig

type MCP3008AnalogConfig struct {
	Name              string `json:"name"`
	Channel           string `json:"channel"`     // analog input pin on the ADC itself
	SPIBus            string `json:"spi_bus"`     // name of the SPI bus (which is configured elsewhere in the config file)
	ChipSelect        string `json:"chip_select"` // the CS line for the ADC chip, typically a pin number on the board
	AverageOverMillis int    `json:"average_over_ms,omitempty"`
	SamplesPerSecond  int    `json:"samples_per_sec,omitempty"`
}

MCP3008AnalogConfig describes the configuration of a MCP3008 analog reader on a board.

func (*MCP3008AnalogConfig) Validate

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

Validate ensures all parts of the config are valid.

type MCP3008AnalogReader

type MCP3008AnalogReader struct {
	Channel int
	Bus     buses.SPI
	Chip    string
}

MCP3008AnalogReader implements a board.AnalogReader using an MCP3008 ADC via SPI.

func (*MCP3008AnalogReader) Close

func (mar *MCP3008AnalogReader) Close(ctx context.Context) error

Close does nothing.

func (*MCP3008AnalogReader) Read

func (mar *MCP3008AnalogReader) Read(ctx context.Context, extra map[string]interface{}) (
	analogVal board.AnalogValue, err error,
)

Read returns a board.AnalogValue, but the Min, Max, and StepSize within it are never initialized and will always be 0!

func (*MCP3008AnalogReader) Write added in v0.26.0

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

Jump to

Keyboard shortcuts

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