Example #1
0
// listEvents lists the event types supported by the device.
func listEvents(set evdev.Bitset) string {
	var list []string

	for n := 0; n < set.Len(); n++ {
		if !set.Test(n) {
			continue
		}

		switch n {
		case evdev.EvSync:
			list = append(list, "Sync Events")
		case evdev.EvKeys:
			list = append(list, "Keys or Buttons")
		case evdev.EvRelative:
			list = append(list, "Relative Axes")
		case evdev.EvAbsolute:
			list = append(list, "Absolute Axes")
		case evdev.EvMisc:
			list = append(list, "Miscellaneous")
		case evdev.EvLed:
			list = append(list, "LEDs")
		case evdev.EvSound:
			list = append(list, "Sounds")
		case evdev.EvRepeat:
			list = append(list, "Repeat")
		case evdev.EvForceFeedback,
			evdev.EvForceFeedbackStatus:
			list = append(list, "Force Feedback")
		case evdev.EvPower:
			list = append(list, "Power Management")
		case evdev.EvSwitch:
			list = append(list, "Binary switches")
		default:
			list = append(list, fmt.Sprintf("Unknown (0x%02x)", n))
		}
	}

	return strings.Join(list, ", ")
}
Example #2
0
// listState prints the global key/button state, as defined
// in the given bitset.
func listState(set evdev.Bitset) {
	for n := 0; n < set.Len(); n++ {
		// The key is considered pressed if the bitset
		// has its corresponding bit set.
		if !set.Test(n) {
			continue
		}

		fmt.Printf("  Key 0x%02x ", n)

		switch n {
		case evdev.KeyReserved:
			fmt.Printf("Reserved")
		case evdev.KeyEscape:
			fmt.Printf("Escape")
		case evdev.BtnStylus2:
			fmt.Printf("2nd stylus button")

			// more keys/buttons..
		}

		fmt.Println()
	}
}