All Projects → risa2000 → lhctrl

risa2000 / lhctrl

Licence: MIT license
Power management of Valve v1 lighthouses over Bluetooth LE

Programming Languages

python
139335 projects - #7 most used programming language

Projects that are alternatives of or similar to lhctrl

Half Life Alyx Novr
SteamVR & TrueOpenVR driver for Half-Life-Alyx for playing without VR / драйвер для игры без VR
Stars: ✭ 227 (+710.71%)
Mutual labels:  valve, steamvr
TurnSignal
An anti-cable-twisting management utility for SteamVR.
Stars: ✭ 73 (+160.71%)
Mutual labels:  valve, steamvr
PhoneVR
Use Steam VR-enabled applications with your phone as HMD (Head-mounted display). The only Open-Source solution to similar commercial packages like VRidge, iVRy, Trinus etc etc.
Stars: ✭ 178 (+535.71%)
Mutual labels:  hmd, steamvr
GameTracking-SteamVR
📥 Game Tracker: SteamVR Home
Stars: ✭ 14 (-50%)
Mutual labels:  valve, steamvr
reshade-vrtoolkit
Modular shader to enhance you HMD clarity & sharpness with minimal performance impact.
Stars: ✭ 40 (+42.86%)
Mutual labels:  hmd, steamvr
esp32-BLEKeyboard
Bluetooth keyboard made from ESP32 board and PS/2 keyboard
Stars: ✭ 26 (-7.14%)
Mutual labels:  bluetooth
rpi3-wifi-conf
A simple Python script to configure wifi over bluetooth for a Raspberry Pi 3
Stars: ✭ 112 (+300%)
Mutual labels:  bluetooth
AirPodsDesktop
☄️ AirPods desktop user experience enhancement program, for Windows and Linux (WIP)
Stars: ✭ 462 (+1550%)
Mutual labels:  bluetooth
gear-vr-controller-linux
Gear VR Controller Linux WebBrowser mouse
Stars: ✭ 37 (+32.14%)
Mutual labels:  bluetooth
playwright-lighthouse
🎭: Playwright Lighthouse Audit
Stars: ✭ 120 (+328.57%)
Mutual labels:  lighthouse
newsteamchat
Metro skin for Steam chat and friends UI.
Stars: ✭ 79 (+182.14%)
Mutual labels:  valve
esp32 bluetooth classic sniffer
Active Bluetooth BR/EDR Sniffer/Injector as cheap as any ESP32 board can get. Works with Scapy ;-)
Stars: ✭ 347 (+1139.29%)
Mutual labels:  bluetooth
AreWeAntiCheatYet
A comprehensive and crowd-sourced list of games using anti-cheats and their compatibility with GNU/Linux or Wine.
Stars: ✭ 289 (+932.14%)
Mutual labels:  valve
coBlue
Use Bluetooth Low Energy for remote commands, file transfer, Based on bluez Bluetooth protocol stack (BLE Terminal)
Stars: ✭ 41 (+46.43%)
Mutual labels:  bluetooth
uberducky
Wireless USB Rubber Ducky triggered via BLE (make your Ubertooth quack!)
Stars: ✭ 80 (+185.71%)
Mutual labels:  bluetooth
joycon-rs
Joy-Con library for Rust 🦀 🎮
Stars: ✭ 104 (+271.43%)
Mutual labels:  bluetooth
ble
Bluetooth Low Energy for Linux / macOS
Stars: ✭ 264 (+842.86%)
Mutual labels:  bluetooth
ESP32 Thing Plus
ESP32 Thing-compatible board using the WROOM module and a QWIIC connector.
Stars: ✭ 18 (-35.71%)
Mutual labels:  bluetooth
ionic-escpos-bluetooth-printer-sample
Sample use of ionic 3 with a bluetooth esc/pos thermal printer
Stars: ✭ 40 (+42.86%)
Mutual labels:  bluetooth
sdk-for-unity-vr-starter-project
[Deprecated] SpatialOS SDK for Unity Virtual Reality Starter Project
Stars: ✭ 43 (+53.57%)
Mutual labels:  steamvr

lhctrl

Power management of Valve v1 lighthouses over Bluetooth LE

Valve v1 lighthouses include a power management feature implemented over the Bluetooth LE protocol. The protocol and the message format used by this feature are briefly described (among others) here https://github.com/nairol/LighthouseRedox. How this feature works will follow.

NOTE: There is a similar Python script to control Valve v2 lighthouses here.

"B" and "C" configuration

In the most usual setup, the lighthouses are used in a pair, where one LH is switched into "B" mode (becomes the master) and the other one into "C" mode (becomes the slave). In this configuration, "C" can only run when also "B" is running. The consequence is that powering off "B" will put "C" into stand-by, i.e. to turn off both LHs it only needs that "B" is turned off. Conversely, if "C" is in stand-by, turning "B" on will also wake up "C".

