Python interface for a Daydream controller.
Project description
snakedream
Python interface for a Daydream controller.
Description
Provides a Python interface to a Daydream controller, by subscribing to GATT notifications for a characteristic (UUID: 00000001-1000-1000-8000-00805f9b34fb).
The DaydreamController class can be found in snakedream.device.
Byte definitions to interpret returned data are found in snakedream.constants (see this Stack Overflow answer for more information).
Data models to represent returned data and handle byte definition calculations are found in snakedream.models.
Please note, ctypes.c_int32 is used when performing bitwise shifts to intentionally allow overflows.
snakedream.mouse and snakedream.graph contain callbacks for mouse and graph support, respectively.
Mouse control is currently supported via two backends: uinput, creating a virtual mouse device, and PyAutoGUI, which controls the cursor directly.
uinput is supported on Linux, both Xorg and Wayland.
PyAutoGUI supports all known platforms, except Wayland on Linux.
To manually specify which backend is used, set snakedream.config.MOUSE_BACKEND to the desired value.
Callbacks
snakedream.base provides an abstract base class, BaseCallback, to provide a parent for subclasses which utilise data from the Daydream controller.
To create a new callback class, create a subclass of BaseCallback, which implements the callback async method, which accepts the following arguments: sender: BleakGATTCharacteristic, data: bytearray.
To register the callback for the controller, call the start method of the instance.
When new data is available from the controller, the callback will be called.
The subclass will also have a controller attribute - passed at instantiation - which can be accessed directly within the callback.
For example:
class ExampleCallback(BaseCallback):
async def callback(self, sender: BleakGATTCharacteristic, data: bytearray) -> None:
if self.controller.buttons.click:
print("Button clicked!")
callback = ExampleCallback(controller)
await callback.start()
Installation
PyPI
- Install project:
pip install snakedream - Run:
snakedream
Source
Alternatively, after cloning the repository with:
git clone https://github.com/Zedeldi/snakedream.git
Build
- Install project:
pip install . - Run:
snakedream
Development
- Install dependencies:
pip install -r requirements.txt - Run:
python -m snakedream
Usage
By default, with no arguments, snakedream will control the mouse with the gyroscope, using the appropriate backend for the host platform.
Additionally, snakedream can output the controller state as JSON or to a graph with matplotlib.
For more information, see snakedream --help.
Libraries
- Bleak - BLE Client
- Matplotlib - Graph support
- python-uinput - Mouse support (device backend)
- PyAutoGUI - Mouse support (GUI backend)
Credits
- daydream-controller.js - WebBluetooth Daydream Controller
- Forrest Porter - Stack Overflow answer for byte definitions
License
snakedream is licensed under the MIT Licence for everyone to use, modify and share freely.
This project is distributed in the hope that it will be useful, but without any warranty.
Donate
If you found this project useful, please consider donating. Any amount is greatly appreciated! Thank you :smiley:
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file snakedream-1.2.2.tar.gz.
File metadata
- Download URL: snakedream-1.2.2.tar.gz
- Upload date:
- Size: 13.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7262911e18eb8c03ec05979ca1185cc0237e964057edd7dc06f1c7d0fffa61a8
|
|
| MD5 |
9c30bb765a714242092be4e22319b308
|
|
| BLAKE2b-256 |
b06439356e26ee1deadb939400d094cdf828ab7c97691f8cbf81194ec65dff76
|
File details
Details for the file snakedream-1.2.2-py3-none-any.whl.
File metadata
- Download URL: snakedream-1.2.2-py3-none-any.whl
- Upload date:
- Size: 15.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.0.1 CPython/3.13.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
34e1924fc7ee6be591ca51d5ca2833690dae85ad43616aab1571ad759e4e10e1
|
|
| MD5 |
d2440f70838e542a70791d281d26b794
|
|
| BLAKE2b-256 |
8f8ee46e442f47c5c805b35d6c6775e52f05222ccd601f6df5c6983f90f1a45f
|