2016-09-04 07:40:40 +01:00
|
|
|
try:
|
|
|
|
import framebuf
|
|
|
|
except ImportError:
|
|
|
|
print("SKIP")
|
2017-06-10 18:14:16 +01:00
|
|
|
raise SystemExit
|
2016-09-04 07:40:40 +01:00
|
|
|
|
|
|
|
w = 5
|
|
|
|
h = 16
|
2017-02-06 10:59:44 +00:00
|
|
|
size = w * h // 8
|
|
|
|
buf = bytearray(size)
|
2020-03-23 02:26:08 +00:00
|
|
|
maps = {
|
|
|
|
framebuf.MONO_VLSB: "MONO_VLSB",
|
|
|
|
framebuf.MONO_HLSB: "MONO_HLSB",
|
|
|
|
framebuf.MONO_HMSB: "MONO_HMSB",
|
|
|
|
}
|
2017-02-06 10:59:44 +00:00
|
|
|
|
|
|
|
for mapping in maps.keys():
|
|
|
|
for x in range(size):
|
|
|
|
buf[x] = 0
|
|
|
|
fbuf = framebuf.FrameBuffer(buf, w, h, mapping)
|
|
|
|
print(maps[mapping])
|
|
|
|
# access as buffer
|
|
|
|
print(memoryview(fbuf)[0])
|
|
|
|
|
|
|
|
# fill
|
|
|
|
fbuf.fill(1)
|
|
|
|
print(buf)
|
|
|
|
fbuf.fill(0)
|
|
|
|
print(buf)
|
|
|
|
|
|
|
|
# put pixel
|
|
|
|
fbuf.pixel(0, 0, 1)
|
|
|
|
fbuf.pixel(4, 0, 1)
|
|
|
|
fbuf.pixel(0, 15, 1)
|
|
|
|
fbuf.pixel(4, 15, 1)
|
|
|
|
print(buf)
|
|
|
|
|
|
|
|
# clear pixel
|
|
|
|
fbuf.pixel(4, 15, 0)
|
|
|
|
print(buf)
|
|
|
|
|
|
|
|
# get pixel
|
|
|
|
print(fbuf.pixel(0, 0), fbuf.pixel(1, 1))
|
|
|
|
|
|
|
|
# hline
|
|
|
|
fbuf.fill(0)
|
|
|
|
fbuf.hline(0, 1, w, 1)
|
2020-03-23 02:26:08 +00:00
|
|
|
print("hline", buf)
|
2017-02-06 10:59:44 +00:00
|
|
|
|
|
|
|
# vline
|
|
|
|
fbuf.fill(0)
|
|
|
|
fbuf.vline(1, 0, h, 1)
|
2020-03-23 02:26:08 +00:00
|
|
|
print("vline", buf)
|
2017-02-06 10:59:44 +00:00
|
|
|
|
|
|
|
# rect
|
|
|
|
fbuf.fill(0)
|
|
|
|
fbuf.rect(1, 1, 3, 3, 1)
|
2020-03-23 02:26:08 +00:00
|
|
|
print("rect", buf)
|
2017-02-06 10:59:44 +00:00
|
|
|
|
2020-03-23 02:26:08 +00:00
|
|
|
# fill rect
|
2017-02-06 10:59:44 +00:00
|
|
|
fbuf.fill(0)
|
2020-03-23 02:26:08 +00:00
|
|
|
fbuf.fill_rect(0, 0, 0, 3, 1) # zero width, no-operation
|
2017-02-06 10:59:44 +00:00
|
|
|
fbuf.fill_rect(1, 1, 3, 3, 1)
|
2020-03-23 02:26:08 +00:00
|
|
|
print("fill_rect", buf)
|
2017-02-06 10:59:44 +00:00
|
|
|
|
|
|
|
# line
|
|
|
|
fbuf.fill(0)
|
|
|
|
fbuf.line(1, 1, 3, 3, 1)
|
2020-03-23 02:26:08 +00:00
|
|
|
print("line", buf)
|
2017-02-06 10:59:44 +00:00
|
|
|
|
|
|
|
# line steep negative gradient
|
|
|
|
fbuf.fill(0)
|
|
|
|
fbuf.line(3, 3, 2, 1, 1)
|
2020-03-23 02:26:08 +00:00
|
|
|
print("line", buf)
|
2017-02-06 10:59:44 +00:00
|
|
|
|
|
|
|
# scroll
|
|
|
|
fbuf.fill(0)
|
|
|
|
fbuf.pixel(2, 7, 1)
|
|
|
|
fbuf.scroll(0, 1)
|
|
|
|
print(buf)
|
|
|
|
fbuf.scroll(0, -2)
|
|
|
|
print(buf)
|
|
|
|
fbuf.scroll(1, 0)
|
|
|
|
print(buf)
|
|
|
|
fbuf.scroll(-1, 0)
|
|
|
|
print(buf)
|
|
|
|
fbuf.scroll(2, 2)
|
|
|
|
print(buf)
|
|
|
|
|
|
|
|
# print text
|
|
|
|
fbuf.fill(0)
|
|
|
|
fbuf.text("hello", 0, 0, 1)
|
|
|
|
print(buf)
|
2020-03-23 02:26:08 +00:00
|
|
|
fbuf.text("hello", 0, 0, 0) # clear
|
2017-02-06 10:59:44 +00:00
|
|
|
print(buf)
|
|
|
|
|
|
|
|
# char out of font range set to chr(127)
|
|
|
|
fbuf.text(str(chr(31)), 0, 0)
|
|
|
|
print(buf)
|
|
|
|
print()
|
2016-12-01 04:51:16 +00:00
|
|
|
|
2017-01-25 12:23:50 +00:00
|
|
|
# test invalid constructor, and stride argument
|
2016-12-13 04:47:58 +00:00
|
|
|
try:
|
2017-01-25 12:23:50 +00:00
|
|
|
fbuf = framebuf.FrameBuffer(buf, w, h, -1, w)
|
2016-12-13 04:47:58 +00:00
|
|
|
except ValueError:
|
2017-01-25 12:23:50 +00:00
|
|
|
print("ValueError")
|
2016-12-13 04:47:58 +00:00
|
|
|
|
2016-12-01 04:51:16 +00:00
|
|
|
# test legacy constructor
|
|
|
|
fbuf = framebuf.FrameBuffer1(buf, w, h)
|
|
|
|
fbuf = framebuf.FrameBuffer1(buf, w, h, w)
|
2017-04-01 07:00:09 +01:00
|
|
|
print(framebuf.MVLSB == framebuf.MONO_VLSB)
|