Fix keyboard delay (#152)

This commit is contained in:
Terence Boldt 2023-11-01 20:00:21 -04:00 committed by GitHub
parent 6edd7ecf11
commit bde5767314
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 14 additions and 9 deletions

View File

@ -49,6 +49,7 @@ body:
label: Driver Version
description: What version of the driver are you running? Check with `RPI a2version`
options:
- 002B (fix keyboard delay)
- 002A (reduce CPU usage)
- 0029 (fix hang after shell exit)
- 0028 (add live drive loading and regeneration)

View File

@ -15,7 +15,7 @@ type A2Io interface {
WriteString(outString string) error
WriteBlock(buffer []byte) error
WriteBuffer(buffer []byte) error
ReadByte() (byte, error)
ReadByte(noDelay ...bool) (byte, error)
ReadString() (string, error)
ReadBlock(buffer []byte) error
SendCharacter(character byte)

View File

@ -154,7 +154,7 @@ func (a2 A2Gpio) WriteString(outString string) error {
}
// ReadByte reads a byte from the Apple II via Raspberry Pi's GPIO ports
func (a2 A2Gpio) ReadByte() (byte, error) {
func (a2 A2Gpio) ReadByte(noDelay ...bool) (byte, error) {
// let the Apple II know we are ready to read
outRead.Low()
@ -168,7 +168,9 @@ func (a2 A2Gpio) ReadByte() (byte, error) {
return 0, errors.New("timed out reading byte -- write stuck high")
}
if time.Since(lastSleepTime) > edgeTimeout/10 {
sleepDuration *= 3;
if len(noDelay) == 0 || !noDelay[0] {
sleepDuration *= 3;
}
time.Sleep(time.Millisecond * time.Duration(sleepDuration));
lastSleepTime = time.Now()
}
@ -225,7 +227,9 @@ func (a2 A2Gpio) ReadByte() (byte, error) {
return 0, errors.New("timed out reading byte -- write stuck low")
}
if time.Since(lastSleepTime) > edgeTimeout/10 {
sleepDuration *= 3;
if len(noDelay) == 0 || !noDelay[0] {
sleepDuration *= 3;
}
time.Sleep(time.Millisecond * time.Duration(sleepDuration));
lastSleepTime = time.Now()
}

View File

@ -66,7 +66,7 @@ func (mockIo MockIo) WriteBuffer(buffer []byte) error {
}
// ReadByte mocks reading a byte from the Apple II
func (mockIo MockIo) ReadByte() (byte, error) {
func (mockIo MockIo) ReadByte(noDelay ...bool) (byte, error) {
b := mockIo.Data.BytesToRead[mockIo.Data.NumberBytesRead]
mockIo.Data.NumberBytesRead++
return b, mockIo.Data.ErrorToThrow

View File

@ -55,7 +55,7 @@ func (userIo UserIo) WriteBuffer(buffer []byte) error {
}
// ReadByte simulates reading to the Apple II but uses stdin instead
func (userIo UserIo) ReadByte() (byte, error) {
func (userIo UserIo) ReadByte(noDelay ...bool) (byte, error) {
fmt.Printf("ReadByte: ")
var b byte
fmt.Scanf("%x", &b)

View File

@ -220,7 +220,7 @@ func sendCharacter(comm A2Io, b byte) {
}
func readCharacter(comm A2Io) (string, error) {
b, err := comm.ReadByte()
b, err := comm.ReadByte(true)
var s = string(b)
if err == nil {
if applicationMode {

View File

@ -75,7 +75,7 @@ func main() {
}
// temporary workaround for busy wait loop heating up the RPi
} else {
time.Sleep(time.Millisecond * 100)
time.Sleep(time.Millisecond * 200)
}
}
}

View File

@ -8,4 +8,4 @@ package info
// Version is the hexadecimal version number that
// should be incremented with each driver update
const Version = "002A"
const Version = "002B"