Virtual Gamepad

A virtual controller for smartphones to operate microcontroller cars and more. (PCs are also supported)

GitHub (Japanese README): TwoSquirrels/virtual-gamepad

Settings

ms

Usage

Server Side (Microcontroller, etc.)

  1. Run a program that can handle HTTP requests in the format of the following protocol. (An example microcomputer car with M5Atom)
  2. Check the address of the target server.

Controller Side

  1. Open the address of the target server (e.g., microcomputer) in your browser.
  2. Adjust the joystick transmission interval (default 100 ms). It is recommended to keep it small enough that it does not choke communication.
  3. Hide the A, B buttons if you are not using them.
  4. Close the settings screen and operate with swipe or WASD (+ Shift).

Protocol

When communicating from an HTTPS page, such as on github.io, to an HTTP host, a security error occurs. This can be handled by configuring the browser, but it is recommended to serve HTML on the same host as the API and access the page from there.

GET /

Request

Basically, it is accessed through a browser.

Response

Please return the gamepad HTML, we recommend that you download the latest HTML from this page.

POST /joystick?p=aaff

Request

When the joystick is being operated or WASD is being used, the polar coordinates of the joystick are sent at the set interval as a 4-digit hexadecimal string in the query.

  • aa: A 2-digit hexadecimal string representing the angle 0 ≤ θ < 256, with the right direction as 0 and increasing counterclockwise, with a full circle being 256.
  • ff: A 2-digit hexadecimal string representing the radial distance 0 ≤ r < 256, with the center as 0 and the maximum stick limit as 255 (for WASD operation, it becomes 7F when Shift is pressed).

The body is always empty.

Response

Ignored, except for being displayed in the debug console.

POST /a, /b

Request

Sent to the path corresponding to the content of the button when the right-side button is pressed. The body is always empty.

Response

Ignored, except for being displayed in the debug console.

OK