diff --git a/dualshock.go b/dualshock.go index 54639dd..7ba6597 100644 --- a/dualshock.go +++ b/dualshock.go @@ -45,7 +45,7 @@ type State struct { Share, Options, PSHome bool Timestamp, BatteryLevel int LeftDPad DPad - RigthDPad DPad + RightDPad DPad Motion Motion Orientation Orientation @@ -101,7 +101,7 @@ func transform(b []byte) State { X: int(b[1]), Y: int(b[2]), }, - RigthDPad: DPad{ + RightDPad: DPad{ X: int(b[3]), Y: int(b[4]), }, @@ -140,7 +140,6 @@ func New(reader io.Reader) *Controller { // read transforms data from the io.Reader and pushes it to the queue of // states func (c *Controller) read() { - var b []byte for { select { case <-c.interrupt: @@ -148,7 +147,7 @@ func (c *Controller) read() { close(c.queue) return default: - b = make([]byte, 64) + b := make([]byte, 64) n, err := c.reader.Read(b) if err != nil { diff --git a/dualshock_test.go b/dualshock_test.go index 2826786..0897311 100644 --- a/dualshock_test.go +++ b/dualshock_test.go @@ -18,12 +18,9 @@ func (f fakeDevice) Read(b []byte) (int, error) { func TestDualshock(t *testing.T) { controller := New(fakeDevice{}) - result := make(chan State, 1) - defer close(result) - controller.Listen(func(state State) { - controller.Close() + go controller.Listen(func(state State) { result <- state })