lepton: add Dev.Bounds()

This is in preparation to support the lepton 3 and refactor the driver to be in
better shape.
pull/1/head
Marc-Antoine Ruel 8 years ago
parent 84ee99bd88
commit ce57d1e222

@ -113,6 +113,8 @@ func New(p spi.Port, i i2c.Bus, cs gpio.PinOut) (*Dev, error) {
Dev: c, Dev: c,
s: s, s: s,
cs: cs, cs: cs,
w: w,
h: h,
prevImg: image.NewGray16(image.Rect(0, 0, w, h)), prevImg: image.NewGray16(image.Rect(0, 0, w, h)),
frameWidth: frameWidth, frameWidth: frameWidth,
frameLines: frameLines, frameLines: frameLines,
@ -142,6 +144,8 @@ type Dev struct {
*cci.Dev *cci.Dev
s spi.Conn s spi.Conn
cs gpio.PinOut cs gpio.PinOut
w int
h int
prevImg *image.Gray16 prevImg *image.Gray16
frameA, frameB []byte frameA, frameB []byte
frameWidth int // in bytes 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) 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. // ReadImg reads an image.
// //
// It is ok to call other functions concurrently to send commands to the // It is ok to call other functions concurrently to send commands to the

@ -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) { func TestReadImg(t *testing.T) {
i := i2ctest.Playback{Ops: initSequence()} i := i2ctest.Playback{Ops: initSequence()}
s := spiStream{data: prepareFrame(t)} s := spiStream{data: prepareFrame(t)}

Loading…
Cancel
Save