Skip to content

Commit

Permalink
Added AutoRepeat for USB Keyboard for Some Selected Functions
Browse files Browse the repository at this point in the history
  • Loading branch information
talkkonnect committed Feb 15, 2022
1 parent 6421708 commit a9402bd
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 73 deletions.
172 changes: 102 additions & 70 deletions usbkeyboard.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ func (b *Talkkonnect) USBKeyboard() {
return
}

var keyPrevStateDown bool

for {
events, err := device.Read()
if err != nil {
Expand All @@ -58,81 +60,111 @@ func (b *Talkkonnect) USBKeyboard() {
case evdev.EV_KEY:
ke := evdev.NewKeyEvent(&ev)

if ke.State != evdev.KeyDown {
continue
if ke.State == evdev.KeyDown {
keyPrevStateDown = true
}

if _, ok := USBKeyMap[rune(ke.Scancode)]; ok {
switch strings.ToLower(USBKeyMap[rune(ke.Scancode)].Command) {
case "channelup":
playIOMedia("usbchannelup")
b.cmdChannelUp()
case "channeldown":
playIOMedia("usbchanneldown")
b.cmdChannelDown()
case "serverup":
playIOMedia("usbserverup")
b.cmdConnNextServer()
case "serverdown":
playIOMedia("usbpreviousserver")
b.cmdConnPreviousServer()
case "mute":
playIOMedia("usbmute")
b.cmdMuteUnmute("mute")
case "unmute":
b.cmdMuteUnmute("unmute")
playIOMedia("usbunmute")
case "mute-toggle":
playIOMedia("usbmutetoggle")
b.cmdMuteUnmute("toggle")
playIOMedia("usbmutetoggle")
case "stream-toggle":
playIOMedia("usbstreamtoggle")
b.cmdPlayback()
case "volumeup":
playIOMedia("usbvolup")
b.cmdVolumeUp()
case "volumedown":
playIOMedia("usbvoldown")
b.cmdVolumeDown()
case "setcomment":
if USBKeyMap[rune(ke.Scancode)].ParamName == "setcomment" {
log.Println("info: Set Commment ", USBKeyMap[rune(ke.Scancode)].ParamValue)
playIOMedia("usbsetcomment")
b.Client.Self.SetComment(USBKeyMap[rune(ke.Scancode)].ParamValue)
// Functions that we allow Repeating Keys Defined Here
if ke.State == evdev.KeyHold {
keyPrevStateDown = false
if _, ok := USBKeyMap[rune(ke.Scancode)]; ok {
switch strings.ToLower(USBKeyMap[rune(ke.Scancode)].Command) {
case "channelup":
playIOMedia("usbchannelup")
b.cmdChannelUp()
case "channeldown":
playIOMedia("usbchanneldown")
b.cmdChannelDown()
case "volumeup":
playIOMedia("usbvolup")
b.cmdVolumeUp()
case "volumedown":
playIOMedia("usbvoldown")
b.cmdVolumeDown()
}
case "transmitstart":
playIOMedia("usbstarttx")
b.cmdStartTransmitting()
case "transmitstop":
playIOMedia("usbstoptx")
b.cmdStopTransmitting()
case "record":
playIOMedia("usbrecord")
b.cmdAudioTrafficRecord()
b.cmdAudioMicRecord()
case "voicetargetset":
voicetarget, err := strconv.Atoi(USBKeyMap[rune(ke.Scancode)].ParamValue)
if err != nil {
log.Println("error: Target is Non-Numeric Value")
} else {
playIOMedia("usbvoicetarget")
b.cmdSendVoiceTargets(uint32(voicetarget))
} else {
if ke.Scancode != uint16(Config.Global.Hardware.USBKeyboard.NumlockScanID) {
log.Println("error: Key Not Mapped ASC ", ke.Scancode)
}
case "mqttpubpayloadset":
if USBKeyMap[rune(ke.Scancode)].ParamName == "payloadvalue" {
playIOMedia("usbmqttpubpayloadset")
MQTTPublish(USBKeyMap[rune(ke.Scancode)].ParamValue)
}
case "repeatertoneplay":
playIOMedia("iorepeatertone")
b.cmdPlayRepeaterTone()
default:
log.Println("error: Command Not Defined ", strings.ToLower(USBKeyMap[rune(ke.Scancode)].Command))
}
} else {
if ke.Scancode != uint16(Config.Global.Hardware.USBKeyboard.NumlockScanID) {
log.Println("error: Key Not Mapped ASC ", ke.Scancode)
continue
}

//Key Up & Down One Shot
if keyPrevStateDown && ke.State == evdev.KeyUp {
keyPrevStateDown = false
if _, ok := USBKeyMap[rune(ke.Scancode)]; ok {
switch strings.ToLower(USBKeyMap[rune(ke.Scancode)].Command) {
case "channelup":
playIOMedia("usbchannelup")
b.cmdChannelUp()
case "channeldown":
playIOMedia("usbchanneldown")
b.cmdChannelDown()
case "serverup":
playIOMedia("usbserverup")
b.cmdConnNextServer()
case "serverdown":
playIOMedia("usbpreviousserver")
b.cmdConnPreviousServer()
case "mute":
playIOMedia("usbmute")
b.cmdMuteUnmute("mute")
case "unmute":
b.cmdMuteUnmute("unmute")
playIOMedia("usbunmute")
case "mute-toggle":
playIOMedia("usbmutetoggle")
b.cmdMuteUnmute("toggle")
playIOMedia("usbmutetoggle")
case "stream-toggle":
playIOMedia("usbstreamtoggle")
b.cmdPlayback()
case "volumeup":
playIOMedia("usbvolup")
b.cmdVolumeUp()
case "volumedown":
playIOMedia("usbvoldown")
b.cmdVolumeDown()
case "setcomment":
if USBKeyMap[rune(ke.Scancode)].ParamName == "setcomment" {
log.Println("info: Set Commment ", USBKeyMap[rune(ke.Scancode)].ParamValue)
playIOMedia("usbsetcomment")
b.Client.Self.SetComment(USBKeyMap[rune(ke.Scancode)].ParamValue)
}
case "transmitstart":
playIOMedia("usbstarttx")
b.cmdStartTransmitting()
case "transmitstop":
playIOMedia("usbstoptx")
b.cmdStopTransmitting()
case "record":
playIOMedia("usbrecord")
b.cmdAudioTrafficRecord()
b.cmdAudioMicRecord()
case "voicetargetset":
voicetarget, err := strconv.Atoi(USBKeyMap[rune(ke.Scancode)].ParamValue)
if err != nil {
log.Println("error: Target is Non-Numeric Value")
} else {
playIOMedia("usbvoicetarget")
b.cmdSendVoiceTargets(uint32(voicetarget))
}
case "mqttpubpayloadset":
if USBKeyMap[rune(ke.Scancode)].ParamName == "payloadvalue" {
playIOMedia("usbmqttpubpayloadset")
MQTTPublish(USBKeyMap[rune(ke.Scancode)].ParamValue)
}
case "repeatertoneplay":
playIOMedia("iorepeatertone")
b.cmdPlayRepeaterTone()
default:
log.Println("error: Command Not Defined ", strings.ToLower(USBKeyMap[rune(ke.Scancode)].Command))
}
} else {
if ke.Scancode != uint16(Config.Global.Hardware.USBKeyboard.NumlockScanID) {
log.Println("error: Key Not Mapped ASC ", ke.Scancode)
}
}
}
}
Expand Down
6 changes: 3 additions & 3 deletions version.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,10 @@
package talkkonnect

const (
talkkonnectVersion string = "2.10.12"
talkkonnectReleased string = "Feb 14 2022"
talkkonnectVersion string = "2.10.13"
talkkonnectReleased string = "Feb 15 2022"
)

/* Release Notes
1. Fixed RXLED Bug for Respeaker bug reported by chaiych maker
1. Added AutoRepeat for USB Keyboard for Some Selected Functions
*/

0 comments on commit a9402bd

Please sign in to comment.