Fixed LED state watcher to consider unknown initial state

This commit is contained in:
mame82 2018-06-07 08:36:23 +00:00
parent 4116893913
commit 055cb4e254
2 changed files with 20 additions and 2 deletions

View File

@ -32,6 +32,7 @@ type HIDKeyboardLEDStateWatcher struct {
listeners *listenersmap
listenerNonZeroCondLock *sync.Mutex
listenerNonZeroCond *sync.Cond
hasInitialSate bool
}
type listenersmap struct {
@ -149,6 +150,25 @@ func (watcher *HIDKeyboardLEDStateWatcher) dispatchListeners(state byte) {
hasChanged = true
}
if !watcher.hasInitialSate {
//This is the first led state reported, so former state is undefined and we consider everything as a change
watcher.ledState.NumLock = nNum
watcher.ledState.CapsLock = nCaps
watcher.ledState.ScrollLock = nScroll
watcher.ledState.Compose = nCompose
watcher.ledState.Kana = nKana
ledsChanged.NumLock = true
ledsChanged.CapsLock = true
ledsChanged.ScrollLock = true
ledsChanged.Compose = true
ledsChanged.Kana = true
hasChanged = true
watcher.hasInitialSate = true //don't do this again
}
//check if we have listeners ready to remove
rmList := make([]*HIDKeyboardLEDListener,0)
for l,_ := range watcher.listeners.m {

View File

@ -80,8 +80,6 @@ func main() {
}
//keyboard, err := hid.NewKeyboard("/dev/hidg0", "keymaps")
if err != nil { fmt.Println(err)}
hidCtl.Keyboard.KeyDelay = 100
// hidCtl.Keyboard.KeyDelayJitter = 200
fmt.Printf("Available language maps:\n%v\n",hidCtl.Keyboard.ListLanguageMapNames())