waveshare213v2: Move display update to testable function

Signed-off-by: Michael Hanselmann <public@hansmi.ch>
pull/42/head
Michael Hanselmann 4 years ago committed by M-A
parent 648f44a621
commit be539b05ff

@ -76,3 +76,14 @@ func configDisplayMode(ctrl controller, mode PartialUpdate, lut LUT) {
ctrl.waitUntilIdle()
}
func updateDisplay(ctrl controller, mode PartialUpdate) {
ctrl.sendCommand(displayUpdateControl1)
ctrl.sendData([]byte{0})
ctrl.sendCommand(displayUpdateControl2)
ctrl.sendData([]byte{0xC7})
ctrl.sendCommand(masterActivation)
ctrl.waitUntilIdle()
}

@ -118,3 +118,40 @@ func TestConfigDisplayMode(t *testing.T) {
})
}
}
func TestUpdateDisplay(t *testing.T) {
for _, tc := range []struct {
name string
mode PartialUpdate
want []record
}{
{
name: "full",
mode: Full,
want: []record{
{cmd: displayUpdateControl1, data: []byte{0}},
{cmd: displayUpdateControl2, data: []byte{0xc7}},
{cmd: masterActivation},
},
},
{
name: "partial",
mode: Partial,
want: []record{
{cmd: displayUpdateControl1, data: []byte{0}},
{cmd: displayUpdateControl2, data: []byte{0xc7}},
{cmd: masterActivation},
},
},
} {
t.Run(tc.name, func(t *testing.T) {
var got fakeController
updateDisplay(&got, tc.mode)
if diff := cmp.Diff([]record(got), tc.want, cmpopts.EquateEmpty(), cmp.AllowUnexported(record{})); diff != "" {
t.Errorf("updateDisplay() difference (-got +want):\n%s", diff)
}
})
}
}

@ -223,7 +223,7 @@ func (d *Dev) Clear(color color.Color) error {
clearDisplay(&eh, image.Pt(d.opts.Width, d.opts.Height), c)
if eh.err == nil {
eh.err = d.turnOnDisplay()
updateDisplay(&eh, Full)
}
return eh.err
@ -255,7 +255,7 @@ func (d *Dev) Draw(dstRect image.Rectangle, src image.Image, srcPts image.Point)
drawImage(&eh, &opts)
if eh.err == nil {
eh.err = d.turnOnDisplay()
updateDisplay(&eh, d.mode)
}
return eh.err
@ -284,7 +284,7 @@ func (d *Dev) DrawPartial(dstRect image.Rectangle, src image.Image, srcPts image
}
if eh.err == nil {
eh.err = d.turnOnDisplay()
updateDisplay(&eh, d.mode)
}
return eh.err
@ -300,18 +300,6 @@ func (d *Dev) String() string {
return fmt.Sprintf("epd.Dev{%s, %s, Height: %d, Width: %d}", d.c, d.dc, d.opts.Height, d.opts.Width)
}
func (d *Dev) turnOnDisplay() error {
eh := errorHandler{d: *d}
eh.sendCommand(displayUpdateControl2)
eh.sendData([]byte{0xC7})
eh.sendCommand(masterActivation)
eh.waitUntilIdle()
return eh.err
}
// Reset the hardware
func (d *Dev) reset() error {
eh := errorHandler{d: *d}

Loading…
Cancel
Save