Esempio n. 1
0
func rumble(e *evdev.Effect) {
	e.Type = evdev.FFRumble

	var r evdev.RumbleEffect
	r.StrongMagnitude = 0
	r.WeakMagnitude = 0xc000
	e.SetData(r)
}
Esempio n. 2
0
func constant(e *evdev.Effect) {
	e.Type = evdev.FFConstant
	e.Direction = 0x6000 // 135 degrees

	var c evdev.ConstantEffect
	c.Level = 0x2000 // Strength : 25 %
	c.Envelope.AttackLength = 0x100
	c.Envelope.AttackLevel = 0
	c.Envelope.FadeLength = 0x100
	c.Envelope.FadeLevel = 0
	e.SetData(c)
}
Esempio n. 3
0
func spring(e *evdev.Effect) {
	e.Type = evdev.FFSpring
	e.Direction = 0x6000 // 135 degrees

	var c [2]evdev.ConditionEffect
	c[0].RightSaturation = 0x7fff
	c[0].LeftSaturation = 0x7fff
	c[0].RightCoeff = 0x2000
	c[0].LeftCoeff = 0x2000
	c[0].Deadband = 0x0
	c[0].Center = 0x0
	c[1] = c[0]
	e.SetData(c)
}
Esempio n. 4
0
func periodic(e *evdev.Effect) {
	e.Type = evdev.FFPeriodic
	e.Direction = evdev.DirLeft // Along X axis

	var p evdev.PeriodicEffect
	p.Waveform = evdev.FFSine
	p.Period = 26        // 0.1*0x100 = 0.1 second
	p.Magnitude = 0x4000 // 0.5 * Maximum magnitude
	p.Offset = 0
	p.Phase = 0
	p.Envelope.AttackLength = 0x100
	p.Envelope.AttackLevel = 0
	p.Envelope.FadeLength = 0x100
	p.Envelope.FadeLevel = 0

	e.SetData(p)
}
Esempio n. 5
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)
}