diff --git a/ds248x/ds248x_test.go b/ds248x/ds248x_test.go index e774e58..1eb8489 100644 --- a/ds248x/ds248x_test.go +++ b/ds248x/ds248x_test.go @@ -11,27 +11,78 @@ import ( "periph.io/x/conn/v3/i2c/i2ctest" ) -// TestNew sadly is testing only for DS2483. -// -func TestNew(t *testing.T) { +// Testing function New for DS2483. +func TestNew_DS2483(t *testing.T) { bus := i2ctest.Playback{ + DontPanic: true, Ops: []i2ctest.IO{ {Addr: 0x18, W: []byte{0xf0}}, {Addr: 0x18, W: []byte{0xe1, 0xf0}, R: []byte{0x18}}, {Addr: 0x18, W: []byte{0xd2, 0xe1}, R: []byte{0x1}}, - {Addr: 0x18, W: []byte{0xe1, 0xb4}}, - // {Addr: 0x18, W: []byte{0xe1, 0xd2}}, // (DS2482-800) - // {Addr: 0x18, W: []byte{0xc3, 0xf0}}, // (DS2482-800) + {Addr: 0x18, W: []byte{0xe1, 0xb4}}, // (DS2483 ptr for port configuration register) {Addr: 0x18, W: []byte{0xc3, 0x6, 0x26, 0x46, 0x66, 0x86}}, // (DS2483) }, } d, err := New(&bus, 0x18, &DefaultOpts) + if s := d.String(); s != "DS2483{playback(24)}" { + t.Fatal(s) + } if err != nil { t.Fatal(err) } - if s := d.String(); s != "DS2483{playback(24)}" { + + if err := d.Halt(); err != nil { + t.Fatal(err) + } + if err := bus.Close(); err != nil { + t.Fatal(err) + } +} + +// Testing function New for DS2482-800. +func TestNew_DS2482x800(t *testing.T) { + bus := i2ctest.Playback{ + DontPanic: true, + Ops: []i2ctest.IO{ + {Addr: 0x18, W: []byte{0xf0}}, + {Addr: 0x18, W: []byte{0xe1, 0xf0}, R: []byte{0x18}}, + {Addr: 0x18, W: []byte{0xd2, 0xe1}, R: []byte{0x1}}, + {Addr: 0x18, W: []byte{0xe1, 0xd2}}, // (DS2482-800 ptr for channel selection register) + {Addr: 0x18, W: []byte{0xc3, 0xf0}}, // (DS2482-800) + }, + } + d, err := New(&bus, 0x18, &DefaultOpts) + if s := d.String(); s != "DS2482-800{playback(24)}" { + t.Fatal(s) + } + if err != nil { + t.Fatal(err) + } + if err := d.Halt(); err != nil { + t.Fatal(err) + } + if err := bus.Close(); err != nil { + t.Fatal(err) + } +} + +// Testing function New for DS2482-100. +func TestNew_DS2482x100(t *testing.T) { + bus := i2ctest.Playback{ + DontPanic: true, + Ops: []i2ctest.IO{ + {Addr: 0x18, W: []byte{0xf0}}, + {Addr: 0x18, W: []byte{0xe1, 0xf0}, R: []byte{0x18}}, + {Addr: 0x18, W: []byte{0xd2, 0xe1}, R: []byte{0x1}}, + }, + } + d, err := New(&bus, 0x18, &DefaultOpts) + if s := d.String(); s != "DS2482-100{playback(24)}" { t.Fatal(s) } + if err != nil { + t.Fatal(err) + } if err := d.Halt(); err != nil { t.Fatal(err) }