A rest client in python for joycontrol. Exposes the joycontrol pro-controller emulation as a restful service. This was tested on an Raspberry PI zero W
This script also needs root to run, as it is a requirement of joycontrol
This project is also used as the backend for https://github.com/choss/joycontrol-web-interface
In addition to the joycontrol packages you also need fastapi and uvicorn.
sudo pip3 install fastapi
sudo pip3 install uvicorn
- Clone this repo including all submodules
- Since we have a git-submodule on joycontrol we need to expose the folder to pythons module path and then we can run it.
export PYTHONPATH=./joycontrol
sudo python3 rest.py
To disable cors validation create a file called .env with the following content
ALLOW_ALL_CORS=True
To see the api just run the script and navigate to :8000. The documentation will be shown The base64 encoded data for spi firmware or nfc data should not contain line breaks. You can achieve this with the sample below.
base64 -w 0 spi_firm.bin > spi_firm_base64.txt
{
"controller_type": "PRO_CONTROLLER"
}
In this example the MAC of the switch is E1:3F:54:0B:DE:BB
{
"controller_type": "PRO_CONTROLLER",
"reconnect_address": "E1:3F:54:0B:DE:BB"
}
{
"controller_type": "PRO_CONTROLLER",
"spi_firm" : "<very long base64 encoded string>",
}
The response of every API method is a status response like the one below.
{
"connected": "true",
"peer": "AA:BB:CC:DD:EE:FF",
"controller_type": "PRO_CONTROLLER",
"buttons": {
"up": false,
"a": false,
"b": false,
"minus": false,
"home": false,
"l_stick": false,
"zr": false,
"r": false,
"zl": false,
"right": false,
"capture": false,
"r_stick": false,
"y": false,
"plus": false,
"left": false,
"x": false,
"l": false,
"down": false
},
"nfc_active": false,
"left_stick": {
"x_axis": 1987,
"y_axis": 1912,
"is_center": true
},
"right_stick": {
"x_axis": 2017,
"y_axis": 2005,
"is_center": true
}
}
sudo apt install python3-dbus libhidapi-hidraw0
sudo pip3 install hid aioconsole dbus-python crc8
In order to do that, change the following line in /lib/systemd/system/bluetooth.service from
ExecStart=/usr/lib/bluetooth/bluetoothd
to
ExecStart=/usr/lib/bluetooth/bluetoothd --noplugin=input
and restart Bluetooth with
sudo systemctl daemon-reload
sudo systemctl restart bluetooth