summaryrefslogtreecommitdiff
path: root/drivers/display/lcd160cr_test.py
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/display/lcd160cr_test.py')
-rw-r--r--drivers/display/lcd160cr_test.py60
1 files changed, 38 insertions, 22 deletions
diff --git a/drivers/display/lcd160cr_test.py b/drivers/display/lcd160cr_test.py
index 8b7ef4555..883c7d3b7 100644
--- a/drivers/display/lcd160cr_test.py
+++ b/drivers/display/lcd160cr_test.py
@@ -3,11 +3,13 @@
import time, math, framebuf, lcd160cr
+
def get_lcd(lcd):
if type(lcd) is str:
lcd = lcd160cr.LCD160CR(lcd)
return lcd
+
def show_adc(lcd, adc):
data = [adc.read_core_temp(), adc.read_core_vbat(), 3.3]
try:
@@ -21,24 +23,26 @@ def show_adc(lcd, adc):
lcd.set_pos(0, 100 + i * 16)
else:
lcd.set_font(2, trans=1)
- lcd.set_pos(0, lcd.h-60 + i * 16)
- lcd.write('%4s: ' % ('TEMP', 'VBAT', 'VREF')[i])
+ lcd.set_pos(0, lcd.h - 60 + i * 16)
+ lcd.write("%4s: " % ("TEMP", "VBAT", "VREF")[i])
if i > 0:
- s = '%6.3fV' % data[i]
+ s = "%6.3fV" % data[i]
else:
- s = '%5.1f°C' % data[i]
+ s = "%5.1f°C" % data[i]
if lcd.h == 160:
lcd.set_font(1, bold=0, scale=1)
else:
lcd.set_font(1, bold=0, scale=1, trans=1)
- lcd.set_pos(45, lcd.h-60 + i * 16)
+ lcd.set_pos(45, lcd.h - 60 + i * 16)
lcd.write(s)
+
def test_features(lcd, orient=lcd160cr.PORTRAIT):
# if we run on pyboard then use ADC and RTC features
try:
import pyb
- adc = pyb.ADCAll(12, 0xf0000)
+
+ adc = pyb.ADCAll(12, 0xF0000)
rtc = pyb.RTC()
except:
adc = None
@@ -53,7 +57,7 @@ def test_features(lcd, orient=lcd160cr.PORTRAIT):
# create M-logo
mlogo = framebuf.FrameBuffer(bytearray(17 * 17 * 2), 17, 17, framebuf.RGB565)
mlogo.fill(0)
- mlogo.fill_rect(1, 1, 15, 15, 0xffffff)
+ mlogo.fill_rect(1, 1, 15, 15, 0xFFFFFF)
mlogo.vline(4, 4, 12, 0)
mlogo.vline(8, 1, 12, 0)
mlogo.vline(12, 4, 12, 0)
@@ -80,15 +84,18 @@ def test_features(lcd, orient=lcd160cr.PORTRAIT):
if tx2 >= 0 and ty2 >= 0 and tx2 < w and ty2 < h:
tx, ty = tx2, ty2
else:
- tx = (tx + 1) % w
- ty = (ty + 1) % h
+ tx = (tx + 1) % w
+ ty = (ty + 1) % h
# create and show the inline framebuf
fbuf.fill(lcd.rgb(128 + int(64 * math.cos(0.1 * i)), 128, 192))
- fbuf.line(w // 2, h // 2,
+ fbuf.line(
+ w // 2,
+ h // 2,
w // 2 + int(40 * math.cos(0.2 * i)),
h // 2 + int(40 * math.sin(0.2 * i)),
- lcd.rgb(128, 255, 64))
+ lcd.rgb(128, 255, 64),
+ )
fbuf.hline(0, ty, w, lcd.rgb(64, 64, 64))
fbuf.vline(tx, 0, h, lcd.rgb(64, 64, 64))
fbuf.rect(tx - 3, ty - 3, 7, 7, lcd.rgb(64, 64, 64))
@@ -97,9 +104,12 @@ def test_features(lcd, orient=lcd160cr.PORTRAIT):
y = h // 2 - 8 + int(32 * math.sin(0.05 * i + phase))
fbuf.blit(mlogo, x, y)
for j in range(-3, 3):
- fbuf.text('MicroPython',
- 5, h // 2 + 9 * j + int(20 * math.sin(0.1 * (i + j))),
- lcd.rgb(128 + 10 * j, 0, 128 - 10 * j))
+ fbuf.text(
+ "MicroPython",
+ 5,
+ h // 2 + 9 * j + int(20 * math.sin(0.1 * (i + j))),
+ lcd.rgb(128 + 10 * j, 0, 128 - 10 * j),
+ )
lcd.show_framebuf(fbuf)
# show results from the ADC
@@ -111,7 +121,10 @@ def test_features(lcd, orient=lcd160cr.PORTRAIT):
lcd.set_pos(2, 0)
lcd.set_font(1)
t = rtc.datetime()
- lcd.write('%4d-%02d-%02d %2d:%02d:%02d.%01d' % (t[0], t[1], t[2], t[4], t[5], t[6], t[7] // 100000))
+ lcd.write(
+ "%4d-%02d-%02d %2d:%02d:%02d.%01d"
+ % (t[0], t[1], t[2], t[4], t[5], t[6], t[7] // 100000)
+ )
# compute the frame rate
t1 = time.ticks_us()
@@ -120,13 +133,14 @@ def test_features(lcd, orient=lcd160cr.PORTRAIT):
# show the frame rate
lcd.set_pos(2, 9)
- lcd.write('%.2f fps' % (1000000 / dt))
+ lcd.write("%.2f fps" % (1000000 / dt))
+
def test_mandel(lcd, orient=lcd160cr.PORTRAIT):
# set orientation and clear screen
lcd = get_lcd(lcd)
lcd.set_orient(orient)
- lcd.set_pen(0, 0xffff)
+ lcd.set_pen(0, 0xFFFF)
lcd.erase()
# function to compute Mandelbrot pixels
@@ -148,24 +162,26 @@ def test_mandel(lcd, orient=lcd160cr.PORTRAIT):
spi = lcd.fast_spi()
# draw the Mandelbrot set line-by-line
- hh = ((h - 1) / 3.2)
- ww = ((w - 1) / 2.4)
+ hh = (h - 1) / 3.2
+ ww = (w - 1) / 2.4
for v in range(h):
for u in range(w):
c = in_set((v / hh - 2.3) + (u / ww - 1.2) * 1j)
if c < 16:
rgb = c << 12 | c << 6
else:
- rgb = 0xf800 | c << 6
+ rgb = 0xF800 | c << 6
line[2 * u] = rgb
line[2 * u + 1] = rgb >> 8
spi.write(line)
+
def test_all(lcd, orient=lcd160cr.PORTRAIT):
lcd = get_lcd(lcd)
test_features(lcd, orient)
test_mandel(lcd, orient)
-print('To run all tests: test_all(<lcd>)')
-print('Individual tests are: test_features, test_mandel')
+
+print("To run all tests: test_all(<lcd>)")
+print("Individual tests are: test_features, test_mandel")
print('<lcd> argument should be a connection, eg "X", or an LCD160CR object')