Files

56 lines
1.2 KiB
Go

package usb
// Linux input event codes for the keys we care about.
const (
KEY_SLASH = 1 // '/' key
KEY_ASTERISK = 55 // '*' key
KEY_PLUS = 78 // '+' key
KEY_MINUS = 12 // '-' key
)
// KeyToChar maps a Linux scancode to its character/action.
// Returns the character and whether it's a valid input key.
func KeyToChar(code uint16, eventType string) (string, bool) {
if eventType == "release" {
return "", false
}
switch code {
case KEY_SLASH:
return "/", true
case KEY_ASTERISK:
return "*", true
case KEY_PLUS:
return "+", true
case KEY_MINUS:
return "-", true
}
return "", false
}
// ScanToAction maps a Linux scancode to a logical action.
type Action string
const (
ActionScoreRed Action = "red"
ActionScoreGreen Action = "green"
ActionNextRound Action = "next"
ActionReset Action = "reset"
)
// ScanToAction returns the logical action for a given scancode.
func ScanToAction(code uint16) (Action, bool) {
switch code {
case KEY_SLASH:
return ActionScoreRed, true
case KEY_ASTERISK:
return ActionScoreGreen, true
case KEY_PLUS:
return ActionNextRound, true
case KEY_MINUS:
return ActionReset, true
}
return "", false
}