Skip to content

Commit c3935f9

Browse files
committed
properly set default input values
1 parent 191c031 commit c3935f9

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

gcadapter.go

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,8 @@ func NewGCAdapter() (*GCAdapter, error) {
5757
adapter.controllers = make(map[uint8]*rawGCInput)
5858
adapter.offsets = make(map[uint8]*Offsets)
5959
for _, PORT := range []uint8{0, 1, 2, 3} {
60-
adapter.controllers[PORT] = &rawGCInput{}
61-
adapter.offsets[PORT] = &Offsets{}
60+
adapter.controllers[PORT] = neutralRawInput()
61+
adapter.offsets[PORT] = neutralRawInput()
6262
}
6363
adapter.mutex.Unlock()
6464
return adapter, nil
@@ -114,6 +114,19 @@ type rawGCInput struct {
114114
PluggedIn bool
115115
}
116116

117+
func neutralRawInput() *rawGCInput {
118+
return &rawGCInput{
119+
Button: Buttons{},
120+
StickX: 128,
121+
StickY: 128,
122+
CX: 128,
123+
CY: 128,
124+
LAnalog: 255,
125+
RAnalog: 255,
126+
PluggedIn: false,
127+
}
128+
}
129+
117130
// GCInputs represent the state of the gamecube controller, with sticks values in [-1, 1], triggers values in [0, 1] and buttons as boolean
118131
// Sticks and triggers values are calibrated, and sticks values are clamped inside the unit circle, but deadzones are not enforced.
119132
type GCInputs struct {
@@ -129,15 +142,7 @@ type GCInputs struct {
129142

130143
// Offsets are the sticks and trigger values read right after plugging the controller or resetting it with X+Y+Start.
131144
// They are used to calibrate the values returned in GCInputs.
132-
type Offsets struct {
133-
StickX uint8
134-
StickY uint8
135-
CX uint8
136-
CY uint8
137-
LAnalog uint8
138-
RAnalog uint8
139-
PluggedIn bool
140-
}
145+
type Offsets = rawGCInput
141146

142147
func (adapter *GCAdapter) step() error {
143148
controllers, err := readGCAdapter(adapter.device)

0 commit comments

Comments
 (0)