-
Notifications
You must be signed in to change notification settings - Fork 50
/
peteensy.py
55 lines (46 loc) · 1.33 KB
/
peteensy.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
#
# Front-end for Teensy 3.5 and 3.6
#
import sys
class IO_DEVICE:
def __init__(self):
try:
from micropython import kbd_intr
kbd_intr(-1)
except ImportError:
pass
if hasattr(sys.stdin, "buffer"):
self.rd_raw_fct = sys.stdin.buffer.read
else:
self.rd_raw_fct = sys.stdin.read
def wr(self, s):
sys.stdout.write(s)
def rd(self):
return sys.stdin.read(1)
def rd_raw(self):
return self.rd_raw_fct(1)
def deinit_tty(self):
try:
from micropython import kbd_intr
kbd_intr(3)
except ImportError:
pass
def get_screen_size(self):
self.wr('\x1b[999;999H\x1b[6n')
pos = ''
char = self.rd() ## expect ESC[yyy;xxxR
while char != 'R':
pos += char
char = self.rd()
return [int(i, 10) for i in pos.lstrip("\n\x1b[").split(';')]
## test, if the Editor class is already present
if "pye_edit" not in globals().keys():
from pye import pye_edit
def pye(*args, tab_size=4, undo=50):
from pyb import USB_VCP
USB_VCP().setinterrupt(-1)
io_device = IO_DEVICE()
ret = pye_edit(*args, tab_size=tab_size, undo=undo, io_device=io_device)
io_device.deinit_tty()
USB_VCP().setinterrupt(3)
return ret