README
¶
haptic
Haptic feedback for Gio applications on Android
Status
Experimental, but working. API is not stable, so use go modules to lock to a particular version.
I'd like to also support iOS in the future, but currently only android support is implemented.
On non-supported OSes, the API is the same but does nothing. This makes it easier to write cross-platform code that depends on haptic.
Usage
Create a Buzzer
:
buzzer := haptic.NewBuzzer(window)
// check for problems:
select {
case err := <- buzzer.Errors():
// handle
case event := <-window.Events():
// normal gio stuff
}
Send a haptic buzz:
if !buzzer.Buzz() {
// Couldn't trigger a buzz without blocking. Handle however you like.
// I recommend just retrying soon (maybe next frame).
}
When you're done:
buzzer.Shutdown()
Why is the API weird?
We can't interact with the JVM from the same OS thread that runs your Gio event processing. Rather than accidentally allow you to deadlock by calling these methods the wrong way, they're written to be safe to invoke from your normal Gio layout code without deadlock. This means that all of the work needs to occur on other goroutines.
Contributing
Send questions, comments, and patches to my public inbox.
License
Dual MIT/Unlicense
Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Buzzer ¶
type Buzzer struct { }
Buzzer provides methods to trigger haptic feedback. On OSes other than android, all methods are no-ops.
func (*Buzzer) Buzz ¶
Buzz attempts to trigger a haptic vibration without blocking. It returns whether or not it was successful. If it returns false, it is safe to retry. On unsupported platforms, it always returns true.
func (*Buzzer) Errors ¶
Errors returns a channel of errors from trying to interface with the JVM. This channel will close when Shutdown() is invoked.