tomnz / button-shim-go

Go library for Pimoroni's Button SHIM
https://shop.pimoroni.com/products/button-shim
MIT License
3 stars 1 forks source link

Support button hold events? #1

Open tomnz opened 6 years ago

tomnz commented 6 years ago

If someone can come up with an elegant way to support button hold events (similar to the Python lib's "repeat" concept), it might be nice to build that in. It can be approximated by doing something like:

pressA := shim.ButtonPressChan(buttonshim.ButtonA)
releaseA := shim.ButtonReleaseChan(buttonshim.ButtonA)

go func() {
  for {
    select {
    case <-pressA:
      println("Pressed!")
      for {
        select {
        case <-time.After(time.Second):
          println("Held!")
        case <-releaseA:
          println("Released!")
          break
        }
      }
    }
  }
}()

... But that's quite verbose, and wanting to respond to a hold may be commonplace.