Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"@fortawesome/free-solid-svg-icons": "^6.4.0",
"@fortawesome/vue-fontawesome": "^3.0.3",
"@j2only/slide-unlock": "^0.5.5",
"@kmamal/sdl": "0.11.9",
"@kmamal/sdl": "github:rafaellehmkuhl/node-sdl#dd1b97aa75bb84a2c899be40b0c48fcb135a4f88",
"@mdi/font": "^7.4.47",
"@mdi/js": "^7.4.47",
"@peermetrics/webrtc-stats": "^5.7.1",
Expand Down
8 changes: 3 additions & 5 deletions src/electron/services/joystick.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
SDLStatus,
} from '@/types/sdl'

import { decimalToHex, scale } from '../utils'
import { decimalToHex } from '../utils'

/**
* Open joystick device type
Expand Down Expand Up @@ -80,7 +80,7 @@ export function loadSDL(): SDLModule {
*/
export const openController = (sdl: SDLModule, device: SDLControllerDevice): void => {
try {
const instance = sdl.controller.openDevice(device)
const instance = sdl.controller.openDevice(device, { rawAxisMode: true })

if (!instance) {
throw new Error('Could not open controller.')
Expand Down Expand Up @@ -116,7 +116,7 @@ export const openController = (sdl: SDLModule, device: SDLControllerDevice): voi
*/
export const openJoystick = (sdl: SDLModule, device: SDLJoystickDevice): void => {
try {
const instance = sdl.joystick.openDevice(device)
const instance = sdl.joystick.openDevice(device, { rawAxisMode: true })

if (!instance) {
throw new Error('Could not open joystick.')
Expand Down Expand Up @@ -203,8 +203,6 @@ export const checkControllerState = (deviceId: number): void => {
}

const state = { buttons: structuredClone(instance.buttons), axes: structuredClone(instance.axes) }
state.axes.leftTrigger = state.axes.leftTrigger > 0 ? scale(state.axes.leftTrigger, 0.5, 1, 0, 1) : 0
state.axes.rightTrigger = state.axes.rightTrigger > 0 ? scale(state.axes.rightTrigger, 0.5, 1, 0, 1) : 0
state.buttons.extra = state.buttons[''] ?? false
delete state.buttons['']

Expand Down
21 changes: 19 additions & 2 deletions src/types/sdl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,17 @@ export interface SDLControllerDevice {
mapping: string
}

/**
* Options for opening SDL devices
*/
export interface SDLOpenOptions {
/**
* When true, axis values are normalized without SDL's initial state calibration.
* This avoids incorrect zero-point calibration when joysticks aren't centered at startup.
*/
rawAxisMode?: boolean
}

/**
* SDL joystick module type
*/
Expand All @@ -175,8 +186,11 @@ export interface SDLJoystickModule {
devices: SDLJoystickDevice[]
/**
* Enable a joystick device by its device identification
* @param device - The joystick device to open
* @param options - Optional settings for opening the device
* @returns {SDLJoystickInstance} The opened joystick instance
*/
openDevice: (device: SDLJoystickDevice) => SDLJoystickInstance
openDevice: (device: SDLJoystickDevice, options?: SDLOpenOptions) => SDLJoystickInstance
}

/**
Expand All @@ -203,8 +217,11 @@ export interface SDLControllerModule {
devices: SDLControllerDevice[]
/**
* Open a controller device
* @param device - The controller device to open
* @param options - Optional settings for opening the device
* @returns {SDLControllerInstance} The opened controller instance
*/
openDevice: (device: SDLControllerDevice) => SDLControllerInstance
openDevice: (device: SDLControllerDevice, options?: SDLOpenOptions) => SDLControllerInstance
}

export interface SDLStatus {
Expand Down
7 changes: 3 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1236,10 +1236,9 @@
"@jridgewell/resolve-uri" "^3.1.0"
"@jridgewell/sourcemap-codec" "^1.4.14"

"@kmamal/sdl@0.11.9":
version "0.11.9"
resolved "https://registry.yarnpkg.com/@kmamal/sdl/-/sdl-0.11.9.tgz#aadbb0e74888149a61244d354d9d4490841d615d"
integrity sha512-rTGtrKTrkj5rwS2dWrcWpMcg85oQL3J4aK/yuxPMe4209D1K1wXK35nCBbWnvhnjZJfH74566qr7hxSROAwfww==
"@kmamal/sdl@github:rafaellehmkuhl/node-sdl#dd1b97aa75bb84a2c899be40b0c48fcb135a4f88":
version "0.11.13-rawaxis.1"
resolved "https://codeload.github.com/rafaellehmkuhl/node-sdl/tar.gz/dd1b97aa75bb84a2c899be40b0c48fcb135a4f88"
dependencies:
tar "^7.4.3"

Expand Down
Loading