Skip to content

Commit 0a70198

Browse files
author
Margaret Matocha
committed
Set for auto update upon add_value, updated examples with display checking
1 parent 8de933e commit 0a70198

File tree

4 files changed

+120
-129
lines changed

4 files changed

+120
-129
lines changed

adafruit_display_shapes/sparkline.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def add_value(self, value):
5454
): # if list is full, remove the first item
5555
self._spark_list.pop(0)
5656
self._spark_list.append(value)
57-
# self.update()
57+
self.update()
5858

5959
@staticmethod
6060
def _xintercept(

examples/display_shapes_sparkline_simpletest.py

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,12 +30,10 @@
3030
import time
3131
from adafruit_display_shapes.sparkline import Sparkline
3232

33-
34-
35-
# from sparkline import sparkline # use this if sparkline.py is used to define the sparkline Class
36-
3733
if "DISPLAY" not in dir(board):
3834
# Setup the LCD display with driver
35+
# You may need to change this to match the display driver for the chipset
36+
# used on your display
3937
from adafruit_ili9341 import ILI9341
4038

4139
displayio.release_displays()
@@ -73,7 +71,7 @@
7371
display_bus,
7472
width=DISPLAY_WIDTH,
7573
height=DISPLAY_HEIGHT,
76-
rotation=180,
74+
rotation=180, # The rotation can be adjusted to match your configuration.
7775
auto_refresh=True,
7876
native_frames_per_second=90,
7977
)
@@ -92,36 +90,36 @@
9290
chartWidth = display.width
9391
chartHeight = display.height
9492

95-
9693
# mySparkline1 uses a vertical y range between 0 to 10 and will contain a maximum of 40 items
9794
mySparkline1 = Sparkline(
9895
width=chartWidth, height=chartHeight, max_items=40, yMin=0, yMax=10, x=0, y=0
9996
)
10097

101-
10298
# Create a group to hold the sparkline and append the sparkline into the group (myGroup)
10399
#
104100
# Note: In cases where display elements will overlap, then the order the elements are added to the
105101
# group will set which is on top. Latter elements are displayed on top of former elemtns.
106102
myGroup = displayio.Group(max_size=1)
107103

104+
# add the sparkline into myGroup
108105
myGroup.append(mySparkline1)
109106

110107

111-
# Display myGroup that contains the sparkline
108+
# Add myGroup (containing the sparkline) to the display
112109
display.show(myGroup)
113110

114-
115111
# Start the main loop
116112
while True:
117113

114+
# turn off the auto_refresh of the display while modifying the sparkline
115+
display.auto_refresh = False
116+
118117
# add_value: add a new value to a sparkline
119118
# Note: The y-range for mySparkline1 is set to 0 to 10, so all these random
120119
# values (between 0 and 10) will fit within the visible range of this sparkline
121120
mySparkline1.add_value(random.uniform(0, 10))
122121

123-
display.auto_refresh = False
124-
mySparkline1.update()
122+
# turn the display auto_refresh back on
125123
display.auto_refresh = True
126124

127125
# The display seems to be less jittery if a small sleep time is provided

examples/display_shapes_sparkline_ticks.py

Lines changed: 54 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -34,64 +34,65 @@
3434
from adafruit_display_shapes.line import Line
3535
from adafruit_display_shapes.rect import Rect
3636

37-
import gc
38-
39-
# from sparkline import sparkline # use this if sparkline.py is used to define the sparkline Class
40-
41-
42-
# Setup the LCD display
43-
44-
displayio.release_displays()
45-
46-
47-
# setup the SPI bus
48-
spi = board.SPI()
49-
tft_cs = board.D9 # arbitrary, pin not used
50-
tft_dc = board.D10
51-
tft_backlight = board.D12
52-
tft_reset = board.D11
53-
54-
while not spi.try_lock():
55-
spi.configure(baudrate=32000000)
56-
pass
57-
spi.unlock()
58-
59-
display_bus = displayio.FourWire(
60-
spi,
61-
command=tft_dc,
62-
chip_select=tft_cs,
63-
reset=tft_reset,
64-
baudrate=32000000,
65-
polarity=1,
66-
phase=1,
67-
)
37+
if "DISPLAY" not in dir(board):
38+
# Setup the LCD display with driver
39+
# You may need to change this to match the display driver for the chipset
40+
# used on your display
41+
from adafruit_ili9341 import ILI9341
42+
43+
displayio.release_displays()
44+
45+
# setup the SPI bus
46+
spi = board.SPI()
47+
tft_cs = board.D9 # arbitrary, pin not used
48+
tft_dc = board.D10
49+
tft_backlight = board.D12
50+
tft_reset = board.D11
51+
52+
while not spi.try_lock():
53+
spi.configure(baudrate=32000000)
54+
pass
55+
spi.unlock()
56+
57+
display_bus = displayio.FourWire(
58+
spi,
59+
command=tft_dc,
60+
chip_select=tft_cs,
61+
reset=tft_reset,
62+
baudrate=32000000,
63+
polarity=1,
64+
phase=1,
65+
)
6866

69-
print("spi.frequency: {}".format(spi.frequency))
67+
print("spi.frequency: {}".format(spi.frequency))
7068

71-
# Number of pixels in the display
72-
DISPLAY_WIDTH = 320
73-
DISPLAY_HEIGHT = 240
69+
# Number of pixels in the display
70+
DISPLAY_WIDTH = 320
71+
DISPLAY_HEIGHT = 240
7472

75-
# create the display
76-
display = ILI9341(
77-
display_bus,
78-
width=DISPLAY_WIDTH,
79-
height=DISPLAY_HEIGHT,
80-
rotation=180,
81-
auto_refresh=True,
82-
native_frames_per_second=90,
83-
)
73+
# create the display
74+
display = ILI9341(
75+
display_bus,
76+
width=DISPLAY_WIDTH,
77+
height=DISPLAY_HEIGHT,
78+
rotation=180, # The rotation can be adjusted to match your configuration.
79+
auto_refresh=True,
80+
native_frames_per_second=90,
81+
)
8482

85-
# reset the display to show nothing.
86-
display.show(None)
83+
# reset the display to show nothing.
84+
display.show(None)
85+
else:
86+
# built-in display
87+
display = board.DISPLAY
8788

8889
##########################################
8990
# Create background bitmaps and sparklines
9091
##########################################
9192

9293
# Baseline size of the sparkline chart, in pixels.
93-
chartWidth = 270
94-
chartHeight = 180
94+
chartWidth = display.width-50
95+
chartHeight = display.height-50
9596

9697
font = terminalio.FONT
9798

@@ -168,30 +169,25 @@
168169
)
169170
)
170171

171-
172-
# Display myGroup that contains all the bitmap TileGrids and sparklines
172+
# Set the display to show myGroup that contains the sparkline and other graphics
173173
display.show(myGroup)
174174

175-
176175
# Start the main loop
177176
while True:
178177

178+
# Turn off auto_refresh to prevent partial updates of the screen during updates
179+
# of the sparkline drawing
180+
display.auto_refresh = False
181+
179182
# add_value: add a new value to a sparkline
180183
# Note: The y-range for mySparkline1 is set to 0 to 10, so all these random
181184
# values (between 0 and 10) will fit within the visible range of this sparkline
182185
mySparkline1.add_value(random.uniform(0, 10))
183186

184-
# Turn off auto_refresh to prevent partial updates of the screen during updates
185-
# of the sparkline drawing
186-
display.auto_refresh = False
187-
# Update all the sparklines
188-
mySparkline1.update()
189187
# Turn on auto_refresh for the display
190188
display.auto_refresh = True
191189

192190
# The display seems to be less jittery if a small sleep time is provided
193191
# You can adjust this to see if it has any effect
194192
time.sleep(0.01)
195193

196-
# Uncomment the next line to print the amount of available memory
197-
# print('memory free: {}'.format(gc.mem_free()))

examples/display_shapes_sparkline_triple.py

Lines changed: 56 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -34,54 +34,57 @@
3434

3535
import gc
3636

