Loading examples/play.go +11 −9 Original line number Diff line number Diff line Loading @@ -12,22 +12,24 @@ import . "github.com/splace/joysticks" import . "github.com/splace/sounds" func main() { jsevents := Capture( Channel{10, HID.OnLong}, // events[0] button #10 long pressed Channel{1, HID.OnClose}, // events[1] button #1 closes Channel{1, HID.OnMove}, // events[2] hat #1 moves events := Capture( Channel{10, HID.OnLong}, // event[0] button #10 long pressed Channel{1, HID.OnClose}, // event[1] button #1 closes Channel{1, HID.OnRotate}, // event[2] hat #1 rotates Channel{2, HID.OnRotate}, // event[2] hat #2 rotates ) var x float32 = .5 var f time.Duration = time.Second / 440 for { select { case <-jsevents[0]: case <-events[0]: return case <-jsevents[1]: case <-events[1]: play(NewSound(NewTone(f, float64(x)), time.Second/3)) case h := <-jsevents[2]: x = h.(HatChangeEvent).X/2 + .5 f = time.Duration(100*math.Pow(2, float64(h.(HatChangeEvent).Y))) * time.Second / 44000 case h := <-events[2]: x = h.(HatAngleEvent).Angle/6.28 + .5 case h := <-events[3]: f = time.Duration(100*math.Pow(2, float64(h.(HatAngleEvent).Angle)/6.28)) * time.Second / 44000 } } } Loading joysticks_test.go +1 −1 Original line number Diff line number Diff line Loading @@ -18,7 +18,7 @@ func TestHIDsCapture(t *testing.T) { Channel{10, HID.OnLong}, // event[0] button #10 long pressed Channel{1, HID.OnClose}, // event[1] button #1 closes Channel{1, HID.OnRotate}, // event[2] hat #1 rotates Channel{2, HID.OnRotate}, // event[2] hat #1 rotates Channel{2, HID.OnRotate}, // event[2] hat #2 rotates ) var x float32 = .5 var f time.Duration = time.Second / 440 Loading Loading
examples/play.go +11 −9 Original line number Diff line number Diff line Loading @@ -12,22 +12,24 @@ import . "github.com/splace/joysticks" import . "github.com/splace/sounds" func main() { jsevents := Capture( Channel{10, HID.OnLong}, // events[0] button #10 long pressed Channel{1, HID.OnClose}, // events[1] button #1 closes Channel{1, HID.OnMove}, // events[2] hat #1 moves events := Capture( Channel{10, HID.OnLong}, // event[0] button #10 long pressed Channel{1, HID.OnClose}, // event[1] button #1 closes Channel{1, HID.OnRotate}, // event[2] hat #1 rotates Channel{2, HID.OnRotate}, // event[2] hat #2 rotates ) var x float32 = .5 var f time.Duration = time.Second / 440 for { select { case <-jsevents[0]: case <-events[0]: return case <-jsevents[1]: case <-events[1]: play(NewSound(NewTone(f, float64(x)), time.Second/3)) case h := <-jsevents[2]: x = h.(HatChangeEvent).X/2 + .5 f = time.Duration(100*math.Pow(2, float64(h.(HatChangeEvent).Y))) * time.Second / 44000 case h := <-events[2]: x = h.(HatAngleEvent).Angle/6.28 + .5 case h := <-events[3]: f = time.Duration(100*math.Pow(2, float64(h.(HatAngleEvent).Angle)/6.28)) * time.Second / 44000 } } } Loading
joysticks_test.go +1 −1 Original line number Diff line number Diff line Loading @@ -18,7 +18,7 @@ func TestHIDsCapture(t *testing.T) { Channel{10, HID.OnLong}, // event[0] button #10 long pressed Channel{1, HID.OnClose}, // event[1] button #1 closes Channel{1, HID.OnRotate}, // event[2] hat #1 rotates Channel{2, HID.OnRotate}, // event[2] hat #1 rotates Channel{2, HID.OnRotate}, // event[2] hat #2 rotates ) var x float32 = .5 var f time.Duration = time.Second / 440 Loading