-
Notifications
You must be signed in to change notification settings - Fork 6
/
bpv.py
72 lines (67 loc) · 1.83 KB
/
bpv.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
import ujson as json
import ubinascii
import time
import framebuf
import gc
def showN(nu,display,x=86,y=64,sx=0,sy=0):
data=bytearray(nu)
fbuf = framebuf.FrameBuffer(data,x,y,framebuf.MONO_HLSB)
display.blit(fbuf,sx,sy)
display.show()
gc.collect()
def pbm(files,oled,sx=0,sy=0,fills=True):
if fills:
oled.fill(0)
with open(files,"rb") as f:
f.readline()
x,y=f.readline().decode("utf8").split()
showN(f.read(),oled,int(x),int(y),sx,sy)
def play(files,display,sx=0,sy=0,qt=1):
f=open(files,"rb")
inf=f.readline()
info=inf.decode()
try:
x,y,times,fps=json.loads(info)
except Exception as e:
print("Wrong File")
return False
# ce=time.ticks_ms()
for i in range(times*fps):
t=time.ticks_ms()
c=f.readline()
q=ubinascii.a2b_base64(c)
showN(q,display,x,y,sx,sy)
if i%10:
time.sleep_ms(round(1000/fps)-time.ticks_ms()+t)
else:
time.sleep_ms(round(1000/fps)-time.ticks_ms()+t-qt)
# print(time.ticks_ms()-ce)
display.fill(0)
display.show()
return 'fin'
def plays(files,display,sx=0,sy=0,qt=0):
f=open(files,"rb")
inf=f.readline()
info=inf.decode()
try:
x,y,times,fps=json.loads(info)
except Exception as e:
print("Wrong File")
return False
ce=time.ticks_ms()
for i in range(times*fps):
t=time.ticks_ms()
c=f.readline()
q=ubinascii.a2b_base64(c)
showN(q,display,x,y,sx,sy)
if i%10:
time.sleep_ms(round(1000/fps)-time.ticks_ms()+t)
else:
time.sleep_ms(round(1000/fps)-time.ticks_ms()+t-qt)
rec=time.ticks_ms()-ce
print(rec)
rex=(times*1000-rec)*10/(fps*times)
print("QT:",rex)
display.fill(0)
display.show()
return 'fin'