Skip to content

Commit 48534c3

Browse files
committed
Accept longer reports and print unsupported reports.
1 parent 2f840e4 commit 48534c3

1 file changed

Lines changed: 5 additions & 3 deletions

File tree

‎stadia.go‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package stadiacontroller
22

33
import (
4+
"encoding/base64"
45
"errors"
6+
"fmt"
57
"log"
68
"time"
79
)
@@ -18,7 +20,7 @@ type StadiaController struct {
1820
}
1921

2022
func NewStadiaController() *StadiaController {
21-
ticker := time.NewTicker(500 * time.Millisecond)
23+
ticker := time.NewTicker(5000 * time.Millisecond)
2224
controller := &StadiaController{nil, ticker, nil}
2325

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

113-
if data[0] == 0x03 && len(data) == 10 {
115+
if data[0] == 0x03 && len(data) >= 10 {
114116
a := data[1]
115117
b := data[2]
116118
c := data[3]
@@ -186,7 +188,7 @@ func ParseReport(data []byte, report *Xbox360ControllerReport) error {
186188
return nil
187189
}
188190

189-
return errors.New("unknown report format")
191+
return fmt.Errorf("unknown report format; raw report was %s", base64.StdEncoding.EncodeToString(data))
190192
}
191193

192194
func convertAxisValue(byteValue byte) int32 {

0 commit comments

Comments
 (0)