github.com/holoplot/go-evdev@v0.0.0-20220721205823-d31c64b9d636/names.go (about)

     1  package evdev
     2  
     3  var EvCodeNameLookup = map[EvType]map[EvCode]string{
     4  	EV_SYN: SYNNames,
     5  	EV_KEY: KEYNames,
     6  	EV_REL: RELNames,
     7  	EV_ABS: ABSNames,
     8  	EV_MSC: MSCNames,
     9  	EV_SW:  SWNames,
    10  	EV_LED: LEDNames,
    11  	EV_SND: SNDNames,
    12  	EV_REP: REPNames,
    13  	EV_FF:  FFNames,
    14  	// EV_PWR:
    15  	// EV_FF_STATUS:
    16  }
    17  
    18  // TypeName returns the name of an EvType as string, or "UNKNOWN" if the type is not valid
    19  func TypeName(t EvType) string {
    20  	name, ok := EVToString[t]
    21  	if ok {
    22  		return name
    23  	}
    24  	return "unknown"
    25  }
    26  
    27  // PropName returns the name of the given EvProp, or "UNKNOWN" if the property is not valid
    28  func PropName(p EvProp) string {
    29  	name, ok := INPUTToString[p]
    30  	if ok {
    31  		return name
    32  	}
    33  	return "unknown"
    34  }
    35  
    36  // CodeName returns the name of an EvfCode in the given EvType, or "UNKNOWN" of the code is not valid.
    37  func CodeName(t EvType, c EvCode) string {
    38  	name, ok := EvCodeNameLookup[t][c]
    39  	if !ok {
    40  		return "unknown"
    41  	}
    42  	return name
    43  }