1
0
mirror of https://github.com/hybridgroup/gobot.git synced 2025-04-26 13:48:49 +08:00

Updated Tinkerboard and sysfs tests to updated PWM polarity contract

Signed-off-by: Erik Agsjö <erik.agsjo@gmail.com>
This commit is contained in:
Erik Agsjö 2017-06-04 00:13:49 +02:00 committed by deadprogram
parent db766f7814
commit 44dec6d800
2 changed files with 16 additions and 12 deletions

View File

@ -174,15 +174,19 @@ func (c *Adaptor) PWMPin(pin string) (sysfsPin sysfs.PWMPinner, err error) {
if err = newPin.Export(); err != nil {
return
}
// Make sure pwm is disabled when setting polarity
if err = newPin.Enable(false); err != nil {
return
}
if err = newPin.InvertPolarity(false); err != nil {
return
}
if err = newPin.Enable(true); err != nil {
return
}
if err = newPin.SetPeriod(10000000); err != nil {
return
}
if err = newPin.InvertPolarity(false); err != nil {
return
}
c.pwmPins[i] = newPin
}

View File

@ -33,6 +33,15 @@ func TestPwmPin(t *testing.T) {
gobottest.Assert(t, err, nil)
gobottest.Assert(t, fs.Files["/sys/class/pwm/pwmchip0/export"].Contents, "10")
gobottest.Assert(t, pin.InvertPolarity(true), nil)
gobottest.Assert(t, fs.Files["/sys/class/pwm/pwmchip0/pwm10/polarity"].Contents, "inverted")
pol, _ := pin.Polarity()
gobottest.Assert(t, pol, "inverted")
gobottest.Assert(t, pin.InvertPolarity(false), nil)
gobottest.Assert(t, fs.Files["/sys/class/pwm/pwmchip0/pwm10/polarity"].Contents, "normal")
pol, _ = pin.Polarity()
gobottest.Assert(t, pol, "normal")
gobottest.Refute(t, fs.Files["/sys/class/pwm/pwmchip0/pwm10/enable"].Contents, "1")
err = pin.Enable(true)
gobottest.Assert(t, err, nil)
@ -45,15 +54,6 @@ func TestPwmPin(t *testing.T) {
data, _ = pin.Period()
gobottest.Assert(t, data, uint32(100000))
gobottest.Assert(t, pin.InvertPolarity(true), nil)
gobottest.Assert(t, fs.Files["/sys/class/pwm/pwmchip0/pwm10/polarity"].Contents, "inverted")
pol, _ := pin.Polarity()
gobottest.Assert(t, pol, "inverted")
gobottest.Assert(t, pin.InvertPolarity(false), nil)
gobottest.Assert(t, fs.Files["/sys/class/pwm/pwmchip0/pwm10/polarity"].Contents, "normal")
pol, _ = pin.Polarity()
gobottest.Assert(t, pol, "normal")
gobottest.Refute(t, fs.Files["/sys/class/pwm/pwmchip0/pwm10/duty_cycle"].Contents, "1")
err = pin.SetDutyCycle(100)
gobottest.Assert(t, err, nil)