Skip to content

Commit 749c807

Browse files
committed
init
1 parent fba570d commit 749c807

File tree

13 files changed

+915
-0
lines changed

13 files changed

+915
-0
lines changed

build/ViGEmClient.dll

308 KB
Binary file not shown.

build/stadia2xbox.exe

7.29 MB
Binary file not shown.

compile.bat

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
@echo off
2+
echo Compiling to /build...
3+
cd src
4+
go build -ldflags "-H windowsgui -linkmode=internal" -o ../build/stadia2xbox.exe

src/bindata.go

Lines changed: 103 additions & 0 deletions
Large diffs are not rendered by default.

src/data/stadia.ico

279 KB
Binary file not shown.

src/main.go

Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
package main
2+
3+
import (
4+
"./stadia"
5+
"./xbox"
6+
"github.com/getlantern/systray"
7+
"github.com/rodolfoag/gow32"
8+
"gopkg.in/toast.v1"
9+
)
10+
11+
var stop = false
12+
13+
func main() {
14+
_, err := gow32.CreateMutex("Stadia2Xbox")
15+
if err != nil {
16+
msg("An instance of Stadia2Xbox is already running!")
17+
} else {
18+
systray.Run(ready, close)
19+
}
20+
}
21+
22+
func ready() {
23+
icon, _ := Asset("data/stadia.ico")
24+
systray.SetIcon(icon)
25+
quit := systray.AddMenuItem("Exit", "Exits the application")
26+
27+
go func() {
28+
<-quit.ClickedCh
29+
systray.Quit()
30+
}()
31+
32+
start()
33+
}
34+
35+
func start() {
36+
defer systray.Quit()
37+
38+
device, err := stadia.Open()
39+
if err != nil {
40+
msg(err.Error())
41+
return
42+
}
43+
defer device.Close()
44+
45+
emu, err := xbox.Open(func(vibration xbox.Vibration) {
46+
device.Vibrate(vibration.LargeMotor, vibration.SmallMotor)
47+
})
48+
if err != nil {
49+
msg(err.Error())
50+
return
51+
}
52+
53+
con, err := emu.Connect()
54+
if err != nil {
55+
msg(err.Error())
56+
return
57+
}
58+
defer emu.Close()
59+
defer con.Close()
60+
61+
msg("Stadia Controller sucessfully connected and emulated as Xbox Controller")
62+
63+
for {
64+
if stop {
65+
return
66+
}
67+
d, err := device.Read()
68+
if err != nil {
69+
msg(err.Error())
70+
return
71+
}
72+
report := xbox.Report{}
73+
74+
report.SetButton(d.DPad.Up, xbox.DPadUp)
75+
report.SetButton(d.DPad.Down, xbox.DPadDown)
76+
report.SetButton(d.DPad.Left, xbox.DPadLeft)
77+
report.SetButton(d.DPad.Right, xbox.DPadRight)
78+
79+
report.SetButton(d.Button.X, xbox.ButtonX)
80+
report.SetButton(d.Button.Y, xbox.ButtonY)
81+
report.SetButton(d.Button.A, xbox.ButtonA)
82+
report.SetButton(d.Button.B, xbox.ButtonB)
83+
84+
report.SetButton(d.Button.Home, xbox.ButtonGuide)
85+
report.SetButton(d.Button.Menu, xbox.ButtonStart)
86+
report.SetButton(d.Button.Options, xbox.ButtonBack)
87+
88+
report.SetButton(d.Stick.Left, xbox.StickLeft)
89+
report.SetButton(d.Stick.Right, xbox.StickRight)
90+
91+
report.SetButton(d.Bumper.Left, xbox.BumperLeft)
92+
report.SetButton(d.Bumper.Right, xbox.BumperRight)
93+
94+
report.SetStick(false, int16(d.Stick.Axis.Left.X), int16(d.Stick.Axis.Left.Y))
95+
report.SetStick(true, int16(d.Stick.Axis.Right.X), int16(d.Stick.Axis.Right.Y))
96+
97+
report.SetTrigger(false, d.Trigger.Pressure.Left)
98+
report.SetTrigger(true, d.Trigger.Pressure.Right)
99+
100+
con.Send(&report)
101+
}
102+
}
103+
104+
func close() {
105+
stop = true
106+
}
107+
108+
func msg(str string) {
109+
notif := toast.Notification{
110+
Title: "Stadia2Xbox",
111+
Message: str,
112+
}
113+
notif.Push()
114+
}

src/rsrc.syso

271 KB
Binary file not shown.

src/stadia/hid/hid.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
// Package hid provides access to Human Interface Devices.
2+
package hid
3+
4+
// DeviceInfo provides general information about a device.
5+
type DeviceInfo struct {
6+
// Path contains a platform-specific device path which is used to identify the device.
7+
Path string
8+
9+
VendorID uint16
10+
ProductID uint16
11+
VersionNumber uint16
12+
Manufacturer string
13+
Product string
14+
15+
UsagePage uint16
16+
Usage uint16
17+
18+
InputReportLength uint16
19+
OutputReportLength uint16
20+
}
21+
22+
// A Device provides access to a HID device.
23+
type Device interface {
24+
// Close closes the device and associated resources.
25+
Close()
26+
27+
// Write writes an output report to device. The first byte must be the
28+
// report number to write, zero if the device does not use numbered reports.
29+
Write([]byte) error
30+
31+
// ReadCh returns a channel that will be sent input reports from the device.
32+
// If the device uses numbered reports, the first byte will be the report
33+
// number.
34+
ReadCh() <-chan []byte
35+
36+
// ReadError returns the read error, if any after the channel returned from
37+
// ReadCh has been closed.
38+
ReadError() error
39+
}

0 commit comments

Comments
 (0)