37-
# from sparkline import sparkline # use this if sparkline.py is used to define the sparkline Class
38-
39-
40-
# Setup the LCD display
41-
42-
displayio.release_displays()
43-
44-
45-
# setup the SPI bus
46-
spi = board.SPI()
47-
tft_cs = board.D9 # arbitrary, pin not used
48-
tft_dc = board.D10
49-
tft_backlight = board.D12
50-
tft_reset = board.D11
51-
52-
while not spi.try_lock():
53-
spi.configure(baudrate=32000000)
54-
pass
55-
spi.unlock()
56-
57-
display_bus = displayio.FourWire(
58-
spi,
59-
command=tft_dc,
60-
chip_select=tft_cs,
61-
reset=tft_reset,
62-
baudrate=32000000,
63-
polarity=1,
64-
phase=1,
65-
)
66-
67-
print("spi.frequency: {}".format(spi.frequency))
68-
69-
# Number of pixels in the display
70-
DISPLAY_WIDTH = 320
71-
DISPLAY_HEIGHT = 240
72-
73-
# create the display
74-
display = ILI9341(
75-
display_bus,
76-
width=DISPLAY_WIDTH,
77-
height=DISPLAY_HEIGHT,
78-
rotation=180,
79-
auto_refresh=True,
80-
native_frames_per_second=90,
81-
)
82-
83-
# reset the display to show nothing.
84-
display.show(None)
37+
if "DISPLAY" not in dir(board):
38+
# Setup the LCD display with driver
39+
# You may need to change this to match the display driver for the chipset
40+
# used on your display
41+
from adafruit_ili9341 import ILI9341
42+
43+
displayio.release_displays()
44+
45+
# setup the SPI bus
46+
spi = board.SPI()
47+
tft_cs = board.D9 # arbitrary, pin not used
48+
tft_dc = board.D10
49+
tft_backlight = board.D12
50+
tft_reset = board.D11
51+
52+
while not spi.try_lock():
53+
spi.configure(baudrate=32000000)
54+
pass
55+
spi.unlock()
56+
57+
display_bus = displayio.FourWire(
58+
spi,
59+
command=tft_dc,
60+
chip_select=tft_cs,
61+
reset=tft_reset,
62+
baudrate=32000000,
63+
polarity=1,
64+
phase=1,
65+
)
66+
67+
print("spi.frequency: {}".format(spi.frequency))
68+
69+
# Number of pixels in the display
70+
DISPLAY_WIDTH = 320
71+
DISPLAY_HEIGHT = 240
72+
73+
# create the display
74+
display = ILI9341(
75+
display_bus,
76+
width=DISPLAY_WIDTH,
77+
height=DISPLAY_HEIGHT,
78+
rotation=180, # The rotation can be adjusted to match your configuration.
79+
auto_refresh=True,
80+
native_frames_per_second=90,
81+
)
82+
83+
# reset the display to show nothing.
84+
display.show(None)
85+
else:
86+
# built-in display
87+
display = board.DISPLAY
8588

8689
##########################################
8790
# Create background bitmaps and sparklines
@@ -165,7 +168,6 @@
165168
color=0xFFFFFF,
166169
)
167170

168-
169171
# Initialize the y-axis labels for mySparkline3 with no text
170172
textLabel3a = label.Label(
171173
font=font, text="", color=0x11FF44, max_glyphs=20
@@ -205,16 +207,18 @@
205207
myGroup.append(textLabel3a)
206208
myGroup.append(textLabel3b)
207209

208-
209-
# Display myGroup that contains all the bitmap TileGrids and sparklines
210+
# Set the display to show myGroup that contains all the bitmap TileGrids and sparklines
210211
display.show(myGroup)
211212

212-
213213
i = 0 # This is a counter for changing the random values for mySparkline3
214214

215215
# Start the main loop
216216
while True:
217217

218+
# Turn off auto_refresh to prevent partial updates of the screen during updates
219+
# of the sparklines
220+
display.auto_refresh = False
221+
218222
# add_value: add a new value to a sparkline
219223
# Note: The y-range for mySparkline1 is set to -1 to 1.25, so all these random
220224
# values (between 0 and 1) will fit within the visible range of this sparkline
@@ -245,13 +249,6 @@
245249
if i > 30: # After 30 times through the loop, reset the counter
246250
i = 0
247251

248-
# Turn off auto_refresh to prevent partial updates of the screen during updates
249-
# of the sparkline drawing
250-
display.auto_refresh = False
251-
# Update all the sparklines
252-
mySparkline1.update()
253-
mySparkline2.update()
254-
mySparkline3.update()
255252
# Turn on auto_refresh for the display
256253
display.auto_refresh = True
257254

0 commit comments

Comments
 (0)