Merge branch 'tristan-wip' of https://gitea.clubconjure.com/Conjure/conjure-os into tristan-wip

This commit is contained in:
club 2025-07-01 16:30:35 -04:00
commit 2763543104
3 changed files with 95 additions and 3 deletions

7
app.go
View File

@ -6,6 +6,7 @@ import (
"conjure-os/lib/provider"
"context"
"fmt"
"github.com/wailsapp/wails/v2/pkg/runtime"
"os"
"os/exec"
)
@ -26,10 +27,14 @@ func NewApp() *App {
// so we can call the runtime methods
func (a *App) startup(ctx context.Context) {
a.ctx = ctx
inputs.Start()
inputs.Start(a.onControllerChange)
provider.Update()
}
func (a *App) onControllerChange(data any) {
runtime.EventsEmit(a.ctx, "controller_change", data)
}
func (a *App) StartGame(id string) {
for _, game := range games {
if game.Id == id {

View File

@ -1,8 +1,10 @@
import { onMounted, onBeforeUnmount } from 'vue';
import { KeyboardManager } from "./keyboard-manager";
import { EventsOn } from "../../wailsjs/runtime";
export function useKeyboardNavigation(): void {
onMounted(() => {
EventsOn("controller_change", (data) => console.log(data));
window.addEventListener('keydown', KeyboardManager.handle.bind(KeyboardManager));
});

View File

@ -19,8 +19,82 @@ const (
JS_EVENT_INIT = 0x80 // Initial state of device
)
func Start() {
return
type Controller struct {
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")
const vendorID = 0x0079
const productID = 0x0006
@ -61,14 +135,25 @@ func Start() {
x := buf[0] // Horizontal axis (0255)
y := buf[1] // Vertical axis (0255)
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)
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)
}
if x != 127 || y != 127 {
onStateChange(state)
fmt.Printf("Joystick moved! %d - %d\n", x, y)
}
}