Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Ron Evans <ron@hybridgroup.com>
- Loading branch information
1 parent
bcf441c
commit 4c8a725
Showing
3 changed files
with
166 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// This is a echo console running on the device UART. | ||
// Connect using default baudrate for this hardware, 8-N-1 with your terminal program. | ||
package main | ||
|
||
import ( | ||
"machine" | ||
"time" | ||
) | ||
|
||
func main() { | ||
machine.UART0.Configure(machine.UARTConfig{}) | ||
machine.UART0.Write([]byte("Echo console enabled. Type something then press enter:\r\n")) | ||
|
||
input := make([]byte, 64) | ||
i := 0 | ||
for { | ||
if machine.UART0.Buffered() > 0 { | ||
data, _ := machine.UART0.ReadByte() | ||
|
||
switch data { | ||
case 13: | ||
// return key | ||
machine.UART0.Write([]byte("\r\n")) | ||
machine.UART0.Write([]byte("You typed: ")) | ||
machine.UART0.Write(input[:i]) | ||
machine.UART0.Write([]byte("\r\n")) | ||
i = 0 | ||
default: | ||
// just echo the character | ||
machine.UART0.WriteByte(data) | ||
input[i] = data | ||
i++ | ||
} | ||
} | ||
time.Sleep(10 * time.Millisecond) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters