gobot: gobot.io/x/gobot/sysfs Index | Files

package sysfs

import "gobot.io/x/gobot/sysfs"

Package sysfs provides generic access to linux gpio.

It is intended to be used while implementing support for a single board linux computer

Index

Package Files

digital_pin.go doc.go fs.go fs_mock.go i2c_device.go pwm_pin.go syscall.go

Constants

const (
    // IN gpio direction
    IN  = "in"
    // OUT gpio direction
    OUT = "out"
    // HIGH gpio level
    HIGH = 1
    // LOW gpio level
    LOW = 0
    // GPIOPATH default linux gpio path
    GPIOPATH = "/sys/class/gpio"
)
const (
    // From  /usr/include/linux/i2c-dev.h:
    // ioctl signals
    I2C_SLAVE = 0x0703
    I2C_FUNCS = 0x0705
    I2C_SMBUS = 0x0720
    // Read/write markers
    I2C_SMBUS_READ  = 1
    I2C_SMBUS_WRITE = 0

    // From  /usr/include/linux/i2c.h:
    // Adapter functionality
    I2C_FUNC_SMBUS_READ_BYTE        = 0x00020000
    I2C_FUNC_SMBUS_WRITE_BYTE       = 0x00040000
    I2C_FUNC_SMBUS_READ_BYTE_DATA   = 0x00080000
    I2C_FUNC_SMBUS_WRITE_BYTE_DATA  = 0x00100000
    I2C_FUNC_SMBUS_READ_WORD_DATA   = 0x00200000
    I2C_FUNC_SMBUS_WRITE_WORD_DATA  = 0x00400000
    I2C_FUNC_SMBUS_READ_BLOCK_DATA  = 0x01000000
    I2C_FUNC_SMBUS_WRITE_BLOCK_DATA = 0x02000000
    // Transaction types
    I2C_SMBUS_BYTE             = 1
    I2C_SMBUS_BYTE_DATA        = 2
    I2C_SMBUS_WORD_DATA        = 3
    I2C_SMBUS_PROC_CALL        = 4
    I2C_SMBUS_BLOCK_DATA       = 5
    I2C_SMBUS_I2C_BLOCK_BROKEN = 6
    I2C_SMBUS_BLOCK_PROC_CALL  = 7 /* SMBus 2.0 */
    I2C_SMBUS_I2C_BLOCK_DATA   = 8 /* SMBus 2.0 */
)

func NewI2cDevice Uses

func NewI2cDevice(location string) (d *i2cDevice, err error)

NewI2cDevice returns an io.ReadWriteCloser with the proper ioctrl given an i2c bus location.

func SetFilesystem Uses

func SetFilesystem(f Filesystem)

SetFilesystem sets the filesystem implementation.

func SetSyscall Uses

func SetSyscall(s SystemCaller)

SetSyscall sets the Syscall implementation

func Stat Uses

func Stat(name string) (os.FileInfo, error)

Stat call either the NativeFilesystem of user defined Stat

func Syscall Uses

func Syscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err syscall.Errno)

Syscall calls either the NativeSyscall or user defined Syscall

type DigitalPin Uses

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

func NewDigitalPin Uses

func NewDigitalPin(pin int, v ...string) *DigitalPin

NewDigitalPin returns a DigitalPin given the pin number and an optional sysfs pin label. If no label is supplied the default label will prepend "gpio" to the pin number, eg. a pin number of 10 will have a label of "gpio10"

func (*DigitalPin) Direction Uses

func (d *DigitalPin) Direction(dir string) error

func (*DigitalPin) Export Uses

func (d *DigitalPin) Export() error

func (*DigitalPin) Read Uses

func (d *DigitalPin) Read() (n int, err error)

func (*DigitalPin) Unexport Uses

func (d *DigitalPin) Unexport() error

func (*DigitalPin) Write Uses

func (d *DigitalPin) Write(b int) error

type DigitalPinner Uses

