forked from hybridgroup/gobot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
pwm_pin_test.go
46 lines (36 loc) · 1.31 KB
/
pwm_pin_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package raspi
import (
"errors"
"testing"
"gobot.io/x/gobot/gobottest"
"gobot.io/x/gobot/sysfs"
)
var _ sysfs.PWMPinner = (*PWMPin)(nil)
func TestPwmPin(t *testing.T) {
pin := NewPWMPin("1")
gobottest.Assert(t, pin.Export(), nil)
gobottest.Assert(t, pin.Enable(true), nil)
val, _ := pin.Polarity()
gobottest.Assert(t, val, "normal")
gobottest.Assert(t, pin.InvertPolarity(true), nil)
val, _ = pin.Polarity()
gobottest.Assert(t, val, "normal")
period, err := pin.Period()
gobottest.Assert(t, err, errors.New("Raspi PWM pin period not set"))
gobottest.Assert(t, pin.SetDutyCycle(10000), errors.New("Raspi PWM pin period not set"))
gobottest.Assert(t, pin.SetPeriod(20000000), nil)
period, _ = pin.Period()
gobottest.Assert(t, period, uint32(20000000))
gobottest.Assert(t, pin.SetPeriod(10000000), errors.New("Cannot set the period of individual PWM pins on Raspi"))
dc, _ := pin.DutyCycle()
gobottest.Assert(t, dc, uint32(0))
// call currently fails in test
gobottest.Refute(t, pin.SetDutyCycle(10000), nil)
dc, _ = pin.DutyCycle()
gobottest.Assert(t, dc, uint32(10000))
gobottest.Assert(t, pin.SetDutyCycle(999999999), errors.New("Duty cycle exceeds period."))
dc, _ = pin.DutyCycle()
gobottest.Assert(t, dc, uint32(10000))
// call currently fails in test
gobottest.Refute(t, pin.Unexport(), nil)
}