Skip to content

Commit

Permalink
Add docs
Browse files Browse the repository at this point in the history
  • Loading branch information
zankich committed Oct 30, 2014
1 parent a7cee22 commit e78257c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
8 changes: 5 additions & 3 deletions sysfs/digital_pin.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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
Expand Down
4 changes: 0 additions & 4 deletions sysfs/digital_pin_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
6 changes: 6 additions & 0 deletions sysfs/doc.go
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion sysfs/i2c_device.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit e78257c

Please sign in to comment.