test
This commit is contained in:
parent
8282473657
commit
8a5de26ca3
7
app.go
7
app.go
@ -6,6 +6,7 @@ import (
|
|||||||
"conjure-os/lib/provider"
|
"conjure-os/lib/provider"
|
||||||
"context"
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/wailsapp/wails/v2/pkg/runtime"
|
||||||
"os"
|
"os"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
)
|
)
|
||||||
@ -26,10 +27,14 @@ func NewApp() *App {
|
|||||||
// so we can call the runtime methods
|
// so we can call the runtime methods
|
||||||
func (a *App) startup(ctx context.Context) {
|
func (a *App) startup(ctx context.Context) {
|
||||||
a.ctx = ctx
|
a.ctx = ctx
|
||||||
inputs.Start()
|
inputs.Start(a.onControllerChange)
|
||||||
provider.Update()
|
provider.Update()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (a *App) onControllerChange(data any) {
|
||||||
|
runtime.EventsEmit(a.ctx, "controller_change", data)
|
||||||
|
}
|
||||||
|
|
||||||
func (a *App) StartGame(id string) {
|
func (a *App) StartGame(id string) {
|
||||||
for _, game := range games {
|
for _, game := range games {
|
||||||
if game.Id == id {
|
if game.Id == id {
|
||||||
|
|||||||
@ -1,8 +1,10 @@
|
|||||||
import { onMounted, onBeforeUnmount } from 'vue';
|
import { onMounted, onBeforeUnmount } from 'vue';
|
||||||
import { KeyboardManager } from "./keyboard-manager";
|
import { KeyboardManager } from "./keyboard-manager";
|
||||||
|
import { EventsOn } from "../../wailsjs/runtime";
|
||||||
|
|
||||||
export function useKeyboardNavigation(): void {
|
export function useKeyboardNavigation(): void {
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
|
EventsOn("controller_change", (data) => console.log(data));
|
||||||
window.addEventListener('keydown', KeyboardManager.handle.bind(KeyboardManager));
|
window.addEventListener('keydown', KeyboardManager.handle.bind(KeyboardManager));
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@ -19,8 +19,82 @@ const (
|
|||||||
JS_EVENT_INIT = 0x80 // Initial state of device
|
JS_EVENT_INIT = 0x80 // Initial state of device
|
||||||
)
|
)
|
||||||
|
|
||||||
func Start() {
|
type Controller struct {
|
||||||
return
|
Device *hid.Device
|
||||||
|
}
|
||||||
|
|
||||||
|
func (c *Controller) ReadState() error {
|
||||||
|
buf := make([]byte, 64)
|
||||||
|
_, err := c.Device.Read(buf)
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Printf("Joystick: X=%d Y=%d Buttons=%08b\n", buf[0], buf[1], buf[6])
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
|
||||||
|
type Vec2B struct {
|
||||||
|
X, Y byte
|
||||||
|
}
|
||||||
|
|
||||||
|
type ControllerState struct {
|
||||||
|
joystick Vec2B
|
||||||
|
buttons byte
|
||||||
|
}
|
||||||
|
|
||||||
|
type ConjureControllerButton int
|
||||||
|
|
||||||
|
const (
|
||||||
|
ButtonA ConjureControllerButton = iota //0
|
||||||
|
ButtonB
|
||||||
|
ButtonC
|
||||||
|
|
||||||
|
Button1
|
||||||
|
Button2
|
||||||
|
Button3
|
||||||
|
|
||||||
|
ButtonStart
|
||||||
|
ButtonPower // 7
|
||||||
|
)
|
||||||
|
|
||||||
|
var ConjureControllerButtons = []ConjureControllerButton{
|
||||||
|
ButtonA,
|
||||||
|
ButtonB,
|
||||||
|
ButtonC,
|
||||||
|
|
||||||
|
Button1,
|
||||||
|
Button2,
|
||||||
|
Button3,
|
||||||
|
|
||||||
|
ButtonStart,
|
||||||
|
ButtonPower,
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s ConjureControllerButton) String() string {
|
||||||
|
switch s {
|
||||||
|
case ButtonA:
|
||||||
|
return "ButtonA"
|
||||||
|
case ButtonB:
|
||||||
|
return "ButtonB"
|
||||||
|
case ButtonC:
|
||||||
|
return "ButtonC"
|
||||||
|
case Button1:
|
||||||
|
return "Button1"
|
||||||
|
case Button2:
|
||||||
|
return "Button2"
|
||||||
|
case Button3:
|
||||||
|
return "Button3"
|
||||||
|
case ButtonStart:
|
||||||
|
return "ButtonStart"
|
||||||
|
case ButtonPower:
|
||||||
|
return "ButtonPower"
|
||||||
|
default:
|
||||||
|
return "Unknown"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func Start(onStateChange func(any)) {
|
||||||
fmt.Println("Opening devices")
|
fmt.Println("Opening devices")
|
||||||
const vendorID = 0x0079
|
const vendorID = 0x0079
|
||||||
const productID = 0x0006
|
const productID = 0x0006
|
||||||
@ -61,14 +135,25 @@ func Start() {
|
|||||||
x := buf[0] // Horizontal axis (0–255)
|
x := buf[0] // Horizontal axis (0–255)
|
||||||
y := buf[1] // Vertical axis (0–255)
|
y := buf[1] // Vertical axis (0–255)
|
||||||
buttons := buf[6] // Buttons as bitfield
|
buttons := buf[6] // Buttons as bitfield
|
||||||
|
state := ControllerState{
|
||||||
|
joystick: Vec2B{x, y},
|
||||||
|
buttons: buttons,
|
||||||
|
}
|
||||||
|
|
||||||
// fmt.Printf("Joystick X: %d, Y: %d, Buttons: %08b\n", x, y, buttons)
|
// fmt.Printf("Joystick X: %d, Y: %d, Buttons: %08b\n", x, y, buttons)
|
||||||
|
|
||||||
if buttons != 0 {
|
if buttons != 0 {
|
||||||
|
for _, button := range ConjureControllerButtons {
|
||||||
|
if buttons&(1<<button) != 0 {
|
||||||
|
fmt.Printf("Button %s pressed\n", (button + 1).String())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
onStateChange(state)
|
||||||
fmt.Printf("Button was pressed! %d\n", buttons)
|
fmt.Printf("Button was pressed! %d\n", buttons)
|
||||||
}
|
}
|
||||||
|
|
||||||
if x != 127 || y != 127 {
|
if x != 127 || y != 127 {
|
||||||
|
onStateChange(state)
|
||||||
fmt.Printf("Joystick moved! %d - %d\n", x, y)
|
fmt.Printf("Joystick moved! %d - %d\n", x, y)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user