mirror of
https://github.com/hybridgroup/gobot.git
synced 2025-04-27 13:48:56 +08:00
Add docs
This commit is contained in:
parent
a7cee22918
commit
e78257c201
@ -21,7 +21,9 @@ type DigitalPin struct {
|
||||
direction string
|
||||
}
|
||||
|
||||
// NewDigitalPin returns a DigitalPin given the pin number and sysfs pin label
|
||||
// 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 NewDigitalPin(pin int, v ...string) *DigitalPin {
|
||||
d := &DigitalPin{pin: strconv.Itoa(pin)}
|
||||
if len(v) > 0 {
|
||||
@ -38,14 +40,14 @@ func (d *DigitalPin) Direction() string {
|
||||
return d.direction
|
||||
}
|
||||
|
||||
// SetDirection sets the current direction for specified pin
|
||||
// SetDirection sets the current direction for the pin
|
||||
func (d *DigitalPin) SetDirection(dir string) error {
|
||||
d.direction = dir
|
||||
_, err := writeFile(fmt.Sprintf("%v/%v/direction", GPIOPATH, d.label), []byte(d.direction))
|
||||
return err
|
||||
}
|
||||
|
||||
// Write writes specified value to the pin
|
||||
// Write writes to the pin
|
||||
func (d *DigitalPin) Write(b int) error {
|
||||
_, err := writeFile(fmt.Sprintf("%v/%v/value", GPIOPATH, d.label), []byte(strconv.Itoa(b)))
|
||||
return err
|
||||
|
@ -40,10 +40,6 @@ func TestDigitalPin(t *testing.T) {
|
||||
gobot.Assert(t, lastPath, "/sys/class/gpio/gpio10/value")
|
||||
gobot.Assert(t, string(lastData), "1")
|
||||
|
||||
pin.Write(1)
|
||||
gobot.Assert(t, lastPath, "/sys/class/gpio/gpio10/value")
|
||||
gobot.Assert(t, string(lastData), "1")
|
||||
|
||||
pin.SetDirection(IN)
|
||||
gobot.Assert(t, lastPath, "/sys/class/gpio/gpio10/direction")
|
||||
gobot.Assert(t, string(lastData), "in")
|
||||
|
6
sysfs/doc.go
Normal file
6
sysfs/doc.go
Normal file
@ -0,0 +1,6 @@
|
||||
/*
|
||||
Package sysfs provides generic access to linux gpio.
|
||||
|
||||
It is intended to be used while implementing support for a single board linux computer
|
||||
*/
|
||||
package sysfs
|
@ -10,7 +10,7 @@ import (
|
||||
|
||||
const I2CSlave = 0x0703
|
||||
|
||||
/// NewI2cDevice creates a new i2c device given a device location and address
|
||||
// NewI2cDevice creates a new io.ReadWriteCloser with the proper ioctrl given an i2c bus location and device address
|
||||
func NewI2cDevice(location string, address byte) (io.ReadWriteCloser, error) {
|
||||
file, err := os.OpenFile(location, os.O_RDWR, os.ModeExclusive)
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user