Skip to content

Commit 25cc737

Browse files
committed
Merge branch 'main' into dev/switch-bus-device
# Conflicts: # adafruit_sharpmemorydisplay.py
2 parents fae7deb + 1e77578 commit 25cc737

File tree

4 files changed

+85
-10
lines changed

4 files changed

+85
-10
lines changed

.gitignore

Lines changed: 40 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,47 @@
1-
# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
1+
# SPDX-FileCopyrightText: 2022 Kattni Rembor, written for Adafruit Industries
22
#
3-
# SPDX-License-Identifier: Unlicense
3+
# SPDX-License-Identifier: MIT
44

5+
# Do not include files and directories created by your personal work environment, such as the IDE
6+
# you use, except for those already listed here. Pull requests including changes to this file will
7+
# not be accepted.
8+
9+
# This .gitignore file contains rules for files generated by working with CircuitPython libraries,
10+
# including building Sphinx, testing with pip, and creating a virual environment, as well as the
11+
# MacOS and IDE-specific files generated by using MacOS in general, or the PyCharm or VSCode IDEs.
12+
13+
# If you find that there are files being generated on your machine that should not be included in
14+
# your git commit, you should create a .gitignore_global file on your computer to include the
15+
# files created by your personal setup. To do so, follow the two steps below.
16+
17+
# First, create a file called .gitignore_global somewhere convenient for you, and add rules for
18+
# the files you want to exclude from git commits.
19+
20+
# Second, configure Git to use the exclude file for all Git repositories by running the
21+
# following via commandline, replacing "path/to/your/" with the actual path to your newly created
22+
# .gitignore_global file:
23+
# git config --global core.excludesfile path/to/your/.gitignore_global
24+
25+
# CircuitPython-specific files
526
*.mpy
6-
.idea
27+
28+
# Python-specific files
729
__pycache__
8-
_build
930
*.pyc
31+
32+
# Sphinx build-specific files
33+
_build
34+
35+
# This file results from running `pip -e install .` in a local repository
36+
*.egg-info
37+
38+
# Virtual environment-specific files
1039
.env
11-
bundles
40+
41+
# MacOS-specific files
1242
*.DS_Store
13-
.eggs
14-
dist
15-
**/*.egg-info
43+
44+
# IDE-specific files
45+
.idea
46+
.vscode
47+
*~

.pre-commit-config.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
repos:
66
- repo: https://github.com/python/black
7-
rev: 20.8b1
7+
rev: 22.3.0
88
hooks:
99
- id: black
1010
- repo: https://github.com/fsfe/reuse-tool

README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Introduction
55
:target: https://docs.circuitpython.org/projects/sharpmemorydisplay/en/latest/
66
:alt: Documentation Status
77

8-
.. image:: https://img.shields.io/discord/327254708534116352.svg
8+
.. image:: https://raw.githubusercontent.com/adafruit/Adafruit_CircuitPython_Bundle/main/badges/adafruit_discord.svg
99
:target: https://adafru.it/discord
1010
:alt: Discord
1111

adafruit_sharpmemorydisplay.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@
3232
import adafruit_framebuf
3333
from adafruit_bus_device.spi_device import SPIDevice
3434

35+
try:
36+
import numpy
37+
except ImportError:
38+
numpy = None
39+
3540
__version__ = "0.0.0-auto.0"
3641
__repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_SharpMemoryDisplay.git"
3742

@@ -97,3 +102,41 @@ def show(self):
97102
self._buf[0] = 0
98103
spi.write(self._buf)
99104
spi.write(self._buf) # we send one last 0 byte
105+
106+
def image(self, img):
107+
"""Set buffer to value of Python Imaging Library image. The image should
108+
be in 1 bit mode and a size equal to the display size."""
109+
# determine our effective width/height, taking rotation into account
110+
width = self.width
111+
height = self.height
112+
if self.rotation in (1, 3):
113+
width, height = height, width
114+
115+
if img.mode != "1":
116+
raise ValueError("Image must be in mode 1.")
117+
118+
imwidth, imheight = img.size
119+
if imwidth != width or imheight != height:
120+
raise ValueError(
121+
"Image must be same dimensions as display ({0}x{1}).".format(
122+
width, height
123+
)
124+
)
125+
126+
if numpy:
127+
self.buffer = bytearray(
128+
numpy.packbits(numpy.asarray(img), axis=1).flatten().tolist()
129+
)
130+
else:
131+
# Grab all the pixels from the image, faster than getpixel.
132+
pixels = img.load()
133+
# Clear buffer
134+
for i in range(len(self.buf)): # pylint: disable=consider-using-enumerate
135+
self.buf[i] = 0
136+
# Iterate through the pixels
137+
for x in range(width): # yes this double loop is slow,
138+
for y in range(height): # but these displays are small!
139+
if img.mode == "RGB":
140+
self.pixel(x, y, pixels[(x, y)])
141+
elif pixels[(x, y)]:
142+
self.pixel(x, y, 1) # only write if pixel is true

0 commit comments

Comments
 (0)