2014-01-16 17:07:08 +00:00
|
|
|
# pyboard testing functions for CPython
|
|
|
|
import time
|
|
|
|
|
2020-02-27 04:36:53 +00:00
|
|
|
|
2014-01-07 17:14:05 +00:00
|
|
|
def delay(n):
|
2020-02-27 04:36:53 +00:00
|
|
|
# time.sleep(float(n) / 1000)
|
2014-01-24 22:26:13 +00:00
|
|
|
pass
|
2014-01-07 17:14:05 +00:00
|
|
|
|
2020-02-27 04:36:53 +00:00
|
|
|
|
2014-01-07 17:14:05 +00:00
|
|
|
rand_seed = 1
|
2020-02-27 04:36:53 +00:00
|
|
|
|
|
|
|
|
2014-10-19 19:02:34 +01:00
|
|
|
def rng():
|
2014-01-07 17:14:05 +00:00
|
|
|
global rand_seed
|
|
|
|
# for these choice of numbers, see P L'Ecuyer, "Tables of linear congruential generators of different sizes and good lattice structure"
|
|
|
|
rand_seed = (rand_seed * 653276) % 8388593
|
|
|
|
return rand_seed
|
2014-10-19 19:02:34 +01:00
|
|
|
|
2020-02-27 04:36:53 +00:00
|
|
|
|
2014-10-19 19:02:34 +01:00
|
|
|
# LCD testing object for PC
|
|
|
|
# uses double buffering
|
|
|
|
class LCD:
|
|
|
|
def __init__(self, port):
|
|
|
|
self.width = 128
|
|
|
|
self.height = 32
|
|
|
|
self.buf1 = [[0 for x in range(self.width)] for y in range(self.height)]
|
|
|
|
self.buf2 = [[0 for x in range(self.width)] for y in range(self.height)]
|
|
|
|
|
|
|
|
def light(self, value):
|
|
|
|
pass
|
|
|
|
|
|
|
|
def fill(self, value):
|
|
|
|
for y in range(self.height):
|
|
|
|
for x in range(self.width):
|
|
|
|
self.buf1[y][x] = self.buf2[y][x] = value
|
|
|
|
|
|
|
|
def show(self):
|
2020-02-27 04:36:53 +00:00
|
|
|
print("") # blank line to separate frames
|
2014-10-19 19:02:34 +01:00
|
|
|
for y in range(self.height):
|
|
|
|
for x in range(self.width):
|
|
|
|
self.buf1[y][x] = self.buf2[y][x]
|
|
|
|
for y in range(self.height):
|
2020-02-27 04:36:53 +00:00
|
|
|
row = "".join(["*" if self.buf1[y][x] else " " for x in range(self.width)])
|
2014-10-19 19:02:34 +01:00
|
|
|
print(row)
|
|
|
|
|
|
|
|
def get(self, x, y):
|
|
|
|
if 0 <= x < self.width and 0 <= y < self.height:
|
|
|
|
return self.buf1[y][x]
|
|
|
|
else:
|
|
|
|
return 0
|
|
|
|
|
|
|
|
def pixel(self, x, y, value):
|
|
|
|
if 0 <= x < self.width and 0 <= y < self.height:
|
|
|
|
self.buf2[y][x] = value
|