devices

package
v0.7.3 Latest Latest
Warning

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

Go to latest
Published: Jan 17, 2023 License: GPL-3.0 Imports: 12 Imported by: 0

Documentation

Overview

Package devices provides the pico-cs device and configuration types.

Index

Constants

View Source
const (
	CtCS   = "cs"
	CtLoco = "loco"
)

Configuration Types

Variables

View Source
var ReservedFctNames = []string{"dir", "speed"}

ReservedFctNames is the list of reserved function names which cannot be used in loco configurations.

Functions

func HTTPHandler added in v0.7.2

func HTTPHandler(w http.ResponseWriter, r *http.Request)

HTTPHandler is a anlder function providing the main html index for the devices.

Types

type CS

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

A CS represents a command station.

func (*CS) AddLoco

func (cs *CS) AddLoco(loco *Loco) (bool, error)

AddLoco adds a loco to the command station.

func (*CS) ServeHTTP

func (cs *CS) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements the http.Handler interface.

type CSConfig

type CSConfig struct {
	// command station name (used in topic)
	Name string `json:"name"`
	// pico_w host in case of WiFi TCP/IP connection
	Host string `json:"host"`
	// TCP/IP port (WiFi) or serial port (serial over USB)
	Port string `json:"port"`
	// filter of devices for which this command station should be a primary device
	Primary *Filter `json:"primary"`
	// filter of devices for which this command station should be a secondary device
	Secondary *Filter `json:"secondary"`
	// command station IO mapping (key is used in topic)
	IOs map[string]CSIOConfig `json:"ios"`
}

CSConfig represents configuration data for a command station.

func NewCSConfig added in v0.7.2

func NewCSConfig() *CSConfig

NewCSConfig returns a new CSConfig instance.

type CSIOConfig

type CSIOConfig struct {
	// command station GPIO
	GPIO uint `json:"gpio"`
}

CSIOConfig represents configuration data for a command station IO.

type CSSet

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

CSSet represents a set of command stations.

func NewCSSet

func NewCSSet(lg logger.Logger, gw *gateway.Gateway) *CSSet

NewCSSet creates new command station set instance.

func (*CSSet) Add

func (s *CSSet) Add(config *CSConfig) (*CS, error)

Add adds a command station via a command station configuration.

func (*CSSet) Close

func (s *CSSet) Close() error

Close closes all command stations.

func (*CSSet) Items

func (s *CSSet) Items() map[string]*CS

Items returns a command station map.

func (*CSSet) ServeHTTP added in v0.7.2

func (s *CSSet) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements the http.Handler interface.

type Filter

type Filter struct {
	// list of regular expressions defining which set of devices should be included
	Incls []string `json:"incls"`
	// list of regular expressions defining which set of devices should be excluded
	// excluding regular expressions do have precedence over including regular expressions
	Excls []string `json:"excls"`
}

Filter represents an including and excluding list of device names.

func NewFilter added in v0.7.2

func NewFilter() *Filter

NewFilter returns a new Filter instance.

type Loco

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

A Loco represents a loco.

func (*Loco) ServeHTTP

func (l *Loco) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements the http.Handler interface.

type LocoConfig

type LocoConfig struct {
	// loco name (used in topic)
	Name string `json:"name"`
	// loco decoder address
	Addr uint `json:"addr"`
	// loco function mapping (key is used in topic)
	Fcts map[string]LocoFctConfig `json:"fcts"`
}

LocoConfig represents configuration data for a loco.

func NewLocoConfig added in v0.7.2

func NewLocoConfig() *LocoConfig

NewLocoConfig returns a new LocoConfig instance.

type LocoFctConfig

type LocoFctConfig struct {
	// loco decoder function number
	No uint `json:"no"`
}

LocoFctConfig represents configuration data for a loco function.

type LocoSet

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

LocoSet represents a set of locos.

func NewLocoSet

func NewLocoSet(lg logger.Logger) *LocoSet

NewLocoSet creates new loco set instance.

func (*LocoSet) Add

func (s *LocoSet) Add(config *LocoConfig) (*Loco, error)

Add adds a loco via a loco configuration.

func (*LocoSet) Close

func (s *LocoSet) Close() error

Close closes all locos.

func (*LocoSet) Items

func (s *LocoSet) Items() map[string]*Loco

Items returns a loco map.

func (*LocoSet) ServeHTTP added in v0.7.2

func (s *LocoSet) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements the http.Handler interface.

Jump to

Keyboard shortcuts

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