Skip to content

refactor: centralize duplicated gamepad axis max constant #489

Closed

Description

@Abfa41

Summary

The Linux and Windows gamepad drivers each define their own local const AXIS_MAX = 32767:

  • src/server/drivers/linux/gamepad.ts
  • src/server/drivers/windows/gamepad.ts

This is the same magic number duplicated in two places. If the axis range ever needs to change, both files must be updated in lockstep, and a missed update would cause inconsistent gamepad behavior between platforms.

Scope

Pure refactor — no behavior change.

  • Add export const GAMEPAD_AXIS_MAX = 32767 to src/server/constants.ts.
  • Remove the local AXIS_MAX definitions from the Linux and Windows gamepad
    drivers.
  • Import and use GAMEPAD_AXIS_MAX in both files.

The scaling math is unchanged: Math.round(norm * GAMEPAD_AXIS_MAX) produces the exact same values as before.

Not in scope

src/server/drivers/mac/gamepad.ts uses an 8-bit HID axis range (-127..127), not 32767, so it is intentionally left untouched.

Verification

  • npm run test passes locally (existing gamepad tests cover both drivers).
  • Grep for 32767 and AXIS_MAX across src/ shows no remaining local definitions in driver code.

Activity

  1. github-actions commented on Nov 15, 2026

    @github-actions

    Discussions are carried on Discord.

    Instead of commenting here, go to the Discord channel.

    If you find this project useful, a GitHub star would be appreciated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions