joule: remove incorrect pin assignment and improve test coverage
Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
parent
edd610e1d7
commit
63bc898a5d
|
@ -136,9 +136,6 @@ func (e *Adaptor) PWMPin(pin string) (sysfsPin sysfs.PWMPinner, err error) {
|
|||
sysPin := sysfsPinMap[pin]
|
||||
if sysPin.pwmPin != -1 {
|
||||
if e.pwmPins[sysPin.pwmPin] == nil {
|
||||
if err = e.DigitalWrite(pin, 1); err != nil {
|
||||
return
|
||||
}
|
||||
e.pwmPins[sysPin.pwmPin] = sysfs.NewPWMPin(sysPin.pwmPin)
|
||||
if err = e.pwmPins[sysPin.pwmPin].Export(); err != nil {
|
||||
return
|
||||
|
|
|
@ -180,3 +180,21 @@ func TestAdaptorPwm(t *testing.T) {
|
|||
err = a.PwmWrite("4", 100)
|
||||
gobottest.Assert(t, err, errors.New("Not a PWM pin"))
|
||||
}
|
||||
|
||||
func TestAdaptorPwmPinExportError(t *testing.T) {
|
||||
a, fs := initTestAdaptor()
|
||||
|
||||
delete(fs.Files, "/sys/class/pwm/pwmchip0/export")
|
||||
|
||||
err := a.PwmWrite("25", 100)
|
||||
gobottest.Assert(t, strings.Contains(err.Error(), "/sys/class/pwm/pwmchip0/export: No such file"), true)
|
||||
}
|
||||
|
||||
func TestAdaptorPwmPinEnableError(t *testing.T) {
|
||||
a, fs := initTestAdaptor()
|
||||
|
||||
delete(fs.Files, "/sys/class/pwm/pwmchip0/pwm0/enable")
|
||||
|
||||
err := a.PwmWrite("25", 100)
|
||||
gobottest.Assert(t, strings.Contains(err.Error(), "/sys/class/pwm/pwmchip0/pwm0/enable: No such file"), true)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue