2017-12-13 21:12:30 +08:00
|
|
|
package spi
|
|
|
|
|
|
|
|
import (
|
|
|
|
"image/color"
|
2022-12-17 18:56:11 +08:00
|
|
|
"strings"
|
2017-12-13 21:12:30 +08:00
|
|
|
"testing"
|
|
|
|
|
2023-05-20 20:25:21 +08:00
|
|
|
"gobot.io/x/gobot/v2"
|
|
|
|
"gobot.io/x/gobot/v2/gobottest"
|
2017-12-13 21:12:30 +08:00
|
|
|
)
|
|
|
|
|
2022-12-17 18:56:11 +08:00
|
|
|
// this ensures that the implementation is based on spi.Driver, which implements the gobot.Driver
|
|
|
|
// and tests all implementations, so no further tests needed here for gobot.Driver interface
|
2017-12-13 21:12:30 +08:00
|
|
|
var _ gobot.Driver = (*APA102Driver)(nil)
|
|
|
|
|
2022-12-17 18:56:11 +08:00
|
|
|
func initTestAPA102DriverWithStubbedAdaptor() *APA102Driver {
|
|
|
|
a := newSpiTestAdaptor()
|
|
|
|
d := NewAPA102Driver(a, 10, 31)
|
|
|
|
if err := d.Start(); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2017-12-13 21:12:30 +08:00
|
|
|
return d
|
|
|
|
}
|
|
|
|
|
2022-12-17 18:56:11 +08:00
|
|
|
func TestNewAPA102Driver(t *testing.T) {
|
|
|
|
var di interface{} = NewAPA102Driver(newSpiTestAdaptor(), 10, 31)
|
|
|
|
d, ok := di.(*APA102Driver)
|
|
|
|
if !ok {
|
|
|
|
t.Errorf("NewAPA102Driver() should have returned a *APA102Driver")
|
|
|
|
}
|
|
|
|
gobottest.Refute(t, d.Driver, nil)
|
|
|
|
gobottest.Assert(t, strings.HasPrefix(d.Name(), "APA102"), true)
|
2017-12-13 21:12:30 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestDriverLEDs(t *testing.T) {
|
2022-12-17 18:56:11 +08:00
|
|
|
d := initTestAPA102DriverWithStubbedAdaptor()
|
2017-12-13 21:12:30 +08:00
|
|
|
|
2019-05-31 17:34:00 +08:00
|
|
|
d.SetRGBA(0, color.RGBA{255, 255, 255, 15})
|
|
|
|
d.SetRGBA(1, color.RGBA{255, 255, 255, 15})
|
|
|
|
d.SetRGBA(2, color.RGBA{255, 255, 255, 15})
|
|
|
|
d.SetRGBA(3, color.RGBA{255, 255, 255, 15})
|
2017-12-13 21:12:30 +08:00
|
|
|
|
|
|
|
gobottest.Assert(t, d.Draw(), nil)
|
|
|
|
}
|