devices

package
v0.0.7 Latest Latest
Warning

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

Go to latest
Published: Jan 10, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AnalogDevice added in v0.0.7

type AnalogDevice struct {
	*Device
	*AnalogPin
}

func NewAnalogDevice added in v0.0.7

func NewAnalogDevice(name string, pin int) *AnalogDevice

type AnalogPin added in v0.0.7

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

func NewAnalogPin added in v0.0.7

func NewAnalogPin(name string, offset int) *AnalogPin

func (*AnalogPin) Get added in v0.0.7

func (a *AnalogPin) Get() float64

func (*AnalogPin) Set added in v0.0.7

func (a *AnalogPin) Set(v float64)

type Device

type Device struct {
	Name string
	Pub  string
	Subs []string
	Mode

	Period time.Duration
	EvtQ   chan gpiocdev.LineEvent
}

func NewDevice added in v0.0.4

func NewDevice(name string) *Device

func (*Device) AddPub added in v0.0.4

func (d *Device) AddPub(p string)

func (*Device) EventLoop added in v0.0.7

func (d *Device) EventLoop(done chan bool, readpub func() error)

func (*Device) Publish added in v0.0.6

func (d *Device) Publish(data any)

func (*Device) Shutdown added in v0.0.7

func (d *Device) Shutdown()

func (*Device) Subscribe added in v0.0.7

func (d *Device) Subscribe(topic string, f func(*messanger.Msg))

func (*Device) TimerLoop added in v0.0.7

func (d *Device) TimerLoop(done chan bool, readpub func() error)

type DeviceManager

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

func GetDeviceManager

func GetDeviceManager() *DeviceManager

func (*DeviceManager) Add

func (dm *DeviceManager) Add(d *Device)

func (*DeviceManager) Get

func (dm *DeviceManager) Get(name string) *Device

type GPIO

type GPIO struct {
	Chipname string       `json:"chipname"`
	Pins     map[int]*Pin `json:"pins"`
	Mock     bool         `json:"mock"`
}

GPIO is used to initialize the GPIO and pins on a raspberry pi

func GetGPIO

func GetGPIO() *GPIO

GetGPIO returns the GPIO singleton for the Raspberry PI

func GetMockGPIO added in v0.0.7

func GetMockGPIO() *GPIO

func (*GPIO) Init

func (gpio *GPIO) Init() error

Init initialized the GPIO

func (*GPIO) JSON

func (gpio *GPIO) JSON() (j []byte, err error)

JSON returns the JSON representation of the GPIO

func (*GPIO) Pin

func (gpio *GPIO) Pin(name string, offset int, opts ...gpiocdev.LineReqOption) (p *Pin)

Pin initializes the given GPIO pin, name and mode

func (*GPIO) Shutdown

func (gpio *GPIO) Shutdown()

Shutdown resets the GPIO line allowing use by another program

func (*GPIO) String

func (gpio *GPIO) String() string

String returns the string representation of the GPIO

type GPIODevice added in v0.0.7

type GPIODevice struct {
	*Device
	*Pin
}

GPIODevice satisfies the Device interface and the GPIO Pin interface

func NewGPIODevice added in v0.0.7

func NewGPIODevice(name string, idx int, mode Mode, opts ...gpiocdev.LineReqOption) *GPIODevice

NewGPIODevice creates a GPIO based device associated with GPIO Pin idx with the corresponding gpiocdev.LineReqOptions. If there is an gpiocdev.EventHandler an Event Q channel will be created. Also a publication topic will be associated. For input devices the Pubs will be used to publish output state to the device. For output devices the Pubs will be used to publish the latest data collected

func (*GPIODevice) Off added in v0.0.7

func (d *GPIODevice) Off()

Off sets the output state of the Pin to OFF (0)

func (*GPIODevice) On added in v0.0.7

func (d *GPIODevice) On()

On sets the output state of the Pin to ON (1)

func (*GPIODevice) Set added in v0.0.7

func (d *GPIODevice) Set(v int)

Set the output state of the pin to the value of v Off(0) or On != 0

type I2CDevice

type I2CDevice struct {
	*Device
	Bus  string
	Addr int
}

func NewI2CDevice

func NewI2CDevice(name string, bus string, addr int) *I2CDevice

type Line

type Line interface {
	Close() error
	Offset() int
	SetValue(int) error
	Reconfigure(...gpiocdev.LineConfigOption) error
	Value() (int, error)
}

Line interface is used to emulate a GPIO pin as implemented by the go-gpiocdev package

type MockLine

type MockLine struct {
	Val                   int `json:"val"`
	gpiocdev.EventHandler `json:"event-handler"`
	// contains filtered or unexported fields
}

MockGPIO fakes the Line interface on computers that don't actually have GPIO pins mostly for mocking tests

func GetMockLine

func GetMockLine(offset int, opts ...gpiocdev.LineReqOption) *MockLine

func (*MockLine) Callback

func (m *MockLine) Callback(msg *messanger.Msg)

func (MockLine) Close

func (m MockLine) Close() error

func (*MockLine) MockHWInput

func (m *MockLine) MockHWInput(v int)

func (MockLine) Offset

func (m MockLine) Offset() int

func (MockLine) Reconfigure

func (m MockLine) Reconfigure(...gpiocdev.LineConfigOption) error

func (*MockLine) SetValue

func (m *MockLine) SetValue(val int) error

func (MockLine) Value

func (m MockLine) Value() (int, error)

type Mode

type Mode int
const (
	ModeNone Mode = iota
	ModeInput
	ModeOutput
	ModePWM
)

type Pin

type Pin struct {
	Opts []gpiocdev.LineReqOption
	Line
	// contains filtered or unexported fields
}

Pin represents a single GPIO Pin

func (Pin) Callback

func (pin Pin) Callback(msg *messanger.Msg)

Callback is the default callback for pins if they are registered with the MQTT.Subscribe() function

func (*Pin) Get

func (pin *Pin) Get() (int, error)

Get returns the value of the pin, an error is returned if the GPIO value fails. Note: you can Get() the value of an input pin so no direction checks are done

func (*Pin) Init

func (p *Pin) Init() error

Init the pin from the offset and mode

func (*Pin) Off

func (pin *Pin) Off() error

Off sets the value of the pin to 0

func (*Pin) On

func (pin *Pin) On() error

On sets the value of the pin to 1

func (*Pin) Set

func (pin *Pin) Set(v int) error

Set the value of the pin. Note: you can NOT set the value of an input pin, so we will check it and return an error. This maybe worthy of making it a panic!

func (*Pin) String

func (pin *Pin) String() string

String returns a string representation of the GPIO pin

func (*Pin) Toggle

func (pin *Pin) Toggle() error

Toggle with flip the value of the pin from 1 to 0 or 0 to 1

type SerialDevice added in v0.0.6

type SerialDevice struct {
	PortName string
	Baud     int
	*serial.Port
	*Device
}

func NewSerialDevice added in v0.0.6

func NewSerialDevice(name, port string, baud int) *SerialDevice

func (*SerialDevice) Open added in v0.0.6

func (s *SerialDevice) Open() (err error)

func (*SerialDevice) Read added in v0.0.6

func (s *SerialDevice) Read(buf []byte) (int, error)

func (*SerialDevice) Write added in v0.0.6

func (s *SerialDevice) Write(buf []byte) (int, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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