controller.go 965 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package gamepad
  2. var Driver ControllerDriver = nil
  3. func Install(out chan<-Event) {
  4. Driver = InstallDriver(out)
  5. }
  6. func Uninstall() {
  7. if (Driver != nil) {
  8. Driver.Exit()
  9. Driver = nil
  10. }
  11. }
  12. func IsInstalled() bool {
  13. return Driver != nil
  14. }
  15. func Recofigure() bool {
  16. if Driver == nil {
  17. return false
  18. }
  19. return Driver.Reconfigure()
  20. }
  21. func Source() Driver {
  22. return Driver
  23. }
  24. func emitEvent(event Event) {
  25. Driver.Emit(event)
  26. }
  27. func NumberOfControllers() int {
  28. if Driver == nil {
  29. return 0
  30. }
  31. return Driver.NumberOfControllers()
  32. }
  33. type Controller interface {
  34. Release() error
  35. Active() bool
  36. Name() string
  37. NumberOfAxes() int
  38. NumberOfButtons() int
  39. Flags() int
  40. }
  41. func ControllerById(id int) Controller {
  42. if Driver == nil {
  43. return nil
  44. }
  45. if id < 0 || id >= NumberOfControllers() {
  46. return nil
  47. }
  48. return Driver.ControllerById()
  49. }