diff --git a/waveshare2in13v2/drawing.go b/waveshare2in13v2/drawing.go index 24e8a0b..038e34e 100644 --- a/waveshare2in13v2/drawing.go +++ b/waveshare2in13v2/drawing.go @@ -5,7 +5,6 @@ package waveshare2in13v2 import ( - "bytes" "image" "image/draw" @@ -130,30 +129,3 @@ func drawImage(ctrl controller, opts *drawOpts) { sendImage(ctrl, cmd, s.MemRect, opts.buffer) } } - -func clearDisplay(ctrl controller, size image.Point, color image1bit.Bit) { - var colorValue byte - - if color == image1bit.On { - colorValue = 0xff - } - - spec := (&drawOpts{ - devSize: size, - dstRect: image.Rectangle{Max: size}, - }).spec() - - if spec.MemRect.Empty() { - return - } - - setMemoryArea(ctrl, spec.MemRect) - - ctrl.sendCommand(writeRAMBW) - - data := bytes.Repeat([]byte{colorValue}, spec.MemRect.Dx()) - - for y := 0; y < spec.MemRect.Max.Y; y++ { - ctrl.sendData(data) - } -} diff --git a/waveshare2in13v2/drawing_test.go b/waveshare2in13v2/drawing_test.go index 9ecfff9..30feb32 100644 --- a/waveshare2in13v2/drawing_test.go +++ b/waveshare2in13v2/drawing_test.go @@ -207,58 +207,3 @@ func TestDrawImage(t *testing.T) { }) } } - -func TestClearDisplay(t *testing.T) { - for _, tc := range []struct { - name string - size image.Point - color image1bit.Bit - want []record - }{ - { - name: "empty", - }, - { - name: "off", - size: image.Pt(100, 10), - color: image1bit.Off, - want: []record{ - {cmd: dataEntryModeSetting, data: []byte{0x3}}, - {cmd: setRAMXAddressStartEndPosition, data: []byte{0, (100+7)/8 - 1}}, - {cmd: setRAMYAddressStartEndPosition, data: []byte{0, 0, 10 - 1, 0}}, - {cmd: setRAMXAddressCounter, data: []byte{0}}, - {cmd: setRAMYAddressCounter, data: []byte{0, 0}}, - { - cmd: writeRAMBW, - data: bytes.Repeat([]byte{0}, 13*10), - }, - }, - }, - { - name: "on", - size: image.Pt(32, 20), - color: image1bit.On, - want: []record{ - {cmd: dataEntryModeSetting, data: []byte{0x3}}, - {cmd: setRAMXAddressStartEndPosition, data: []byte{0, 32/8 - 1}}, - {cmd: setRAMYAddressStartEndPosition, data: []byte{0, 0, 20 - 1, 0}}, - {cmd: setRAMXAddressCounter, data: []byte{0}}, - {cmd: setRAMYAddressCounter, data: []byte{0, 0}}, - { - cmd: writeRAMBW, - data: bytes.Repeat([]byte{0xff}, 4*20), - }, - }, - }, - } { - t.Run(tc.name, func(t *testing.T) { - var got fakeController - - clearDisplay(&got, tc.size, tc.color) - - if diff := cmp.Diff([]record(got), tc.want, cmpopts.EquateEmpty(), cmp.AllowUnexported(record{})); diff != "" { - t.Errorf("clearDisplay() difference (-got +want):\n%s", diff) - } - }) - } -} diff --git a/waveshare2in13v2/waveshare213v2.go b/waveshare2in13v2/waveshare213v2.go index fddfdcf..5d1849e 100644 --- a/waveshare2in13v2/waveshare213v2.go +++ b/waveshare2in13v2/waveshare213v2.go @@ -229,18 +229,9 @@ func (d *Dev) SetUpdateMode(mode PartialUpdate) error { // Clear clears the display. func (d *Dev) Clear(color color.Color) error { - eh := errorHandler{d: *d} - - c := image1bit.BitModel.Convert(color).(image1bit.Bit) - draw.Src.Draw(d.buffer, d.buffer.Bounds(), &image.Uniform{c}, image.Point{}) - - clearDisplay(&eh, image.Pt(d.opts.Width, d.opts.Height), c) - - if eh.err == nil { - updateDisplay(&eh, Full) - } - - return eh.err + return d.Draw(d.buffer.Bounds(), &image.Uniform{ + C: image1bit.BitModel.Convert(color).(image1bit.Bit), + }, image.Point{}) } // ColorModel returns a 1Bit color model.