Пример #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()
	}
}
Пример #2
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)
}