type DigitalPinner interface {
    // Export exports the pin for use by the operating system
    Export() error
    // Unexport unexports the pin and releases the pin from the operating system
    Unexport() error
    // Direction sets the direction for the pin
    Direction(string) error
    // Read reads the current value of the pin
    Read() (int, error)
    // Write writes to the pin
    Write(int) error
}

DigitalPinner is the interface for sysfs gpio interactions

type DigitalPinnerProvider Uses

type DigitalPinnerProvider interface {
    DigitalPin(string, string) (DigitalPinner, error)
}

DigitalPinnerProvider is the interface that an Adaptor should implement to allow clients to obtain access to any DigitalPin's available on that board.

type File Uses

type File interface {
    Write(b []byte) (n int, err error)
    WriteString(s string) (ret int, err error)
    Sync() (err error)
    Read(b []byte) (n int, err error)
    ReadAt(b []byte, off int64) (n int, err error)
    Seek(offset int64, whence int) (ret int64, err error)
    Fd() uintptr
    Close() error
}

A File represents basic IO interactions with the underlying file system

func OpenFile Uses

func OpenFile(name string, flag int, perm os.FileMode) (file File, err error)

OpenFile calls either the NativeFilesystem or user defined OpenFile

type Filesystem Uses

type Filesystem interface {
    OpenFile(name string, flag int, perm os.FileMode) (file File, err error)
    Stat(name string) (os.FileInfo, error)
}

Filesystem opens files and returns either a native file system or user defined

type MockFile Uses

type MockFile struct {
    Contents string
    Seq      int // When this file was last written or read.
    Opened   bool
    Closed   bool
    // contains filtered or unexported fields
}

A MockFile represents a mock file that contains a single string. Any write overwrites, and any read returns from the start.

func (*MockFile) Close Uses

func (f *MockFile) Close() error

Close implements the File interface Close function

func (*MockFile) Fd Uses

func (f *MockFile) Fd() uintptr

Fd returns a random uintprt based on the time of the MockFile creation

func (*MockFile) Read Uses

func (f *MockFile) Read(b []byte) (n int, err error)

Read copies b bytes from f.Contents

func (*MockFile) ReadAt Uses

func (f *MockFile) ReadAt(b []byte, off int64) (n int, err error)

ReadAt calls MockFile.Read

func (*MockFile) Seek Uses

func (f *MockFile) Seek(offset int64, whence int) (ret int64, err error)

Seek seeks to a specific offset in a file

func (*MockFile) Sync Uses

func (f *MockFile) Sync() (err error)

Sync implements the File interface Sync function

func (*MockFile) Write Uses

func (f *MockFile) Write(b []byte) (n int, err error)

Write writes string(b) to f.Contents

func (*MockFile) WriteString Uses

func (f *MockFile) WriteString(s string) (ret int, err error)

WriteString writes s to f.Contents

type MockFilesystem Uses

type MockFilesystem struct {
    Seq            int // Increases with each write or read.
    Files          map[string]*MockFile
    WithReadError  bool
    WithWriteError bool
}

MockFilesystem represents a filesystem of mock files.

func NewMockFilesystem Uses

func NewMockFilesystem(files []string) *MockFilesystem

NewMockFilesystem returns a new MockFilesystem given a list of file paths

func (*MockFilesystem) Add Uses

func (fs *MockFilesystem) Add(name string) *MockFile

Add adds a new file to fs.Files given a name, and returns the newly created file

func (*MockFilesystem) OpenFile Uses

func (fs *MockFilesystem) OpenFile(name string, flag int, perm os.FileMode) (file File, err error)

OpenFile opens file name from fs.Files, if the file does not exist it returns an os.PathError

func (*MockFilesystem) Stat Uses

func (fs *MockFilesystem) Stat(name string) (os.FileInfo, error)

Stat returns a generic FileInfo for all files in fs.Files. If the file does not exist it returns an os.PathError

type MockSyscall Uses

type MockSyscall struct {
    Impl func(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err syscall.Errno)
}

MockSyscall represents the mock Syscall

func (*MockSyscall) Syscall Uses

