devices

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Dec 31, 2024 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Device

type Device struct {
	Name string
	Pubs []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)

type DeviceGPIO

type DeviceGPIO struct {
	*Device
	*Pin
}

DeviceGPIO satisfies the Device interface and the GPIO Pin interface

func NewDeviceGPIO

func NewDeviceGPIO(name string, idx int, mode Mode, opts ...gpiocdev.LineReqOption) *DeviceGPIO

NewDeviceGPIO 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 (*DeviceGPIO) Off

func (d *DeviceGPIO) Off()

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

func (*DeviceGPIO) On

func (d *DeviceGPIO) On()

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

func (*DeviceGPIO) Set

func (d *DeviceGPIO) Set(v int)

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

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 (*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 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 *message.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 *message.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

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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