haptic

package module
v0.0.0-...-78675de Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 7, 2020 License: MIT, Unlicense Imports: 1 Imported by: 0

README

haptic

GoDoc

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 NewBuzzer

func NewBuzzer(_ *app.Window) *Buzzer

NewBuzzer constructs a buzzer.

func (*Buzzer) Buzz

func (b *Buzzer) Buzz() bool

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

func (b *Buzzer) Errors() <-chan error

Errors returns a channel of errors from trying to interface with the JVM. This channel will close when Shutdown() is invoked.

func (*Buzzer) SetView

func (b *Buzzer) SetView(_ uintptr)

Update does nothing on platforms other than Android. See the documentation with GOOS=android for information on using this method correctly on that platform.

func (*Buzzer) Shutdown

func (b *Buzzer) Shutdown()

Shutdown stops the background event loop that interfaces with the JVM. Call this when you are done with a Buzzer to allow it to be garbage collected. Do not call this method more than per Buzzer.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL