tinygo.org/x/drivers@v0.27.1-0.20240509133757-7dbca2a54349/adt7410/adt7410_test.go (about) 1 package adt7410 2 3 import ( 4 "testing" 5 6 qt "github.com/frankban/quicktest" 7 "tinygo.org/x/drivers/tester" 8 ) 9 10 func TestDefaultI2CAddress(t *testing.T) { 11 c := qt.New(t) 12 bus := tester.NewI2CBus(c) 13 dev := New(bus) 14 c.Assert(dev.Address, qt.Equals, uint8(Address)) 15 } 16 17 func TestWhoAmI(t *testing.T) { 18 c := qt.New(t) 19 bus := tester.NewI2CBus(c) 20 fake := tester.NewI2CDevice(c, Address) 21 copy(fake.Registers[:], defaultRegisters()) 22 bus.AddDevice(fake) 23 24 dev := New(bus) 25 c.Assert(dev.Connected(), qt.Equals, true) 26 27 fake.Registers[RegID] = 0x99 28 c.Assert(dev.Connected(), qt.Equals, false) 29 } 30 31 // defaultRegisters returns the default values for all of the device's registers. 32 // see table 22 on page 27 of the datasheet. 33 func defaultRegisters() []uint8 { 34 return []uint8{ 35 RegTempValueMSB: 0, 36 RegTempValueLSB: 0, 37 RegStatus: 0, 38 RegConfig: 0, 39 RegTHIGHMsbReg: 0x20, 40 RegTHIGHLsbReg: 0, 41 RegTLOWMsbReg: 0x05, 42 RegTLOWLsbReg: 0, 43 RegTCRITMsbReg: 0x49, 44 RegTCRITLsbReg: 0x80, 45 RegTHYSTReg: 0x05, 46 RegID: 0xC8, 47 RegReset: 0, 48 } 49 }