/
load.py
380 lines (305 loc) · 9.61 KB
/
load.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
# This file is full of tests, experiments and tinkering
# used to verify changes to serialtft.py and prototype
# new examples. Don't expect it to do anything predictable.
#
# It has been included for posterity and is subject to change.
#
# The tests below have been used for determining
# optimum delay times at 9600baud
#
# Certain commands will cause a serial buffer overflow
# if they are not allowed time to complete
import time
from time import localtime, strftime
from random import randint
from serialtft import SerialTFT
from functools import reduce
tft = SerialTFT("/dev/ttyAMA0", 9600, True, False)
BAR_WIDTH = 4
BAR_MARGIN = 1
# Clear Screen
tft.screen_rotation(SerialTFT.Rotation.landscape)
tft.bg_color(SerialTFT.Color.black)
tft.clear_screen()
colors = [
SerialTFT.Color.blue,
SerialTFT.Color.red,
SerialTFT.Color.green,
SerialTFT.Color.cyan,
SerialTFT.Color.magenta,
SerialTFT.Color.yellow,
SerialTFT.Color.white
]
tft.font_size(SerialTFT.Font.small)
tft.fg_color(SerialTFT.Color.white)
print('Drawing text')
tft.write_line('Lorem ipsum dolor sit amet, consectetur adipiscing elit. Praesent eu turpis enim, at luctus quam. Mauris augue augue, blandit quis dictum in, accumsan eget odio. In id laoreet massa.')
tft.font_size(SerialTFT.Font.medium)
tft.write_line('Starting load tests')
tft.font_size(SerialTFT.Font.large)
tft.write_line('Soooon')
time.sleep(5)
print('Testing pixel draw rate')
result = []
circle_count = 0
last_sec = time.localtime().tm_sec
total_count = 0
while len(result) < 10:
for color in colors:
#tft.fg_color(color)
tft.draw_pixel(randint(0,tft.Screen.width),randint(0,tft.Screen.height),color)
circle_count += 1
total_count += 1
if time.localtime().tm_sec !=last_sec:
last_sec = time.localtime().tm_sec
print('Drawn ' + str(circle_count))
result.append(circle_count)
circle_count = 0
# First result is unreliable
result.pop(0)
print('Average rate: ' + str(reduce(lambda x, y: x + y, result) / len(result)))
'''
print('Testing fast box draw rate')
result = []
circle_count = 0
last_sec = time.localtime().tm_sec
for x in range(0,200):
for color in colors:
#tft.fg_color(color)
tft.draw_box_fast(randint(0,tft.Screen.width),randint(0,tft.Screen.height),randint(0,tft.Screen.width),randint(0,tft.Screen.height),color)
circle_count += 1
if time.localtime().tm_sec !=last_sec:
last_sec = time.localtime().tm_sec
print('Drawn ' + str(circle_count))
result.append(circle_count)
circle_count = 0
# First result is unreliable
result.pop(0)
print('Average rate: ' + str(reduce(lambda x, y: x + y, result) / len(result)))
'''
print('Testing box draw rate')
result = []
circle_count = 0
last_sec = time.localtime().tm_sec
total_count = 0
while len(result) < 10:
for color in colors:
#tft.fg_color(color)
tft.draw_box(randint(0,tft.Screen.width),randint(0,tft.Screen.height),randint(0,tft.Screen.width),randint(0,tft.Screen.height),color)
circle_count += 1
total_count += 1
if time.localtime().tm_sec !=last_sec:
last_sec = time.localtime().tm_sec
print('Drawn ' + str(circle_count))
result.append(circle_count)
circle_count = 0
# First result is unreliable
result.pop(0)
print('Average rate: ' + str(reduce(lambda x, y: x + y, result) / len(result)))
print('Testing filled box draw rate')
result = []
circle_count = 0
last_sec = time.localtime().tm_sec
total_count = 0
while len(result) < 10:
for color in colors:
#tft.fg_color(color)
tft.draw_filled_box(randint(0,tft.Screen.width),randint(0,tft.Screen.height),randint(0,tft.Screen.width),randint(0,tft.Screen.height),color)
circle_count += 1
total_count += 1
if time.localtime().tm_sec !=last_sec:
last_sec = time.localtime().tm_sec
print('Drawn ' + str(circle_count))
result.append(circle_count)
circle_count = 0
# First result is unreliable
result.pop(0)
print('Average rate: ' + str(reduce(lambda x, y: x + y, result) / len(result)))
print('--------------------------------------')
print('Testing line draw rate')
result = []
circle_count = 0
last_sec = time.localtime().tm_sec
total_count = 0
while len(result) < 10:
for color in colors:
#tft.fg_color(color)
tft.draw_line(randint(0,tft.Screen.width),randint(0,tft.Screen.height),randint(0,tft.Screen.width),randint(0,tft.Screen.height),color)
circle_count += 1
total_count += 1
if time.localtime().tm_sec !=last_sec:
last_sec = time.localtime().tm_sec
print('Drawn ' + str(circle_count))
result.append(circle_count)
circle_count = 0
# First result is unreliable
result.pop(0)
print('Average rate: ' + str(reduce(lambda x, y: x + y, result) / len(result)))
print('--------------------------------------')
print('Testing circle draw rate')
result = []
circle_count = 0
last_sec = time.localtime().tm_sec
total_count = 0
while len(result) < 10:
for color in colors:
#tft.fg_color(color)
tft.draw_circle(SerialTFT.Screen.width_half+randint(-50,50),SerialTFT.Screen.height_half+randint(-40,40),randint(1,40),color)
circle_count += 1
total_count += 1
if time.localtime().tm_sec !=last_sec:
last_sec = time.localtime().tm_sec
print('Drawn ' + str(circle_count))
result.append(circle_count)
circle_count = 0
# First result is unreliable
result.pop(0)
print('Average rate: ' + str(reduce(lambda x, y: x + y, result) / len(result)))
print('--------------------------------------')
print('Testing filled circle draw rate')
result = []
circle_count = 0
last_sec = time.localtime().tm_sec
total_count = 0
while len(result) < 10:
for color in colors:
#tft.fg_color(color)
tft.draw_filled_circle(SerialTFT.Screen.width_half+randint(-50,50),SerialTFT.Screen.height_half+randint(-40,40),randint(1,40),color)
circle_count += 1
total_count += 1
if time.localtime().tm_sec !=last_sec:
last_sec = time.localtime().tm_sec
print('Drawn ' + str(circle_count))
result.append(circle_count)
circle_count = 0
# First result is unreliable
result.pop(0)
print('Average rate: ' + str(reduce(lambda x, y: x + y, result) / len(result)))
print('--------------------------------------')
tft.flush = True
print('Testing circle draw rate, flush enabled')
result = []
circle_count = 0
last_sec = time.localtime().tm_sec
total_count = 0
while len(result) < 10:
for color in colors:
tft.fg_color(color)
tft.draw_circle(SerialTFT.Screen.width_half+randint(-50,50),SerialTFT.Screen.height_half+randint(-40,40),randint(1,40))
circle_count += 1
total_count += 1
if time.localtime().tm_sec !=last_sec:
last_sec = time.localtime().tm_sec
print('Drawn ' + str(circle_count))
result.append(circle_count)
circle_count = 0
# First result is unreliable
result.pop(0)
print('Average rate: ' + str(reduce(lambda x, y: x + y, result) / len(result)))
print('--------------------------------------')
print('Testing filled circle draw rate, flush enabled')
result = []
circle_count = 0
last_sec = time.localtime().tm_sec
total_count = 0
while len(result) < 10:
for color in colors:
tft.fg_color(color)
tft.draw_filled_circle(SerialTFT.Screen.width_half+randint(-50,50),SerialTFT.Screen.height_half+randint(-40,40),randint(1,40))
circle_count += 1
total_count += 1
if time.localtime().tm_sec !=last_sec:
last_sec = time.localtime().tm_sec
print('Drawn ' + str(circle_count))
result.append(circle_count)
circle_count = 0
# First result is unreliable
result.pop(0)
print('Average rate: ' + str(reduce(lambda x, y: x + y, result) / len(result)))
print('--------------------------------------')
exit(0)
while 1:
for color in colors:
#tft.fg_color(color)
tft.draw_filled_circle(SerialTFT.Screen.width_half,SerialTFT.Screen.height_half,50-randint(0,49),color)
PIX_PER_COL = 17
tft.set_theme(SerialTFT.Theme.matrix)
bar_left = BAR_MARGIN
letters = []
left = 0
for letter in range(0,32):
letters.append([letter,randint(0,150),randint(0,110),randint(0,60),randint(0,1),randint(3,6)])
left += 10
left = 0
while 1:
for letter in letters:
letter[2] += randint(3,6)
letter[3] += randint(3,6)
if( letter[2] > 120 ):
letter[2] = 0
letter[1] = randint(0,150)
letter[3] = randint(0,60)
letter[4] = randint(0,1)
letter[5] = randint(3,6)
left = letter[1]
top = letter[2]
col_idx = int(round(letter[3] / PIX_PER_COL,0))
if( col_idx > 6 ):
col_idx = 6
col = colors[ col_idx ]
if(letter[4]==1):
col = 0
#tft.fg_color(col)
tft.draw_circle(left,top,letter[5],col)
#tft.goto_pixel(left,top)
#tft.write(letter[0])
time.sleep(0.1)
'''
while 1:
for color in colors:
tft.fg_color(color)
tft.draw_circle(SerialTFT.Screen.width_half,SerialTFT.Screen.height_half,50-color)
'''
'''
while 1:
for color in colors:
tft.fg_color(color)
tft.draw_circle(SerialTFT.Screen.width_half+randint(-50,50),SerialTFT.Screen.height_half+randint(-40,40),randint(1,20))
'''
'''
for color in colors:
tft.bg_color(color)
tft.clear_screen()
time.sleep(0.5)
tft.bg_color(SerialTFT.Color.black)
tft.clear_screen()
color_idx = 0;
while (bar_left + BAR_MARGIN < SerialTFT.Screen.width):
tft.fg_color(colors[color_idx])
tft.draw_filled_rect(bar_left,1,BAR_WIDTH,randint(1,119))
bar_left += BAR_MARGIN + BAR_WIDTH
color_idx += 1
if( color_idx > 6 ):
color_idx = 0
'''
'''
square_left = 0
square_top = 0
square_width = 2
square_height = 8
square_margin = 1
square_top = square_margin
square_left = square_margin
tft.clear_screen()
color_idx = 0;
while (square_top + square_margin < SerialTFT.Screen.height):
while (square_left + square_margin < SerialTFT.Screen.width):
tft.fg_color(colors[color_idx])
tft.draw_filled_rect(square_left,square_top,square_width,square_height)
square_left += square_width + square_margin
color_idx += 1
if( color_idx > 6 ):
color_idx = 0
square_top += square_height + square_margin
square_left = square_margin
'''