WIP Terminal interface with commands

This commit is contained in:
Daniele Verducci (ZenPenguin) 2021-01-02 07:56:11 +01:00
parent 4d9fd83cdd
commit ff4823b3ad
2 changed files with 21 additions and 11 deletions

View File

@ -41,9 +41,10 @@ void setup() {
}
void loop() {
if (Serial.available() > 0) {
if (Serial.available() > 1) {
switch (Serial.read()) {
case COMMAND_WRITE:
while (Serial.available() < 1) {} // Waits for the second byte
incomingBuffer = Serial.read();
availableBytes = 1; // TODO: Implement a 256 byte buffer and store the avail bytes number in this var
break;

View File

@ -31,7 +31,6 @@ import os
class TerminalEmulator:
SYNC_SLEEP = 0.001
def __init__(self, w, ser):
w.clear()
@ -48,8 +47,7 @@ class TerminalEmulator:
key = w.getch()
if key == 10 or (key > 31 and key < 256):
# Is a character
time.sleep(self.SYNC_SLEEP)
ser.write(bytes([key]))
self.sendByte(bytes([key]))
elif int(key) == 1: # CTRL+A, enter ADB mode
# Save cursor position
(xPos, yPos) = w.getyx()
@ -82,18 +80,15 @@ class TerminalEmulator:
w.refresh()
# Send the two heading bytes (most significant first)
ser.write(header[0:1])
time.sleep(self.SYNC_SLEEP)
ser.write(header[1:2])
time.sleep(self.SYNC_SLEEP)
self.sendByte(header[0:1])
self.sendByte(header[1:2])
# Send the actual binary stream
with open(path, "rb") as f:
byte = f.read(1)
while byte:
ser.write(byte)
self.sendByte(byte)
byte = f.read(1)
time.sleep(self.SYNC_SLEEP)
except IOError as e:
w.move(0,0)
w.clrtoeol()
@ -102,7 +97,21 @@ class TerminalEmulator:
curses.noecho()
stdscr.nodelay(True)
# Sends a byte checking if the interface is busy
def sendByte(self, b):
busy = True
while busy:
# check if busy
ser.write(b'\x01') # send COMMAND_BUFFER
while not ser.inWaiting():
# wait for answer from interface
pass
busy = ser.read() != 0
# interface is free: write byte
ser.write(b'\x00') # send COMMAND_WRITE
ser.write(b) # send byte
if __name__ == '__main__':
import argparse