From 52a86cc8a1706378138acb95ab5ec3d530ce706c Mon Sep 17 00:00:00 2001 From: Terence Boldt Date: Thu, 24 Dec 2020 09:01:46 -0500 Subject: [PATCH] Fix command execution (this is being committed from my Apple //e) --- RaspberryPi/Driver.go | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/RaspberryPi/Driver.go b/RaspberryPi/Driver.go index e351877..ea2123c 100644 --- a/RaspberryPi/Driver.go +++ b/RaspberryPi/Driver.go @@ -9,6 +9,7 @@ import ( "periph.io/x/periph/conn/gpio" "periph.io/x/periph/conn/gpio/gpioreg" "periph.io/x/periph/host" + "strings" "time" ) @@ -124,7 +125,8 @@ func handleExecCommand() { return } fmt.Printf("Command output: %s\n", cmdOut) - err = writeString(string(cmdOut)) + apple2string := strings.Replace(string(cmdOut), "\n", "\r", -1) + err = writeString(apple2string) if err != nil { fmt.Printf("Failed to send command output\n") return @@ -219,14 +221,15 @@ func dumpBlock(buffer []byte) { } func readString() (string, error) { - inByte := byte(255) var inBytes bytes.Buffer - var err error - for inByte != 0 { - inByte,err = readByte() + for { + inByte,err := readByte() if err != nil { return "", err } + if inByte == 0 { + break + } inBytes.WriteByte(inByte) } return string(inBytes.Bytes()), nil @@ -234,7 +237,6 @@ func readString() (string, error) { func writeString(outString string) error { for _, character := range outString { - fmt.Printf("Out: %s\n", character); err := writeByte(byte(character)|128) if err != nil { fmt.Printf("Failed to write string\n")