WIP Terminal interface with commands
This commit is contained in:
parent
4d9fd83cdd
commit
ff4823b3ad
@ -41,9 +41,10 @@ void setup() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void loop() {
|
void loop() {
|
||||||
if (Serial.available() > 0) {
|
if (Serial.available() > 1) {
|
||||||
switch (Serial.read()) {
|
switch (Serial.read()) {
|
||||||
case COMMAND_WRITE:
|
case COMMAND_WRITE:
|
||||||
|
while (Serial.available() < 1) {} // Waits for the second byte
|
||||||
incomingBuffer = Serial.read();
|
incomingBuffer = Serial.read();
|
||||||
availableBytes = 1; // TODO: Implement a 256 byte buffer and store the avail bytes number in this var
|
availableBytes = 1; // TODO: Implement a 256 byte buffer and store the avail bytes number in this var
|
||||||
break;
|
break;
|
||||||
|
@ -31,7 +31,6 @@ import os
|
|||||||
|
|
||||||
|
|
||||||
class TerminalEmulator:
|
class TerminalEmulator:
|
||||||
SYNC_SLEEP = 0.001
|
|
||||||
|
|
||||||
def __init__(self, w, ser):
|
def __init__(self, w, ser):
|
||||||
w.clear()
|
w.clear()
|
||||||
@ -48,8 +47,7 @@ class TerminalEmulator:
|
|||||||
key = w.getch()
|
key = w.getch()
|
||||||
if key == 10 or (key > 31 and key < 256):
|
if key == 10 or (key > 31 and key < 256):
|
||||||
# Is a character
|
# Is a character
|
||||||
time.sleep(self.SYNC_SLEEP)
|
self.sendByte(bytes([key]))
|
||||||
ser.write(bytes([key]))
|
|
||||||
elif int(key) == 1: # CTRL+A, enter ADB mode
|
elif int(key) == 1: # CTRL+A, enter ADB mode
|
||||||
# Save cursor position
|
# Save cursor position
|
||||||
(xPos, yPos) = w.getyx()
|
(xPos, yPos) = w.getyx()
|
||||||
@ -82,18 +80,15 @@ class TerminalEmulator:
|
|||||||
w.refresh()
|
w.refresh()
|
||||||
|
|
||||||
# Send the two heading bytes (most significant first)
|
# Send the two heading bytes (most significant first)
|
||||||
ser.write(header[0:1])
|
self.sendByte(header[0:1])
|
||||||
time.sleep(self.SYNC_SLEEP)
|
self.sendByte(header[1:2])
|
||||||
ser.write(header[1:2])
|
|
||||||
time.sleep(self.SYNC_SLEEP)
|
|
||||||
|
|
||||||
# Send the actual binary stream
|
# Send the actual binary stream
|
||||||
with open(path, "rb") as f:
|
with open(path, "rb") as f:
|
||||||
byte = f.read(1)
|
byte = f.read(1)
|
||||||
while byte:
|
while byte:
|
||||||
ser.write(byte)
|
self.sendByte(byte)
|
||||||
byte = f.read(1)
|
byte = f.read(1)
|
||||||
time.sleep(self.SYNC_SLEEP)
|
|
||||||
except IOError as e:
|
except IOError as e:
|
||||||
w.move(0,0)
|
w.move(0,0)
|
||||||
w.clrtoeol()
|
w.clrtoeol()
|
||||||
@ -102,7 +97,21 @@ class TerminalEmulator:
|
|||||||
|
|
||||||
curses.noecho()
|
curses.noecho()
|
||||||
stdscr.nodelay(True)
|
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__':
|
if __name__ == '__main__':
|
||||||
import argparse
|
import argparse
|
||||||
|
Loading…
Reference in New Issue
Block a user