Skip to content

Commit

Permalink
Accept longer reports and print unsupported reports.
Browse files Browse the repository at this point in the history
  • Loading branch information
71 committed Oct 19, 2020
1 parent 2f840e4 commit 48534c3
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions stadia.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package stadiacontroller

import (
"encoding/base64"
"errors"
"fmt"
"log"
"time"
)
Expand All @@ -18,7 +20,7 @@ type StadiaController struct {
}

func NewStadiaController() *StadiaController {
ticker := time.NewTicker(500 * time.Millisecond)
ticker := time.NewTicker(5000 * time.Millisecond)
controller := &StadiaController{nil, ticker, nil}

go func() {
Expand Down Expand Up @@ -110,7 +112,7 @@ func ParseReport(data []byte, report *Xbox360ControllerReport) error {
return errors.New("cannot parse empty report")
}

if data[0] == 0x03 && len(data) == 10 {
if data[0] == 0x03 && len(data) >= 10 {
a := data[1]
b := data[2]
c := data[3]
Expand Down Expand Up @@ -186,7 +188,7 @@ func ParseReport(data []byte, report *Xbox360ControllerReport) error {
return nil
}

return errors.New("unknown report format")
return fmt.Errorf("unknown report format; raw report was %s", base64.StdEncoding.EncodeToString(data))
}

func convertAxisValue(byteValue byte) int32 {
Expand Down

0 comments on commit 48534c3

Please sign in to comment.