func (sys *MockSyscall) Syscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err syscall.Errno)

Syscall implements the SystemCaller interface

type NativeFilesystem Uses

type NativeFilesystem struct{}

NativeFilesystem represents the native file system implementation

func (*NativeFilesystem) OpenFile Uses

func (fs *NativeFilesystem) OpenFile(name string, flag int, perm os.FileMode) (file File, err error)

OpenFile calls os.OpenFile().

func (*NativeFilesystem) Stat Uses

func (fs *NativeFilesystem) Stat(name string) (os.FileInfo, error)

Stat calls os.Stat()

type NativeSyscall Uses

type NativeSyscall struct{}

NativeSyscall represents the native Syscall

func (*NativeSyscall) Syscall Uses

func (sys *NativeSyscall) Syscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err syscall.Errno)

Syscall calls syscall.Syscall

type PWMPin Uses

type PWMPin struct {
    Path string
    // contains filtered or unexported fields
}

func NewPWMPin Uses

func NewPWMPin(pin int) *PWMPin

NewPwmPin returns a new pwmPin

func (*PWMPin) DutyCycle Uses

func (p *PWMPin) DutyCycle() (duty uint32, err error)

DutyCycle reads from pwm duty cycle path and returns value in nanoseconds

func (*PWMPin) Enable Uses

func (p *PWMPin) Enable(enable bool) (err error)

Enable writes value to pwm enable path

func (*PWMPin) Export Uses

func (p *PWMPin) Export() error

Export writes pin to pwm export path

func (*PWMPin) InvertPolarity Uses

func (p *PWMPin) InvertPolarity(invert bool) (err error)

InvertPolarity writes value to pwm polarity path

func (*PWMPin) Period Uses

func (p *PWMPin) Period() (period uint32, err error)

Period reads from pwm period path and returns value in nanoseconds

func (*PWMPin) Polarity Uses

func (p *PWMPin) Polarity() (polarity string, err error)

Polarity returns current polarity value

func (*PWMPin) SetDutyCycle Uses

func (p *PWMPin) SetDutyCycle(duty uint32) (err error)

SetDutyCycle writes value to pwm duty cycle path duty is in nanoseconds

func (*PWMPin) SetPeriod Uses

func (p *PWMPin) SetPeriod(period uint32) (err error)

SetPeriod sets pwm period in nanoseconds

func (*PWMPin) Unexport Uses

func (p *PWMPin) Unexport() (err error)

Unexport writes pin to pwm unexport path

type PWMPinner Uses

type PWMPinner interface {
    // Export exports the pin for use by the operating system
    Export() error
    // Unexport unexports the pin and releases the pin from the operating system
    Unexport() error
    // Enable enables/disables the PWM pin
    Enable(bool) (err error)
    // Polarity returns the polarity either normal or inverted
    Polarity() (polarity string, err error)
    // InvertPolarity sets the polarity to inverted if called with true
    InvertPolarity(invert bool) (err error)
    // Period returns the current PWM period for pin
    Period() (period uint32, err error)
    // SetPeriod sets the current PWM period for pin
    SetPeriod(period uint32) (err error)
    // DutyCycle returns the duty cycle for the pin
    DutyCycle() (duty uint32, err error)
    // SetDutyCycle writes the duty cycle to the pin
    SetDutyCycle(duty uint32) (err error)
}

PWMPin is the interface for sysfs PWM interactions

type PWMPinnerProvider Uses

type PWMPinnerProvider interface {
    PWMPin(string) (PWMPinner, error)
}

PWMPinnerProvider is the interface that an Adaptor should implement to allow clients to obtain access to any PWMPin's available on that board.

type SystemCaller Uses

type SystemCaller interface {
    Syscall(trap, a1, a2, a3 uintptr) (r1, r2 uintptr, err syscall.Errno)
}

SystemCaller represents a Syscall

Package sysfs imports 10 packages (graph) and is imported by 9 packages. Updated 2019-05-23. Refresh now. Tools for package owners.