diff --git a/devices/lepton/lepton.go b/devices/lepton/lepton.go index 3e82008..980106c 100644 --- a/devices/lepton/lepton.go +++ b/devices/lepton/lepton.go @@ -113,6 +113,8 @@ func New(p spi.Port, i i2c.Bus, cs gpio.PinOut) (*Dev, error) { Dev: c, s: s, cs: cs, + w: w, + h: h, prevImg: image.NewGray16(image.Rect(0, 0, w, h)), frameWidth: frameWidth, frameLines: frameLines, @@ -142,6 +144,8 @@ type Dev struct { *cci.Dev s spi.Conn cs gpio.PinOut + w int + h int prevImg *image.Gray16 frameA, frameB []byte frameWidth int // in bytes @@ -154,6 +158,11 @@ func (d *Dev) String() string { return fmt.Sprintf("Lepton(%s/%s/%s)", d.Dev, d.s, d.cs) } +// Bounds returns the device frame size. +func (d *Dev) Bounds() image.Rectangle { + return image.Rect(0, 0, d.w, d.h) +} + // ReadImg reads an image. // // It is ok to call other functions concurrently to send commands to the diff --git a/devices/lepton/lepton_test.go b/devices/lepton/lepton_test.go index b241a88..5f02f7d 100644 --- a/devices/lepton/lepton_test.go +++ b/devices/lepton/lepton_test.go @@ -163,6 +163,24 @@ func TestNew_cci_New_fail(t *testing.T) { } } +func TestBounds(t *testing.T) { + i := i2ctest.Playback{Ops: initSequence()} + s := spitest.Playback{CSPin: &gpiotest.Pin{N: "CS"}} + d, err := New(&s, &i, nil) + if err != nil { + t.Fatal(err) + } + if r := d.Bounds(); r != image.Rect(0, 0, 80, 60) { + t.Fatal(r) + } + if err := i.Close(); err != nil { + t.Fatal(err) + } + if err := s.Close(); err != nil { + t.Fatal(err) + } +} + func TestReadImg(t *testing.T) { i := i2ctest.Playback{Ops: initSequence()} s := spiStream{data: prepareFrame(t)}