This is an API-breaking change, albeit a simple one: Previously the
Dev.Clear function received a byte named "color". It was sent directly
to the display, thus acting more like a pattern to fill the display
with. In practice only 0 and 255 are likely to be used.
With this change the function is changed to receive a value of type
color.Color which is then converted to image1bit.Bit before filling the
display. The latter is also given a unittest.
Signed-off-by: Michael Hanselmann <public@hansmi.ch>
When the destination rectangle didn't start at (0,0) or cover the whole
display the Dev.Draw function would continue to update the display in
full. Obviously that didn't result in a good output.
This change updates the drawing logic to only update the affected area
(aligned to whole bytes on the horizontal axis) and limits the amount of
transferred data to the minimum needed to cover the destination
rectangle.
The calculation of the various offsets as well as the function sending
the image data are written to support unittesting.
Signed-off-by: Michael Hanselmann <public@hansmi.ch>
The structure definition and the functions were already split up. Moving
to a separate file simplifies the code structure.
Signed-off-by: Michael Hanselmann <public@hansmi.ch>
Set the start/end positions as well as the number of bytes to write by
computing them from an `image.Rectangle`. This is a preparatory step for
implementing partial image updates.
Also change the data entry mode setting to 0x03, the value applied at
power-on reset. It's not actually used given the way memory updates are
written (one large block instead of chunks).
Signed-off-by: Michael Hanselmann <public@hansmi.ch>
Introduce named constants where possible (based on the data sheet) and
compute values instead of using hardcoded ones.
Signed-off-by: Michael Hanselmann <public@hansmi.ch>
Dev.Clear: Avoid writing one beyond the end of the line. Also build the
row data only once before sending it for each line.
Dev.Draw, Dev.DrawPartial: Deduplicate logic for iterating over pixels
and simplify it such that a whole row of bits is built before sending
them in one go.
Tested using a Waveshare e-Paper 2.13in V2 display.
Signed-off-by: Michael Hanselmann <public@hansmi.ch>
Avoid using strconv.Itoa
fmt.Sprintf() can format numbers directly using the "%d" format
specifier.
Call Dev.Init in example code
Without initializing the hardware nothing is shown on the display.
Add constants for commands
Translate the command names from the datasheet into constant names,
similar to `epd/epd.go`. These names make it easier to understand what
the driver does.
One command, 0x37, is not documented in any of the datasheets available
(Waveshare 2.13inch e-Paper, Good Display GDEH0213B72).
Signed-off-by: Michael Hanselmann <public@hansmi.ch>