Skip to content

GCA Async API 2.0

Mario Martínez edited this page Aug 7, 2021 · 6 revisions

gca-js uses an asynchronous version of the 2.1 version of the GCA API shared by gca+.

Globals

ControllerStatus

The interface struct used for handling the controller status of any given port of the adapter.

  • port: number - The port number of the adapter (from 1 to 4)
  • plugged: boolean - If there's a controller plugged on this port or not.
  • buttons: - A collection of the states of buttons being pressed.
    • buttonA: boolean
    • buttonB: boolean
    • buttonX: boolean
    • buttonY: boolean
    • padUp: boolean - D-Pad Up
    • padDown: boolean - D-Pad Down
    • padLeft: boolean - D-Pad Left
    • padRight: boolean - D-Pad Right
    • buttonStart: boolean
    • buttonZ: boolean
    • buttonL: boolean - When the L trigger is pressed all the way down (a click is heard)
    • buttonR: boolean - When the R trigger is pressed all the way down (a click is heard)
  • axes: - A collection of the values of the controller sticks in vertical and horizontal axes, as well as the axes for the triggers, ranging from -1 to 1.
    • mainStickHorizontal: number
    • mainStickVertical: number
    • cStickHorizontal: number
    • cStickVertical: number
    • triggerL: number
    • triggerR: number

getAdaptersList() => Promise<USB.Device[]>

Detects all Nintendo® Wii U GameCube™ Adapter connected in your computer.

  • Returns a Promise with all compatible adapters detected in an array.

startAdapter(adapter: USB.Device) => Promise

Claims the usage of the adapter and enables the communication with a given adapter and sends a command to it so that it can begin polling data.

  • Returns a Promise that is fulfilled when the adapter has started.

readData(adapter: USB.Device) => Promise

Makes a single, synchronous communication to the selected adapter to get the current input data. This is a blocking communication and the process will stall until the communication is complete.

  • Returns a Promise with the input data that is fulfilled once the communication is complete.

readData(adapter: USB.Device, callback: function(data: Buffer)) => void

This is a legacy alias of the previous function, that uses a callback instead of returning a promise.

pollData(adapter: USB.Device, callback: function(data: Buffer)) => void

Enables a continuous, asynchronous communication via events with the selected adapter, and executes the callback function when a communication is complete. This is a non-blocking communication, so the process will continue to be running even if the communication is still in progress.

sendRumble(adapter: USB.Device, controllers: boolean[4]) => Promise

Sends a rumble command to the adapter to toggle the rumble on all controller ports of the adapter.

controllers is an array of 4 booleans, one for each port. When true, the controller plugged in that port will start rumbling. When false, it will stop rumbling.

  • Returns a Promise that is fulfilled once the communication is complete.

stopAdapter(adapter: USB.Device) => Promise

Stops the communication with the adapter and makes it available for other processes.

  • Returns a Promise.

DataProcess functions

These built-in functions allow processing the input data received from the adapter.

raw(data: Buffer) => Buffer

Returns a copy of the data buffer.

binary(data: Buffer) => string[37]

Returns a list of 37 bytes in binary strings about the adapter's current state (9 status bytes * 4 ports + 1 header byte = 37 bytes) The list contains the following information (using LSB 0 bit numbering). Multiply the byte number by the port number you want to use to get the element of the list that contains the same information for said port):

  • Byte 0: GameCube Adapter header
  • Byte 1: Port connection status.
    • High nibble: Least significant bit is 1 when a controller is connected to said port, 0 when nothing is connected.
    • Low nibble: Not used.
  • Byte 2: Main buttons and D-Pad status.
    • High nibble:
      • Bit 7: D-Pad Left
      • Bit 6: D-Pad Right
      • Bit 5: D-Pad Down
      • Bit 4: D-Pad Up
    • Low nibble:
      • Bit 3: Y button
      • Bit 2: X button
      • Bit 1: B button
      • Bit 0: A button
  • Byte 3: Auxiliar buttons
    • High nibble: Not used
    • Low nibble:
      • Bit 3: Start button
      • Bit 2: Z button
      • Bit 1: R trigger button
      • Bit 0: L trigger button
  • Byte 4: Main stick horizontal axis (left-right)
  • Byte 5: Main stick vertical axis (up-down)
  • Byte 6: C-Stick horizontal axis (left-right)
  • Byte 7: C-Stick vertical axis (left-right)
  • Byte 8: L trigger axis
  • Byte 9: R trigger axis

uintArray(data: Buffer) => Uint8Array

Returns a list of the 37 bytes received in a UInt8Array.

object(data: Buffer) => ControllerStatus[4]

Processes the data obtained to an array of 4 ControllerStatus objects, one for each port. Each one corresponds to one of the four ports of the adapter, and contains the input status the GameCube controller was in when the data was sent to the computer.