Skip to content

GCA Async API 2.0

Mario Martínez edited this page Aug 4, 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.

getAdaptersList()

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)

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)

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))

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))

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])

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)

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)

Returns a copy of the data buffer.

binary(data: Buffer)

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)

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

object(data: Buffer)

Processes the data obtained to an ControllerStatus object.

  • Returns an array of 4 Controller objects. Each one corresponds to one of the four ports of the adapter, and contains the status the GameCube controller was when the data was sent to the computer.
Clone this wiki locally