Skip to content

Commit

Permalink
Merge pull request #16 from lucasgpulcinelli/keyboardAtomics
Browse files Browse the repository at this point in the history
change keyboard input to use atomic.Int32
  • Loading branch information
lucasgpulcinelli authored Feb 13, 2024
2 parents 8c5def0 + fa396a4 commit 084411f
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
26 changes: 13 additions & 13 deletions display/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ var (
icmcSimulator *processor.ICMCProcessor // main simulator instance itself
simulatorMutex sync.Mutex // mutex to sync simulator actions

currentKey atomic.Value // current key pressed by the user in ascii
currentKey atomic.Int32 // current key pressed by the user in ascii
instructionPeriod *time.Duration // period between instructions
window fyne.Window // main window instance for the ICMC simulator
)
Expand All @@ -29,8 +29,8 @@ var (
// the current key pressed and null it out to make sure the key for a single
// press is only read once by the processor.
func FyneInChar() (uint8, error) {
ret := currentKey.Swap(uint8(255))
return ret.(uint8), nil
ret := currentKey.Swap(255)
return uint8(ret), nil
}

// setupInput creates hooks for when the user types keys while the simulator
Expand All @@ -42,27 +42,27 @@ func setupInput() {
if icmcSimulator.IsRunning {
switch ev.Name {
case fyne.KeyReturn:
currentKey.Store(uint8('\r'))
currentKey.Store('\r')
case fyne.KeyBackspace:
currentKey.Store(uint8(8))
currentKey.Store(8)
case fyne.KeyDelete:
currentKey.Store(uint8(127))
currentKey.Store(127)
case fyne.KeyEscape:
currentKey.Store(uint8(27))
currentKey.Store(27)
case fyne.KeyUp:
currentKey.Store(uint8(38))
currentKey.Store(38)
case fyne.KeyDown:
currentKey.Store(uint8(40))
currentKey.Store(40)
case fyne.KeyLeft:
currentKey.Store(uint8(37))
currentKey.Store(37)
case fyne.KeyRight:
currentKey.Store(uint8(39))
currentKey.Store(39)
}
}
})
window.Canvas().SetOnTypedRune(func(r rune) {
if icmcSimulator.IsRunning {
currentKey.Store(uint8(r))
currentKey.Store(r)
}
})
}
Expand All @@ -73,7 +73,7 @@ func StartSimulatorWindow(codem, charm io.ReadCloser) {
instructionPeriod = new(time.Duration)

// initializes the first key pressed with 255
currentKey.Store(uint8(255))
currentKey.Store(255)

// create a new processor with out input and output functions
icmcSimulator = processor.NewEmptyProcessor(FyneInChar, draw.FyneOutChar)
Expand Down
2 changes: 1 addition & 1 deletion display/draw/draw.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var (
screen *image.Paletted // the actual image with the simulator output characters
charMIF [128][8]byte // the binary representation of characters: an 8x8 bitfield for each ascii character
viewport *canvas.Image // the fyne component to display screen
shouldDraw atomic.Value // an atomic variable to ease the draw thread but keep it from missing updates
shouldDraw atomic.Int32 // an atomic variable to ease the draw thread but keep it from missing updates
icmcColors = []color.Color{
color.RGBA{0xff, 0xff, 0xff, 0xff},
color.RGBA{0xa5, 0x2a, 0x2a, 0xff},
Expand Down

0 comments on commit 084411f

Please sign in to comment.