1 Star 0 Fork 0

麻本法 / go.gpio-ctl

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
gpio.go 851 Bytes
一键复制 编辑 原始数据 按行查看 历史
麻本法 提交于 2022-12-21 16:13 . repo: 添加 pkg/gpio 基本包
package devices
import (
"errors"
"fmt"
"os"
)
const (
GPIO = "/sys/class/gpio"
GPIO_EXPORT = GPIO + "/export"
GPIO_UNEXPORT = GPIO + "/unexport"
// GPIO_FMT_DIRECTION = GPIO + "/direction"
)
var (
// GPIO_ERROR_NOT_EXPORTED
ErrGPIONotExported error = errors.New("GPIO Not Exported")
ErrGPIODirectionNotValue error = errors.New("GPIO Direction Not Value")
)
// GPIO Direction Mode
type GPIOMode int
const (
DIRECTION_IN GPIOMode = iota
DIRECTION_OUT
)
// GPIO Level Value
type GPIOValue int
const (
LEVEL_LOW GPIOValue = iota
LEVEL_HIGH
)
func GPIOExport(gpio int) error {
buffer := fmt.Sprintf("%d", gpio)
return os.WriteFile(GPIO_EXPORT, []byte(buffer), os.ModePerm)
}
func GPIOUnExport(gpio int) error {
buffer := fmt.Sprintf("%d", gpio)
return os.WriteFile(GPIO_UNEXPORT, []byte(buffer), os.ModePerm)
}
1
https://gitee.com/zinface/gpio-ctl.git
git@gitee.com:zinface/gpio-ctl.git
zinface
gpio-ctl
go.gpio-ctl
3957fa38168a

搜索帮助