From f63d174d2e0618ccbd052ff93dbbe85a69e472ce Mon Sep 17 00:00:00 2001 From: deadprogram Date: Wed, 19 Apr 2017 13:06:25 +0200 Subject: [PATCH] edison: move read/write functions within file for organization purposes Signed-off-by: deadprogram --- platforms/intel-iot/edison/edison_adaptor.go | 71 ++++++++++---------- 1 file changed, 36 insertions(+), 35 deletions(-) diff --git a/platforms/intel-iot/edison/edison_adaptor.go b/platforms/intel-iot/edison/edison_adaptor.go index c6634ec6..df97772f 100644 --- a/platforms/intel-iot/edison/edison_adaptor.go +++ b/platforms/intel-iot/edison/edison_adaptor.go @@ -12,36 +12,11 @@ import ( "gobot.io/x/gobot/sysfs" ) -func writeFile(path string, data []byte) (i int, err error) { - file, err := sysfs.OpenFile(path, os.O_WRONLY, 0644) - defer file.Close() - if err != nil { - return - } - - return file.Write(data) -} - -func readFile(path string) ([]byte, error) { - file, err := sysfs.OpenFile(path, os.O_RDONLY, 0644) - defer file.Close() - if err != nil { - return make([]byte, 0), err - } - - buf := make([]byte, 200) - var i int - i, err = file.Read(buf) - if i == 0 { - return buf, err - } - return buf[:i], err -} - type mux struct { pin int value int } + type sysfsPin struct { pin int resistor int @@ -64,15 +39,6 @@ type Adaptor struct { readFile func(path string) ([]byte, error) } -// changePinMode writes pin mode to current_pinmux file -func changePinMode(a *Adaptor, pin, mode string) (err error) { - _, err = a.writeFile( - "/sys/kernel/debug/gpio_debug/gpio"+pin+"/current_pinmux", - []byte("mode"+mode), - ) - return -} - // NewAdaptor returns a new Edison Adaptor func NewAdaptor() *Adaptor { return &Adaptor{ @@ -431,3 +397,38 @@ func (e *Adaptor) newDigitalPin(i int, level int) (err error) { err = io.Unexport() return } + +func writeFile(path string, data []byte) (i int, err error) { + file, err := sysfs.OpenFile(path, os.O_WRONLY, 0644) + defer file.Close() + if err != nil { + return + } + + return file.Write(data) +} + +func readFile(path string) ([]byte, error) { + file, err := sysfs.OpenFile(path, os.O_RDONLY, 0644) + defer file.Close() + if err != nil { + return make([]byte, 0), err + } + + buf := make([]byte, 200) + var i int + i, err = file.Read(buf) + if i == 0 { + return buf, err + } + return buf[:i], err +} + +// changePinMode writes pin mode to current_pinmux file +func changePinMode(a *Adaptor, pin, mode string) (err error) { + _, err = a.writeFile( + "/sys/kernel/debug/gpio_debug/gpio"+pin+"/current_pinmux", + []byte("mode"+mode), + ) + return +}