forked from wasp-os/wasp-os
-
Notifications
You must be signed in to change notification settings - Fork 0
/
corona.py
180 lines (157 loc) · 6.9 KB
/
corona.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
import wasp
import gc
import micropython
from micropython import const
CHUNK_SIZE = const(64)
# 2-bit RLE, 96x64, generated from virus.png, 1494 bytes
VIRUS_ICON = (
b'\x02'
b'`@'
b'.@\x85AAAA?\x1bAACAAA?'
b'\x18AAFA\x80\xd2\x81?\x17AHA?\x16A'
b'AHA?\x16AIA?\x16\x81AHA?\x17'
b'AGAA?\x08\xc08\xc1\xc1\xc1\xc1\xc1@\\A'
b'\t\x80\x86\x81\xc0\x85\xc1\xc5\xc1\xc1?\x08@8AA'
b'DA\x80\\\x81\t\xc1\xc5\xc1?\x08\x81GA\x81\x08'
b'\xc1\xc4\xc1\x07\xc0\xff\xc1@1AAAA;\x81\x80'
b'8\x81\x88\xc0\\\xc1\x08@\x80A\x80\x85\x81\x83\x81\x06'
b'\xc01\xc1\xc1\xc4\xc1@7A9\x808\x81\x89\x81\t'
b'\xc0\x85\xc1\xc2\xc1@\x86A\x05\x801\x81\x81\x86\x81\xc0'
b'7\xc18@\\A\x808\x89\x81\t\xc0\x85\xc1\xc2\xc1'
b'\x06@1AHA8\x80\x1e\x81\xc0\\\xc1@8H'
b'A\t\x80\xe1\x81\xc0\x85\xc1\xc1\xc1@\x86A\x04\x801'
b'\x81\x81\x88\x819\xc08\xc1\xc8\xc1\n@\x85ABA'
b'\x04\x81\x89\x819\x80\x1e\x81\xc1\xc7\xc0\\\xc1\tAA'
b'BA\x04@7A\x801\x81\x88\x81;\xc08\xc1\xc1'
b'\xc6\xc1\x06@=A\x80\\\x81\xc0a\xc1@\x85CA'
b'\x81\x808\x81\xc0=\xc1\x02@1AGA\x807\x81'
b'<\xc0b\xc1@\\A\x808\x81\x84\x81A\x03A\x81'
b'\x81\xc1\xc0\x85\xc5@bA\x81\x81\x81\x807\x81\xc01'
b'\xc1\xc6\xc1\xc1?\x00@\\A\x808\x81\x84A\x81\x81'
b'A\x81\x82A\xc0a\xc1@\x85AAA\x80b\x81\xc0'
b'\\\xc1@8CA\x807\x81\x81\xc01\xc3\xc1\xc1\xc1'
b'?\x02AAD@\\A\x808\x81\x86AA\x88\x81'
b'\xc07\xc1@1A\xc1\xc1?\x05\x81\x81\x96\x81\x81?'
b'\x08\x81\x88\x80b\x81\x81\xc0\xde\xc1\x81@\\A\x808'
b'\x8a\x81A\tA\x81A\x819\xc0\xdb\xc1\x81\x85A@'
b'\x87A\x80\xee\x81\x83\x81\xc0b\xc1@8J\x80\\\x81'
b'\xc0=\xc1\x07AACA\x818AE@\x87A\x80'
b'\xee\x86\x81\xc0b\xc1@8JA\x06\x80\\\x81AE'
b'A(\xc01\xc1\xc1\xc1\xc1\xc1\xc1\t@7A\x808'
b'\x81\x84\xc0b\xc1@\xeeAGA\x80\\\x81\xc08\xc9'
b"\xc1\x81\x04\xc1\xc1\xc6\xc1'@7A\x801\x81\x84\x81"
b'\x81\x01\x06\x81A\xc5\xc0\xde\xc1@\xeeI\x80b\x81\xc0'
b"8\xca@\\AA\xc1\xc1A\xc1\xc7\xc1'\x801\x81"
b'\x87\x81\x81\x81\xc07\xc1\x81\x81\x81\xc1@8AE\x80'
b"\x86\x81\xc0\xee\xc9@bA\x808\x96\x81\x81'\xc01"
b'\xc1\xce@7A\x86\x80\xde\x81\xc0\xee\xc9@bA\x80'
b'8\x95\x81\x81(\xc01\xc1\xce@7A\x86\x80\\\x81'
b'\xc0\xee\xc1\xc7@\x87A\x808\x8d\xc0\\\xc1\xc1\xc1@'
b'=A\x01\xc1\xc1\x81\xc1\xc1)\x801\x81\x81\x86\x81\x81'
b'\x81\x84\xc07\xc1@8G\x80b\x81\xc0\xee\xc1\xc5\xc1'
b'\x81LA4@1AAAAAA\x807\x81\x02'
b'\xc0\xff\xc1AAAA\x81@8H\x80b\x81\xc0\x87'
b'\xc1@\xeeAAA\xc1\x81\x808\x8d\x816\xc07\xc1'
b'@1A\x08\xc1A\xc1\x8a\x80\\\x81\x81\xc08\xd0\xc1'
b'?\x02@7AA\xdc\xc1?\x03A\xc7\x80b\x81\xc0'
b'\x87\xc1\xc1\x81@8E\x81\x81\x81IA?\x03\x807'
b'\x81F\xc0b\xc1@\xfbABA\xc1\x808\x82\xc0\\'
b'\xc1@\x87A\x80\xfa\x81\xc0\xb2\xc2@\xeeA\x80b\x81'
b'\xc08\xc5\x81@\x85AA\x80\x86\x81?\x02\xc1\xc6\xc0'
b'\x87\xc1@\xfbD\x80\xde\x81\xc08\xc2\x81@\xb2E\x80'
b'\x87\x81\xc4\xc0\\\xc1@\x85ABAA\x80\x80\x81\x05'
b'\xc0\x86\xc1A\xc1,@\xdbA\x80\\\x81\xc08\xc1\xc1'
b'\x81\x81\xc1\x03A\x81\xc6@\x87A\x80\xfb\x84\xc0\xde\xc1'
b'@8B\x80\xee\x81\xc0\xb2\xc5\xc1@bA\x808\x83'
b'A\xc0\x85\xc5\xc1\xc1\xc1\xc1\xc1\xc1\xc2\xc1\xc1\xc1)@'
b'=A\x81\x85\x81\x81\x81\x81\x81\x87\x80b\x81\xc0\xb2\xc1'
b'@\xfbB\x80\xee\x81\xc0\\\xc1@8B\x80\xfa\x81\xc0'
b'\xb2\xc6@bA\x808\x83A\xc0\x85\xcf\xc1\xc1(\x81'
b'\x93@\\A\x80\xde\x81\xc0b\xc1A@8C\x80\xee'
b'\x81\xc0\xb2\xc5@\xfaA\x80\\\x81\xc08\xc3\x81@b'
b'A\x80\x85\x81\x81\x81\x8c\x81\x81&\xc0\xdb\xc1@8A'
b'KAAAAK\x80b\x81\xc0\xfa\xc1@\xb2D\x80'
b'\xde\x81\xc08\xc4\xc1@\\A\x03\x80\x85\x81\x81\x8b\x81'
b'&\xc1\xcb\xc1\xc1\x02\xc07\xc1@8AK\x80b\x81'
b'\xc0\xee\xc1@\xfaA\xc1\x80\xde\x81\xc08\xc4\xc1@7'
b'A\x05\x80\x85\x81\x81\x8a\x81&\xc1\xc1\xc9\xc1\xc1\x04A'
b"\xc1\xd2\xc1A\xc01\xc1\x06\x81\x81\x89\x81'@\\A"
b'\x808\x88\x81\x06\xc1\xc07\xc1\x81\x90\x81\xc1@1A'
b"A\x07\x80\x85\x81\x81\x88\x81'\xc08\xc1\xc1\xc6\xc1\xc1"
b'\x06\x01A@7AA\xc6\x80\\\x81\x81\xc0b\xc1\x81'
b'@8D\x807\x81\x81\xc01\xc2\xc1\x08@\x85AG'
b'A\x80\x86\x81(\xc0\\\xc1@8ADA\x80=\x81'
b'\x07\xc01\xc1\xc3@7AA\x808\x81\x82\xc0b\xc1'
b'@\x85AC\xc1\x81\x81\x807\x81\xc01\xc1\xc3\xc1\t'
b'AADAA*@8A\x80\\\x81AAA\xc0'
b'\x1e\xc1\x08@1ABAA\x807\x81\xc0\\\xc1@'
b'8AA\x80a\x81\xc0\x85\xc4\x81A\x02@1AC'
b'AAA\x08\xc1\xc1\xc1\xc1\xc1\xc18AAAA\x80'
b'7\x81\x05\xc0\x86\xc1@\x85ACA\x03\x801\x81\x86'
b'\x81\xc07\xc1?\x03\x81\x81\x83\x81\x07ACA\x03\x81'
b'\x87\x81\x81>\x81\x81\x81\x84\x81\x08AABA\x03\x81'
b'\x88\x81>\x81\x86\x81\tABA\x03\x81\x88\x81\x81<'
b'\x81\x87\x81\tABA\x03\x81\x89\xc1<\x81\x86\x81\t'
b'AACA\x02\x81\x88\x81@\x12A<\xc1\x81\x85\x81'
b'\x08\x80\x85\x81\x81\x84\x81\x02\xc01\xc1\xc8\xc1>\xc1\xc4'
b'\xc1@7A\x06\x81\x81\x81\x85\x81\x03\xc1\xc6\xc1\xc1?'
b'\x00\xc1\xc1\xc1\xc1\xc1\x06\x81\x81\x87\x81\x03\x80\xff\x81\xc1'
b'\xc1\xc2\xc1\xc1A?\x0c\xc0\x85\xc1\xc8\xc1\x05@1A'
b'\x807\x81AA?\x0e\xc1\xc8\xc1?\x17\xc1\xc8\xc1?'
b'\x17\xc1\xc8\xc1?\x17\xc1\xc8\xc1?\x17\xc1\xc1\xc6\xc1\xc1'
b'?\x18\xc0\x86\xc1@\x85AABAAA?\x1b\xc1'
b'BA.'
)
class CoronaApp():
NAME = "Corona"
ICON = VIRUS_ICON
def __init__(self):
pass
def foreground(self):
self._draw()
wasp.system.request_tick(1000)
self._brightness = wasp.system.brightness
wasp.system.brightness = 3
def background(self):
wasp.system.brightness = self._brightness
def tick(self, ticks):
wasp.system.keep_awake()
def rleblit_file(self, path, pos, sx, sy, fg=0xffff, bg=0):
display = wasp.watch.drawable._display
write_data = display.write_data
with open(path, 'rb') as f:
display.set_window(pos[0], pos[1], sx, sy)
buf = display.linebuffer[0:2*sx]
bp = 0
color = bg
chunk = f.read(CHUNK_SIZE)
while len(chunk) != 0:
for rl in chunk:
while rl:
count = min(sx - bp, rl)
self._fill(buf, color, count, bp)
bp += count
rl -= count
if bp >= sx:
write_data(buf)
bp = 0
if color == bg:
color = fg
else:
color = bg
chunk = f.read(CHUNK_SIZE)
@micropython.viper
def _fill(self, mv, color: int, count: int, offset: int):
p = ptr16(mv)
color = (color >> 8) + ((color & 0xff) << 8)
for x in range(offset, offset+count):
p[x] = color
def _draw(self):
draw = wasp.watch.drawable
draw.set_color(0x0000, bg=0xffff)
draw.fill()
draw.set_color(0x0000, bg=0xffff)
try:
self.rleblit_file('/flash/certificate.bin', (20,20), 200, 197, fg=0, bg=0xffff)
except OSError:
draw.string("Error", 0, 108, width=240)