From ee0bff582a684a8356c8593170a79d4bec280039 Mon Sep 17 00:00:00 2001 From: INSEOB KANG Date: Sun, 23 Oct 2022 08:41:22 +0900 Subject: [PATCH] little fix --- examples/jetson-nano_blink.go | 4 ++ examples/jetson-nano_servo.go | 4 ++ platforms/jetson/jetson_adaptor.go | 75 +++++++++++++++--------------- 3 files changed, 45 insertions(+), 38 deletions(-) diff --git a/examples/jetson-nano_blink.go b/examples/jetson-nano_blink.go index c8fa0b07..72f8ba70 100644 --- a/examples/jetson-nano_blink.go +++ b/examples/jetson-nano_blink.go @@ -1,3 +1,7 @@ +// +build example +// +// Do not build by default. + package main import ( diff --git a/examples/jetson-nano_servo.go b/examples/jetson-nano_servo.go index 06341da4..98586376 100644 --- a/examples/jetson-nano_servo.go +++ b/examples/jetson-nano_servo.go @@ -1,3 +1,7 @@ +// +build example +// +// Do not build by default. + package main // diff --git a/platforms/jetson/jetson_adaptor.go b/platforms/jetson/jetson_adaptor.go index 06f58c91..ac0e587c 100644 --- a/platforms/jetson/jetson_adaptor.go +++ b/platforms/jetson/jetson_adaptor.go @@ -3,7 +3,6 @@ package jetson import ( "errors" "fmt" - "sync" multierror "github.com/hashicorp/go-multierror" @@ -130,20 +129,6 @@ func (j *Adaptor) DigitalPin(pin string, dir string) (sysfsPin sysfs.DigitalPinn return currentPin, nil } -func (j *Adaptor) getExportedDigitalPin(translatedPin int, dir string) (sysfsPin sysfs.DigitalPinner, err error) { - j.mutex.Lock() - defer j.mutex.Unlock() - - if j.digitalPins[translatedPin] == nil { - j.digitalPins[translatedPin] = sysfs.NewDigitalPin(translatedPin) - if err = j.digitalPins[translatedPin].Export(); err != nil { - return - } - } - - return j.digitalPins[translatedPin], nil -} - // DigitalRead reads digital value from pin func (j *Adaptor) DigitalRead(pin string) (val int, err error) { sysfsPin, err := j.DigitalPin(pin, sysfs.IN) @@ -174,17 +159,6 @@ func (j *Adaptor) GetConnection(address int, bus int) (connection i2c.Connection return i2c.NewConnection(device, address), err } -func (j *Adaptor) getI2cBus(bus int) (_ i2c.I2cDevice, err error) { - j.mutex.Lock() - defer j.mutex.Unlock() - - if j.i2cBuses[bus] == nil { - j.i2cBuses[bus], err = sysfs.NewI2cDevice(fmt.Sprintf("/dev/i2c-%d", bus)) - } - - return j.i2cBuses[bus], err -} - // GetDefaultBus returns the default i2c bus for this platform func (j *Adaptor) GetDefaultBus() int { return j.i2cDefaultBus @@ -232,18 +206,6 @@ func (j *Adaptor) GetSpiDefaultMaxSpeed() int64 { return j.spiDefaultMaxSpeed } -func (j *Adaptor) translatePin(pin string) (i int, err error) { - if val, ok := pins[pin][j.revision]; ok { - i = val - } else if val, ok := pins[pin]["*"]; ok { - i = val - } else { - err = errors.New("Not a valid pin") - return - } - return -} - //PWMPin returns a Jetson Nano. PWMPin which provides the sysfs.PWMPinner interface func (j *Adaptor) PWMPin(pin string) (JetsonPWMPin sysfs.PWMPinner, err error) { i, err := j.translatePin(pin) @@ -289,3 +251,40 @@ func (j *Adaptor) ServoWrite(pin string, angle byte) (err error) { duty := uint32(gobot.FromScale(float64(angle), 0, 180) * float64(j.JSBlasterPeriod)) return sysfsPin.SetDutyCycle(duty) } + +func (j *Adaptor) getExportedDigitalPin(translatedPin int, dir string) (sysfsPin sysfs.DigitalPinner, err error) { + j.mutex.Lock() + defer j.mutex.Unlock() + + if j.digitalPins[translatedPin] == nil { + j.digitalPins[translatedPin] = sysfs.NewDigitalPin(translatedPin) + if err = j.digitalPins[translatedPin].Export(); err != nil { + return + } + } + + return j.digitalPins[translatedPin], nil +} + +func (j *Adaptor) getI2cBus(bus int) (_ i2c.I2cDevice, err error) { + j.mutex.Lock() + defer j.mutex.Unlock() + + if j.i2cBuses[bus] == nil { + j.i2cBuses[bus], err = sysfs.NewI2cDevice(fmt.Sprintf("/dev/i2c-%d", bus)) + } + + return j.i2cBuses[bus], err +} + +func (j *Adaptor) translatePin(pin string) (i int, err error) { + if val, ok := pins[pin][j.revision]; ok { + i = val + } else if val, ok := pins[pin]["*"]; ok { + i = val + } else { + err = errors.New("Not a valid pin") + return + } + return +}