From e78257c2014d260889280275d45adcc976e7ee6b Mon Sep 17 00:00:00 2001 From: Adrian Zankich Date: Thu, 30 Oct 2014 16:22:25 -0700 Subject: [PATCH] Add docs --- sysfs/digital_pin.go | 8 +++++--- sysfs/digital_pin_test.go | 4 ---- sysfs/doc.go | 6 ++++++ sysfs/i2c_device.go | 2 +- 4 files changed, 12 insertions(+), 8 deletions(-) create mode 100644 sysfs/doc.go diff --git a/sysfs/digital_pin.go b/sysfs/digital_pin.go index dd617361..87028467 100644 --- a/sysfs/digital_pin.go +++ b/sysfs/digital_pin.go @@ -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 diff --git a/sysfs/digital_pin_test.go b/sysfs/digital_pin_test.go index b15ada8c..44d7018e 100644 --- a/sysfs/digital_pin_test.go +++ b/sysfs/digital_pin_test.go @@ -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") diff --git a/sysfs/doc.go b/sysfs/doc.go new file mode 100644 index 00000000..b9da3266 --- /dev/null +++ b/sysfs/doc.go @@ -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 diff --git a/sysfs/i2c_device.go b/sysfs/i2c_device.go index b2614b73..05cc417d 100644 --- a/sysfs/i2c_device.go +++ b/sysfs/i2c_device.go @@ -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)