devices

package
v0.0.0-...-3957fa3 Latest Latest
Warning

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

Go to latest
Published: Dec 21, 2022 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	GPIO          = "/sys/class/gpio"
	GPIO_EXPORT   = GPIO + "/export"
	GPIO_UNEXPORT = GPIO + "/unexport"
)

Variables

View Source
var (
	// GPIO_ERROR_NOT_EXPORTED
	ErrGPIONotExported       error = errors.New("GPIO Not Exported")
	ErrGPIODirectionNotValue error = errors.New("GPIO Direction Not Value")
)

Functions

func GPIOExport

func GPIOExport(gpio int) error

func GPIOUnExport

func GPIOUnExport(gpio int) error

Types

type GPIODevice

type GPIODevice struct {
	Id   int    // GPIO 编号
	Path string // GPIO 设备目录
}

GPIODevice 设备信息

func NewGPIODevice

func NewGPIODevice(id int) *GPIODevice

NewGPIODevice 实例化一个设备

func (*GPIODevice) ChangeMode

func (device *GPIODevice) ChangeMode(mode GPIOMode) (err error)

ChangeMode 改变工作模式

func (*GPIODevice) ChangeValue

func (device *GPIODevice) ChangeValue(value GPIOValue) (err error)

ChangeValue 改变value值

func (*GPIODevice) Export

func (device *GPIODevice) Export() (bool, error)

Export 导出设备

func (*GPIODevice) GetDevicePath

func (device *GPIODevice) GetDevicePath() string

GetDevicePath 获取GPIO设备的 device 路径

func (*GPIODevice) GetDirectionPath

func (device *GPIODevice) GetDirectionPath() string

GetDirectionPath 获取GPIO设备的 direction 路径

func (*GPIODevice) GetPath

func (device *GPIODevice) GetPath() string

GetPath 获取设备目录路径

func (*GPIODevice) GetValuePath

func (device *GPIODevice) GetValuePath() string

GetValuePath 获取GPIO设备的 value 路径

func (*GPIODevice) IsExported

func (device *GPIODevice) IsExported() bool

IsExported 检查是否已经导出设备引脚

func (*GPIODevice) IsUnExported

func (device *GPIODevice) IsUnExported() bool

IsUnExported 检查是否已经导出设备引脚

func (*GPIODevice) Mode

func (device *GPIODevice) Mode() (mode GPIOMode, err error)

Mode 获取当前工作模式

func (*GPIODevice) UnExport

func (device *GPIODevice) UnExport() (bool, error)

UnExport 取消导出设备

func (*GPIODevice) Value

func (device *GPIODevice) Value() (value GPIOValue, err error)

获取

type GPIOMode

type GPIOMode int

GPIO Direction Mode

const (
	DIRECTION_IN GPIOMode = iota
	DIRECTION_OUT
)

type GPIOValue

type GPIOValue int

GPIO Level Value

const (
	LEVEL_LOW GPIOValue = iota
	LEVEL_HIGH
)

type IGPIODevice

type IGPIODevice interface {
	GetPath() string
	GetValuePath() string
	GetDirectionPath() string
	GetDevicePath() string

	Export() (bool, error)
	UnExport() (bool, error)

	IsExported() bool
	IsUnExported() bool

	Value() (GPIOValue, error)
	ChangeValue(value GPIOValue) error

	Mode() (GPIOMode, error)
	ChangeMode(mode GPIOMode) error
}

IGPIODevice GPIO 设备操作接口 /sys/class/gpio/gpio141 active_low device direction edge power subsystem uevent value

Jump to

Keyboard shortcuts

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