Exemple #1
0
// listCapabilities lists Force feedback capabilities for a given device.
//
// Testing for individual effect types can be done using the
// Device.Supports() method.
func listCapabilities(dev *evdev.Device) {
	// Fetch the force feedback capabilities.
	// The number of simultaneous effects and a
	// bitset describing the type of effects.
	count, caps := dev.ForceFeedbackCaps()

	fmt.Printf("Number of simultaneous effects: %d\n", count)

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

		fmt.Printf(" - Effect 0x%02x: ", n)

		switch n {
		case evdev.FFConstant:
			fmt.Printf("Constant")
		case evdev.FFPeriodic:
			fmt.Printf("Periodic")
		case evdev.FFSpring:
			fmt.Printf("Spring")
		case evdev.FFFriction:
			fmt.Printf("Friction")
		case evdev.FFRumble:
			fmt.Printf("Rumble")
		case evdev.FFDamper:
			fmt.Printf("Damper")
		case evdev.FFRamp:
			fmt.Printf("Ramp")
		}

		fmt.Println()
	}
}
Exemple #2
0
// Testing for support of specific axes can be
// done with the `dev.Supports()` method.
func absAxes(dev *evdev.Device) {
	axes := dev.AbsoluteAxes()
	for n := 0; n < axes.Len(); n++ {
		if !axes.Test(n) {
			continue
		}

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

		switch n {
		case evdev.AbsX:
			fmt.Printf("X Axis: ")
		case evdev.AbsY:
			fmt.Printf("Y Axis: ")
		case evdev.AbsZ:
			fmt.Printf("Z Axis: ")
		default: // More axes types...
			fmt.Printf("Other axis\n")
		}

		// Get axis information.
		abs := dev.AbsoluteInfo(n)
		fmt.Printf("%+v\n", abs)
	}
}
Exemple #3
0
func checkDevice(dev *evdev.Device) (string, bool) {
	if !correctDevice(dev) {
		return "", false
	}

	return dev.Name(), true
}
Exemple #4
0
// Testing for support of specific axes can be
// done with the `dev.Supports()` method.
func relAxes(dev *evdev.Device) {
	axes := dev.RelativeAxes()
	for n := 0; n < axes.Len(); n++ {
		if !axes.Test(n) {
			continue
		}

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

		switch n {
		case evdev.RelX:
			fmt.Printf("X Axis: ")
		case evdev.RelY:
			fmt.Printf("Y Axis: ")
		case evdev.RelZ:
			fmt.Printf("Z Axis: ")
		default: // More axes types...
			fmt.Printf("Other axis\n")
		}

		fmt.Println()
	}
}
func OpenFLIRC(grab bool) {
	i := 0
	var dev *evdev.Device
	var err error
	for {
		node := fmt.Sprintf("/dev/input/event%d", i)
		dev, err = evdev.Open(node)
		i++
		if err != nil {
			if os.IsNotExist(err) {
				log.Fatalln("could not find FLIRC device")
			}
			log.Fatalln(err)
		}
		if strings.TrimRight(dev.Name(), "\x00") != FLIRCName {
			dev.Close()
			continue
		}
		break
	}

	if grab && !dev.Grab() {
		log.Warnln("failed to grab device")
	}
	log.Infoln("using device:", strings.TrimRight(dev.Path(), "\x00"))
	for event := range dev.Inbox {
		if event.Type != evdev.EvKeys {
			continue
		}
		if event.Value != 0 {
			continue
		}

		log.Infoln("FLIRC event", event.Code)
		for i, code := range flircMap {
			if int(event.Code) == code {
				setState(i)
				break
			}
		}
	}
}
Exemple #6
0
// setEffects creates, uploads and plays a new Force feedback effect.
// This function uploads only 1 effect, but it can deal with
// up to N effects at the same time. Where N is whatever value
// returned from `Device.ForceFeedbackCaps()`.
func setEffects(dev *evdev.Device) {
	_, caps := dev.ForceFeedbackCaps()

	var effect evdev.Effect
	effect.Id = -1
	effect.Trigger.Button = 0
	effect.Trigger.Interval = 0
	effect.Replay.Length = 20000 // 20 seconds
	effect.Replay.Delay = 0

	// Some samples of various effect types.
	// (un)comment any one to try them out. Note that
	// the device must support a given effect type.

	switch {
	case dev.Test(caps, evdev.FFRumble):
		rumble(&effect)
	case dev.Test(caps, evdev.FFPeriodic):
		periodic(&effect)
	case dev.Test(caps, evdev.FFConstant):
		constant(&effect)
	case dev.Test(caps, evdev.FFSpring):
		spring(&effect)
	case dev.Test(caps, evdev.FFDamper):
		damper(&effect)
	}

	// Upload the effect.
	dev.SetEffects(&effect)

	fmt.Printf("Effect id: %d\n", effect.Id)

	// Play the effect.
	dev.PlayEffect(effect.Id)

	// Delete the effect.
	dev.UnsetEffects(&effect)
}
Exemple #7
0
// check if device is a keyboard, mouse or touchpad.
func correctDevice(dev *evdev.Device) bool {
	// check if device is a keyboard
	if dev.Test(dev.EventTypes(), evdev.EvSync, evdev.EvKeys, evdev.EvMisc, evdev.EvLed, evdev.EvRepeat) {
		return true
	}

	// check if device is a mouse
	if dev.Test(dev.EventTypes(), evdev.EvSync, evdev.EvKeys, evdev.EvRelative, evdev.EvMisc) {
		return true
	}

	// check if device is a touchpad
	if dev.Test(dev.EventTypes(), evdev.EvSync, evdev.EvKeys, evdev.EvAbsolute) {
		return true
	}

	return false
}