"B" can be turned off either by simply cutting the power (disconnecting from the power outlet). "B" cannot be directly turned off by a BT LE command, because the BT LE power management of the lighthouses is based on the notion of keeping the lighthouses on rather than on turning them on and off.

To keep "B" running, one needs to ping "B" regularly over BT LE. If those pings stop then "B" will turn off after the specified timeout has been reached. This setup ensures that "B" will turn off even if the controller (e.g. SteamVR running on the user's PC) crashes. This also explains why there is no command for turning the lighthouse off - it will not be reliable.

The ping itself, apart from keeping the lighthouse on, can also turn it on (from stand-by). So the only solution to turn the already running lighthouse off is to instruct it with relatively short timeout, and then let the timeout expire.

Pinging the lighthouse

The ping uses the command described here. Following examples assume a linux machine with bluez package installed. hcitool, hciconfig, gatttool are parts of this package.

Offset | Type   | Name             | Description
-------|--------|------------------|------------
0x00   | uint8  | unknown          | 0x12
0x01   | uint8  | cc               | command: 0x00, 0x01, 0x02
0x02   | uint16 | tttt             | timeout in sec. (big-endian)
0x04   | uint32 | YYXXVVUU         | lighthouse ID or 0xffffffff (little-endian)
0x08   | uint8  |                  | 0x00
...    | ...    |                  | ...
0x13   | uint8  |                  | 0x00

Let's assume that aa:bb:cc:dd:ee:ff is "B" LH MAC address and UUVVXXYY is its binhex ID, which can be found either on the LH enclosure or read from OpenVR database, where the LH is identified as LHB-UUVVXXYY. Ping can be then executed as BT LE write command to the characteristic with the handle 0x0035 this way:

gatttool --device=aa:bb:cc:dd:ee:ff -I
[aa:bb:cc:dd:ee:ff][LE]> connect
[aa:bb:cc:dd:ee:ff][LE]> char-write-req 0x0035 12ccttttYYXXVVUU000000000000000000000000

Note that timeout tttt is encoded in big-endian, while lighthouse ID uses little-endian. The timeout specifies the time in seconds in which the lighthouse will go into stand-by if it does not receive another ping. For the detailed description of the communication protocol (commands) see PROTOCOL.md.

Solution

The implemented solution lhctrl.py uses Python bluepy package to access bluez BT LE API. The script runs the ping command explained above in the loop. First it wakes the LH "B" up, with the specified timeout, and then keeps pinging it, until it is either killed, or the global timeout expires.

Usage

usage: lhctrl.py [-h] -b LH_B_ID [-c LH_C_ID] [--lh_b_mac LH_B_MAC]
                 [--lh_c_mac LH_C_MAC] [--lh_timeout LH_TIMEOUT] [--hndl HNDL]
                 [-g GLOBAL_TIMEOUT] [-i INTERFACE] [-p PING_SLEEP]
                 [--try_count TRY_COUNT] [--try_pause TRY_PAUSE] [--cmd2 CMD2]
                 [-v]

Wakes up and runs Vive lighthouse(s) using BT LE power management

optional arguments:
  -h, --help            show this help message and exit
  -b LH_B_ID, --lh_b_id LH_B_ID
                        BinHex ID of the "B" lighthouse (as in
                        LHB-<8_char_id>)
  -c LH_C_ID, --lh_c_id LH_C_ID
                        Hex ID of the "C" lighthouse (as in LHB-<8char_id>)
  --lh_b_mac LH_B_MAC   BT MAC of the "B" lighthouse (in format
                        aa:bb:cc:dd:ee:ff)
  --lh_c_mac LH_C_MAC   BT MAC of the "C" lighthouse (in format
                        aa:bb:cc:dd:ee:ff)
  --lh_timeout LH_TIMEOUT
                        time (sec) in which LH powers off if not pinged [60]
  --hndl HNDL           characteristic handle [53]
  -g GLOBAL_TIMEOUT, --global_timeout GLOBAL_TIMEOUT
                        time (sec) how long to keep the lighthouse(s) alive
                        (0=forever) [0]
  -i INTERFACE, --interface INTERFACE
                        The Bluetooth interface on which to make the
                        connection to be set. On Linux, 0 means /dev/hci0, 1
                        means /dev/hci1 and so on.
  -p PING_SLEEP, --ping_sleep PING_SLEEP
                        time (sec) between two consecutive pings [20.0]
  --try_count TRY_COUNT
                        number of tries to set up a connection [5]
  --try_pause TRY_PAUSE
                        sleep time when reconnecting [2]
  --cmd2 CMD2           second byte in the data written to the LH [2]
  -v, --verbose         increase verbosity of the log to stdout
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].