2016-12-21 01:59:26 +08:00
|
|
|
package i2c
|
|
|
|
|
|
|
|
import (
|
2017-02-14 23:51:55 +08:00
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
2023-10-20 16:27:09 +08:00
|
|
|
"github.com/stretchr/testify/assert"
|
2023-11-16 03:51:52 +08:00
|
|
|
|
2023-05-20 20:25:21 +08:00
|
|
|
"gobot.io/x/gobot/v2"
|
2016-12-21 01:59:26 +08:00
|
|
|
)
|
|
|
|
|
2023-10-21 02:50:42 +08:00
|
|
|
var (
|
|
|
|
_ gobot.Driver = (*GroveLcdDriver)(nil)
|
|
|
|
_ gobot.Driver = (*GroveAccelerometerDriver)(nil)
|
|
|
|
)
|
2017-02-14 23:51:55 +08:00
|
|
|
|
2023-11-16 03:51:52 +08:00
|
|
|
func initTestGroveLcdDriver() *GroveLcdDriver {
|
|
|
|
d, _ := initGroveLcdDriverWithStubbedAdaptor()
|
|
|
|
return d
|
2017-02-14 23:51:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func initGroveLcdDriverWithStubbedAdaptor() (*GroveLcdDriver, *i2cTestAdaptor) {
|
|
|
|
adaptor := newI2cTestAdaptor()
|
|
|
|
return NewGroveLcdDriver(adaptor), adaptor
|
|
|
|
}
|
|
|
|
|
2023-11-16 03:51:52 +08:00
|
|
|
func initTestGroveAccelerometerDriver() *GroveAccelerometerDriver {
|
|
|
|
d, _ := initGroveAccelerometerDriverWithStubbedAdaptor()
|
|
|
|
return d
|
2017-02-14 23:51:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func initGroveAccelerometerDriverWithStubbedAdaptor() (*GroveAccelerometerDriver, *i2cTestAdaptor) {
|
|
|
|
adaptor := newI2cTestAdaptor()
|
|
|
|
return NewGroveAccelerometerDriver(adaptor), adaptor
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestGroveLcdDriverName(t *testing.T) {
|
|
|
|
g := initTestGroveLcdDriver()
|
2023-10-20 16:27:09 +08:00
|
|
|
assert.NotNil(t, g.Connection())
|
|
|
|
assert.True(t, strings.HasPrefix(g.Name(), "JHD1313M1"))
|
2017-02-14 23:51:55 +08:00
|
|
|
}
|
|
|
|
|
2017-04-04 03:35:32 +08:00
|
|
|
func TestLcdDriverWithAddress(t *testing.T) {
|
|
|
|
adaptor := newI2cTestAdaptor()
|
|
|
|
g := NewGroveLcdDriver(adaptor, WithAddress(0x66))
|
2023-10-20 16:27:09 +08:00
|
|
|
assert.Equal(t, 0x66, g.GetAddressOrDefault(0x33))
|
2017-04-04 03:35:32 +08:00
|
|
|
}
|
|
|
|
|
2017-02-14 23:51:55 +08:00
|
|
|
func TestGroveAccelerometerDriverName(t *testing.T) {
|
|
|
|
g := initTestGroveAccelerometerDriver()
|
2023-10-20 16:27:09 +08:00
|
|
|
assert.NotNil(t, g.Connection())
|
|
|
|
assert.True(t, strings.HasPrefix(g.Name(), "MMA7660"))
|
2017-02-14 23:51:55 +08:00
|
|
|
}
|
2017-02-15 00:10:04 +08:00
|
|
|
|
|
|
|
func TestGroveAccelerometerDriverWithAddress(t *testing.T) {
|
|
|
|
adaptor := newI2cTestAdaptor()
|
|
|
|
g := NewGroveAccelerometerDriver(adaptor, WithAddress(0x66))
|
2023-10-20 16:27:09 +08:00
|
|
|
assert.Equal(t, 0x66, g.GetAddressOrDefault(0x33))
|
2017-02-15 00:10:04 +08:00
|
|
|
}
|