Initial release of 8BitDo Control Center
Provide a Linux desktop controller configuration app with evdev input, uinput remapping, profiles, calibration, and reconnect recovery. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
43
src/services/tauriControllerService.ts
Normal file
43
src/services/tauriControllerService.ts
Normal file
@@ -0,0 +1,43 @@
|
||||
import { listen } from "@tauri-apps/api/event";
|
||||
import { invoke } from "@tauri-apps/api/core";
|
||||
|
||||
import type { ControllerInfo, RawInputEvent } from "@/types/controller";
|
||||
import type { Profile } from "@/types/profile";
|
||||
|
||||
const INPUT_EVENT = "controller-input";
|
||||
const READER_STATUS_EVENT = "controller-reader-status";
|
||||
|
||||
interface NativeInputEvent {
|
||||
timestamp: number;
|
||||
eventType: "button" | "axis";
|
||||
code: string;
|
||||
rawValue: number;
|
||||
processedValue: number;
|
||||
}
|
||||
|
||||
interface ReaderStatus {
|
||||
devicePath: string;
|
||||
connected: boolean;
|
||||
message: string | null;
|
||||
}
|
||||
|
||||
function toRawInputEvent(event: NativeInputEvent): RawInputEvent {
|
||||
return {
|
||||
timestamp: event.timestamp,
|
||||
type: event.eventType,
|
||||
code: event.code,
|
||||
rawValue: event.rawValue,
|
||||
processedValue: event.processedValue,
|
||||
};
|
||||
}
|
||||
|
||||
export const tauriControllerService = {
|
||||
list: () => invoke<ControllerInfo[]>("list_devices"),
|
||||
startReader: (devicePath: string) => invoke<void>("start_device_reader", { devicePath }),
|
||||
applyRemappingProfile: (profile: Profile) => invoke<void>("apply_remapping_profile", { profile }),
|
||||
setRemappingEnabled: (enabled: boolean) => invoke<void>("set_remapping_enabled", { enabled }),
|
||||
onInput: async (callback: (event: RawInputEvent) => void): Promise<() => void> =>
|
||||
listen<NativeInputEvent>(INPUT_EVENT, (event) => callback(toRawInputEvent(event.payload))),
|
||||
onReaderStatus: async (callback: (status: ReaderStatus) => void): Promise<() => void> =>
|
||||
listen<ReaderStatus>(READER_STATUS_EVENT, (event) => callback(event.payload)),
|
||||
};
|
||||
Reference in New Issue
Block a user