beaglebone: remove code no longer needed and increase test coverage
Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
parent
971af75bbe
commit
4d49cd4ed2
|
@ -19,7 +19,6 @@ const pwmDefaultPeriod = 500000
|
|||
// Adaptor is the gobot.Adaptor representation for the Beaglebone
|
||||
type Adaptor struct {
|
||||
name string
|
||||
kernel string
|
||||
digitalPins []*sysfs.DigitalPin
|
||||
pwmPins map[string]*sysfs.PWMPin
|
||||
i2cBuses map[int]sysfs.I2cDevice
|
||||
|
@ -44,6 +43,7 @@ func NewAdaptor() *Adaptor {
|
|||
func (b *Adaptor) setSlots() {
|
||||
b.slots = "/sys/devices/platform/bone_capemgr/slots"
|
||||
b.usrLed = "/sys/class/leds/beaglebone:green:"
|
||||
b.analogPath = "/sys/bus/iio/devices/iio:device0"
|
||||
}
|
||||
|
||||
// Name returns the Adaptor name
|
||||
|
@ -52,30 +52,25 @@ func (b *Adaptor) Name() string { return b.name }
|
|||
// SetName sets the Adaptor name
|
||||
func (b *Adaptor) SetName(n string) { b.name = n }
|
||||
|
||||
// Kernel returns the Linux kernel version for the BeagleBone
|
||||
func (b *Adaptor) Kernel() string { return b.kernel }
|
||||
|
||||
// Connect initializes the pwm and analog dts.
|
||||
func (b *Adaptor) Connect() error {
|
||||
if err := ensureSlot(b.slots, "BB-ADC"); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
b.analogPath = "/sys/bus/iio/devices/iio:device0"
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// Finalize releases all i2c devices and exported analog, digital, pwm pins.
|
||||
func (b *Adaptor) Finalize() (err error) {
|
||||
for _, pin := range b.pwmPins {
|
||||
for _, pin := range b.digitalPins {
|
||||
if pin != nil {
|
||||
if e := pin.Unexport(); e != nil {
|
||||
err = multierror.Append(err, e)
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, pin := range b.digitalPins {
|
||||
for _, pin := range b.pwmPins {
|
||||
if pin != nil {
|
||||
if e := pin.Unexport(); e != nil {
|
||||
err = multierror.Append(err, e)
|
||||
|
|
|
@ -29,10 +29,15 @@ func TestBeagleboneAdaptor(t *testing.T) {
|
|||
"/dev/i2c-2",
|
||||
"/sys/devices/platform/bone_capemgr",
|
||||
"/sys/devices/platform/ocp/ocp:P9_21_pinmux/state",
|
||||
"/sys/devices/platform/ocp/ocp:P9_22_pinmux/state",
|
||||
"/sys/class/leds/beaglebone:green:usr1/brightness",
|
||||
"/sys/bus/iio/devices/iio:device0/in_voltage1_raw",
|
||||
"/sys/devices/platform/ocp/48300000.epwmss/48300200.pwm/pwm/pwmchip0/export",
|
||||
"/sys/devices/platform/ocp/48300000.epwmss/48300200.pwm/pwm/pwmchip0/unexport",
|
||||
"/sys/devices/platform/ocp/48300000.epwmss/48300200.pwm/pwm/pwmchip0/pwm0/enable",
|
||||
"/sys/devices/platform/ocp/48300000.epwmss/48300200.pwm/pwm/pwmchip0/pwm0/period",
|
||||
"/sys/devices/platform/ocp/48300000.epwmss/48300200.pwm/pwm/pwmchip0/pwm0/duty_cycle",
|
||||
"/sys/devices/platform/ocp/48300000.epwmss/48300200.pwm/pwm/pwmchip0/pwm0/polarity",
|
||||
"/sys/devices/platform/ocp/48300000.epwmss/48300200.pwm/pwm/pwmchip0/pwm1/enable",
|
||||
"/sys/devices/platform/ocp/48300000.epwmss/48300200.pwm/pwm/pwmchip0/pwm1/period",
|
||||
"/sys/devices/platform/ocp/48300000.epwmss/48300200.pwm/pwm/pwmchip0/pwm1/duty_cycle",
|
||||
|
@ -45,6 +50,8 @@ func TestBeagleboneAdaptor(t *testing.T) {
|
|||
"/sys/class/gpio/gpio66/direction",
|
||||
"/sys/class/gpio/gpio10/value",
|
||||
"/sys/class/gpio/gpio10/direction",
|
||||
"/sys/class/gpio/gpio30/value",
|
||||
"/sys/class/gpio/gpio30/direction",
|
||||
})
|
||||
|
||||
sysfs.SetFilesystem(fs)
|
||||
|
@ -52,8 +59,6 @@ func TestBeagleboneAdaptor(t *testing.T) {
|
|||
|
||||
a.Connect()
|
||||
|
||||
a.analogPath = "/sys/bus/iio/devices/iio:device0"
|
||||
|
||||
// PWM
|
||||
gobottest.Assert(t, a.PwmWrite("P9_99", 175), errors.New("Not a valid PWM pin"))
|
||||
a.PwmWrite("P9_21", 175)
|
||||
|
@ -79,9 +84,16 @@ func TestBeagleboneAdaptor(t *testing.T) {
|
|||
fs.Files["/sys/devices/platform/ocp/48300000.epwmss/48300200.pwm/pwm/pwmchip0/pwm1/duty_cycle"].Contents,
|
||||
"66666",
|
||||
)
|
||||
|
||||
gobottest.Assert(t, a.ServoWrite("P9_99", 175), errors.New("Not a valid PWM pin"))
|
||||
|
||||
fs.WithReadError = true
|
||||
gobottest.Assert(t, a.PwmWrite("P9_21", 175), errors.New("read error"))
|
||||
fs.WithReadError = false
|
||||
|
||||
fs.WithWriteError = true
|
||||
gobottest.Assert(t, a.PwmWrite("P9_22", 175), errors.New("write error"))
|
||||
fs.WithWriteError = false
|
||||
|
||||
// Analog
|
||||
fs.Files["/sys/bus/iio/devices/iio:device0/in_voltage1_raw"].Contents = "567\n"
|
||||
i, err := a.AnalogRead("P9_40")
|
||||
|
@ -91,6 +103,11 @@ func TestBeagleboneAdaptor(t *testing.T) {
|
|||
_, err = a.AnalogRead("P9_99")
|
||||
gobottest.Assert(t, err, errors.New("Not a valid analog pin"))
|
||||
|
||||
fs.WithReadError = true
|
||||
_, err = a.AnalogRead("P9_40")
|
||||
gobottest.Assert(t, err, errors.New("read error"))
|
||||
fs.WithReadError = false
|
||||
|
||||
// DigitalIO
|
||||
a.DigitalWrite("usr1", 1)
|
||||
gobottest.Assert(t,
|
||||
|
@ -120,6 +137,11 @@ func TestBeagleboneAdaptor(t *testing.T) {
|
|||
gobottest.Assert(t, err, errors.New("read error"))
|
||||
fs.WithReadError = false
|
||||
|
||||
fs.WithWriteError = true
|
||||
_, err = a.DigitalRead("P9_11")
|
||||
gobottest.Assert(t, err, errors.New("write error"))
|
||||
fs.WithWriteError = false
|
||||
|
||||
// I2c
|
||||
sysfs.SetSyscall(&sysfs.MockSyscall{})
|
||||
|
||||
|
|
Loading…
Reference in New Issue