Documentation
¶
Overview ¶
The drivers include GPIO (digital), analog (via ads1115), serial, I2C at this point.
I have to admit these drivers are not the cleanest of interfaces that they could perhaps be.
Each of the said drivers can be put into mock mode for testing and development on a non-raspberry pi.
Index ¶
- func GetI2CDriver(bus string, addr int) (device *i2c.Device, err error)
- type ADS1115
- type ADS1115Pin
- type AnalogPin
- type DigitalPin
- func (d *DigitalPin) Close() error
- func (d *DigitalPin) EventLoop(done chan any, readpub func())
- func (pin *DigitalPin) Get() (int, error)
- func (p *DigitalPin) ID() string
- func (p *DigitalPin) Init() error
- func (d *DigitalPin) MockHWInput(v int)
- func (pin *DigitalPin) OFF() error
- func (pin *DigitalPin) ON() error
- func (p *DigitalPin) PinName() string
- func (pin *DigitalPin) Set(v int) error
- func (p *DigitalPin) SetOpts(opts ...gpiocdev.LineReqOption)
- func (pin *DigitalPin) String() string
- func (pin *DigitalPin) Toggle() error
- type GPIO
- type Line
- type MockAnalogPin
- type MockLine
- type Serial
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type ADS1115 ¶
type ADS1115 struct {
// contains filtered or unexported fields
}
ADS1115 is an i2c ADC chip that will use the i2c device type to provide 4 single analog pins to be used by the raspberry pi to access analog sensors via the i2c bus. In a sense this device is a higher level device than the device_i2c.
func GetADS1115 ¶
func GetADS1115() *ADS1115
GetADS1115 will return the default ads1115 struct singleton. The first time GetADS1115 is called it will create a new device. Subsequent calls will return the global variable.
func NewADS1115 ¶
NewADS creates a new ADS1115 giving it the provided name, I2C bus (default /dev/i2c-1) and address (default 0x48).
type ADS1115Pin ¶
ADS1115Pin is an analog analagous to a digital pin
func (ADS1115Pin) Close ¶
func (a ADS1115Pin) Close() error
Close the pin and set it back to it's defaults. TODO set the pin back to its defaults
func (ADS1115Pin) Read ¶
func (p ADS1115Pin) Read() (float64, error)
Read returns a single float64 reading from the pin
func (ADS1115Pin) ReadContinuous ¶
func (p ADS1115Pin) ReadContinuous() <-chan float64
ReadContinous returns a channel that will continually read data from respective ads1115 pin and make the float64 values available as soon as the data is ready.
func (*ADS1115Pin) String ¶
func (p *ADS1115Pin) String() string
String is written text to hopefully drop some old eyeball style of knowledge.
type DigitalPin ¶
type DigitalPin struct {
Line
On func() error
Off func() error
gpiocdev.EventHandler `json:"event-handler"`
EvtQ chan gpiocdev.LineEvent
// contains filtered or unexported fields
}
func NewDigitalPin ¶
func NewDigitalPin(name string, offset int, opts ...gpiocdev.LineReqOption) *DigitalPin
func (*DigitalPin) Close ¶
func (d *DigitalPin) Close() error
func (*DigitalPin) EventLoop ¶
func (d *DigitalPin) EventLoop(done chan any, readpub func())
func (*DigitalPin) Get ¶
func (pin *DigitalPin) 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 (*DigitalPin) ID ¶
func (p *DigitalPin) ID() string
func (*DigitalPin) MockHWInput ¶
func (d *DigitalPin) MockHWInput(v int)
func (*DigitalPin) ON ¶
func (pin *DigitalPin) ON() error
func (*DigitalPin) PinName ¶
func (p *DigitalPin) PinName() string
func (*DigitalPin) Set ¶
func (pin *DigitalPin) 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 (*DigitalPin) SetOpts ¶
func (p *DigitalPin) SetOpts(opts ...gpiocdev.LineReqOption)
func (*DigitalPin) String ¶
func (pin *DigitalPin) String() string
String returns a string representation of the GPIO pin
func (*DigitalPin) Toggle ¶
func (pin *DigitalPin) Toggle() error
Toggle with flip the value of the pin from 1 to 0 or 0 to 1
type GPIO ¶
type GPIO struct {
Chipname string `json:"chipname"`
Mock bool `json:"mock"`
// contains filtered or unexported fields
}
GPIO is used to initialize the GPIO and pins on a raspberry pi
func (*GPIO) Pin ¶
func (gpio *GPIO) Pin(name string, offset int, opts ...gpiocdev.LineReqOption) *DigitalPin
Pin initializes the given GPIO pin, name and mode
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 MockAnalogPin ¶
func NewMockAnalogPin ¶
func NewMockAnalogPin(name string, pin int, opts ...any) *MockAnalogPin
func (*MockAnalogPin) Close ¶
func (a *MockAnalogPin) Close() error
func (*MockAnalogPin) Read ¶
func (a *MockAnalogPin) Read() (float64, error)
func (*MockAnalogPin) ReadContinuous ¶
func (a *MockAnalogPin) ReadContinuous() <-chan float64
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) MockHWInput ¶
func (MockLine) Reconfigure ¶
func (m MockLine) Reconfigure(...gpiocdev.LineConfigOption) error