diff --git a/waveshare2in13v2/controller.go b/waveshare2in13v2/controller.go index f7827e7..2af1568 100644 --- a/waveshare2in13v2/controller.go +++ b/waveshare2in13v2/controller.go @@ -78,8 +78,15 @@ func configDisplayMode(ctrl controller, mode PartialUpdate, lut LUT) { } func updateDisplay(ctrl controller, mode PartialUpdate) { + var displayUpdateFlags byte + + if mode == Partial { + // Make use of red buffer + displayUpdateFlags = 0b1000_0000 + } + ctrl.sendCommand(displayUpdateControl1) - ctrl.sendData([]byte{0}) + ctrl.sendData([]byte{displayUpdateFlags}) ctrl.sendCommand(displayUpdateControl2) ctrl.sendData([]byte{0xC7}) diff --git a/waveshare2in13v2/controller_test.go b/waveshare2in13v2/controller_test.go index 45d8ede..c536ea7 100644 --- a/waveshare2in13v2/controller_test.go +++ b/waveshare2in13v2/controller_test.go @@ -138,7 +138,7 @@ func TestUpdateDisplay(t *testing.T) { name: "partial", mode: Partial, want: []record{ - {cmd: displayUpdateControl1, data: []byte{0}}, + {cmd: displayUpdateControl1, data: []byte{0x80}}, {cmd: displayUpdateControl2, data: []byte{0xc7}}, {cmd: masterActivation}, }, diff --git a/waveshare2in13v2/waveshare213v2.go b/waveshare2in13v2/waveshare213v2.go index d119960..c3d68a1 100644 --- a/waveshare2in13v2/waveshare213v2.go +++ b/waveshare2in13v2/waveshare213v2.go @@ -239,30 +239,10 @@ func (d *Dev) Bounds() image.Rectangle { return image.Rect(0, 0, d.opts.Width, d.opts.Height) } -// Draw draws the given image to the display. +// Draw draws the given image to the display. Only the destination area is +// uploaded. Depending on the update mode the whole display or the destination +// area is refreshed. func (d *Dev) Draw(dstRect image.Rectangle, src image.Image, srcPts image.Point) error { - opts := drawOpts{ - cmd: writeRAMBW, - devSize: image.Pt(d.opts.Width, d.opts.Height), - buffer: d.buffer, - dstRect: dstRect, - src: src, - srcPts: srcPts, - } - - eh := errorHandler{d: *d} - - drawImage(&eh, &opts) - - if eh.err == nil { - updateDisplay(&eh, d.mode) - } - - return eh.err -} - -// DrawPartial draws the given image to the display. Display will update only changed pixel. -func (d *Dev) DrawPartial(dstRect image.Rectangle, src image.Image, srcPts image.Point) error { opts := drawOpts{ devSize: image.Pt(d.opts.Width, d.opts.Height), buffer: d.buffer, @@ -273,6 +253,7 @@ func (d *Dev) DrawPartial(dstRect image.Rectangle, src image.Image, srcPts image eh := errorHandler{d: *d} + // Keep the two buffers in sync. for _, cmd := range []byte{writeRAMBW, writeRAMRed} { opts.cmd = cmd @@ -290,6 +271,13 @@ func (d *Dev) DrawPartial(dstRect image.Rectangle, src image.Image, srcPts image return eh.err } +// DrawPartial draws the given image to the display. +// +// Deprecated: Use Draw instead. DrawPartial merely forwards all calls. +func (d *Dev) DrawPartial(dstRect image.Rectangle, src image.Image, srcPts image.Point) error { + return d.Draw(dstRect, src, srcPts) +} + // Halt clears the display. func (d *Dev) Halt() error { return d.Clear(image1bit.On)