mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-16 04:43:25 +00:00
lis2mdl: starting point for adding unit tests
Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
+4
-3
@@ -6,14 +6,15 @@
|
|||||||
package lis2mdl // import "tinygo.org/x/drivers/lis2mdl"
|
package lis2mdl // import "tinygo.org/x/drivers/lis2mdl"
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"machine"
|
|
||||||
"math"
|
"math"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"tinygo.org/x/drivers"
|
||||||
)
|
)
|
||||||
|
|
||||||
// Device wraps an I2C connection to a LIS2MDL device.
|
// Device wraps an I2C connection to a LIS2MDL device.
|
||||||
type Device struct {
|
type Device struct {
|
||||||
bus machine.I2C
|
bus drivers.I2C
|
||||||
Address uint8
|
Address uint8
|
||||||
PowerMode uint8
|
PowerMode uint8
|
||||||
SystemMode uint8
|
SystemMode uint8
|
||||||
@@ -31,7 +32,7 @@ type Configuration struct {
|
|||||||
// configured.
|
// configured.
|
||||||
//
|
//
|
||||||
// This function only creates the Device object, it does not touch the device.
|
// This function only creates the Device object, it does not touch the device.
|
||||||
func New(bus machine.I2C) Device {
|
func New(bus drivers.I2C) Device {
|
||||||
return Device{bus: bus, Address: MAG_ADDRESS}
|
return Device{bus: bus, Address: MAG_ADDRESS}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,15 @@
|
|||||||
|
package lis2mdl
|
||||||
|
|
||||||
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
qt "github.com/frankban/quicktest"
|
||||||
|
"tinygo.org/x/drivers/tester"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestI2CAddress(t *testing.T) {
|
||||||
|
c := qt.New(t)
|
||||||
|
bus := tester.NewI2CBus(c)
|
||||||
|
dev := New(bus)
|
||||||
|
c.Assert(dev.Address, qt.Equals, uint8(MAG_ADDRESS))
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user