mirror of
https://github.com/DeeJanuz/frametop.git
synced 2026-10-06 09:00:11 +02:00
Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
e44837cee6 | ||
|
|
95c5d056cf | ||
|
|
0c95d1d731 | ||
|
|
060b4957f8 | ||
|
|
7851ce90cc | ||
|
|
a11cef49ba | ||
|
|
8a02e41b21 |
No files matched your search
+4
-6
@@ -116,9 +116,9 @@ The driver starts disconnected, because holding the right-hand role while SteamV
|
|||||||
|
|
||||||
### The cursor
|
### The cursor
|
||||||
|
|
||||||
Mouse motion turns into yaw and pitch around an anchor, the head position at the last recenter. A ray from the anchor is tested against every visible overlay with `ComputeOverlayIntersection`. On a hit, the cursor sits on that surface; otherwise it floats at `POINTER_DISTANCE`. Since the anchor isn't your current eye position, a second test runs along your line of sight to the cursor point, and anything nearer wins, so the cursor always lands on what you see under it. Overlays in `POINTER_IGNORE` are left out of both tests. A display-only panel, like a performance overlay locked to your view, has no input method, so SteamVR's laser passes through it, but `ComputeOverlayIntersection` still hits it, and the cursor stuck to it. The laser starts just before the cursor point, so an ignored panel nearer to you doesn't catch it either. Both tests ask SteamVR about every visible overlay, so a frame where nothing moved (the mouse, the anchor, the eye by more than 5 mm, which overlays show) reuses the last result, for up to 100 ms, since overlays can also move on their own. The dots' overlay settings go to SteamVR only when they change, and the pose goes to the driver, which keeps the last one, only when the laser would land 0.1 mm or more elsewhere, and at least every 100 ms.
|
Mouse motion turns into yaw and pitch around an anchor, the head position at the last recenter. A ray from the anchor is tested against every visible overlay with `ComputeOverlayIntersection`. On a hit, the cursor sits on that surface; otherwise it floats at `POINTER_DISTANCE`. Since the anchor isn't your current eye position, a second test runs along your line of sight to the cursor point, and anything nearer wins, so the cursor always lands on what you see under it. Overlays in `POINTER_IGNORE` are left out of both tests. A display-only panel, like a performance overlay locked to your view, has no input method, so SteamVR's laser passes through it, but `ComputeOverlayIntersection` still hits it, and the cursor stuck to it. The laser starts just before the cursor point, so an ignored panel nearer to you doesn't catch it either.
|
||||||
|
|
||||||
OpenVR has no call to list other programs' overlays, so the helper runs `vrcmd --overlays` in the background. It includes hidden overlays, because a floating window's controls only appear while something hovers the window, and the cursor has to find them immediately. Each run is a shell and a new SteamVR client, about 30 ms of CPU, and it ran every second while the pointer was awake, which in gaze mode is all the time. Now it runs every 20 seconds, and at once when the pointer wakes, when the dashboard opens or closes, when a game starts or ends, and when a left click hits nothing (a panel that came up since). An overlay already on the list showing or hiding needs no new list: the helper checks the visibility of the ones it knows every 50 ms.
|
OpenVR has no call to list other programs' overlays, so the helper runs `vrcmd --overlays` in the background. It includes hidden overlays, because a floating window's controls only appear while something hovers the window, and the cursor has to find them immediately.
|
||||||
|
|
||||||
The laser starts partway along your line of sight to the cursor rather than at your eye. SteamVR sizes its hit dot by distance from the laser's origin, and a laser from the eye still shows a beam in each eye. Starting it close to the target makes the beam and the dot tiny, while `POINTER_ORIGIN_MARGIN` keeps the origin in front of the small window controls, which float a few centimetres in front of their panels. The helper's own white dot is the visible cursor. In empty space it's an interactive overlay that the laser lands on, so SteamVR never draws a laser into nothing.
|
The laser starts partway along your line of sight to the cursor rather than at your eye. SteamVR sizes its hit dot by distance from the laser's origin, and a laser from the eye still shows a beam in each eye. Starting it close to the target makes the beam and the dot tiny, while `POINTER_ORIGIN_MARGIN` keeps the origin in front of the small window controls, which float a few centimetres in front of their panels. The helper's own white dot is the visible cursor. In empty space it's an interactive overlay that the laser lands on, so SteamVR never draws a laser into nothing.
|
||||||
|
|
||||||
@@ -141,7 +141,7 @@ Replacing a loaded driver's files, as re-running the installer used to do, leave
|
|||||||
|
|
||||||
The dashboard follows whichever device summoned it or last pressed its trigger. Frametop adds "last used wins": moving a real controller releases the pointer, and the next mouse movement takes the laser back. Moving means faster than 0.35 m/s or 2 rad/s (both times `POINTER_CONTROLLER_PICKUP`, 1 by default) for 100 ms in a row, while the controller is tracked normally. A single sample over the limit used to be enough, and controllers resting on a desk took the laser back on a knock or a tracking jump while the mouse was in use. Small movements don't count; waking needs `POINTER_WAKE_COUNTS` of mouse motion within a second, so desk jitter doesn't steal the laser. While the pointer is awake, a tiny transparent overlay with `MakeOverlaysInteractiveIfVisible` keeps SteamVR's laser mouse on, since otherwise the first click would only switch the laser on.
|
The dashboard follows whichever device summoned it or last pressed its trigger. Frametop adds "last used wins": moving a real controller releases the pointer, and the next mouse movement takes the laser back. Moving means faster than 0.35 m/s or 2 rad/s (both times `POINTER_CONTROLLER_PICKUP`, 1 by default) for 100 ms in a row, while the controller is tracked normally. A single sample over the limit used to be enough, and controllers resting on a desk took the laser back on a knock or a tracking jump while the mouse was in use. Small movements don't count; waking needs `POINTER_WAKE_COUNTS` of mouse motion within a second, so desk jitter doesn't steal the laser. While the pointer is awake, a tiny transparent overlay with `MakeOverlaysInteractiveIfVisible` keeps SteamVR's laser mouse on, since otherwise the first click would only switch the laser on.
|
||||||
|
|
||||||
When the headset comes off, SteamVR reports its activity level as idle at once and turns the displays off 5 seconds later (`power.turnOffScreensTimeout`), unless something keeps it awake. An awake pointer did, and so did the helper's `vrcmd` runs: each is a new SteamVR client, and a new client every second kept SteamVR out of standby. The helper now releases the pointer as soon as the headset is idle, ignores the mouse until you're wearing it again, and pauses the overlay list whenever the pointer is off. With the pointer off it also stops running its loop every 8 ms, about 116 wakeups a second for nothing: it waits up to 250 ms for a command on its socket (20 ms while it reads mapped controller buttons, which SteamVR input only offers by polling), and leaves the overlay lookups until the pointer wakes.
|
When the headset comes off, SteamVR reports its activity level as idle at once and turns the displays off 5 seconds later (`power.turnOffScreensTimeout`), unless something keeps it awake. An awake pointer did, and so did the helper's `vrcmd` runs: each is a new SteamVR client, and a new client every second kept SteamVR out of standby. The helper now releases the pointer as soon as the headset is idle, ignores the mouse until you're wearing it again, and pauses the overlay list whenever the pointer is off.
|
||||||
|
|
||||||
### Moving floating windows
|
### Moving floating windows
|
||||||
|
|
||||||
@@ -153,8 +153,6 @@ SteamVR opens every input device only when it starts. When a Bluetooth mouse sle
|
|||||||
|
|
||||||
Keyboards aren't grabbed by default, because a grabbed keyboard's keys went into a virtual keyboard nothing typed from; the relay forwards them to ft-screens instead.
|
Keyboards aren't grabbed by default, because a grabbed keyboard's keys went into a virtual keyboard nothing typed from; the relay forwards them to ft-screens instead.
|
||||||
|
|
||||||
The relay never waits on the pointer helper. Its socket to the helper used to block, so when the helper stalled (a layout placement or `grabprobe` holds it for seconds, and the gaze service fills its socket 90 times a second meanwhile), the whole relay stopped with it: keyboards, the volume keys, and pausing. Now what the helper doesn't take waits in order and goes out on the next loops. Mouse moves add up into one while they wait, and a scroll notch is dropped, since scrolling seconds late is no use; presses and releases are kept, so no button stays down. Mouse motion goes to the helper at most every 4 ms, rather than once per report, which from a 1000 Hz mouse was 1000 datagrams a second to a helper that runs every 8 ms; a button sends the motion before it first, so the click lands where the pointer was.
|
|
||||||
|
|
||||||
An ungrabbed keyboard reaches both sides at once. In VR, gamescope reads every input device itself (the SteamOS build's `InputStealer`, libinput with udev hotplug, so new devices too) and types into its focused app, and ft-screens types the same keys into the desktop. So Space in the desktop also paused Spotify on the dashboard. Typing now follows the last click. ft-screens sees clicks on its own screens, from the mouse or a controller. A click anywhere else is only visible for the mouse: overlay apps get SteamVR's `OverlayFocusChanged` (which panel the laser is on) but no controller button events, so the pointer helper reports the panel under the dot on each left press. ft-screens tells the relay where typing goes every second, from an unbound socket so the relay's replies can't loop back into its control socket, and the relay grabs pass-through keyboards while it's the desktop. A grab waits until the keyboard has no key down, so no key stays held on either side, and the relay lets go if ft-screens stops reporting. A program that reads every keyboard for a hotkey (a dictation tool, say) loses a grabbed keyboard. Repeating the keys on another input device doesn't work: gamescope reads that device too, whether it's the relay's virtual keyboard or one created later, and every Space, typed or dictated, paused Spotify again. So with `SHARE_KEYS=1` the relay sends a grabbed keyboard's keys to `@frametop_keys` as datagrams (`key <code> <value> <device name>`). It's off by default, because the relay can't tell who is listening: abstract sockets have no permissions, and any local process that binds the name first gets every key typed into the desktop, passwords included. A listener should accept only its own user (`SO_PASSCRED`) and skip any keyboard of its own that the relay grabs too.
|
An ungrabbed keyboard reaches both sides at once. In VR, gamescope reads every input device itself (the SteamOS build's `InputStealer`, libinput with udev hotplug, so new devices too) and types into its focused app, and ft-screens types the same keys into the desktop. So Space in the desktop also paused Spotify on the dashboard. Typing now follows the last click. ft-screens sees clicks on its own screens, from the mouse or a controller. A click anywhere else is only visible for the mouse: overlay apps get SteamVR's `OverlayFocusChanged` (which panel the laser is on) but no controller button events, so the pointer helper reports the panel under the dot on each left press. ft-screens tells the relay where typing goes every second, from an unbound socket so the relay's replies can't loop back into its control socket, and the relay grabs pass-through keyboards while it's the desktop. A grab waits until the keyboard has no key down, so no key stays held on either side, and the relay lets go if ft-screens stops reporting. A program that reads every keyboard for a hotkey (a dictation tool, say) loses a grabbed keyboard. Repeating the keys on another input device doesn't work: gamescope reads that device too, whether it's the relay's virtual keyboard or one created later, and every Space, typed or dictated, paused Spotify again. So with `SHARE_KEYS=1` the relay sends a grabbed keyboard's keys to `@frametop_keys` as datagrams (`key <code> <value> <device name>`). It's off by default, because the relay can't tell who is listening: abstract sockets have no permissions, and any local process that binds the name first gets every key typed into the desktop, passwords included. A listener should accept only its own user (`SO_PASSCRED`) and skip any keyboard of its own that the relay grabs too.
|
||||||
|
|
||||||
Volume keys must never reach gamescope. With the openvr backend, gamescope sends volume up and down to Steam by moving keyboard focus to Steam for the key and then back to the previously focused surface. When nothing had focus, the one it moves back to is null, and wlroots aborts on a null focus surface (`wlr_seat_keyboard_notify_enter: Assertion 'surface' failed`), which ends the whole VR session. Keyboard focus is often empty while you work in VR, so one press of the headset's volume button could take everything down. gamescope reads the headset's buttons and every keyboard itself (`InputStealer`), as do SteamVR's processes, so the relay has to stop volume keys at the device. Grabbing `gpio-keys` would also take the headset's click button, so the relay remaps the volume entries in each device's keymap (`EVIOCSKEYCODE`) and handles the stand-in codes itself. That fix covers every device at once, including keyboards that aren't grabbed.
|
Volume keys must never reach gamescope. With the openvr backend, gamescope sends volume up and down to Steam by moving keyboard focus to Steam for the key and then back to the previously focused surface. When nothing had focus, the one it moves back to is null, and wlroots aborts on a null focus surface (`wlr_seat_keyboard_notify_enter: Assertion 'surface' failed`), which ends the whole VR session. Keyboard focus is often empty while you work in VR, so one press of the headset's volume button could take everything down. gamescope reads the headset's buttons and every keyboard itself (`InputStealer`), as do SteamVR's processes, so the relay has to stop volume keys at the device. Grabbing `gpio-keys` would also take the headset's click button, so the relay remaps the volume entries in each device's keymap (`EVIOCSKEYCODE`) and handles the stand-in codes itself. That fix covers every device at once, including keyboards that aren't grabbed.
|
||||||
@@ -197,7 +195,7 @@ Hiding the screens during a game kept them out of view, but Frametop kept using
|
|||||||
|
|
||||||
- A hidden screen still cost as much as a visible one. ft-screens sent every committed screen its frame callback at 90 Hz whether its overlay showed or not, so KWin kept drawing, and its apps with it. Paused, ft-screens sends the callbacks once a second. A Wayland client draws again only after its last frame's callback, so KWin's output stalls, KWin's own clients stop getting theirs, and the whole desktop idles, without anything losing its connection. A second's pace, rather than none, keeps any client that waits on a callback from waiting forever. Stopping KWin or the apps with SIGSTOP would free the same, but a Wayland peer that stops reading overflows the other side's 4 KB socket buffer, which ends the connection: that's how the live desktop died once when its KWin stalled (`Data too big for buffer`). They also sit in different cgroups (KWin under steam.service when the VR launcher starts it, ft-screens in the dev container's), so no single freeze stops them together.
|
- A hidden screen still cost as much as a visible one. ft-screens sent every committed screen its frame callback at 90 Hz whether its overlay showed or not, so KWin kept drawing, and its apps with it. Paused, ft-screens sends the callbacks once a second. A Wayland client draws again only after its last frame's callback, so KWin's output stalls, KWin's own clients stop getting theirs, and the whole desktop idles, without anything losing its connection. A second's pace, rather than none, keeps any client that waits on a callback from waiting forever. Stopping KWin or the apps with SIGSTOP would free the same, but a Wayland peer that stops reading overflows the other side's 4 KB socket buffer, which ends the connection: that's how the live desktop died once when its KWin stalled (`Data too big for buffer`). They also sit in different cgroups (KWin under steam.service when the VR launcher starts it, ft-screens in the dev container's), so no single freeze stops them together.
|
||||||
- The relay does the pausing because it's the one part that always runs, and the pointer helper keeps running because stopping it leaves its virtual controller connected with its last pose (the driver has no staleness timeout), maybe holding a hand role, with the 3D mouse dead. Releasing it does the job. The helper already checks for a scene app twice a second, so it's what tells the relay a game started.
|
- The relay does the pausing because it's the one part that always runs, and the pointer helper keeps running because stopping it leaves its virtual controller connected with its last pose (the driver has no staleness timeout), maybe holding a hand role, with the 3D mouse dead. Releasing it does the job. The helper already checks for a scene app twice a second, so it's what tells the relay a game started.
|
||||||
- The gesture has to work during a game, but SteamVR input reaches only the app with input focus, and an overlay with global input (`steamvr/globalActionSetPriority`) takes the buttons it binds from the game. vrserver's web socket on 127.0.0.1:27062, which its controller binding page uses for the live view, reports every controller component whatever has focus, and reading it takes nothing. The game sees the clicks too, so the default is a gesture games hardly use: both thumbsticks, together, twice. "Together" means within 0.3 seconds of each other, so a stick held down to sprint while the other clicks doesn't count. The stream is about 160 messages a second, nearly all capacitive sensing, so the reader parses only the few that mention a gesture's button. A controller's root path changes while the 3D mouse holds its hand role (`/devices/cv/<serial>` instead of `/user/hand/right`), so the reader looks the controllers up again (an HTTP request to vrserver): when the relay's 3D mouse connects or lets go, when a message comes from a device it doesn't know, and every 30 seconds. It used to be every 3 seconds.
|
- The gesture has to work during a game, but SteamVR input reaches only the app with input focus, and an overlay with global input (`steamvr/globalActionSetPriority`) takes the buttons it binds from the game. vrserver's web socket on 127.0.0.1:27062, which its controller binding page uses for the live view, reports every controller component whatever has focus, and reading it takes nothing. The game sees the clicks too, so the default is a gesture games hardly use: both thumbsticks, together, twice. "Together" means within 0.3 seconds of each other, so a stick held down to sprint while the other clicks doesn't count. The stream is about 160 messages a second, nearly all capacitive sensing, so the reader parses only the few that mention a gesture's button. A controller's root path changes while the 3D mouse holds its hand role (`/devices/cv/<serial>` instead of `/user/hand/right`), so the reader looks the controllers up again every 3 seconds.
|
||||||
- Resuming starts remote desktop through `systemd-run --scope`: started straight from the relay, it would join the relay's cgroup and end with the next relay restart.
|
- Resuming starts remote desktop through `systemd-run --scope`: started straight from the relay, it would join the relay's cgroup and end with the next relay restart.
|
||||||
|
|
||||||
## SteamOS updates
|
## SteamOS updates
|
||||||
|
|||||||
+2
-2
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
The Steam Frame's eye tracking as pointer input: a gaze mode for the 3D mouse (the pointer goes where you look, and the mouse does the last bit), and the tools to calibrate and measure it.
|
The Steam Frame's eye tracking as pointer input: a gaze mode for the 3D mouse (the pointer goes where you look, and the mouse does the last bit), and the tools to calibrate and measure it.
|
||||||
|
|
||||||
- `ft-gaze` (C++, OpenVR, runs in the dev container) reads the eye tracker and prints one JSON line per sample (90 Hz). For each source, it gives the gaze direction relative to the head and the Frametop screen pixel it lands on.
|
- `ft-gaze` (C++, OpenVR, runs in the dev container) reads the eye tracker and prints one JSON line per sample (90 Hz). For each source, it gives the gaze direction relative to the head and the Frametop screen pixel it lands on. The gaze service asks it for only the sources it uses (`--sources`, and `sources LIST` on its stdin): our tracker and mmap set 1 with Own tracker, about 700 bytes a line instead of 1.3 KB, and every source while a check or the calibration runs. So SteamVR's gaze action, the only source that calls into vrserver (twice a sample), is read only then. The probe gets them all.
|
||||||
- `gazecal.py` has what the probe and the gaze service share: the correction models, filters, and the reader for SteamVR's eye tracking log.
|
- `gazecal.py` has what the probe and the gaze service share: the correction models, filters, and the reader for SteamVR's eye tracking log.
|
||||||
- `tracker/` is our own eye tracker, an alternative to SteamVR's: `ft-eyes` finds the pupils and glints in the eye-camera frames that `ft-eyegrab` (a small root service) copies out of SteamVR's tracker. See "Our own eye tracker" below.
|
- `tracker/` is our own eye tracker, an alternative to SteamVR's: `ft-eyes` finds the pupils and glints in the eye-camera frames that `ft-eyegrab` (a small root service) copies out of SteamVR's tracker. See "Our own eye tracker" below.
|
||||||
- `probe/ft-gazeprobe` (GTK 4, host Python) is a fullscreen playground, for developing the gaze tracking: day to day, the calibration and the checks run in the headset panel (Quick check, Calibrate, and Check headset fit on the Gaze page). It runs ft-gaze, draws where you're looking, measures accuracy, and tries out hold-to-adjust clicking with a calibration that learns from your adjustments.
|
- `probe/ft-gazeprobe` (GTK 4, host Python) is a fullscreen playground, for developing the gaze tracking: day to day, the calibration and the checks run in the headset panel (Quick check, Calibrate, and Check headset fit on the Gaze page). It runs ft-gaze, draws where you're looking, measures accuracy, and tries out hold-to-adjust clicking with a calibration that learns from your adjustments.
|
||||||
@@ -63,7 +63,7 @@ Ground rules, for anyone changing it:
|
|||||||
- **Clean room.** Nothing of Valve's goes in: we don't decompile, disassemble, or patch the `eyetracking` binary or its network weights, and we don't copy their code or weights. Its public output (eye-server.mmap, read-only) is fair game as a baseline and as labels, and so are published papers and openly licensed pupil detectors (check each one's license: PuRe, PuReST, ElSe, and ExCuSe are non-commercial only).
|
- **Clean room.** Nothing of Valve's goes in: we don't decompile, disassemble, or patch the `eyetracking` binary or its network weights, and we don't copy their code or weights. Its public output (eye-server.mmap, read-only) is fair game as a baseline and as labels, and so are published papers and openly licensed pupil detectors (check each one's license: PuRe, PuReST, ElSe, and ExCuSe are non-commercial only).
|
||||||
- **Root only reads.** ft-eyegrab never writes to, stops, or signals the `eyetracking` process, vrserver, or vrcompositor, never opens `/dev/adsp`, `/dev/cdsp`, or `/dev/spidev0.1`, and never writes to `/dev/shm/eye-server.mmap` (it also carries calibration clicks into SteamVR's tracker), `/opt`, or `/persist`.
|
- **Root only reads.** ft-eyegrab never writes to, stops, or signals the `eyetracking` process, vrserver, or vrcompositor, never opens `/dev/adsp`, `/dev/cdsp`, or `/dev/spidev0.1`, and never writes to `/dev/shm/eye-server.mmap` (it also carries calibration clicks into SteamVR's tracker), `/opt`, or `/persist`.
|
||||||
- **Eye images are biometric data.** Recordings live outside the repo, in `~/.local/share/frametop/eyes/captures` (0700), and `.gitignore` catches stray frame dumps. They go nowhere but the machine that runs your offline jobs.
|
- **Eye images are biometric data.** Recordings live outside the repo, in `~/.local/share/frametop/eyes/captures` (0700), and `.gitignore` catches stray frame dumps. They go nowhere but the machine that runs your offline jobs.
|
||||||
- **Mind the headset's budget.** Finding a pupil takes about 0.4 ms a frame while ft-eyes follows it, and 1.4-2.1 ms when it searches the whole frame. Replays, scoring, and training go to a PC.
|
- **Mind the headset's budget.** Finding a pupil takes about 0.4 ms a frame while ft-eyes follows it, and 1.4-2.1 ms when it searches the whole frame. ft-eyes keeps OpenCV and numpy to one thread: their pools of one per core spun idle workers at about a quarter of a core, for frames this small. It also runs at nice 10 with SCHED_BATCH, and ft-gaze at nice 5 (not batch, since each sample goes on to the pointer): both run in the dev container's podman scope, out of reach of the gaze service's unit, on the cores vrcompositor and vrserver use at nice 0. Replays, scoring, and training go to a PC.
|
||||||
|
|
||||||
## Headset fit
|
## Headset fit
|
||||||
|
|
||||||
|
|||||||
+85
-16
@@ -4,7 +4,14 @@
|
|||||||
// Every eye tracker sample (90 Hz) becomes one JSON line on stdout with each gaze source
|
// Every eye tracker sample (90 Hz) becomes one JSON line on stdout with each gaze source
|
||||||
// hit-tested against the Frametop screens:
|
// hit-tested against the Frametop screens:
|
||||||
//
|
//
|
||||||
// Options: -v (log action errors), --watch-stdin (quit when stdin closes).
|
// Options: -v (log action errors), --watch-stdin (quit when stdin closes; until then, a line
|
||||||
|
// "sources LIST" on stdin switches the sources as --sources does), --sources LIST (comma-
|
||||||
|
// separated: action, mmap1, mmap2, left, right, own, and eye for EYE; or all, the default).
|
||||||
|
// Sources left out are read not at all and print as {"ok":0} ("eye" as null), so every line
|
||||||
|
// keeps the same keys. The gaze service asks for the ones it uses (own and mmap1 with our
|
||||||
|
// tracker), and all of them while a check or the calibration runs. Only the action costs
|
||||||
|
// SteamVR anything (two calls into vrserver per sample), and a line with every source is
|
||||||
|
// about 1.5 KB, 130 KB a second through podman's relay.
|
||||||
//
|
//
|
||||||
// {"t":<sample time, CLOCK_MONOTONIC_RAW s>,"age":<ms old when read>,"n":<sample counter>,
|
// {"t":<sample time, CLOCK_MONOTONIC_RAW s>,"age":<ms old when read>,"n":<sample counter>,
|
||||||
// "head":{"yaw":..,"pitch":..,"hit":HIT}, head forward ray (for head nudging)
|
// "head":{"yaw":..,"pitch":..,"hit":HIT}, head forward ray (for head nudging)
|
||||||
@@ -58,6 +65,7 @@
|
|||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <atomic>
|
#include <atomic>
|
||||||
|
#include <cerrno>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <climits>
|
#include <climits>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
@@ -72,6 +80,7 @@
|
|||||||
|
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
|
#include <sys/resource.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/un.h>
|
#include <sys/un.h>
|
||||||
@@ -389,6 +398,30 @@ std::string SrcJson(const std::vector<Screen> &screens, const vr::HmdMatrix34_t
|
|||||||
return buf + extra + "\"hit\":" + HitJson(screens, head, yaw, pitch) + "}";
|
return buf + extra + "\"hit\":" + HitJson(screens, head, yaw, pitch) + "}";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Sources (--sources, "sources LIST" on stdin): a bit each.
|
||||||
|
enum : unsigned { kAction = 1, kMmap1 = 2, kMmap2 = 4, kLeft = 8, kRight = 16, kOwn = 32, kEye = 64, kAll = 127 };
|
||||||
|
|
||||||
|
bool ParseSources(const std::string &list, unsigned &mask) {
|
||||||
|
static const struct {
|
||||||
|
const char *name;
|
||||||
|
unsigned bit;
|
||||||
|
} names[] = {{"action", kAction}, {"mmap1", kMmap1}, {"mmap2", kMmap2}, {"left", kLeft},
|
||||||
|
{"right", kRight}, {"own", kOwn}, {"eye", kEye}, {"all", kAll}};
|
||||||
|
unsigned m = 0;
|
||||||
|
size_t at = 0;
|
||||||
|
while (at <= list.size()) {
|
||||||
|
const size_t comma = std::min(list.find(',', at), list.size());
|
||||||
|
const std::string name = list.substr(at, comma - at);
|
||||||
|
bool known = false;
|
||||||
|
for (const auto &n : names)
|
||||||
|
if (name == n.name) m |= n.bit, known = true;
|
||||||
|
if (!known) return false;
|
||||||
|
at = comma + 1;
|
||||||
|
}
|
||||||
|
mask = m;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
// Head poses of the last half second, so a sample can use the pose at its own time.
|
// Head poses of the last half second, so a sample can use the pose at its own time.
|
||||||
class PoseHistory {
|
class PoseHistory {
|
||||||
public:
|
public:
|
||||||
@@ -426,17 +459,42 @@ std::string ExeDir() {
|
|||||||
|
|
||||||
int main(int argc, char **argv) {
|
int main(int argc, char **argv) {
|
||||||
bool verbose = false, watchStdin = false;
|
bool verbose = false, watchStdin = false;
|
||||||
|
std::atomic<unsigned> sources{kAll};
|
||||||
for (int i = 1; i < argc; ++i) {
|
for (int i = 1; i < argc; ++i) {
|
||||||
if (std::strcmp(argv[i], "-v") == 0) verbose = true;
|
if (std::strcmp(argv[i], "-v") == 0) verbose = true;
|
||||||
if (std::strcmp(argv[i], "--watch-stdin") == 0) watchStdin = true;
|
if (std::strcmp(argv[i], "--watch-stdin") == 0) watchStdin = true;
|
||||||
|
if (std::strcmp(argv[i], "--sources") == 0 && i + 1 < argc) {
|
||||||
|
unsigned m;
|
||||||
|
if (ParseSources(argv[++i], m))
|
||||||
|
sources = m;
|
||||||
|
else
|
||||||
|
std::fprintf(stderr, "ft-gaze: --sources %s: unknown source (all used)\n", argv[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
// Nice 5, before any thread starts (they inherit it): we run in the dev container's podman
|
||||||
|
// scope, beside vrcompositor and vrserver at nice 0, and the gaze service's unit doesn't
|
||||||
|
// reach us. Not SCHED_BATCH, as ft-eyes is: that would let each wakeup wait out another
|
||||||
|
// task's turn, and each sample goes on to the pointer.
|
||||||
|
errno = 0;
|
||||||
|
const int nice0 = getpriority(PRIO_PROCESS, 0);
|
||||||
|
if (errno == 0 && nice0 < 5 && setpriority(PRIO_PROCESS, 0, 5) != 0)
|
||||||
|
std::fprintf(stderr, "ft-gaze: nice: %s\n", std::strerror(errno));
|
||||||
// --watch-stdin: quit when stdin closes. The probe runs us through distrobox, which
|
// --watch-stdin: quit when stdin closes. The probe runs us through distrobox, which
|
||||||
// passes neither its signals nor a closed stdout on to us, but does pass stdin's end.
|
// passes neither its signals nor a closed stdout on to us, but does pass stdin's end.
|
||||||
|
// Lines on stdin until then: "sources LIST".
|
||||||
std::atomic<bool> stdinClosed{false};
|
std::atomic<bool> stdinClosed{false};
|
||||||
if (watchStdin)
|
if (watchStdin)
|
||||||
std::thread([&stdinClosed] {
|
std::thread([&stdinClosed, &sources] {
|
||||||
char c[256];
|
char c[256];
|
||||||
while (read(0, c, sizeof c) > 0) {
|
std::string line;
|
||||||
|
ssize_t n;
|
||||||
|
while ((n = read(0, c, sizeof c)) > 0) {
|
||||||
|
line.append(c, size_t(n));
|
||||||
|
for (size_t nl; (nl = line.find('\n')) != std::string::npos; line.erase(0, nl + 1)) {
|
||||||
|
unsigned m;
|
||||||
|
if (line.compare(0, 8, "sources ") == 0 && ParseSources(line.substr(8, nl - 8), m)) sources = m;
|
||||||
|
}
|
||||||
|
if (line.size() > 4096) line.clear(); // no newline in sight: not ours
|
||||||
}
|
}
|
||||||
stdinClosed = true;
|
stdinClosed = true;
|
||||||
}).detach();
|
}).detach();
|
||||||
@@ -509,6 +567,7 @@ int main(int argc, char **argv) {
|
|||||||
|
|
||||||
if (fresh && hp.bPoseIsValid) {
|
if (fresh && hp.bPoseIsValid) {
|
||||||
lastEmit = now;
|
lastEmit = now;
|
||||||
|
const unsigned want = sources;
|
||||||
const auto list = screens.Get();
|
const auto list = screens.Get();
|
||||||
const vr::HmdMatrix34_t &headNow = hp.mDeviceToAbsoluteTracking;
|
const vr::HmdMatrix34_t &headNow = hp.mDeviceToAbsoluteTracking;
|
||||||
vr::HmdMatrix34_t headThen = headNow;
|
vr::HmdMatrix34_t headThen = headNow;
|
||||||
@@ -517,7 +576,7 @@ int main(int argc, char **argv) {
|
|||||||
// SteamVR's action: a room-space origin and fixation point, turned into the head
|
// SteamVR's action: a room-space origin and fixation point, turned into the head
|
||||||
// frame so every source reports the same kind of angles.
|
// frame so every source reports the same kind of angles.
|
||||||
std::string action = "{\"ok\":0}";
|
std::string action = "{\"ok\":0}";
|
||||||
if (!inGame) {
|
if (!inGame && (want & kAction)) {
|
||||||
vr::VRActiveActionSet_t active{};
|
vr::VRActiveActionSet_t active{};
|
||||||
active.ulActionSet = set;
|
active.ulActionSet = set;
|
||||||
active.nPriority = vr::k_nActionSetOverlayGlobalPriorityMin;
|
active.nPriority = vr::k_nActionSetOverlayGlobalPriorityMin;
|
||||||
@@ -560,26 +619,33 @@ int main(int argc, char **argv) {
|
|||||||
return std::string(b);
|
return std::string(b);
|
||||||
};
|
};
|
||||||
char extra[256];
|
char extra[256];
|
||||||
std::snprintf(extra, sizeof extra, "\"dist\":%.3f,\"open\":[%.3f,%.3f],\"lr\":%.3f,", Length(s.fix1),
|
if (want & kMmap1) {
|
||||||
s.open[0], s.open[1], lr(s.left1, s.right1));
|
std::snprintf(extra, sizeof extra, "\"dist\":%.3f,\"open\":[%.3f,%.3f],\"lr\":%.3f,", Length(s.fix1),
|
||||||
m1 = SrcJson(list, headThen, s.left1 + s.right1, extra + eyes(s.left1, s.right1) + unc(s.var1));
|
s.open[0], s.open[1], lr(s.left1, s.right1));
|
||||||
std::snprintf(extra, sizeof extra, "\"lr\":%.3f,", lr(s.left2, s.right2));
|
m1 = SrcJson(list, headThen, s.left1 + s.right1, extra + eyes(s.left1, s.right1) + unc(s.var1));
|
||||||
m2 = SrcJson(list, headThen, s.left2 + s.right2, extra + eyes(s.left2, s.right2) + unc(s.var2));
|
}
|
||||||
left = SrcJson(list, headThen, s.left2);
|
if (want & kMmap2) {
|
||||||
right = SrcJson(list, headThen, s.right2);
|
std::snprintf(extra, sizeof extra, "\"lr\":%.3f,", lr(s.left2, s.right2));
|
||||||
|
m2 = SrcJson(list, headThen, s.left2 + s.right2, extra + eyes(s.left2, s.right2) + unc(s.var2));
|
||||||
|
}
|
||||||
|
if (want & kLeft) left = SrcJson(list, headThen, s.left2);
|
||||||
|
if (want & kRight) right = SrcJson(list, headThen, s.right2);
|
||||||
|
// "new" compares with the last sample, so the last measurement is kept either way.
|
||||||
const float *m = s.meas;
|
const float *m = s.meas;
|
||||||
const bool newL = m[0] != lastMeas[0] || m[1] != lastMeas[1];
|
const bool newL = m[0] != lastMeas[0] || m[1] != lastMeas[1];
|
||||||
const bool newR = m[2] != lastMeas[2] || m[3] != lastMeas[3];
|
const bool newR = m[2] != lastMeas[2] || m[3] != lastMeas[3];
|
||||||
std::memcpy(lastMeas, m, sizeof lastMeas);
|
std::memcpy(lastMeas, m, sizeof lastMeas);
|
||||||
std::snprintf(extra, sizeof extra, "{\"q\":[%.3g,%.3g],\"m\":[[%.4f,%.4f],[%.4f,%.4f]],\"new\":[%d,%d]}",
|
if (want & kEye) {
|
||||||
(m[4] + m[5]) / 2, (m[6] + m[7]) / 2, m[0], m[1], m[2], m[3], int(newL), int(newR));
|
std::snprintf(extra, sizeof extra, "{\"q\":[%.3g,%.3g],\"m\":[[%.4f,%.4f],[%.4f,%.4f]],\"new\":[%d,%d]}",
|
||||||
eye = extra;
|
(m[4] + m[5]) / 2, (m[6] + m[7]) / 2, m[0], m[1], m[2], m[3], int(newL), int(newR));
|
||||||
|
eye = extra;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Our tracker: its own sample time picks the head pose, like the mmap's.
|
// Our tracker: its own sample time picks the head pose, like the mmap's.
|
||||||
std::string own = "{\"ok\":0}";
|
std::string own = "{\"ok\":0}";
|
||||||
OwnSample o;
|
OwnSample o;
|
||||||
if (ownFile.Read(o) && now - o.t < 0.1) {
|
if ((want & kOwn) && ownFile.Read(o) && now - o.t < 0.1) {
|
||||||
vr::HmdMatrix34_t headOwn = headNow;
|
vr::HmdMatrix34_t headOwn = headNow;
|
||||||
history.At(o.t, headOwn);
|
history.At(o.t, headOwn);
|
||||||
auto pair = [](bool ok, float a, float b) {
|
auto pair = [](bool ok, float a, float b) {
|
||||||
@@ -624,7 +690,10 @@ int main(int argc, char **argv) {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if (stdinClosed) break;
|
if (stdinClosed) break;
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(2));
|
// 250 passes a second: a new sample is printed within 4 ms (2 on average) of appearing,
|
||||||
|
// and the pose history has a pose within 2 ms of any sample's time (a 0.2 degree head
|
||||||
|
// turn at 100 degrees a second). Every 2 ms read the pose and the events twice as often.
|
||||||
|
std::this_thread::sleep_for(std::chrono::milliseconds(4));
|
||||||
}
|
}
|
||||||
screens.Stop();
|
screens.Stop();
|
||||||
vr::VR_Shutdown();
|
vr::VR_Shutdown();
|
||||||
|
|||||||
+38
-3
@@ -76,6 +76,12 @@ off. A check asked for while idle waits for the tracker to start (at most WAKE_S
|
|||||||
tracker's next click after it starts again re-seats it, as after the headset was off, so turning
|
tracker's next click after it starts again re-seats it, as after the headset was off, so turning
|
||||||
gaze mode on after a while opens the quick check.
|
gaze mode on after a while opens the quick check.
|
||||||
|
|
||||||
|
ft-gaze prints only the sources this uses ("sources LIST" on its stdin, see wanted_sources):
|
||||||
|
own and mmap1 with our tracker, left, right and mmap1 with SteamVR's eyes, and every source
|
||||||
|
while a check or the calibration runs or is asked for, since those record them all. So
|
||||||
|
SteamVR's gaze action, the one source that calls into vrserver, is read only then (or with
|
||||||
|
--source action).
|
||||||
|
|
||||||
Checks and calibration (gaze/gazecheck.py): a one-dot quick check when the headset goes on or
|
Checks and calibration (gaze/gazecheck.py): a one-dot quick check when the headset goes on or
|
||||||
our tracker asks for a click, and the full calibration when gaze mode comes on without one,
|
our tracker asks for a click, and the full calibration when gaze mode comes on without one,
|
||||||
both in a panel fixed to the headset (gaze/panel/ft-gazepanel, which this service runs too).
|
both in a panel fixed to the headset (gaze/panel/ft-gazepanel, which this service runs too).
|
||||||
@@ -260,6 +266,7 @@ class Service:
|
|||||||
self.sel.register(self.eyes_sock, selectors.EVENT_READ, "own")
|
self.sel.register(self.eyes_sock, selectors.EVENT_READ, "own")
|
||||||
self.checks = Checks(self, self.sel)
|
self.checks = Checks(self, self.sel)
|
||||||
self.proc = None
|
self.proc = None
|
||||||
|
self.proc_sources = None # what ft-gaze was last told to print
|
||||||
self.buf = b""
|
self.buf = b""
|
||||||
self.restart_at = 0.0
|
self.restart_at = 0.0
|
||||||
self.running = True
|
self.running = True
|
||||||
@@ -459,6 +466,31 @@ class Service:
|
|||||||
|
|
||||||
# --- ft-gaze ---
|
# --- ft-gaze ---
|
||||||
|
|
||||||
|
def wanted_sources(self):
|
||||||
|
"""The sources ft-gaze should print (its --sources): what on_sample and the checks read.
|
||||||
|
mmap1 always (blinks, lost eyes, and the headset going on, from its openness and
|
||||||
|
variances); everything while a check runs or waits, since they record every source."""
|
||||||
|
c = self.checks
|
||||||
|
if c.active or c.pending:
|
||||||
|
return "all"
|
||||||
|
kind = self.kind
|
||||||
|
if kind == "own":
|
||||||
|
return "own,mmap1"
|
||||||
|
if kind == "eyes":
|
||||||
|
return "left,right,mmap1"
|
||||||
|
return ",".join(dict.fromkeys((self.source, "mmap1", "mmap2"))) # mmap2: each eye, for the fallback
|
||||||
|
|
||||||
|
def sync_sources(self):
|
||||||
|
want = self.wanted_sources()
|
||||||
|
if not self.proc or want == self.proc_sources:
|
||||||
|
return
|
||||||
|
try:
|
||||||
|
self.proc.stdin.write(f"sources {want}\n".encode())
|
||||||
|
self.proc.stdin.flush()
|
||||||
|
except (OSError, ValueError):
|
||||||
|
return # it's stopping: read_stdout notices
|
||||||
|
self.proc_sources = want
|
||||||
|
|
||||||
def start_helper(self):
|
def start_helper(self):
|
||||||
if not HELPER.exists():
|
if not HELPER.exists():
|
||||||
log(f"ft-gaze isn't built: run {REPO}/gaze/build.sh")
|
log(f"ft-gaze isn't built: run {REPO}/gaze/build.sh")
|
||||||
@@ -469,9 +501,11 @@ class Service:
|
|||||||
subprocess.run([str(REPO / "scripts" / "container-up.sh")], env=env, check=False)
|
subprocess.run([str(REPO / "scripts" / "container-up.sh")], env=env, check=False)
|
||||||
distrobox = Path.home() / ".local" / "bin" / "distrobox"
|
distrobox = Path.home() / ".local" / "bin" / "distrobox"
|
||||||
# ft-gaze quits when its stdin closes: the one thing distrobox passes on.
|
# ft-gaze quits when its stdin closes: the one thing distrobox passes on.
|
||||||
self.proc = subprocess.Popen([str(distrobox), "enter", "dev", "--", str(HELPER), "--watch-stdin"], env=env,
|
sources = self.wanted_sources()
|
||||||
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
|
self.proc = subprocess.Popen([str(distrobox), "enter", "dev", "--", str(HELPER), "--watch-stdin",
|
||||||
start_new_session=True)
|
"--sources", sources], env=env, stdin=subprocess.PIPE, stdout=subprocess.PIPE,
|
||||||
|
stderr=subprocess.PIPE, start_new_session=True)
|
||||||
|
self.proc_sources = sources
|
||||||
os.set_blocking(self.proc.stdout.fileno(), False)
|
os.set_blocking(self.proc.stdout.fileno(), False)
|
||||||
os.set_blocking(self.proc.stderr.fileno(), False)
|
os.set_blocking(self.proc.stderr.fileno(), False)
|
||||||
self.sel.register(self.proc.stdout, selectors.EVENT_READ, "stdout")
|
self.sel.register(self.proc.stdout, selectors.EVENT_READ, "stdout")
|
||||||
@@ -876,6 +910,7 @@ class Service:
|
|||||||
elif key.data == "stderr" and self.proc:
|
elif key.data == "stderr" and self.proc:
|
||||||
self.read_stderr()
|
self.read_stderr()
|
||||||
self.checks.tick()
|
self.checks.tick()
|
||||||
|
self.sync_sources()
|
||||||
if now >= next_periodic:
|
if now >= next_periodic:
|
||||||
self.periodic()
|
self.periodic()
|
||||||
next_periodic = now + 1.0
|
next_periodic = now + 1.0
|
||||||
|
|||||||
@@ -47,6 +47,7 @@
|
|||||||
#include <drm_fourcc.h>
|
#include <drm_fourcc.h>
|
||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <gbm.h>
|
#include <gbm.h>
|
||||||
|
#include <poll.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/un.h>
|
#include <sys/un.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
@@ -524,7 +525,11 @@ int main(int argc, char **argv) {
|
|||||||
if (!shown) ov->ShowOverlay(h), shown = true;
|
if (!shown) ov->ShowOverlay(h), shown = true;
|
||||||
dirty = false;
|
dirty = false;
|
||||||
}
|
}
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(visible ? 10 : 50));
|
// Until a command comes, or 10 ms while shown (SteamVR's events). Hidden, it waits up to a
|
||||||
|
// second: it woke 20 to 30 times a second for nothing, the main cost left with gaze idle.
|
||||||
|
// A closed stdin (--watch-stdin) wakes it too, so quitting doesn't wait.
|
||||||
|
pollfd fds[2] = {{sock, POLLIN, 0}, {0, POLLIN, 0}};
|
||||||
|
poll(fds, watchStdin ? 2 : 1, visible ? 10 : 1000);
|
||||||
}
|
}
|
||||||
ov->DestroyOverlay(h);
|
ov->DestroyOverlay(h);
|
||||||
buffers.Drop();
|
buffers.Drop();
|
||||||
|
|||||||
+26
-6
@@ -37,14 +37,26 @@ gazed.read_settings = lambda: ("steam", "steam", "auto", 55.0)
|
|||||||
logs = []
|
logs = []
|
||||||
gazed.log = gazecheck.log = lambda msg: logs.append(msg)
|
gazed.log = gazecheck.log = lambda msg: logs.append(msg)
|
||||||
|
|
||||||
# The fake ft-gaze: 90 samples a second, both eyes seen, until its stdin closes.
|
# The fake ft-gaze: 90 samples a second, both eyes seen, until its stdin closes. It logs the
|
||||||
|
# sources it was asked for: "argv LIST" (--sources), then "line LIST" for each "sources LIST".
|
||||||
tmp = tempfile.mkdtemp(prefix="ft-gaze-idle-test-")
|
tmp = tempfile.mkdtemp(prefix="ft-gaze-idle-test-")
|
||||||
FAKE = os.path.join(tmp, "ft-gaze")
|
FAKE = os.path.join(tmp, "ft-gaze")
|
||||||
|
SOURCES_LOG = os.path.join(tmp, "sources.log")
|
||||||
with open(FAKE, "w") as f:
|
with open(FAKE, "w") as f:
|
||||||
f.write('''import json, select, sys, time
|
f.write('''import json, os, select, sys, time
|
||||||
|
log = open(sys.argv[1], "a", buffering=1)
|
||||||
|
log.write("argv " + (sys.argv[sys.argv.index("--sources") + 1] if "--sources" in sys.argv else "-") + "\\n")
|
||||||
|
buf = b""
|
||||||
while True:
|
while True:
|
||||||
if select.select([sys.stdin], [], [], 1 / 90)[0] and not sys.stdin.read(1):
|
if select.select([sys.stdin], [], [], 1 / 90)[0]:
|
||||||
break
|
data = os.read(0, 4096)
|
||||||
|
if not data:
|
||||||
|
break
|
||||||
|
buf += data
|
||||||
|
while b"\\n" in buf:
|
||||||
|
line, buf = buf.split(b"\\n", 1)
|
||||||
|
if line.startswith(b"sources "):
|
||||||
|
log.write("line " + line[8:].decode() + "\\n")
|
||||||
eye = {"hy": 1.0, "hp": 2.0}
|
eye = {"hy": 1.0, "hp": 2.0}
|
||||||
print(json.dumps({"t": time.monotonic(), "src": {"mmap1": {"hy": 1.0, "hp": 2.0, "unc": [0.001, 0.001],
|
print(json.dumps({"t": time.monotonic(), "src": {"mmap1": {"hy": 1.0, "hp": 2.0, "unc": [0.001, 0.001],
|
||||||
"open": [0.8, 0.8]}, "left": eye, "right": eye}}), flush=True)
|
"open": [0.8, 0.8]}, "left": eye, "right": eye}}), flush=True)
|
||||||
@@ -55,8 +67,9 @@ started = []
|
|||||||
def start_helper(self):
|
def start_helper(self):
|
||||||
"""ft-gaze, straight from here instead of the dev container."""
|
"""ft-gaze, straight from here instead of the dev container."""
|
||||||
import selectors
|
import selectors
|
||||||
self.proc = subprocess.Popen([sys.executable, FAKE], stdin=subprocess.PIPE, stdout=subprocess.PIPE,
|
self.proc = subprocess.Popen([sys.executable, FAKE, SOURCES_LOG, "--sources", self.wanted_sources()],
|
||||||
stderr=subprocess.PIPE)
|
stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
|
self.proc_sources = self.wanted_sources()
|
||||||
os.set_blocking(self.proc.stdout.fileno(), False)
|
os.set_blocking(self.proc.stdout.fileno(), False)
|
||||||
os.set_blocking(self.proc.stderr.fileno(), False)
|
os.set_blocking(self.proc.stderr.fileno(), False)
|
||||||
self.sel.register(self.proc.stdout, selectors.EVENT_READ, "stdout")
|
self.sel.register(self.proc.stdout, selectors.EVENT_READ, "stdout")
|
||||||
@@ -142,17 +155,24 @@ check("lease over (2 s + IDLE_AFTER): idle", wait(lambda: not svc.awake, 4.5), T
|
|||||||
|
|
||||||
time.sleep(0.5)
|
time.sleep(0.5)
|
||||||
logs.clear()
|
logs.clear()
|
||||||
|
open(SOURCES_LOG, "w").close()
|
||||||
count = len(started)
|
count = len(started)
|
||||||
check("quick check while idle: queued, waking", ask("quickcal"), "ok waking the eye tracker first")
|
check("quick check while idle: queued, waking", ask("quickcal"), "ok waking the eye tracker first")
|
||||||
check("it woke", wait(lambda: svc.awake and len(started) > count, 1.5), True)
|
check("it woke", wait(lambda: svc.awake and len(started) > count, 1.5), True)
|
||||||
check("once the tracker sends, it ran (and says why it couldn't open)",
|
check("once the tracker sends, it ran (and says why it couldn't open)",
|
||||||
wait(lambda: any("quickcal, asked for while idle: the panel isn't running" in m for m in logs), 3), True)
|
wait(lambda: any("quickcal, asked for while idle: the panel isn't running" in m for m in logs), 3), True)
|
||||||
check("nothing left pending", svc.checks.pending, None)
|
check("nothing left pending", svc.checks.pending, None)
|
||||||
|
sources = open(SOURCES_LOG).read().split("\n")
|
||||||
|
check("ft-gaze started with every source for the check", sources[0], "argv all")
|
||||||
|
in_use = svc.wanted_sources()
|
||||||
|
check("then only those in use (SteamVR's tracker: not the action, not own)",
|
||||||
|
(f"line {in_use}" in sources, in_use != "all", "action" in in_use, "own" in in_use), (True, True, False, False))
|
||||||
check("idle again after", wait(lambda: not svc.awake, 3), True)
|
check("idle again after", wait(lambda: not svc.awake, 3), True)
|
||||||
|
|
||||||
print("FAILED: " + ", ".join(failures) if failures else "all passed", flush=True)
|
print("FAILED: " + ", ".join(failures) if failures else "all passed", flush=True)
|
||||||
svc.running = False
|
svc.running = False
|
||||||
time.sleep(0.7)
|
time.sleep(0.7)
|
||||||
os.remove(FAKE)
|
os.remove(FAKE)
|
||||||
|
os.remove(SOURCES_LOG)
|
||||||
os.rmdir(tmp)
|
os.rmdir(tmp)
|
||||||
os._exit(1 if failures else 0)
|
os._exit(1 if failures else 0)
|
||||||
@@ -9,7 +9,12 @@ the search runs again with a smaller closing.
|
|||||||
import cv2
|
import cv2
|
||||||
import numpy as np
|
import numpy as np
|
||||||
|
|
||||||
DARK = 30 # pupil pixels are below this (the face around it is 40-180)
|
# One thread: OpenCV's pool of one per core costs more than it saves on a frame this small
|
||||||
|
# (a 140-240 px window while it follows the pupil). Its idle workers spun and yielded about
|
||||||
|
# 14,000 times a second each, a quarter of a core, beside SteamVR's compositor.
|
||||||
|
cv2.setNumThreads(1)
|
||||||
|
|
||||||
|
DARK = 30 # pupil pixels are below this (the face around it is 40-180)
|
||||||
MIN_AREA = 150 # pupil area range in pixels
|
MIN_AREA = 150 # pupil area range in pixels
|
||||||
MAX_AREA = 20000
|
MAX_AREA = 20000
|
||||||
MIN_FILL = 0.75 # blob area / fitted-ellipse area
|
MIN_FILL = 0.75 # blob area / fitted-ellipse area
|
||||||
|
|||||||
@@ -63,6 +63,13 @@ reading only.
|
|||||||
frame when its camera starts the frame after next (no slot is rewritten sooner than three
|
frame when its camera starts the frame after next (no slot is rewritten sooner than three
|
||||||
frames), ignores late writes to the frame just finished, and saves from a separate
|
frames), ignores late writes to the frame just finished, and saves from a separate
|
||||||
thread. fit1 may hold a few percent of torn frames.
|
thread. fit1 may hold a few percent of torn frames.
|
||||||
|
- `--share` (2026-10-03) checks only the slot each camera writes next, from the two before
|
||||||
|
(the orders above, learned again if they change; all four slots for 2 s after a frame turns
|
||||||
|
up elsewhere), sleeps until 2.5 ms before the next frame is due, then looks every 1 ms with
|
||||||
|
0.5 ms of timer slack. Against the 0.3 ms poll of all eight slots, on simulated cameras:
|
||||||
|
207 wakeups a second instead of 1,486, 0.8% of a core instead of 3.6% (more on the real
|
||||||
|
DMA-BUF memory), no torn or skipped frames, and a frame's start seen 1.35 ms late on
|
||||||
|
average instead of 0.76. `--rec` still polls all slots every 0.3 ms, for its times.
|
||||||
- Eye tracking stops when the headset is off ("HMD off, stopping eye tracking"), so
|
- Eye tracking stops when the headset is off ("HMD off, stopping eye tracking"), so
|
||||||
recordings are empty then.
|
recordings are empty then.
|
||||||
- **Which camera is which eye** (capture fit1, 2026-09-29, closing one eye at a time):
|
- **Which camera is which eye** (capture fit1, 2026-09-29, closing one eye at a time):
|
||||||
|
|||||||
+73
-16
@@ -46,6 +46,7 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
|
#include <sys/prctl.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
#include <sys/syscall.h>
|
#include <sys/syscall.h>
|
||||||
#include <time.h>
|
#include <time.h>
|
||||||
@@ -288,20 +289,53 @@ static int eye_buffer(void) {
|
|||||||
|
|
||||||
// Calls done(frame, slot, time) for every complete eye-camera frame until `seconds` pass
|
// Calls done(frame, slot, time) for every complete eye-camera frame until `seconds` pass
|
||||||
// (forever if negative), a stop signal comes, the tracker process goes away, or keep()
|
// (forever if negative), a stop signal comes, the tracker process goes away, or keep()
|
||||||
// (checked about every 0.25 s, when given) says to stop.
|
// (checked about every 0.25 s, when given) says to stop. Looks every `poll_us`.
|
||||||
//
|
//
|
||||||
// A frame lands over several milliseconds, in bursts, and its last bursts can come after
|
// A frame lands over several milliseconds, in bursts, and its last bursts can come after
|
||||||
// the camera has started its next frame. A slot isn't rewritten until at least three frames
|
// the camera has started its next frame. A slot isn't rewritten until at least three frames
|
||||||
// later (camera 0 cycles 3,0,1,2; camera 1 7,5,4,6,5,7,6,4), so a frame is passed on when
|
// later (camera 0 cycles 3,0,1,2; camera 1 7,5,4,6,5,7,6,4), so a frame is passed on when
|
||||||
// its camera starts the frame after next. Changes to the slot just finished are late bursts,
|
// its camera starts the frame after next. Changes to the slot just finished are late bursts,
|
||||||
// not a new frame. A frame's time is when its slot first changed.
|
// not a new frame. A frame's time is when its slot first changed.
|
||||||
|
//
|
||||||
|
// Each look checks only the slot each camera writes next: the one that followed the last two
|
||||||
|
// before (after[][], seeded with the orders above and learned as frames come). Every check
|
||||||
|
// reads 256 words spread over a frame in DMA-BUF memory, so all eight slots each time was
|
||||||
|
// most of the cost. A camera with nothing in its expected slot for 1.5 frames, or with no
|
||||||
|
// order known yet, has all its slots checked until a frame comes. When that finds a frame
|
||||||
|
// somewhere else (the order changed, or a frame was missed), all its slots are checked for
|
||||||
|
// SCAN_AFTER_MISS, as before, while after[][] learns the new order. A slot's fingerprint is
|
||||||
|
// taken again when it stops being one of the two in use, so a check later sees only a new frame.
|
||||||
|
// Between frames it sleeps until FRAME_EARLY before the next one is due (the cameras run at
|
||||||
|
// 90 fps, within a ms of each other), then looks every `poll_us`.
|
||||||
|
#define FRAME_DUE (1.5 / 90) // s: a camera that hasn't started a frame by then gets all its slots checked
|
||||||
|
#define SCAN_AFTER_MISS 2.0 // s of checking all slots after a frame came in an unexpected one
|
||||||
|
#define CAMS_IDLE 0.5 // s without a frame from either camera: look 4 times less often
|
||||||
|
#define FRAME_EARLY 0.0025 // s before a frame is due to start looking for it
|
||||||
|
|
||||||
|
// When to start looking for the next frame: FRAME_EARLY before the first camera's is due. A
|
||||||
|
// camera already late (it lost its order, or stopped) means now.
|
||||||
|
static double next_due(const double last[2], double t) {
|
||||||
|
double due = 1e300;
|
||||||
|
for (int cam = 0; cam < 2; cam++) {
|
||||||
|
double d = last[cam] + 1.0 / 90 - FRAME_EARLY;
|
||||||
|
if (t - last[cam] > CAMS_IDLE) continue; // stopped: the other one sets the pace
|
||||||
|
if (d < due) due = d;
|
||||||
|
}
|
||||||
|
return due < 1e300 ? due : t;
|
||||||
|
}
|
||||||
|
|
||||||
static void poll_frames(int b, double seconds, int pid, void (*done)(const uint8_t *, int, double),
|
static void poll_frames(int b, double seconds, int pid, void (*done)(const uint8_t *, int, double),
|
||||||
int (*keep)(void)) {
|
int (*keep)(void), unsigned poll_us) {
|
||||||
|
static const int order[2][8] = {{3, 0, 1, 2, 3, 0, 1, 2}, {7, 5, 4, 6, 5, 7, 6, 4}};
|
||||||
|
int after[EYE_SLOTS][EYE_SLOTS];
|
||||||
|
memset(after, -1, sizeof after);
|
||||||
|
for (int c = 0; c < 2; c++)
|
||||||
|
for (int i = 0; i < 8; i++) after[order[c][i]][order[c][(i + 1) % 8]] = order[c][(i + 2) % 8];
|
||||||
uint64_t sig[EYE_SLOTS];
|
uint64_t sig[EYE_SLOTS];
|
||||||
double first[EYE_SLOTS];
|
double first[EYE_SLOTS];
|
||||||
int cur[2] = {-1, -1}, prev[2] = {-1, -1};
|
int cur[2] = {-1, -1}, prev[2] = {-1, -1};
|
||||||
for (int k = 0; k < EYE_SLOTS; k++) sig[k] = frame_sig(bufs[b].p + slot_start(k)), first[k] = 0;
|
for (int k = 0; k < EYE_SLOTS; k++) sig[k] = frame_sig(bufs[b].p + slot_start(k)), first[k] = 0;
|
||||||
double start = now(), checked = start, kept = start;
|
double start = now(), checked = start, kept = start, last[2] = {start, start}, scan_until[2] = {0, 0};
|
||||||
char proc[64];
|
char proc[64];
|
||||||
snprintf(proc, sizeof proc, "/proc/%d", pid);
|
snprintf(proc, sizeof proc, "/proc/%d", pid);
|
||||||
while ((seconds < 0 || now() - start < seconds) && !stop_rec) {
|
while ((seconds < 0 || now() - start < seconds) && !stop_rec) {
|
||||||
@@ -315,18 +349,36 @@ static void poll_frames(int b, double seconds, int pid, void (*done)(const uint8
|
|||||||
if (!keep()) return;
|
if (!keep()) return;
|
||||||
kept = t;
|
kept = t;
|
||||||
}
|
}
|
||||||
for (int k = 0; k < EYE_SLOTS; k++) {
|
for (int cam = 0; cam < 2; cam++) {
|
||||||
uint64_t s = frame_sig(bufs[b].p + slot_start(k));
|
int next = prev[cam] >= 0 ? after[prev[cam]][cur[cam]] : -1;
|
||||||
if (s == sig[k]) continue;
|
int all = next < 0 || t - last[cam] > FRAME_DUE || t < scan_until[cam];
|
||||||
sig[k] = s;
|
int from = all ? cam * 4 : next, to = all ? cam * 4 + 4 : next + 1;
|
||||||
int cam = k >= 4;
|
for (int k = from; k < to; k++) {
|
||||||
if (k == cur[cam] || k == prev[cam]) continue; // landing, or a late burst
|
uint64_t s = frame_sig(bufs[b].p + slot_start(k));
|
||||||
if (prev[cam] >= 0) done(bufs[b].p + slot_start(prev[cam]), prev[cam], first[prev[cam]]);
|
if (s == sig[k]) continue;
|
||||||
prev[cam] = cur[cam];
|
sig[k] = s;
|
||||||
cur[cam] = k;
|
if (k == cur[cam] || k == prev[cam]) continue; // landing, or a late burst
|
||||||
first[k] = t;
|
if (next >= 0 && k != next) scan_until[cam] = t + SCAN_AFTER_MISS;
|
||||||
|
if (prev[cam] >= 0) {
|
||||||
|
done(bufs[b].p + slot_start(prev[cam]), prev[cam], first[prev[cam]]);
|
||||||
|
after[prev[cam]][cur[cam]] = k;
|
||||||
|
// Out of use from now on: later changes are a new frame.
|
||||||
|
sig[prev[cam]] = frame_sig(bufs[b].p + slot_start(prev[cam]));
|
||||||
|
}
|
||||||
|
prev[cam] = cur[cam];
|
||||||
|
cur[cam] = k;
|
||||||
|
first[k] = t;
|
||||||
|
last[cam] = t;
|
||||||
|
next = prev[cam] >= 0 ? after[prev[cam]][cur[cam]] : -1;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
usleep(300);
|
double wait = poll_us * 1e-6;
|
||||||
|
if (t - last[0] > CAMS_IDLE && t - last[1] > CAMS_IDLE) {
|
||||||
|
wait *= 4;
|
||||||
|
} else if (next_due(last, t) - t > wait) {
|
||||||
|
wait = next_due(last, t) - t;
|
||||||
|
}
|
||||||
|
usleep((useconds_t)(wait * 1e6));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -356,7 +408,7 @@ static int rec(double seconds, const char *dir, int pid) {
|
|||||||
pthread_t writer;
|
pthread_t writer;
|
||||||
pthread_create(&writer, NULL, ring_writer, NULL);
|
pthread_create(&writer, NULL, ring_writer, NULL);
|
||||||
double start = now();
|
double start = now();
|
||||||
poll_frames(b, seconds, pid, rec_frame, NULL);
|
poll_frames(b, seconds, pid, rec_frame, NULL, 300); // 0.3 ms: recordings' times
|
||||||
pthread_mutex_lock(&ring.mu);
|
pthread_mutex_lock(&ring.mu);
|
||||||
ring.done = 1;
|
ring.done = 1;
|
||||||
pthread_cond_signal(&ring.cv);
|
pthread_cond_signal(&ring.cv);
|
||||||
@@ -383,6 +435,10 @@ static int rec(double seconds, const char *dir, int pid) {
|
|||||||
#define SHARE_SLOTS 8
|
#define SHARE_SLOTS 8
|
||||||
#define SHARE_MAGIC 0x31434546u // "FEC1"
|
#define SHARE_MAGIC 0x31434546u // "FEC1"
|
||||||
#define WANT_FRESH 3.0 // seconds a touch of the --want file lasts
|
#define WANT_FRESH 3.0 // seconds a touch of the --want file lasts
|
||||||
|
// How often --share looks for frames, with a timer slack that lets the kernel group the
|
||||||
|
// wakeups: a frame reaches ft-eyes 1 to 1.5 ms after its camera starts the next, not 0.3.
|
||||||
|
#define SHARE_POLL_US 1000
|
||||||
|
#define SHARE_SLACK_NS 500000
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
uint32_t magic, version, width, height, slots, entry_size;
|
uint32_t magic, version, width, height, slots, entry_size;
|
||||||
@@ -462,6 +518,7 @@ static int share_loop(const char *path) {
|
|||||||
.slots = SHARE_SLOTS, .entry_size = (uint32_t)esize};
|
.slots = SHARE_SLOTS, .entry_size = (uint32_t)esize};
|
||||||
signal(SIGINT, on_stop);
|
signal(SIGINT, on_stop);
|
||||||
signal(SIGTERM, on_stop);
|
signal(SIGTERM, on_stop);
|
||||||
|
if (prctl(PR_SET_TIMERSLACK, SHARE_SLACK_NS, 0, 0, 0) != 0) perror("PR_SET_TIMERSLACK");
|
||||||
fprintf(stderr, "ft-eyegrab: sharing frames in %s%s%s\n", path, want_path ? " while wanted by " : "",
|
fprintf(stderr, "ft-eyegrab: sharing frames in %s%s%s\n", path, want_path ? " while wanted by " : "",
|
||||||
want_path ? want_path : "");
|
want_path ? want_path : "");
|
||||||
int pid = -1, idle = -1, missing = 0;
|
int pid = -1, idle = -1, missing = 0;
|
||||||
@@ -486,7 +543,7 @@ static int share_loop(const char *path) {
|
|||||||
if (idle != 0 || missing) fprintf(stderr, "ft-eyegrab: copying frames from eyetracking %d\n", pid);
|
if (idle != 0 || missing) fprintf(stderr, "ft-eyegrab: copying frames from eyetracking %d\n", pid);
|
||||||
idle = 0, missing = 0;
|
idle = 0, missing = 0;
|
||||||
h->tracker_pid = pid;
|
h->tracker_pid = pid;
|
||||||
poll_frames(eye_buffer(), -1, pid, share_frame, wanted);
|
poll_frames(eye_buffer(), -1, pid, share_frame, wanted, SHARE_POLL_US);
|
||||||
struct stat st;
|
struct stat st;
|
||||||
char proc[64];
|
char proc[64];
|
||||||
snprintf(proc, sizeof proc, "/proc/%d", pid);
|
snprintf(proc, sizeof proc, "/proc/%d", pid);
|
||||||
|
|||||||
+42
-4
@@ -50,6 +50,7 @@ import json
|
|||||||
import math
|
import math
|
||||||
import mmap
|
import mmap
|
||||||
import os
|
import os
|
||||||
|
import select
|
||||||
import socket
|
import socket
|
||||||
import struct
|
import struct
|
||||||
import sys
|
import sys
|
||||||
@@ -58,7 +59,12 @@ import time
|
|||||||
from collections import deque
|
from collections import deque
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
import numpy as np
|
# One thread for numpy's BLAS and OpenMP, set before numpy loads: it would start one per core
|
||||||
|
# (8 here) for small arrays that never need them. eyes_pupil keeps OpenCV to one as well.
|
||||||
|
for _var in ("OPENBLAS_NUM_THREADS", "OMP_NUM_THREADS"):
|
||||||
|
os.environ.setdefault(_var, "1")
|
||||||
|
|
||||||
|
import numpy as np # noqa: E402
|
||||||
|
|
||||||
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
sys.path.insert(0, str(Path(__file__).resolve().parent))
|
||||||
import eyes_model # noqa: E402
|
import eyes_model # noqa: E402
|
||||||
@@ -82,6 +88,15 @@ GAP = 3.0 # s without frames: the headset was off, and may sit diffe
|
|||||||
CLICK_BEFORE = 0.3 # a click's frames: the 300 ms before it (like the probe's fixation)
|
CLICK_BEFORE = 0.3 # a click's frames: the 300 ms before it (like the probe's fixation)
|
||||||
CALIB_MIN = 15 # frames an eye needs in a calibration dot's window
|
CALIB_MIN = 15 # frames an eye needs in a calibration dot's window
|
||||||
CALIB_SPREAD = 4.0 # px: more than this and the eye moved during the dot
|
CALIB_SPREAD = 4.0 # px: more than this and the eye moved during the dot
|
||||||
|
# Waiting for frames. They come only as a counter in shared memory, so there's nothing to block
|
||||||
|
# on: sleep until a camera's next frame is due, then look every POLL. ft-eyegrab passes each one
|
||||||
|
# on within a ms or two of when its camera starts the one after, so they arrive 11.1 ms apart,
|
||||||
|
# give or take that.
|
||||||
|
PERIOD = 1 / 90 # s between a camera's frames
|
||||||
|
EARLY = 0.002 # start looking this long before a frame is due
|
||||||
|
POLL = 0.001 # then this often until it comes
|
||||||
|
STALLED = 0.1 # s without a frame: that camera stopped (headset off), and isn't waited for
|
||||||
|
IDLE_POLL = 0.02 # how often to look while both are stopped
|
||||||
|
|
||||||
|
|
||||||
class Cams:
|
class Cams:
|
||||||
@@ -352,7 +367,7 @@ def wait_for_cams(sock, tracker, want):
|
|||||||
return Cams()
|
return Cams()
|
||||||
except (OSError, ValueError, RuntimeError):
|
except (OSError, ValueError, RuntimeError):
|
||||||
serve(sock, tracker)
|
serve(sock, tracker)
|
||||||
time.sleep(0.2)
|
select.select([sock], [], [], 0.2)
|
||||||
|
|
||||||
|
|
||||||
def serve(sock, tracker):
|
def serve(sock, tracker):
|
||||||
@@ -372,7 +387,24 @@ def serve(sock, tracker):
|
|||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def below_steamvr():
|
||||||
|
"""Nice 10 and SCHED_BATCH, for this thread and those it starts. ft-eyes runs in the dev
|
||||||
|
container's podman scope, where the gaze service's unit doesn't reach it, so it ran at
|
||||||
|
nice 0 on the cores vrcompositor and vrserver use. Batch also lets a waking ft-eyes wait
|
||||||
|
for the running task's turn instead of taking the core: a frame a few ms late costs the
|
||||||
|
gaze little, a late compositor frame costs a dropped frame in the headset."""
|
||||||
|
try:
|
||||||
|
os.setpriority(os.PRIO_PROCESS, 0, max(os.getpriority(os.PRIO_PROCESS, 0), 10))
|
||||||
|
except OSError as e:
|
||||||
|
print(f"ft-eyes: nice: {e}", file=sys.stderr, flush=True)
|
||||||
|
try:
|
||||||
|
os.sched_setscheduler(0, os.SCHED_BATCH, os.sched_param(0))
|
||||||
|
except (OSError, AttributeError) as e:
|
||||||
|
print(f"ft-eyes: SCHED_BATCH: {e}", file=sys.stderr, flush=True)
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
below_steamvr()
|
||||||
verbose = "-v" in sys.argv
|
verbose = "-v" in sys.argv
|
||||||
if "--watch-stdin" in sys.argv:
|
if "--watch-stdin" in sys.argv:
|
||||||
# Run by ft-gazed through distrobox, which doesn't pass a stop on: quit when our
|
# Run by ft-gazed through distrobox, which doesn't pass a stop on: quit when our
|
||||||
@@ -398,6 +430,7 @@ def main():
|
|||||||
print("ft-eyes: frames found, tracking", file=sys.stderr, flush=True)
|
print("ft-eyes: frames found, tracking", file=sys.stderr, flush=True)
|
||||||
seen = [cams.count(0), cams.count(1)]
|
seen = [cams.count(0), cams.count(1)]
|
||||||
report = time.monotonic()
|
report = time.monotonic()
|
||||||
|
arrived = [0.0, 0.0] # when each camera's newest frame was seen (monotonic)
|
||||||
while True:
|
while True:
|
||||||
serve(sock, tracker)
|
serve(sock, tracker)
|
||||||
want()
|
want()
|
||||||
@@ -407,6 +440,7 @@ def main():
|
|||||||
if n == seen[c]:
|
if n == seen[c]:
|
||||||
continue
|
continue
|
||||||
seen[c] = n
|
seen[c] = n
|
||||||
|
arrived[c] = time.monotonic()
|
||||||
got = cams.frame(c, n - 1) # only the newest: never fall behind
|
got = cams.frame(c, n - 1) # only the newest: never fall behind
|
||||||
if got:
|
if got:
|
||||||
eyes[c].feed(*got)
|
eyes[c].feed(*got)
|
||||||
@@ -425,8 +459,6 @@ def main():
|
|||||||
shifts += [float(v) for v in e.shift.value]
|
shifts += [float(v) for v in e.shift.value]
|
||||||
pupils += [e.gaze[3], e.gaze[4]] if fresh else [math.nan, math.nan]
|
pupils += [e.gaze[3], e.gaze[4]] if fresh else [math.nan, math.nan]
|
||||||
out.write(latest, (yaw, pitch), flags, per, shifts, pupils)
|
out.write(latest, (yaw, pitch), flags, per, shifts, pupils)
|
||||||
else:
|
|
||||||
time.sleep(0.001)
|
|
||||||
now = time.monotonic()
|
now = time.monotonic()
|
||||||
if now - report >= 5:
|
if now - report >= 5:
|
||||||
if verbose:
|
if verbose:
|
||||||
@@ -444,6 +476,12 @@ def main():
|
|||||||
print("ft-eyes: frames went away; waiting", file=sys.stderr, flush=True)
|
print("ft-eyes: frames went away; waiting", file=sys.stderr, flush=True)
|
||||||
cams = wait_for_cams(sock, tracker, want)
|
cams = wait_for_cams(sock, tracker, want)
|
||||||
seen = [cams.count(0), cams.count(1)]
|
seen = [cams.count(0), cams.count(1)]
|
||||||
|
# Until the next frame is due (a command on the socket wakes us sooner).
|
||||||
|
wait = IDLE_POLL
|
||||||
|
for c in (0, 1):
|
||||||
|
if now - arrived[c] < STALLED:
|
||||||
|
wait = min(wait, max(arrived[c] + PERIOD - EARLY - now, POLL))
|
||||||
|
select.select([sock], [], [], wait)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
+2
-34
@@ -65,18 +65,6 @@ RESUME_DELAY = 5.0 # after a VR game ends: loading the next one can end one sce
|
|||||||
GAME_STALE = 12.0 # the helper repeats "vrgame" every 5 s; silence this long means no game (or no SteamVR)
|
GAME_STALE = 12.0 # the helper repeats "vrgame" every 5 s; silence this long means no game (or no SteamVR)
|
||||||
CHORD_WINDOW = 0.3 # a two-button gesture's buttons go down within this of each other
|
CHORD_WINDOW = 0.3 # a two-button gesture's buttons go down within this of each other
|
||||||
DOUBLE_WINDOW = 0.7 # a double press's second press comes within this of the first
|
DOUBLE_WINDOW = 0.7 # a double press's second press comes within this of the first
|
||||||
LOOKUP_EVERY = 30.0 # the controllers are looked up again this often (and sooner when they may have changed)
|
|
||||||
LOOKUP_GAP = 3.0 # but not more often than this for a message from a device it doesn't know
|
|
||||||
|
|
||||||
|
|
||||||
def device_of(text):
|
|
||||||
"""A web socket message's "device", without parsing all of it (there are about 160 a second)."""
|
|
||||||
at = text.find('"device"')
|
|
||||||
if at < 0:
|
|
||||||
return None
|
|
||||||
start = text.find('"', text.find(":", at) + 1)
|
|
||||||
end = text.find('"', start + 1)
|
|
||||||
return text[start + 1:end] if 0 <= start < end else None
|
|
||||||
|
|
||||||
|
|
||||||
def gesture_of(rules, buttons):
|
def gesture_of(rules, buttons):
|
||||||
@@ -149,12 +137,6 @@ class ControllerWatch(threading.Thread):
|
|||||||
self.changed = threading.Event()
|
self.changed = threading.Event()
|
||||||
self.connected = False
|
self.connected = False
|
||||||
self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
|
self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
|
||||||
self.lookup_at = None # look the controllers up again then (see recheck)
|
|
||||||
|
|
||||||
def recheck(self, delay=1.5):
|
|
||||||
"""The controllers' root paths may change soon: the 3D mouse's virtual controller is taking
|
|
||||||
or giving back its hand role. SteamVR takes a moment to hand the role over."""
|
|
||||||
self.lookup_at = time.monotonic() + delay
|
|
||||||
|
|
||||||
def set_gesture(self, spec):
|
def set_gesture(self, spec):
|
||||||
"""(buttons, presses), or None for no gesture."""
|
"""(buttons, presses), or None for no gesture."""
|
||||||
@@ -194,22 +176,15 @@ class ControllerWatch(threading.Thread):
|
|||||||
ws.open(f"frametop_pause_{os.getpid()}")
|
ws.open(f"frametop_pause_{os.getpid()}")
|
||||||
sides = {} # root path -> side
|
sides = {} # root path -> side
|
||||||
next_poll = 0.0
|
next_poll = 0.0
|
||||||
last_poll = 0.0
|
|
||||||
while True:
|
while True:
|
||||||
g = self.current()
|
g = self.current()
|
||||||
if g is None:
|
if g is None:
|
||||||
return
|
return
|
||||||
now = time.monotonic()
|
now = time.monotonic()
|
||||||
lookup_at = self.lookup_at
|
|
||||||
if lookup_at is not None and now >= lookup_at:
|
|
||||||
self.lookup_at = None
|
|
||||||
next_poll = now
|
|
||||||
if now >= next_poll:
|
if now >= next_poll:
|
||||||
# A controller connects later, or changes its root path when the 3D mouse's
|
# A controller connects later, or changes its root path when the 3D mouse's
|
||||||
# virtual controller takes or gives back its hand role. Each lookup is an HTTP
|
# virtual controller takes or gives back its hand role.
|
||||||
# request to vrserver, so it's at connect, every LOOKUP_EVERY, when a message
|
next_poll = now + 3.0
|
||||||
# comes from a device not on the list, and when the relay says (recheck).
|
|
||||||
next_poll, last_poll = now + LOOKUP_EVERY, now
|
|
||||||
found = vrws.controllers()
|
found = vrws.controllers()
|
||||||
if found != sides:
|
if found != sides:
|
||||||
for path in sides.keys() - found.keys():
|
for path in sides.keys() - found.keys():
|
||||||
@@ -224,9 +199,6 @@ class ControllerWatch(threading.Thread):
|
|||||||
f"controller{'s' if len(sides) != 1 else ''} on SteamVR's web socket")
|
f"controller{'s' if len(sides) != 1 else ''} on SteamVR's web socket")
|
||||||
wanted = {b: (b.split("/", 1)[0], f"/input/{b.split('/', 1)[1]}/click") for b in g.buttons}
|
wanted = {b: (b.split("/", 1)[0], f"/input/{b.split('/', 1)[1]}/click") for b in g.buttons}
|
||||||
for text in ws.messages(timeout=1.0):
|
for text in ws.messages(timeout=1.0):
|
||||||
device = device_of(text)
|
|
||||||
if device and device not in sides:
|
|
||||||
next_poll = min(next_poll, last_poll + LOOKUP_GAP) # its root path changed, maybe
|
|
||||||
# About 160 messages a second, nearly all capacitive sensing: parse only the
|
# About 160 messages a second, nearly all capacitive sensing: parse only the
|
||||||
# few that carry one of the gesture's buttons.
|
# few that carry one of the gesture's buttons.
|
||||||
if not any(c in text for _, c in wanted.values()):
|
if not any(c in text for _, c in wanted.values()):
|
||||||
@@ -498,10 +470,6 @@ class GamePause:
|
|||||||
return max(0.05, self.resume_at - now)
|
return max(0.05, self.resume_at - now)
|
||||||
return 1.0 if self.game else 3600.0
|
return 1.0 if self.game else 3600.0
|
||||||
|
|
||||||
def controllers_changed(self):
|
|
||||||
"""The 3D mouse took or gave back its hand role, which changes a controller's root path."""
|
|
||||||
self.watch.recheck()
|
|
||||||
|
|
||||||
def helper_started(self):
|
def helper_started(self):
|
||||||
"""The pointer helper (re)started, so SteamVR did too, maybe with the gaze service."""
|
"""The pointer helper (re)started, so SteamVR did too, maybe with the gaze service."""
|
||||||
if self.paused:
|
if self.paused:
|
||||||
|
|||||||
+16
-97
@@ -128,7 +128,6 @@ kernel's evdev and uinput interfaces.
|
|||||||
"""
|
"""
|
||||||
import array
|
import array
|
||||||
import atexit
|
import atexit
|
||||||
import collections
|
|
||||||
import errno
|
import errno
|
||||||
import fcntl
|
import fcntl
|
||||||
import json
|
import json
|
||||||
@@ -460,22 +459,14 @@ class Pointer:
|
|||||||
CLAIM_PULSE = 0.06 # seconds the claim button (switchlaserhand, no click) is held
|
CLAIM_PULSE = 0.06 # seconds the claim button (switchlaserhand, no click) is held
|
||||||
RESUME_PAUSE = 1.5 # mouse idle this long, then moving again, re-claims the laser
|
RESUME_PAUSE = 1.5 # mouse idle this long, then moving again, re-claims the laser
|
||||||
WAKE_WINDOW = 1.0 # seconds in which WAKE_COUNTS of motion must add up
|
WAKE_WINDOW = 1.0 # seconds in which WAKE_COUNTS of motion must add up
|
||||||
QUEUE_MAX = 512 # commands kept while the helper is behind (see send)
|
|
||||||
MOVE_EVERY = 0.004 # mouse motion goes to the helper at most this often (see flush)
|
|
||||||
|
|
||||||
def __init__(self, sensitivity, idle, wake_counts=40):
|
def __init__(self, sensitivity, idle, wake_counts=40):
|
||||||
# Never blocks (see send): a stalled helper must not stall the keyboard, volume keys and pausing.
|
self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM)
|
||||||
self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_DGRAM | socket.SOCK_NONBLOCK)
|
|
||||||
# Commands the helper's full socket didn't take yet, in order: text, or [dyaw, dpitch] for
|
|
||||||
# mouse moves, which add up into one while they wait.
|
|
||||||
self.queue = collections.deque()
|
|
||||||
self.behind_logged = -60.0
|
|
||||||
self.sensitivity = sensitivity # degrees per mouse count
|
self.sensitivity = sensitivity # degrees per mouse count
|
||||||
self.idle = idle
|
self.idle = idle
|
||||||
self.active = False
|
self.active = False
|
||||||
self.last_used = 0.0
|
self.last_used = 0.0
|
||||||
self.dx = self.dy = 0
|
self.dx = self.dy = 0
|
||||||
self.move_at = 0.0 # motion last went to the helper then
|
|
||||||
self.scroll_until = None
|
self.scroll_until = None
|
||||||
self.claim_at = None # when to press the claim button
|
self.claim_at = None # when to press the claim button
|
||||||
self.claim_release = None
|
self.claim_release = None
|
||||||
@@ -488,59 +479,11 @@ class Pointer:
|
|||||||
self.pending_since = 0.0
|
self.pending_since = 0.0
|
||||||
self.gaze_awake_until = 0.0 # the helper's gaze mode keeps the pointer until then
|
self.gaze_awake_until = 0.0 # the helper's gaze mode keeps the pointer until then
|
||||||
|
|
||||||
def send(self, command, droppable=False):
|
def send(self, command):
|
||||||
"""To the helper, in order, without blocking. While the helper doesn't keep up (place and
|
try:
|
||||||
grabprobe hold it for seconds, and ft-gazed's 90 Hz gaze fills its socket meanwhile), commands
|
self.sock.sendto(command.encode(), HELPER)
|
||||||
wait in the queue and go out from tick(). A droppable one (a scroll notch: scrolling seconds
|
except OSError:
|
||||||
late is no use) is dropped instead; presses, releases and the rest are kept, so no button
|
pass # helper not running (SteamVR not running)
|
||||||
stays down. Moves add up (_move)."""
|
|
||||||
if not self.queue:
|
|
||||||
try:
|
|
||||||
self.sock.sendto(command.encode(), HELPER)
|
|
||||||
return
|
|
||||||
except BlockingIOError:
|
|
||||||
pass
|
|
||||||
except OSError:
|
|
||||||
return # helper not running (SteamVR not running)
|
|
||||||
if not droppable:
|
|
||||||
self._queue(command)
|
|
||||||
|
|
||||||
def _move(self, dyaw, dpitch):
|
|
||||||
if self.queue and isinstance(self.queue[-1], list):
|
|
||||||
self.queue[-1][0] += dyaw
|
|
||||||
self.queue[-1][1] += dpitch
|
|
||||||
return
|
|
||||||
if not self.queue:
|
|
||||||
try:
|
|
||||||
self.sock.sendto(f"move {dyaw:.4f} {dpitch:.4f}".encode(), HELPER)
|
|
||||||
return
|
|
||||||
except BlockingIOError:
|
|
||||||
pass
|
|
||||||
except OSError:
|
|
||||||
return
|
|
||||||
self._queue([dyaw, dpitch])
|
|
||||||
|
|
||||||
def _queue(self, item):
|
|
||||||
if not self.queue and time.monotonic() - self.behind_logged > 60:
|
|
||||||
self.behind_logged = time.monotonic()
|
|
||||||
log("pointer helper is behind: holding its commands (logged once a minute)")
|
|
||||||
self.queue.append(item)
|
|
||||||
if len(self.queue) > self.QUEUE_MAX:
|
|
||||||
self.queue.popleft() # stalled for long: the oldest goes
|
|
||||||
|
|
||||||
def drain(self):
|
|
||||||
"""Send what waits, in order, as far as the helper takes it."""
|
|
||||||
while self.queue:
|
|
||||||
item = self.queue[0]
|
|
||||||
text = f"move {item[0]:.4f} {item[1]:.4f}" if isinstance(item, list) else item
|
|
||||||
try:
|
|
||||||
self.sock.sendto(text.encode(), HELPER)
|
|
||||||
except BlockingIOError:
|
|
||||||
return
|
|
||||||
except OSError:
|
|
||||||
self.queue.clear() # the helper went away: nothing to deliver to
|
|
||||||
return
|
|
||||||
self.queue.popleft()
|
|
||||||
|
|
||||||
def wake(self, now):
|
def wake(self, now):
|
||||||
if not self.active:
|
if not self.active:
|
||||||
@@ -568,7 +511,7 @@ class Pointer:
|
|||||||
elif code == REL_Y:
|
elif code == REL_Y:
|
||||||
self.dy += value
|
self.dy += value
|
||||||
elif code == REL_WHEEL and value:
|
elif code == REL_WHEEL and value:
|
||||||
self.send(f"scroll 0 {1 if value > 0 else -1}", droppable=True)
|
self.send(f"scroll 0 {1 if value > 0 else -1}")
|
||||||
self.scroll_until = now + self.SCROLL_PULSE
|
self.scroll_until = now + self.SCROLL_PULSE
|
||||||
|
|
||||||
def action(self, name, value, now, source="mouse"):
|
def action(self, name, value, now, source="mouse"):
|
||||||
@@ -600,7 +543,7 @@ class Pointer:
|
|||||||
return # the rest act on press
|
return # the rest act on press
|
||||||
elif name in ("scroll_up", "scroll_down"):
|
elif name in ("scroll_up", "scroll_down"):
|
||||||
self.wake(now)
|
self.wake(now)
|
||||||
self.send(f"scroll 0 {1 if name == 'scroll_up' else -1}", droppable=True)
|
self.send(f"scroll 0 {1 if name == 'scroll_up' else -1}")
|
||||||
self.scroll_until = now + self.SCROLL_PULSE
|
self.scroll_until = now + self.SCROLL_PULSE
|
||||||
elif name == "dashboard":
|
elif name == "dashboard":
|
||||||
self.dashboard(now)
|
self.dashboard(now)
|
||||||
@@ -639,16 +582,11 @@ class Pointer:
|
|||||||
self.sensitivity *= 1.25 if name == "sens_up" else 0.8
|
self.sensitivity *= 1.25 if name == "sens_up" else 0.8
|
||||||
log(f"sensitivity {self.sensitivity:.4f} deg/count")
|
log(f"sensitivity {self.sensitivity:.4f} deg/count")
|
||||||
|
|
||||||
def flush(self, now=None):
|
def flush(self):
|
||||||
"""Send the motion so far. With now (a mouse's SYN_REPORT), only once MOVE_EVERY has passed
|
if self.dx or self.dy:
|
||||||
since the last: a 1000 Hz mouse sent the helper, which runs every 8 ms, 1000 datagrams a
|
# Mouse right turns the ray right (negative yaw); mouse down tilts it down.
|
||||||
second. tick() sends the rest when it's due; a button sends it first, so it lands there."""
|
self.send(f"move {-self.dx * self.sensitivity:.4f} {-self.dy * self.sensitivity:.4f}")
|
||||||
if not (self.dx or self.dy) or (now is not None and now - self.move_at < self.MOVE_EVERY):
|
self.dx = self.dy = 0
|
||||||
return
|
|
||||||
self.move_at = time.monotonic() if now is None else now
|
|
||||||
# Mouse right turns the ray right (negative yaw); mouse down tilts it down.
|
|
||||||
self._move(-self.dx * self.sensitivity, -self.dy * self.sensitivity)
|
|
||||||
self.dx = self.dy = 0
|
|
||||||
|
|
||||||
def dashboard(self, now=None):
|
def dashboard(self, now=None):
|
||||||
"""Toggle the SteamVR dashboard with the virtual controller's system button.
|
"""Toggle the SteamVR dashboard with the virtual controller's system button.
|
||||||
@@ -663,8 +601,6 @@ class Pointer:
|
|||||||
self.system_at = now + (0.4 if woke else 0.0)
|
self.system_at = now + (0.4 if woke else 0.0)
|
||||||
|
|
||||||
def tick(self, now):
|
def tick(self, now):
|
||||||
self.drain()
|
|
||||||
self.flush(now)
|
|
||||||
if self.system_at is not None and now >= self.system_at:
|
if self.system_at is not None and now >= self.system_at:
|
||||||
self.send("btn system 1")
|
self.send("btn system 1")
|
||||||
self.system_at = None
|
self.system_at = None
|
||||||
@@ -689,10 +625,7 @@ class Pointer:
|
|||||||
|
|
||||||
def timeout(self):
|
def timeout(self):
|
||||||
pending = (self.scroll_until, self.claim_at, self.claim_release, self.system_at, self.system_release)
|
pending = (self.scroll_until, self.claim_at, self.claim_release, self.system_at, self.system_release)
|
||||||
wait = 0.02 if self.queue or any(t is not None for t in pending) else 0.5
|
return 0.02 if any(t is not None for t in pending) else 0.5
|
||||||
if self.dx or self.dy: # motion held back by flush
|
|
||||||
wait = max(0.0, min(wait, self.move_at + self.MOVE_EVERY - time.monotonic()))
|
|
||||||
return wait
|
|
||||||
|
|
||||||
def stand_down(self):
|
def stand_down(self):
|
||||||
"""Frametop is pausing: a pulse under way ends now, and the pointer lets go."""
|
"""Frametop is pausing: a pulse under way ends now, and the pointer lets go."""
|
||||||
@@ -796,8 +729,7 @@ def main():
|
|||||||
# pointer: the 3D mouse while it's in use, pointer_conf: the one the config asks for (they
|
# pointer: the 3D mouse while it's in use, pointer_conf: the one the config asks for (they
|
||||||
# differ while Frametop is paused).
|
# differ while Frametop is paused).
|
||||||
state = {"pointer": None, "pointer_conf": None, "rules": {}, "share_keys": False,
|
state = {"pointer": None, "pointer_conf": None, "rules": {}, "share_keys": False,
|
||||||
"desktop_until": 0.0, "typing_applied": None, "vr_capture_until": 0.0, "vr_bind_retry": False,
|
"desktop_until": 0.0, "typing_applied": None, "vr_capture_until": 0.0}
|
||||||
"pointer_holding": False}
|
|
||||||
|
|
||||||
def pause_changed(paused):
|
def pause_changed(paused):
|
||||||
"""Frametop paused or resumed (game_pause.py): the relay's own part."""
|
"""Frametop paused or resumed (game_pause.py): the relay's own part."""
|
||||||
@@ -847,11 +779,8 @@ def main():
|
|||||||
and a not in GAZE_ACTIONS and (not pause.paused or works_paused(a))) or "-"
|
and a not in GAZE_ACTIONS and (not pause.paused or works_paused(a))) or "-"
|
||||||
if state["rules"].get("controller_in_games"):
|
if state["rules"].get("controller_in_games"):
|
||||||
buttons = "+games " + buttons
|
buttons = "+games " + buttons
|
||||||
state["vr_bind_retry"] = False
|
|
||||||
try:
|
try:
|
||||||
screens_sock.sendto(f"vrbind {buttons}".encode(), HELPER)
|
screens_sock.sendto(f"vrbind {buttons}".encode(), HELPER)
|
||||||
except BlockingIOError:
|
|
||||||
state["vr_bind_retry"] = True # the helper is behind: again on the next loop
|
|
||||||
except OSError:
|
except OSError:
|
||||||
pass # helper not running; it says vrhello when it starts
|
pass # helper not running; it says vrhello when it starts
|
||||||
|
|
||||||
@@ -1304,21 +1233,11 @@ def main():
|
|||||||
if added:
|
if added:
|
||||||
apply_roles()
|
apply_roles()
|
||||||
|
|
||||||
# The 3D mouse connecting or letting go moves a hand role, so the pause gesture's reader
|
|
||||||
# looks the controllers up again (game_pause.py).
|
|
||||||
holding = bool(state["pointer_conf"] and state["pointer_conf"].active)
|
|
||||||
if holding != state["pointer_holding"]:
|
|
||||||
state["pointer_holding"] = holding
|
|
||||||
pause.controllers_changed()
|
|
||||||
ready, _, _ = select.select(list(nodes) + [control], [], [],
|
ready, _, _ = select.select(list(nodes) + [control], [], [],
|
||||||
min(volume.timeout(now, pointer.timeout() if pointer else 0.5), pause.timeout(now)))
|
min(volume.timeout(now, pointer.timeout() if pointer else 0.5), pause.timeout(now)))
|
||||||
now = time.monotonic()
|
now = time.monotonic()
|
||||||
if pointer:
|
if pointer:
|
||||||
pointer.tick(now)
|
pointer.tick(now)
|
||||||
elif state["pointer_conf"]:
|
|
||||||
state["pointer_conf"].drain() # paused: what waited still goes, in order
|
|
||||||
if state["vr_bind_retry"]:
|
|
||||||
vr_bind(now)
|
|
||||||
volume.tick(now)
|
volume.tick(now)
|
||||||
pause.tick(now)
|
pause.tick(now)
|
||||||
if state["vr_capture_until"] and now >= state["vr_capture_until"]:
|
if state["vr_capture_until"] and now >= state["vr_capture_until"]:
|
||||||
@@ -1400,7 +1319,7 @@ def main():
|
|||||||
mouse.emit(etype, code, value)
|
mouse.emit(etype, code, value)
|
||||||
elif etype == EV_SYN and code == SYN_REPORT:
|
elif etype == EV_SYN and code == SYN_REPORT:
|
||||||
if pointer:
|
if pointer:
|
||||||
pointer.flush(now)
|
pointer.flush()
|
||||||
mouse.sync()
|
mouse.sync()
|
||||||
keyboard.sync()
|
keyboard.sync()
|
||||||
|
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ class StubPause:
|
|||||||
def configure(self, *args):
|
def configure(self, *args):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
game_state = tick = helper_started = controllers_changed = configure
|
game_state = tick = helper_started = configure
|
||||||
|
|
||||||
|
|
||||||
stub = {}
|
stub = {}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
// aim <yaw_deg> <pitch_deg> absolute direction (yaw 0 = -Z, the SteamVR forward)
|
// aim <yaw_deg> <pitch_deg> absolute direction (yaw 0 = -Z, the SteamVR forward)
|
||||||
// gaze follow the head (origin and direction) again
|
// gaze follow the head (origin and direction) again
|
||||||
// distance <metres> cursor distance from the anchor (default 1.5)
|
// distance <metres> cursor distance from the anchor (default 1.5)
|
||||||
// pose <x> <y> <z> <yaw> <pitch> exact pose, from the ft-pointer helper when it changes (it holds)
|
// pose <x> <y> <z> <yaw> <pitch> exact pose, sent every frame by the ft-pointer helper
|
||||||
// posq <x> <y> <z> <qw> <qx> <qy> <qz> exact pose with a full rotation (tilting a panel while moving it)
|
// posq <x> <y> <z> <qw> <qx> <qy> <qz> exact pose with a full rotation (tilting a panel while moving it)
|
||||||
// btn <name> <0|1> name: trigger, b, x, system, joystick, a (a = claim the laser, no click)
|
// btn <name> <0|1> name: trigger, b, x, system, joystick, a (a = claim the laser, no click)
|
||||||
// scroll <x> <y> joystick deflection -1..1
|
// scroll <x> <y> joystick deflection -1..1
|
||||||
@@ -224,23 +224,12 @@ public:
|
|||||||
pose.result = ok ? TrackingResult_Running_OK : TrackingResult_Uninitialized;
|
pose.result = ok ? TrackingResult_Running_OK : TrackingResult_Uninitialized;
|
||||||
pose.deviceIsConnected = snapshot.visible;
|
pose.deviceIsConnected = snapshot.visible;
|
||||||
pose_ = pose;
|
pose_ = pose;
|
||||||
// Connected, the pose goes out every frame, as SteamVR expects of a tracked device.
|
VRServerDriverHost()->TrackedDevicePoseUpdated(objectId_, pose_, sizeof(DriverPose_t));
|
||||||
// Disconnected, once: it says the same thing every frame after.
|
|
||||||
if (snapshot.visible || !reportedOff_) {
|
|
||||||
VRServerDriverHost()->TrackedDevicePoseUpdated(objectId_, pose_, sizeof(DriverPose_t));
|
|
||||||
reportedOff_ = !snapshot.visible;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Inputs only when they change (and all of them the first time).
|
|
||||||
auto input = VRDriverInput();
|
auto input = VRDriverInput();
|
||||||
for (int i = 0; i < kButtons; ++i)
|
for (int i = 0; i < kButtons; ++i) input->UpdateBooleanComponent(buttons_[i], snapshot.buttons[i], 0);
|
||||||
if (!inputsSent_ || snapshot.buttons[i] != sentButtons_[i])
|
input->UpdateScalarComponent(scrollX_, snapshot.scrollX, 0);
|
||||||
input->UpdateBooleanComponent(buttons_[i], sentButtons_[i] = snapshot.buttons[i], 0);
|
input->UpdateScalarComponent(scrollY_, snapshot.scrollY, 0);
|
||||||
if (!inputsSent_ || snapshot.scrollX != sentScrollX_)
|
|
||||||
input->UpdateScalarComponent(scrollX_, sentScrollX_ = snapshot.scrollX, 0);
|
|
||||||
if (!inputsSent_ || snapshot.scrollY != sentScrollY_)
|
|
||||||
input->UpdateScalarComponent(scrollY_, sentScrollY_ = snapshot.scrollY, 0);
|
|
||||||
inputsSent_ = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -250,10 +239,6 @@ private:
|
|||||||
int32_t role_ = TrackedControllerRole_RightHand;
|
int32_t role_ = TrackedControllerRole_RightHand;
|
||||||
bool hinted_ = false; // whether the role hint currently claims role_
|
bool hinted_ = false; // whether the role hint currently claims role_
|
||||||
DriverPose_t pose_{};
|
DriverPose_t pose_{};
|
||||||
bool reportedOff_ = false; // the disconnected pose has gone out (it isn't repeated)
|
|
||||||
// What the input components were last set to.
|
|
||||||
bool inputsSent_ = false, sentButtons_[kButtons] = {};
|
|
||||||
float sentScrollX_ = 0.f, sentScrollY_ = 0.f;
|
|
||||||
VRInputComponentHandle_t buttons_[kButtons] = {};
|
VRInputComponentHandle_t buttons_[kButtons] = {};
|
||||||
VRInputComponentHandle_t scrollX_ = 0, scrollY_ = 0;
|
VRInputComponentHandle_t scrollX_ = 0, scrollY_ = 0;
|
||||||
};
|
};
|
||||||
@@ -308,102 +293,65 @@ private:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Parsed first, then applied under the lock, which RunFrame (vrserver's frame) takes too.
|
|
||||||
void Handle(const char *cmd) {
|
void Handle(const char *cmd) {
|
||||||
enum { kNone, kPosq, kPose, kMove, kRecenter, kAim, kGaze, kHide, kShow, kRole, kBtn, kDistance, kScroll };
|
|
||||||
int kind = kNone;
|
|
||||||
char name[32];
|
|
||||||
float f[7];
|
|
||||||
int v = 0, role = 0, button = -1;
|
|
||||||
if (std::sscanf(cmd, "posq %f %f %f %f %f %f %f", &f[0], &f[1], &f[2], &f[3], &f[4], &f[5], &f[6]) == 7) {
|
|
||||||
kind = kPosq;
|
|
||||||
} else if (std::sscanf(cmd, "pose %f %f %f %f %f", &f[0], &f[1], &f[2], &f[3], &f[4]) == 5) {
|
|
||||||
kind = kPose;
|
|
||||||
} else if (std::sscanf(cmd, "move %f %f", &f[0], &f[1]) == 2) {
|
|
||||||
kind = kMove;
|
|
||||||
} else if (std::strncmp(cmd, "recenter", 8) == 0) {
|
|
||||||
kind = kRecenter;
|
|
||||||
} else if (std::sscanf(cmd, "aim %f %f", &f[0], &f[1]) == 2) {
|
|
||||||
kind = kAim;
|
|
||||||
} else if (std::strncmp(cmd, "gaze", 4) == 0) {
|
|
||||||
kind = kGaze;
|
|
||||||
} else if (std::strncmp(cmd, "hide", 4) == 0) {
|
|
||||||
kind = kHide;
|
|
||||||
} else if (std::strncmp(cmd, "show", 4) == 0) {
|
|
||||||
kind = kShow;
|
|
||||||
} else if (std::sscanf(cmd, "role %31s", name) == 1) {
|
|
||||||
role = !std::strcmp(name, "left") ? TrackedControllerRole_LeftHand
|
|
||||||
: !std::strcmp(name, "right") ? TrackedControllerRole_RightHand
|
|
||||||
: !std::strcmp(name, "stylus") ? TrackedControllerRole_Stylus
|
|
||||||
: 0;
|
|
||||||
if (role) kind = kRole;
|
|
||||||
} else if (std::sscanf(cmd, "btn %31s %d", name, &v) == 2) {
|
|
||||||
for (int i = 0; i < kButtons; ++i)
|
|
||||||
if (std::strcmp(name, kButtonNames[i]) == 0) button = i;
|
|
||||||
if (button >= 0) kind = kBtn;
|
|
||||||
} else if (std::sscanf(cmd, "distance %f", &f[0]) == 1) {
|
|
||||||
kind = kDistance;
|
|
||||||
} else if (std::sscanf(cmd, "scroll %f %f", &f[0], &f[1]) == 2) {
|
|
||||||
kind = kScroll;
|
|
||||||
}
|
|
||||||
if (kind == kNone) return;
|
|
||||||
|
|
||||||
std::lock_guard<std::mutex> guard(state_.lock);
|
std::lock_guard<std::mutex> guard(state_.lock);
|
||||||
switch (kind) {
|
char name[32];
|
||||||
case kPosq:
|
float a, b;
|
||||||
|
int v;
|
||||||
|
float x, y, z, qw, qx, qy, qz;
|
||||||
|
if (std::sscanf(cmd, "posq %f %f %f %f %f %f %f", &x, &y, &z, &qw, &qx, &qy, &qz) == 7) {
|
||||||
state_.explicitPose = true;
|
state_.explicitPose = true;
|
||||||
state_.hasQuat = true;
|
state_.hasQuat = true;
|
||||||
state_.gaze = false;
|
state_.gaze = false;
|
||||||
std::memcpy(state_.pos, f, sizeof state_.pos);
|
state_.pos[0] = x;
|
||||||
std::memcpy(state_.quat, f + 3, sizeof state_.quat);
|
state_.pos[1] = y;
|
||||||
break;
|
state_.pos[2] = z;
|
||||||
case kPose:
|
state_.quat[0] = qw;
|
||||||
|
state_.quat[1] = qx;
|
||||||
|
state_.quat[2] = qy;
|
||||||
|
state_.quat[3] = qz;
|
||||||
|
} else if (std::sscanf(cmd, "pose %f %f %f %f %f", &x, &y, &z, &a, &b) == 5) {
|
||||||
state_.explicitPose = true;
|
state_.explicitPose = true;
|
||||||
state_.hasQuat = false;
|
state_.hasQuat = false;
|
||||||
state_.gaze = false;
|
state_.gaze = false;
|
||||||
std::memcpy(state_.pos, f, sizeof state_.pos);
|
state_.pos[0] = x;
|
||||||
state_.yaw = f[3];
|
state_.pos[1] = y;
|
||||||
state_.pitch = f[4];
|
state_.pos[2] = z;
|
||||||
break;
|
state_.yaw = a;
|
||||||
case kMove:
|
state_.pitch = b;
|
||||||
|
} else if (std::sscanf(cmd, "move %f %f", &a, &b) == 2) {
|
||||||
state_.explicitPose = false;
|
state_.explicitPose = false;
|
||||||
if (state_.gaze) state_.recenter = true; // first move starts from the gaze
|
if (state_.gaze) state_.recenter = true; // first move starts from the gaze
|
||||||
state_.yaw += f[0]; // wrap by hand: libm remainder() is GLIBC_2.43 in the build container
|
state_.yaw += a; // wrap by hand: libm remainder() is GLIBC_2.43 in the build container
|
||||||
while (state_.yaw > 180.f) state_.yaw -= 360.f;
|
while (state_.yaw > 180.f) state_.yaw -= 360.f;
|
||||||
while (state_.yaw < -180.f) state_.yaw += 360.f;
|
while (state_.yaw < -180.f) state_.yaw += 360.f;
|
||||||
state_.pitch = std::fmax(-85.f, std::fmin(85.f, state_.pitch + f[1]));
|
state_.pitch = std::fmax(-85.f, std::fmin(85.f, state_.pitch + b));
|
||||||
break;
|
} else if (std::strncmp(cmd, "recenter", 8) == 0) {
|
||||||
case kRecenter:
|
|
||||||
state_.explicitPose = false;
|
state_.explicitPose = false;
|
||||||
state_.recenter = true;
|
state_.recenter = true;
|
||||||
break;
|
} else if (std::sscanf(cmd, "aim %f %f", &a, &b) == 2) {
|
||||||
case kAim:
|
|
||||||
state_.gaze = false;
|
state_.gaze = false;
|
||||||
state_.yaw = f[0];
|
state_.yaw = a;
|
||||||
state_.pitch = f[1];
|
state_.pitch = b;
|
||||||
break;
|
} else if (std::strncmp(cmd, "gaze", 4) == 0) {
|
||||||
case kGaze:
|
|
||||||
state_.gaze = true;
|
state_.gaze = true;
|
||||||
break;
|
} else if (std::strncmp(cmd, "hide", 4) == 0) {
|
||||||
case kHide:
|
|
||||||
state_.visible = false;
|
state_.visible = false;
|
||||||
break;
|
} else if (std::strncmp(cmd, "show", 4) == 0) {
|
||||||
case kShow:
|
|
||||||
state_.visible = true;
|
state_.visible = true;
|
||||||
break;
|
} else if (std::sscanf(cmd, "role %31s", name) == 1) {
|
||||||
case kRole:
|
state_.role = !std::strcmp(name, "left") ? TrackedControllerRole_LeftHand
|
||||||
state_.role = role;
|
: !std::strcmp(name, "right") ? TrackedControllerRole_RightHand
|
||||||
break;
|
: !std::strcmp(name, "stylus") ? TrackedControllerRole_Stylus
|
||||||
case kBtn:
|
: state_.role;
|
||||||
state_.buttons[button] = v != 0;
|
} else if (std::sscanf(cmd, "btn %31s %d", name, &v) == 2) {
|
||||||
break;
|
for (int i = 0; i < kButtons; ++i)
|
||||||
case kDistance:
|
if (std::strcmp(name, kButtonNames[i]) == 0) state_.buttons[i] = v != 0;
|
||||||
state_.distance = std::fmax(0.3f, std::fmin(10.f, f[0]));
|
} else if (std::sscanf(cmd, "distance %f", &a) == 1) {
|
||||||
break;
|
state_.distance = std::fmax(0.3f, std::fmin(10.f, a));
|
||||||
case kScroll:
|
} else if (std::sscanf(cmd, "scroll %f %f", &a, &b) == 2) {
|
||||||
state_.scrollX = f[0];
|
state_.scrollX = a;
|
||||||
state_.scrollY = f[1];
|
state_.scrollY = b;
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+154
-316
@@ -36,22 +36,6 @@
|
|||||||
// pointer is off the helper also stops listing overlays with vrcmd, whose connection every
|
// pointer is off the helper also stops listing overlays with vrcmd, whose connection every
|
||||||
// second kept SteamVR from going to standby.
|
// second kept SteamVR from going to standby.
|
||||||
//
|
//
|
||||||
// Idle: while the pointer is off (and hand gestures are off), the main loop waits for a command
|
|
||||||
// on its socket for up to 250 ms instead of running every 8 ms, or 20 ms while it reads mapped
|
|
||||||
// Frame controller buttons (vrbuttons.h), which have no event to wait for. What has to go on
|
|
||||||
// meanwhile still does: the headset's activity level, the game check and the relay's "vrgame"
|
|
||||||
// and "gazeawake" repeats, and a mouse command wakes it at once. The overlay lookups (the 50 ms
|
|
||||||
// visibility poll, the once-a-second handles) wait for the pointer to wake, and run right then.
|
|
||||||
//
|
|
||||||
// Unchanged frames: while the pointer is awake, a frame where nothing moved reuses the last one's
|
|
||||||
// result. The collision passes (ComputeOverlayIntersection on every visible overlay, twice) run
|
|
||||||
// again when the mouse or the anchor moved, the eye moved 5 mm, an overlay showed or hid, or
|
|
||||||
// 100 ms have passed (overlays also move by themselves), and always while dragging. The dots'
|
|
||||||
// setters go to SteamVR only when their value changes, and a dot's placement only when it moved
|
|
||||||
// 0.2 mm or the eye 5 mm (its facing and size then change by well under 1%). The pose goes to the
|
|
||||||
// driver, which keeps the last one, when the laser's origin moved 0.2 mm or its direction 0.04
|
|
||||||
// deg (0.1 mm where it lands, 15 cm on), and at least every 100 ms.
|
|
||||||
//
|
|
||||||
// Last used wins: when a real controller moves (picked up), the pointer is released
|
// Last used wins: when a real controller moves (picked up), the pointer is released
|
||||||
// (driver "hide", which also drops its hand role hint), so the controller gets
|
// (driver "hide", which also drops its hand role hint), so the controller gets
|
||||||
// its role and laser back. The next mouse input reconnects and claims the laser again.
|
// its role and laser back. The next mouse input reconnects and claims the laser again.
|
||||||
@@ -327,7 +311,6 @@ extern "C" {
|
|||||||
#include <atomic>
|
#include <atomic>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
#include <condition_variable>
|
|
||||||
#include <cstdio>
|
#include <cstdio>
|
||||||
#include <cstdlib>
|
#include <cstdlib>
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
@@ -345,7 +328,6 @@ extern "C" {
|
|||||||
#include <fcntl.h>
|
#include <fcntl.h>
|
||||||
#include <fnmatch.h>
|
#include <fnmatch.h>
|
||||||
|
|
||||||
#include <poll.h>
|
|
||||||
#include <sys/mman.h>
|
#include <sys/mman.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
@@ -518,62 +500,29 @@ std::string JsonQuote(const std::string &s) {
|
|||||||
// public call to enumerate other apps' overlays). Hidden ones are listed too: the
|
// public call to enumerate other apps' overlays). Hidden ones are listed too: the
|
||||||
// window controls under a floating panel only appear while something hovers the
|
// window controls under a floating panel only appear while something hovers the
|
||||||
// panel, and the cursor has to find them the moment they do, not a second later.
|
// panel, and the cursor has to find them the moment they do, not a second later.
|
||||||
// Each vrcmd run is a shell and a new SteamVR client, about 30 ms of CPU, so the list is read
|
|
||||||
// every 20 seconds (kEvery) while the pointer is awake, and at once when something says it may
|
|
||||||
// have changed (Kick: the pointer waking, the dashboard opening or closing, a click that hit
|
|
||||||
// nothing), at most once a second. Showing and hiding the overlays it knows doesn't need a new
|
|
||||||
// list: the main loop polls their visibility (IsOverlayVisible) every 50 ms.
|
|
||||||
// Paused while the pointer is off: each vrcmd run connects to SteamVR as a new app, and a new
|
// Paused while the pointer is off: each vrcmd run connects to SteamVR as a new app, and a new
|
||||||
// app every second kept SteamVR (and the headset's displays) from going to standby.
|
// app every second kept SteamVR (and the headset's displays) from going to standby.
|
||||||
// "overlays" requests (Frametop Input Settings' Ignored panels page) refresh the list even
|
// "overlays" requests (Frametop Input Settings' Ignored panels page) refresh the list even
|
||||||
// while paused, and are answered from this thread once it's fresh.
|
// while paused, and are answered from this thread once it's fresh.
|
||||||
class OverlayList {
|
class OverlayList {
|
||||||
public:
|
public:
|
||||||
static constexpr auto kEvery = std::chrono::seconds(20), kGap = std::chrono::seconds(1);
|
|
||||||
void Start() {
|
void Start() {
|
||||||
out_ = socket(AF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC, 0);
|
out_ = socket(AF_UNIX, SOCK_DGRAM | SOCK_CLOEXEC, 0);
|
||||||
thread_ = std::thread([this] {
|
thread_ = std::thread([this] {
|
||||||
std::unique_lock<std::mutex> lk(lock_);
|
|
||||||
while (running_) {
|
while (running_) {
|
||||||
// Sleeps while paused (until a request or the wake); otherwise until it's time, or
|
if (!paused_ || requested_) Refresh();
|
||||||
// a kick once kGap has passed since the last read.
|
// Wait a second, or less when the pointer wakes (refresh right away then).
|
||||||
const auto due = std::max(last_ + kGap, kicked_ ? last_ : last_ + kEvery);
|
for (int i = 0; i < 10 && running_; ++i) {
|
||||||
if (!waiting_.empty()) {
|
const bool wasPaused = paused_;
|
||||||
} else if (paused_) {
|
std::this_thread::sleep_for(std::chrono::milliseconds(100));
|
||||||
cv_.wait(lk);
|
if ((wasPaused && !paused_) || requested_) break;
|
||||||
continue;
|
|
||||||
} else if (std::chrono::steady_clock::now() < due) {
|
|
||||||
cv_.wait_until(lk, due);
|
|
||||||
continue;
|
|
||||||
}
|
}
|
||||||
kicked_ = false;
|
|
||||||
lk.unlock();
|
|
||||||
Refresh();
|
|
||||||
lk.lock();
|
|
||||||
last_ = std::chrono::steady_clock::now();
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
// Unpausing (the pointer woke) reads the list again at once.
|
void SetPaused(bool paused) { paused_ = paused; }
|
||||||
void SetPaused(bool paused) {
|
|
||||||
std::lock_guard<std::mutex> guard(lock_);
|
|
||||||
if (paused == paused_) return;
|
|
||||||
if (!paused) kicked_ = true, last_ = {};
|
|
||||||
paused_ = paused;
|
|
||||||
cv_.notify_one();
|
|
||||||
}
|
|
||||||
// The list may have changed: read it again soon (not while paused).
|
|
||||||
void Kick() {
|
|
||||||
std::lock_guard<std::mutex> guard(lock_);
|
|
||||||
kicked_ = true;
|
|
||||||
cv_.notify_one();
|
|
||||||
}
|
|
||||||
void Stop() {
|
void Stop() {
|
||||||
{
|
running_ = false;
|
||||||
std::lock_guard<std::mutex> guard(lock_);
|
|
||||||
running_ = false;
|
|
||||||
cv_.notify_one();
|
|
||||||
}
|
|
||||||
if (thread_.joinable()) thread_.join();
|
if (thread_.joinable()) thread_.join();
|
||||||
}
|
}
|
||||||
std::vector<std::string> Keys() {
|
std::vector<std::string> Keys() {
|
||||||
@@ -582,14 +531,12 @@ public:
|
|||||||
for (const auto &e : entries_) keys.push_back(e.key);
|
for (const auto &e : entries_) keys.push_back(e.key);
|
||||||
return keys;
|
return keys;
|
||||||
}
|
}
|
||||||
// Goes up by one each time the list is read, so the main loop knows to look the keys up again.
|
|
||||||
unsigned Generation() const { return generation_; }
|
|
||||||
// Answer `to` with {"t":"overlays","list":[{"key","name","visible"}...]} after the next refresh.
|
// Answer `to` with {"t":"overlays","list":[{"key","name","visible"}...]} after the next refresh.
|
||||||
void Request(const sockaddr_un &to, socklen_t len) {
|
void Request(const sockaddr_un &to, socklen_t len) {
|
||||||
if (len <= offsetof(sockaddr_un, sun_path)) return;
|
if (len <= offsetof(sockaddr_un, sun_path)) return;
|
||||||
std::lock_guard<std::mutex> guard(lock_);
|
std::lock_guard<std::mutex> guard(lock_);
|
||||||
if (waiting_.size() < 8) waiting_.push_back({to, len});
|
if (waiting_.size() < 8) waiting_.push_back({to, len});
|
||||||
cv_.notify_one();
|
requested_ = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
@@ -598,6 +545,7 @@ private:
|
|||||||
bool visible;
|
bool visible;
|
||||||
};
|
};
|
||||||
void Refresh() {
|
void Refresh() {
|
||||||
|
requested_ = false;
|
||||||
FILE *p = popen("LD_LIBRARY_PATH=/opt/steamvr/bin/linuxarm64 /opt/steamvr/bin/linuxarm64/vrcmd --overlays 2>/dev/null", "r");
|
FILE *p = popen("LD_LIBRARY_PATH=/opt/steamvr/bin/linuxarm64 /opt/steamvr/bin/linuxarm64/vrcmd --overlays 2>/dev/null", "r");
|
||||||
if (!p) return;
|
if (!p) return;
|
||||||
std::vector<Entry> entries;
|
std::vector<Entry> entries;
|
||||||
@@ -629,7 +577,6 @@ private:
|
|||||||
entries_ = std::move(entries);
|
entries_ = std::move(entries);
|
||||||
waiting.swap(waiting_);
|
waiting.swap(waiting_);
|
||||||
}
|
}
|
||||||
++generation_;
|
|
||||||
if (waiting.empty()) return;
|
if (waiting.empty()) return;
|
||||||
std::string msg = "{\"t\":\"overlays\",\"list\":[";
|
std::string msg = "{\"t\":\"overlays\",\"list\":[";
|
||||||
for (size_t i = 0; i < entries_.size(); ++i)
|
for (size_t i = 0; i < entries_.size(); ++i)
|
||||||
@@ -642,11 +589,10 @@ private:
|
|||||||
|
|
||||||
std::thread thread_;
|
std::thread thread_;
|
||||||
int out_ = -1;
|
int out_ = -1;
|
||||||
std::mutex lock_; // guards everything below
|
std::atomic<bool> paused_{false};
|
||||||
std::condition_variable cv_;
|
std::atomic<bool> running_{true};
|
||||||
bool paused_ = false, running_ = true, kicked_ = false;
|
std::atomic<bool> requested_{false};
|
||||||
std::chrono::steady_clock::time_point last_{}; // the last read
|
std::mutex lock_;
|
||||||
std::atomic<unsigned> generation_{0};
|
|
||||||
std::vector<Entry> entries_; // written only by the thread; the lock guards readers
|
std::vector<Entry> entries_; // written only by the thread; the lock guards readers
|
||||||
std::vector<std::pair<sockaddr_un, socklen_t>> waiting_;
|
std::vector<std::pair<sockaddr_un, socklen_t>> waiting_;
|
||||||
};
|
};
|
||||||
@@ -674,36 +620,6 @@ bool Ignored(const std::vector<std::string> &patterns, const std::string &key) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
vr::HmdMatrix34_t Billboard(Vec3 at, Vec3 eye);
|
|
||||||
|
|
||||||
// One of our dots, with what was last set on it: each setter goes to SteamVR only when its value
|
|
||||||
// changes (see "Unchanged frames" at the top).
|
|
||||||
struct DotOverlay {
|
|
||||||
vr::VROverlayHandle_t h = vr::k_ulOverlayHandleInvalid;
|
|
||||||
int shown = -1; // unknown at first
|
|
||||||
float alpha = -1, width = -1;
|
|
||||||
bool placed = false;
|
|
||||||
Vec3 at, eye;
|
|
||||||
void Show(bool on) {
|
|
||||||
if (shown == int(on)) return;
|
|
||||||
shown = on;
|
|
||||||
if (on) vr::VROverlay()->ShowOverlay(h);
|
|
||||||
else vr::VROverlay()->HideOverlay(h);
|
|
||||||
}
|
|
||||||
void Alpha(float a) {
|
|
||||||
if (a != alpha) vr::VROverlay()->SetOverlayAlpha(h, alpha = a);
|
|
||||||
}
|
|
||||||
// Width w, at `to`, facing `from`: left as it is for a change under 0.5% in width, and while
|
|
||||||
// it moved less than 0.2 mm and the eye less than 5 mm.
|
|
||||||
void Place(Vec3 to, Vec3 from, float w) {
|
|
||||||
if (std::fabs(w - width) > 0.005f * width) vr::VROverlay()->SetOverlayWidthInMeters(h, width = w);
|
|
||||||
if (placed && Length(to - at) < 0.0002 && Length(from - eye) < 0.005) return;
|
|
||||||
placed = true, at = to, eye = from;
|
|
||||||
const auto m = Billboard(to, from);
|
|
||||||
vr::VROverlay()->SetOverlayTransformAbsolute(h, vr::TrackingUniverseStanding, &m);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
vr::HmdMatrix34_t Billboard(Vec3 at, Vec3 eye) {
|
vr::HmdMatrix34_t Billboard(Vec3 at, Vec3 eye) {
|
||||||
// Overlay faces +Z; point +Z at the eye, keep +Y roughly up.
|
// Overlay faces +Z; point +Z at the eye, keep +Y roughly up.
|
||||||
const Vec3 z = Normalize(eye - at);
|
const Vec3 z = Normalize(eye - at);
|
||||||
@@ -887,8 +803,6 @@ int main() {
|
|||||||
below.m[1][3] = -50;
|
below.m[1][3] = -50;
|
||||||
overlay->SetOverlayTransformTrackedDeviceRelative(laserMode, vr::k_unTrackedDeviceIndex_Hmd, &below);
|
overlay->SetOverlayTransformTrackedDeviceRelative(laserMode, vr::k_unTrackedDeviceIndex_Hmd, &below);
|
||||||
bool laserModeShown = false;
|
bool laserModeShown = false;
|
||||||
DotOverlay cursorDot, markerDot; // the setters for `cursor` and `marker` (see "Unchanged frames" at the top)
|
|
||||||
cursorDot.h = cursor, markerDot.h = marker;
|
|
||||||
// Controller beams keep the user's width; nothing here changes it any more.
|
// Controller beams keep the user's width; nothing here changes it any more.
|
||||||
vr::VRSettings()->SetFloat("dashboard", "laserRayWidthScale", laserWidth);
|
vr::VRSettings()->SetFloat("dashboard", "laserRayWidthScale", laserWidth);
|
||||||
|
|
||||||
@@ -908,34 +822,12 @@ int main() {
|
|||||||
std::map<std::string, bool> sceneGraph; // no texture: plane test instead of ComputeOverlayIntersection
|
std::map<std::string, bool> sceneGraph; // no texture: plane test instead of ComputeOverlayIntersection
|
||||||
std::map<std::string, bool> visible; // refreshed every 50 ms
|
std::map<std::string, bool> visible; // refreshed every 50 ms
|
||||||
auto lastVisible = std::chrono::steady_clock::now();
|
auto lastVisible = std::chrono::steady_clock::now();
|
||||||
auto lastSlow = std::chrono::steady_clock::now() - std::chrono::seconds(10);
|
|
||||||
unsigned listGeneration = 0; // the overlay list the handles were looked up from
|
|
||||||
// The plane of the last panel the cursor was on, and the last point on it (panel edges).
|
// The plane of the last panel the cursor was on, and the last point on it (panel edges).
|
||||||
Vec3 edgePoint, edgeNormal, edgeLast;
|
Vec3 edgePoint, edgeNormal, edgeLast;
|
||||||
std::string edgeKey;
|
std::string edgeKey;
|
||||||
|
|
||||||
bool active = false, recenter = false, anchored = false;
|
bool active = false, recenter = false, anchored = false;
|
||||||
using Clock = std::chrono::steady_clock;
|
using Clock = std::chrono::steady_clock;
|
||||||
// Unchanged frames (see the top): visibleGen goes up when an overlay shows or hides or the
|
|
||||||
// handles change; pass is the last collision pass, posed the last plain pose sent.
|
|
||||||
unsigned visibleGen = 0;
|
|
||||||
struct Pass {
|
|
||||||
bool valid = false;
|
|
||||||
Clock::time_point at{};
|
|
||||||
unsigned gen = 0;
|
|
||||||
double yaw = 0, pitch = 0;
|
|
||||||
Vec3 anchor, eye;
|
|
||||||
double best = 1e9, distance = 0;
|
|
||||||
std::string key;
|
|
||||||
bool scene = false, onEdge = false, occluded = false;
|
|
||||||
Vec3 point;
|
|
||||||
} pass;
|
|
||||||
struct Posed {
|
|
||||||
bool valid = false;
|
|
||||||
Clock::time_point at{};
|
|
||||||
Vec3 origin;
|
|
||||||
double yaw = 0, pitch = 0;
|
|
||||||
} posed;
|
|
||||||
Clock::time_point lastMouse{}, claimAt{}, claimRelease{}, wokeAt{}, noWakeUntil{};
|
Clock::time_point lastMouse{}, claimAt{}, claimRelease{}, wokeAt{}, noWakeUntil{};
|
||||||
bool claimPending = false, claimHeld = false;
|
bool claimPending = false, claimHeld = false;
|
||||||
// Last used wins: since when each controller has been moving (zero: it isn't).
|
// Last used wins: since when each controller has been moving (zero: it isn't).
|
||||||
@@ -972,9 +864,6 @@ int main() {
|
|||||||
wokeAt = t;
|
wokeAt = t;
|
||||||
active = true;
|
active = true;
|
||||||
recenter = true;
|
recenter = true;
|
||||||
// Overlay handles and visibility weren't looked at while it was off (see "Idle" at the top).
|
|
||||||
lastSlow = lastVisible = t - std::chrono::seconds(10);
|
|
||||||
pass.valid = posed.valid = false;
|
|
||||||
SendTo(out, "ft_pointer", "role " + role); // POINTER_ROLE, before it takes it
|
SendTo(out, "ft_pointer", "role " + role); // POINTER_ROLE, before it takes it
|
||||||
SendTo(out, "ft_pointer", "show");
|
SendTo(out, "ft_pointer", "show");
|
||||||
claimPending = true; // take the laser without clicking, once SteamVR has bound the device
|
claimPending = true; // take the laser without clicking, once SteamVR has bound the device
|
||||||
@@ -1076,8 +965,6 @@ int main() {
|
|||||||
if (debug) std::fflush(stdout);
|
if (debug) std::fflush(stdout);
|
||||||
}
|
}
|
||||||
nudging = confirmLesson = false;
|
nudging = confirmLesson = false;
|
||||||
// A click on nothing: maybe on an overlay that came up since the list was read.
|
|
||||||
if (lastHit.empty()) overlays.Kick();
|
|
||||||
leftHeld = true;
|
leftHeld = true;
|
||||||
dragDistance = lastDistance;
|
dragDistance = lastDistance;
|
||||||
pressKey.clear();
|
pressKey.clear();
|
||||||
@@ -1201,6 +1088,7 @@ int main() {
|
|||||||
return gazeOn && gazeMouseHeld && !inGame && !headsetOff && Clock::now() - gz.at < std::chrono::seconds(1) &&
|
return gazeOn && gazeMouseHeld && !inGame && !headsetOff && Clock::now() - gz.at < std::chrono::seconds(1) &&
|
||||||
!aimHeld && !leftHeld && !tilting && hold.src == Src::None && !clickPress && !clickRelease;
|
!aimHeld && !leftHeld && !tilting && hold.src == Src::None && !clickPress && !clickRelease;
|
||||||
};
|
};
|
||||||
|
auto lastSlow = std::chrono::steady_clock::now() - std::chrono::seconds(10);
|
||||||
|
|
||||||
// --- Panel placement (see "Placement" at the top of the file) ---
|
// --- Panel placement (see "Placement" at the top of the file) ---
|
||||||
// Device pose, given in the standing universe, sent to the driver in raw space.
|
// Device pose, given in the standing universe, sent to the driver in raw space.
|
||||||
@@ -1216,7 +1104,6 @@ int main() {
|
|||||||
char msg[200];
|
char msg[200];
|
||||||
std::snprintf(msg, sizeof msg, "posq %.5f %.5f %.5f %.6f %.6f %.6f %.6f", o.x, o.y, o.z, q[0], q[1], q[2], q[3]);
|
std::snprintf(msg, sizeof msg, "posq %.5f %.5f %.5f %.6f %.6f %.6f %.6f", o.x, o.y, o.z, q[0], q[1], q[2], q[3]);
|
||||||
SendTo(out, "ft_pointer", msg);
|
SendTo(out, "ft_pointer", msg);
|
||||||
posed.valid = false;
|
|
||||||
};
|
};
|
||||||
auto sleepMs = [](int ms) { std::this_thread::sleep_for(std::chrono::milliseconds(ms)); };
|
auto sleepMs = [](int ms) { std::this_thread::sleep_for(std::chrono::milliseconds(ms)); };
|
||||||
auto headPos = [&] {
|
auto headPos = [&] {
|
||||||
@@ -1228,8 +1115,8 @@ int main() {
|
|||||||
auto borrow = [&] {
|
auto borrow = [&] {
|
||||||
SendTo(out, "ft_pointer", "show");
|
SendTo(out, "ft_pointer", "show");
|
||||||
overlay->ShowOverlay(laserMode);
|
overlay->ShowOverlay(laserMode);
|
||||||
cursorDot.Show(false);
|
overlay->HideOverlay(cursor);
|
||||||
markerDot.Show(false);
|
overlay->HideOverlay(marker);
|
||||||
sleepMs(active ? 50 : 400); // a fresh connect needs SteamVR to bind the device
|
sleepMs(active ? 50 : 400); // a fresh connect needs SteamVR to bind the device
|
||||||
SendTo(out, "ft_pointer", "btn a 1");
|
SendTo(out, "ft_pointer", "btn a 1");
|
||||||
sleepMs(60);
|
sleepMs(60);
|
||||||
@@ -1356,36 +1243,6 @@ int main() {
|
|||||||
return msg;
|
return msg;
|
||||||
};
|
};
|
||||||
|
|
||||||
// "move <dyaw> <dpitch>" from the relay.
|
|
||||||
auto mouseMove = [&](double a, double b) {
|
|
||||||
// A move held back (POINTER_GAZE_MOUSE_MOVE=held) only wakes the pointer: it isn't using
|
|
||||||
// the mouse, so a drifting mouse doesn't keep the gaze from taking the pointer back.
|
|
||||||
const bool heldBack = mouseMoveHeld();
|
|
||||||
if (!heldBack) lastMouse = Clock::now();
|
|
||||||
// Any mouse input wakes the pointer (after a controller took over, or a helper restart).
|
|
||||||
if (!active) wake(Clock::now());
|
|
||||||
if (heldBack) return;
|
|
||||||
if (tilting) {
|
|
||||||
tiltYaw += a;
|
|
||||||
tiltPitch = std::clamp(tiltPitch + b, -80.0, 80.0);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
lastMove = Clock::now(); // the dot shows while the mouse moves it (gaze mode)
|
|
||||||
if (gazeOn && gazeOwns) {
|
|
||||||
// The mouse takes the pointer from the gaze, from where the gaze left it.
|
|
||||||
gazeOwns = false;
|
|
||||||
nudging = haveHead && Clock::now() - gz.at < std::chrono::milliseconds(200);
|
|
||||||
nudgeRawHy = gz.rhy, nudgeRawHp = gz.rhp, nudgeHead = lastHead;
|
|
||||||
nudgeAt = Clock::now(), nudgeMoved = 0;
|
|
||||||
}
|
|
||||||
if (nudging || aimHeld) nudgeMoved += std::hypot(a, b);
|
|
||||||
if (!anchored) recenter = true;
|
|
||||||
yaw += a;
|
|
||||||
while (yaw > 180) yaw -= 360;
|
|
||||||
while (yaw < -180) yaw += 360;
|
|
||||||
pitch = std::clamp(pitch + b, -85.0, 85.0);
|
|
||||||
};
|
|
||||||
|
|
||||||
std::printf("ft-pointer running: free distance %.2f m, dot %.2f deg\n", freeDistance, cursorDeg);
|
std::printf("ft-pointer running: free distance %.2f m, dot %.2f deg\n", freeDistance, cursorDeg);
|
||||||
std::fflush(stdout);
|
std::fflush(stdout);
|
||||||
|
|
||||||
@@ -1400,8 +1257,8 @@ int main() {
|
|||||||
if (headsetOff && active) {
|
if (headsetOff && active) {
|
||||||
active = false;
|
active = false;
|
||||||
claimPending = claimHeld = false;
|
claimPending = claimHeld = false;
|
||||||
cursorDot.Show(false);
|
overlay->HideOverlay(cursor);
|
||||||
markerDot.Show(false);
|
overlay->HideOverlay(marker);
|
||||||
SendTo(out, "ft_pointer", "btn a 0");
|
SendTo(out, "ft_pointer", "btn a 0");
|
||||||
SendTo(out, "ft_pointer", "hide");
|
SendTo(out, "ft_pointer", "hide");
|
||||||
std::printf("headset off: pointer released\n");
|
std::printf("headset off: pointer released\n");
|
||||||
@@ -1451,12 +1308,6 @@ int main() {
|
|||||||
if (senderLen > offsetof(sockaddr_un, sun_path))
|
if (senderLen > offsetof(sockaddr_un, sun_path))
|
||||||
sendto(out, msg.data(), msg.size(), 0, reinterpret_cast<const sockaddr *>(&sender), senderLen);
|
sendto(out, msg.data(), msg.size(), 0, reinterpret_cast<const sockaddr *>(&sender), senderLen);
|
||||||
};
|
};
|
||||||
// Mouse moves first, the most frequent command.
|
|
||||||
double mx, my;
|
|
||||||
if (std::strncmp(buf, "move ", 5) == 0 && std::sscanf(buf + 5, "%lf %lf", &mx, &my) == 2) {
|
|
||||||
mouseMove(mx, my);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
// The gaze, from ft-gazed: not mouse input, it never wakes the pointer.
|
// The gaze, from ft-gazed: not mouse input, it never wakes the pointer.
|
||||||
double g[4];
|
double g[4];
|
||||||
if (std::sscanf(buf, "gz %lf %lf %lf %lf", &g[0], &g[1], &g[2], &g[3]) == 4) {
|
if (std::sscanf(buf, "gz %lf %lf %lf %lf", &g[0], &g[1], &g[2], &g[3]) == 4) {
|
||||||
@@ -1545,11 +1396,16 @@ int main() {
|
|||||||
reply(gazeOn ? "ok on" : "ok off");
|
reply(gazeOn ? "ok on" : "ok off");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// (Moves were taken first, above.)
|
const bool mouseInput = std::strncmp(buf, "move", 4) == 0 || std::strncmp(buf, "btn", 3) == 0 ||
|
||||||
const bool mouseInput = std::strncmp(buf, "btn", 3) == 0 || std::strncmp(buf, "scroll", 6) == 0;
|
std::strncmp(buf, "scroll", 6) == 0;
|
||||||
if (mouseInput) lastMouse = Clock::now();
|
// A move held back (POINTER_GAZE_MOUSE_MOVE=held) only wakes the pointer: it isn't using
|
||||||
|
// the mouse, so a drifting mouse doesn't keep the gaze from taking the pointer back.
|
||||||
|
const bool moveHeldBack = std::strncmp(buf, "move", 4) == 0 && mouseMoveHeld();
|
||||||
|
if (mouseInput && !moveHeldBack) lastMouse = Clock::now();
|
||||||
// Any mouse input wakes the pointer (after a controller took over, or a helper restart).
|
// Any mouse input wakes the pointer (after a controller took over, or a helper restart).
|
||||||
if (!active && mouseInput) wake(Clock::now());
|
if (!active && mouseInput) wake(Clock::now());
|
||||||
|
if (moveHeldBack) continue;
|
||||||
|
double a, b;
|
||||||
char key[128];
|
char key[128];
|
||||||
double px, py, pz, pyaw, ppitch, proll = 0, pgrab = -1;
|
double px, py, pz, pyaw, ppitch, proll = 0, pgrab = -1;
|
||||||
if (std::sscanf(buf, "grabprobe %127s", key) == 1) {
|
if (std::sscanf(buf, "grabprobe %127s", key) == 1) {
|
||||||
@@ -1608,12 +1464,31 @@ int main() {
|
|||||||
tilting = swallowedRight = false;
|
tilting = swallowedRight = false;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (std::strncmp(buf, "recenter", 8) == 0) {
|
if (tilting && std::sscanf(buf, "move %lf %lf", &a, &b) == 2) {
|
||||||
|
tiltYaw += a;
|
||||||
|
tiltPitch = std::clamp(tiltPitch + b, -80.0, 80.0);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (std::sscanf(buf, "move %lf %lf", &a, &b) == 2) {
|
||||||
|
lastMove = Clock::now(); // the dot shows while the mouse moves it (gaze mode)
|
||||||
|
if (gazeOn && gazeOwns) {
|
||||||
|
// The mouse takes the pointer from the gaze, from where the gaze left it.
|
||||||
|
gazeOwns = false;
|
||||||
|
nudging = haveHead && Clock::now() - gz.at < std::chrono::milliseconds(200);
|
||||||
|
nudgeRawHy = gz.rhy, nudgeRawHp = gz.rhp, nudgeHead = lastHead;
|
||||||
|
nudgeAt = Clock::now(), nudgeMoved = 0;
|
||||||
|
}
|
||||||
|
if (nudging || aimHeld) nudgeMoved += std::hypot(a, b);
|
||||||
|
if (!anchored) recenter = true;
|
||||||
|
yaw += a;
|
||||||
|
while (yaw > 180) yaw -= 360;
|
||||||
|
while (yaw < -180) yaw += 360;
|
||||||
|
pitch = std::clamp(pitch + b, -85.0, 85.0);
|
||||||
|
} else if (std::strncmp(buf, "recenter", 8) == 0) {
|
||||||
recenter = true;
|
recenter = true;
|
||||||
} else if (std::strncmp(buf, "reload", 6) == 0) {
|
} else if (std::strncmp(buf, "reload", 6) == 0) {
|
||||||
loadConfig();
|
loadConfig();
|
||||||
lastSlow = Clock::now() - std::chrono::seconds(10); // apply POINTER_IGNORE now
|
lastSlow = Clock::now() - std::chrono::seconds(10); // apply POINTER_IGNORE now
|
||||||
pass.valid = false;
|
|
||||||
std::printf("reloaded: free distance %.2f m, dot %.2f deg, origin %.2f, head follow %s, leash %.0f deg, "
|
std::printf("reloaded: free distance %.2f m, dot %.2f deg, origin %.2f, head follow %s, leash %.0f deg, "
|
||||||
"controller pickup %.1fx, %zu ignored\n",
|
"controller pickup %.1fx, %zu ignored\n",
|
||||||
freeDistance, cursorDeg, originFraction, follow ? "on" : "off", leashDeg, pickupScale,
|
freeDistance, cursorDeg, originFraction, follow ? "on" : "off", leashDeg, pickupScale,
|
||||||
@@ -1631,8 +1506,8 @@ int main() {
|
|||||||
if (!active) wake(Clock::now());
|
if (!active) wake(Clock::now());
|
||||||
} else if (std::strncmp(buf, "hide", 4) == 0) {
|
} else if (std::strncmp(buf, "hide", 4) == 0) {
|
||||||
active = false;
|
active = false;
|
||||||
cursorDot.Show(false);
|
overlay->HideOverlay(cursor);
|
||||||
markerDot.Show(false);
|
overlay->HideOverlay(marker);
|
||||||
SendTo(out, "ft_pointer", "hide");
|
SendTo(out, "ft_pointer", "hide");
|
||||||
} else {
|
} else {
|
||||||
SendTo(out, "ft_pointer", buf); // btn, scroll
|
SendTo(out, "ft_pointer", buf); // btn, scroll
|
||||||
@@ -1674,8 +1549,8 @@ int main() {
|
|||||||
sys->GetControllerRoleForTrackedDeviceIndex(ours) == vr::TrackedControllerRole_Invalid) {
|
sys->GetControllerRoleForTrackedDeviceIndex(ours) == vr::TrackedControllerRole_Invalid) {
|
||||||
active = false;
|
active = false;
|
||||||
claimPending = claimHeld = false;
|
claimPending = claimHeld = false;
|
||||||
cursorDot.Show(false);
|
overlay->HideOverlay(cursor);
|
||||||
markerDot.Show(false);
|
overlay->HideOverlay(marker);
|
||||||
SendTo(out, "ft_pointer", "btn a 0");
|
SendTo(out, "ft_pointer", "btn a 0");
|
||||||
SendTo(out, "ft_pointer", "hide");
|
SendTo(out, "ft_pointer", "hide");
|
||||||
noWakeUntil = tnow + std::chrono::seconds(2);
|
noWakeUntil = tnow + std::chrono::seconds(2);
|
||||||
@@ -1703,8 +1578,8 @@ int main() {
|
|||||||
if (tnow - movingSince[i] >= std::chrono::milliseconds(100)) {
|
if (tnow - movingSince[i] >= std::chrono::milliseconds(100)) {
|
||||||
active = false;
|
active = false;
|
||||||
claimPending = claimHeld = false;
|
claimPending = claimHeld = false;
|
||||||
cursorDot.Show(false);
|
overlay->HideOverlay(cursor);
|
||||||
markerDot.Show(false);
|
overlay->HideOverlay(marker);
|
||||||
SendTo(out, "ft_pointer", "btn a 0");
|
SendTo(out, "ft_pointer", "btn a 0");
|
||||||
SendTo(out, "ft_pointer", "hide");
|
SendTo(out, "ft_pointer", "hide");
|
||||||
std::printf("controller %u moved (%.2f m/s, %.1f rad/s): pointer released\n", i, speed, spin);
|
std::printf("controller %u moved (%.2f m/s, %.1f rad/s): pointer released\n", i, speed, spin);
|
||||||
@@ -1754,7 +1629,7 @@ int main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Hands (see the top): pinches and grips from ft-hands.
|
// Hands (see the top): pinches and grips from ft-hands.
|
||||||
if (handsOn) {
|
{
|
||||||
vr::TrackedDevicePose_t h0;
|
vr::TrackedDevicePose_t h0;
|
||||||
sys->GetDeviceToAbsoluteTrackingPose(vr::TrackingUniverseStanding, 0, &h0, 1);
|
sys->GetDeviceToAbsoluteTrackingPose(vr::TrackingUniverseStanding, 0, &h0, 1);
|
||||||
if (h0.bPoseIsValid) poses.Add(tnow, h0.mDeviceToAbsoluteTracking);
|
if (h0.bPoseIsValid) poses.Add(tnow, h0.mDeviceToAbsoluteTracking);
|
||||||
@@ -2053,13 +1928,10 @@ int main() {
|
|||||||
}
|
}
|
||||||
followAt = tnow;
|
followAt = tnow;
|
||||||
|
|
||||||
// Slow work, once a second and when the overlay list is new: overlay handles, our device
|
// Slow work, once a second: overlay handles, our device index, laser width.
|
||||||
// index. Only while the pointer is awake (see "Idle" at the top).
|
|
||||||
const auto now = std::chrono::steady_clock::now();
|
const auto now = std::chrono::steady_clock::now();
|
||||||
if (active && (now - lastSlow > std::chrono::seconds(1) || overlays.Generation() != listGeneration)) {
|
if (now - lastSlow > std::chrono::seconds(1)) {
|
||||||
lastSlow = now;
|
lastSlow = now;
|
||||||
listGeneration = overlays.Generation();
|
|
||||||
const auto before = handles;
|
|
||||||
handles.clear();
|
handles.clear();
|
||||||
for (const auto &key : overlays.Keys()) {
|
for (const auto &key : overlays.Keys()) {
|
||||||
if (Ignored(ignore, key)) continue;
|
if (Ignored(ignore, key)) continue;
|
||||||
@@ -2079,21 +1951,19 @@ int main() {
|
|||||||
sceneGraph[key] = (tw == 0 || th == 0) && tt == vr::VROverlayTransform_Absolute &&
|
sceneGraph[key] = (tw == 0 || th == 0) && tt == vr::VROverlayTransform_Absolute &&
|
||||||
key.rfind("frametop.", 0) != 0;
|
key.rfind("frametop.", 0) != 0;
|
||||||
}
|
}
|
||||||
if (handles != before) ++visibleGen;
|
ours = vr::k_unTrackedDeviceIndexInvalid;
|
||||||
// Our device keeps its index; it's looked for again when a device is activated or
|
for (vr::TrackedDeviceIndex_t i = 0; i < vr::k_unMaxTrackedDeviceCount; ++i) {
|
||||||
// deactivated (the events below).
|
|
||||||
for (vr::TrackedDeviceIndex_t i = 0; ours == vr::k_unTrackedDeviceIndexInvalid && i < vr::k_unMaxTrackedDeviceCount; ++i) {
|
|
||||||
char type[64] = "";
|
char type[64] = "";
|
||||||
sys->GetStringTrackedDeviceProperty(i, vr::Prop_ControllerType_String, type, sizeof type);
|
sys->GetStringTrackedDeviceProperty(i, vr::Prop_ControllerType_String, type, sizeof type);
|
||||||
if (std::strcmp(type, "ft_pointer") == 0) ours = i;
|
if (std::strcmp(type, "ft_pointer") == 0) ours = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (active && (now - lastVisible > std::chrono::milliseconds(50) || visible.size() != handles.size())) {
|
if (now - lastVisible > std::chrono::milliseconds(50) || visible.size() != handles.size()) {
|
||||||
lastVisible = now;
|
lastVisible = now;
|
||||||
std::map<std::string, bool> seen;
|
visible.clear();
|
||||||
for (const auto &[key, h] : handles) seen[key] = overlay->IsOverlayVisible(h);
|
for (const auto &[key, h] : handles) visible[key] = overlay->IsOverlayVisible(h);
|
||||||
if (seen != visible) visible.swap(seen), ++visibleGen;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (active && anchored && hmd.bPoseIsValid && tilting) {
|
if (active && anchored && hmd.bPoseIsValid && tilting) {
|
||||||
@@ -2103,8 +1973,8 @@ int main() {
|
|||||||
tiltOrigin = lastOrigin;
|
tiltOrigin = lastOrigin;
|
||||||
tiltBasis = AimBasis(lastAim);
|
tiltBasis = AimBasis(lastAim);
|
||||||
tiltStart = false; // angles carry on from any earlier tilt in this drag
|
tiltStart = false; // angles carry on from any earlier tilt in this drag
|
||||||
cursorDot.Show(false);
|
overlay->HideOverlay(cursor);
|
||||||
markerDot.Show(false);
|
overlay->HideOverlay(marker);
|
||||||
}
|
}
|
||||||
const double yr = tiltYaw * M_PI / 180, pr = tiltPitch * M_PI / 180;
|
const double yr = tiltYaw * M_PI / 180, pr = tiltPitch * M_PI / 180;
|
||||||
const Vec3 up{0, 1, 0}, side = tiltBasis.x;
|
const Vec3 up{0, 1, 0}, side = tiltBasis.x;
|
||||||
@@ -2120,7 +1990,6 @@ int main() {
|
|||||||
std::snprintf(msg, sizeof msg, "posq %.5f %.5f %.5f %.6f %.6f %.6f %.6f", originRaw.x, originRaw.y,
|
std::snprintf(msg, sizeof msg, "posq %.5f %.5f %.5f %.6f %.6f %.6f %.6f", originRaw.x, originRaw.y,
|
||||||
originRaw.z, q[0], q[1], q[2], q[3]);
|
originRaw.z, q[0], q[1], q[2], q[3]);
|
||||||
SendTo(out, "ft_pointer", msg);
|
SendTo(out, "ft_pointer", msg);
|
||||||
posed.valid = false;
|
|
||||||
} else if (active && anchored && hmd.bPoseIsValid) {
|
} else if (active && anchored && hmd.bPoseIsValid) {
|
||||||
const bool dragging = leftHeld || tnow < dropHoldUntil;
|
const bool dragging = leftHeld || tnow < dropHoldUntil;
|
||||||
if (!dragging) tiltYaw = tiltPitch = 0; // drop finished: back to plain pointing
|
if (!dragging) tiltYaw = tiltPitch = 0; // drop finished: back to plain pointing
|
||||||
@@ -2164,98 +2033,85 @@ int main() {
|
|||||||
}
|
}
|
||||||
return h;
|
return h;
|
||||||
};
|
};
|
||||||
// Unchanged frames (see the top): the last pass still holds.
|
Hit first;
|
||||||
const bool reuse = !dragging && pass.valid && tnow - pass.at < std::chrono::milliseconds(100) &&
|
if (!dragging) first = nearest(anchor, dir);
|
||||||
pass.gen == visibleGen && std::fabs(yaw - pass.yaw) < 1e-6 &&
|
double best = first.along;
|
||||||
std::fabs(pitch - pass.pitch) < 1e-6 && Length(anchor - pass.anchor) < 0.001 &&
|
std::string bestKey = first.key;
|
||||||
Length(eye - pass.eye) < 0.005;
|
bool bestScene = first.scene;
|
||||||
double best = pass.best, distance = pass.distance;
|
Vec3 bestPoint = first.point, bestNormal = first.normal;
|
||||||
std::string bestKey = pass.key;
|
bool onEdge = false;
|
||||||
bool bestScene = pass.scene, onEdge = pass.onEdge, occluded = pass.occluded;
|
if (!dragging && best < 1e8 && !bestScene) {
|
||||||
Vec3 point = pass.point;
|
edgeKey = bestKey, edgePoint = bestPoint, edgeNormal = Normalize(bestNormal), edgeLast = bestPoint;
|
||||||
if (!reuse) {
|
} else if (!dragging && best >= 1e8 && !edgeKey.empty() && visible[edgeKey]) {
|
||||||
Hit first;
|
// Just off a panel: stay on its plane (see "Panel edges" at the top).
|
||||||
if (!dragging) first = nearest(anchor, dir);
|
const double denom = Dot(dir, edgeNormal);
|
||||||
best = first.along;
|
if (std::fabs(denom) > 1e-4) {
|
||||||
bestKey = first.key;
|
const double along = Dot(edgePoint - anchor, edgeNormal) / denom;
|
||||||
bestScene = first.scene;
|
const Vec3 at = anchor + dir * along;
|
||||||
Vec3 bestPoint = first.point, bestNormal = first.normal;
|
if (along > 0.05 && std::sqrt(Dot(at - edgeLast, at - edgeLast)) <= edgeReach) {
|
||||||
onEdge = false;
|
best = along;
|
||||||
if (!dragging && best < 1e8 && !bestScene) {
|
bestKey = edgeKey;
|
||||||
edgeKey = bestKey, edgePoint = bestPoint, edgeNormal = Normalize(bestNormal), edgeLast = bestPoint;
|
onEdge = true;
|
||||||
} else if (!dragging && best >= 1e8 && !edgeKey.empty() && visible.count(edgeKey) &&
|
|
||||||
visible.at(edgeKey)) {
|
|
||||||
// Just off a panel: stay on its plane (see "Panel edges" at the top).
|
|
||||||
const double denom = Dot(dir, edgeNormal);
|
|
||||||
if (std::fabs(denom) > 1e-4) {
|
|
||||||
const double along = Dot(edgePoint - anchor, edgeNormal) / denom;
|
|
||||||
const Vec3 at = anchor + dir * along;
|
|
||||||
if (along > 0.05 && std::sqrt(Dot(at - edgeLast, at - edgeLast)) <= edgeReach) {
|
|
||||||
best = along;
|
|
||||||
bestKey = edgeKey;
|
|
||||||
onEdge = true;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Held on one of ft-screens' panels that stays where it is: onto whichever of them
|
}
|
||||||
// the ray meets (see the top).
|
// Held on one of ft-screens' panels that stays where it is: onto whichever of them
|
||||||
if (leftHeld && !pressKey.empty()) {
|
// the ray meets (see the top).
|
||||||
vr::ETrackingUniverseOrigin uo;
|
if (leftHeld && !pressKey.empty()) {
|
||||||
vr::HmdMatrix34_t now{};
|
vr::ETrackingUniverseOrigin uo;
|
||||||
auto it = handles.find(pressKey);
|
vr::HmdMatrix34_t now{};
|
||||||
bool still = it != handles.end() &&
|
auto it = handles.find(pressKey);
|
||||||
overlay->GetOverlayTransformAbsolute(it->second, &uo, &now) == vr::VROverlayError_None;
|
bool still = it != handles.end() &&
|
||||||
for (int i = 0; still && i < 3; ++i)
|
overlay->GetOverlayTransformAbsolute(it->second, &uo, &now) == vr::VROverlayError_None;
|
||||||
for (int j = 0; j < 4; ++j)
|
for (int i = 0; still && i < 3; ++i)
|
||||||
if (std::fabs(now.m[i][j] - pressPose.m[i][j]) > 0.001f) still = false;
|
for (int j = 0; j < 4; ++j)
|
||||||
if (still) {
|
if (std::fabs(now.m[i][j] - pressPose.m[i][j]) > 0.001f) still = false;
|
||||||
Hit h;
|
if (still) {
|
||||||
for (const auto &[key, handle] : handles) {
|
Hit h;
|
||||||
if (!visible[key] || !FramePanel(key)) continue;
|
for (const auto &[key, handle] : handles) {
|
||||||
vr::VROverlayIntersectionParams_t params{};
|
if (!visible[key] || !FramePanel(key)) continue;
|
||||||
params.vSource = {float(anchor.x), float(anchor.y), float(anchor.z)};
|
vr::VROverlayIntersectionParams_t params{};
|
||||||
params.vDirection = {float(dir.x), float(dir.y), float(dir.z)};
|
params.vSource = {float(anchor.x), float(anchor.y), float(anchor.z)};
|
||||||
params.eOrigin = vr::TrackingUniverseStanding;
|
params.vDirection = {float(dir.x), float(dir.y), float(dir.z)};
|
||||||
vr::VROverlayIntersectionResults_t r{};
|
params.eOrigin = vr::TrackingUniverseStanding;
|
||||||
if (overlay->ComputeOverlayIntersection(handle, ¶ms, &r) && r.fDistance > 0.05f &&
|
vr::VROverlayIntersectionResults_t r{};
|
||||||
r.fDistance < h.along)
|
if (overlay->ComputeOverlayIntersection(handle, ¶ms, &r) && r.fDistance > 0.05f &&
|
||||||
h.along = r.fDistance, h.key = key;
|
r.fDistance < h.along)
|
||||||
}
|
h.along = r.fDistance, h.key = key;
|
||||||
if (h.along < 1e8) dragDistance = h.along, lastHit = h.key;
|
|
||||||
} else {
|
|
||||||
pressKey.clear(); // carried: the lock holds for the rest of this press
|
|
||||||
}
|
}
|
||||||
|
if (h.along < 1e8) dragDistance = h.along, lastHit = h.key;
|
||||||
|
} else {
|
||||||
|
pressKey.clear(); // carried: the lock holds for the rest of this press
|
||||||
}
|
}
|
||||||
// While dragging: keep the press-time distance and show the non-interactive marker.
|
}
|
||||||
// On a scene-graph plane or a panel's edge: the laser-catching dot goes 5 cm behind it.
|
// While dragging: keep the press-time distance and show the non-interactive marker.
|
||||||
distance = dragging ? dragDistance : (best < 1e8 ? best : freeDistance);
|
// On a scene-graph plane or a panel's edge: the laser-catching dot goes 5 cm behind it.
|
||||||
point = anchor + dir * distance;
|
double distance = dragging ? dragDistance : (best < 1e8 ? best : freeDistance);
|
||||||
occluded = false;
|
Vec3 point = anchor + dir * distance;
|
||||||
if (!dragging) {
|
bool occluded = false;
|
||||||
// The cursor lands on what you see under it: the ray above starts at the anchor,
|
if (!dragging) {
|
||||||
// not the eye, so after leaning it can pick a panel that something nearer
|
// The cursor lands on what you see under it: the ray above starts at the anchor,
|
||||||
// covers from where you are now (panels close together in view, at different
|
// not the eye, so after leaning it can pick a panel that something nearer
|
||||||
// depths). Anything in front of the point on the eye's line of sight wins.
|
// covers from where you are now (panels close together in view, at different
|
||||||
const double toPoint = std::sqrt(Dot(point - eye, point - eye));
|
// depths). Anything in front of the point on the eye's line of sight wins.
|
||||||
const Hit front = nearest(eye, Normalize(point - eye));
|
const double toPoint = std::sqrt(Dot(point - eye, point - eye));
|
||||||
if (front.along < toPoint - 0.02) {
|
const Hit front = nearest(eye, Normalize(point - eye));
|
||||||
occluded = true;
|
if (front.along < toPoint - 0.02) {
|
||||||
bestKey = front.key, bestScene = front.scene;
|
occluded = true;
|
||||||
point = front.point;
|
bestKey = front.key, bestScene = front.scene;
|
||||||
if (!front.scene)
|
point = front.point;
|
||||||
edgeKey = front.key, edgePoint = front.point, edgeNormal = Normalize(front.normal),
|
if (!front.scene) edgeKey = front.key, edgePoint = front.point, edgeNormal = Normalize(front.normal),
|
||||||
edgeLast = front.point;
|
edgeLast = front.point;
|
||||||
distance = std::sqrt(Dot(point - anchor, point - anchor));
|
distance = std::sqrt(Dot(point - anchor, point - anchor));
|
||||||
best = distance;
|
best = distance;
|
||||||
onEdge = false;
|
onEdge = false;
|
||||||
}
|
|
||||||
lastDistance = distance, lastHit = bestKey;
|
|
||||||
}
|
}
|
||||||
|
lastDistance = distance, lastHit = bestKey;
|
||||||
}
|
}
|
||||||
const bool onScene = !dragging && ((bestScene && best < 1e8) || onEdge);
|
const bool onScene = !dragging && ((bestScene && best < 1e8) || onEdge);
|
||||||
const bool onPanel = dragging || (best < 1e8 && !onScene);
|
const bool onPanel = dragging || (best < 1e8 && !onScene);
|
||||||
const Vec3 sight = Normalize(point - eye);
|
const Vec3 sight = Normalize(point - eye);
|
||||||
if (!dragging && !reuse) {
|
if (!dragging) {
|
||||||
// SteamVR Settings (see the top): the dashboard's main panel is hidden and its
|
// SteamVR Settings (see the top): the dashboard's main panel is hidden and its
|
||||||
// scene-graph panel shows the page.
|
// scene-graph panel shows the page.
|
||||||
onVrSettings = false;
|
onVrSettings = false;
|
||||||
@@ -2271,10 +2127,6 @@ int main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!reuse) {
|
|
||||||
pass = {!dragging, tnow, visibleGen, yaw, pitch, anchor, eye,
|
|
||||||
best, distance, bestKey, bestScene, onEdge, occluded, point};
|
|
||||||
}
|
|
||||||
if (onVrSettings != catcherHidesHit) {
|
if (onVrSettings != catcherHidesHit) {
|
||||||
overlay->SetOverlayFlag(cursor, vr::VROverlayFlags_HideLaserIntersection, onVrSettings);
|
overlay->SetOverlayFlag(cursor, vr::VROverlayFlags_HideLaserIntersection, onVrSettings);
|
||||||
catcherHidesHit = onVrSettings;
|
catcherHidesHit = onVrSettings;
|
||||||
@@ -2291,16 +2143,20 @@ int main() {
|
|||||||
alpha = std::clamp(1 - std::min(secs(lastMove) - gazeShow, secs(lastHeld)) / 0.25, 0.0, 1.0);
|
alpha = std::clamp(1 - std::min(secs(lastMove) - gazeShow, secs(lastHeld)) / 0.25, 0.0, 1.0);
|
||||||
}
|
}
|
||||||
if (tnow < calPanelUntil) alpha = 0;
|
if (tnow < calPanelUntil) alpha = 0;
|
||||||
markerDot.Alpha(float(alpha));
|
overlay->SetOverlayAlpha(marker, float(alpha));
|
||||||
markerDot.Place(near, eye, float(2 * SETTINGS_DOT * std::tan(cursorDeg * M_PI / 360)));
|
overlay->SetOverlayWidthInMeters(marker, float(2 * SETTINGS_DOT * std::tan(cursorDeg * M_PI / 360)));
|
||||||
cursorDot.Alpha(0);
|
auto mm = Billboard(near, eye);
|
||||||
cursorDot.Place(far, eye, float(2 * SETTINGS_CATCHER * std::tan(cursorDeg * M_PI / 360)));
|
overlay->SetOverlayTransformAbsolute(marker, vr::TrackingUniverseStanding, &mm);
|
||||||
markerDot.Show(true);
|
overlay->SetOverlayAlpha(cursor, 0);
|
||||||
cursorDot.Show(true);
|
overlay->SetOverlayWidthInMeters(cursor, float(2 * SETTINGS_CATCHER * std::tan(cursorDeg * M_PI / 360)));
|
||||||
|
auto mc = Billboard(far, eye);
|
||||||
|
overlay->SetOverlayTransformAbsolute(cursor, vr::TrackingUniverseStanding, &mc);
|
||||||
|
overlay->ShowOverlay(marker);
|
||||||
|
overlay->ShowOverlay(cursor);
|
||||||
} else {
|
} else {
|
||||||
// On a panel: the non-interactive marker, pulled 5 mm toward the eye so it
|
// On a panel: the non-interactive marker, pulled 5 mm toward the eye so it
|
||||||
// draws on top. In free space: the interactive dot the laser lands on.
|
// draws on top. In free space: the interactive dot the laser lands on.
|
||||||
DotOverlay &show = onPanel ? markerDot : cursorDot, &hide = onPanel ? cursorDot : markerDot;
|
const vr::VROverlayHandle_t show = onPanel ? marker : cursor, hide = onPanel ? cursor : marker;
|
||||||
const Vec3 at = onPanel ? point + Normalize(eye - point) * 0.005 : onScene ? point + dir * 0.05 : point;
|
const Vec3 at = onPanel ? point + Normalize(eye - point) * 0.005 : onScene ? point + dir * 0.05 : point;
|
||||||
const double dist = std::sqrt(Dot(at - eye, at - eye));
|
const double dist = std::sqrt(Dot(at - eye, at - eye));
|
||||||
// Gaze mode: a pulse for each click, and with POINTER_GAZE_DOT=moving, shown only
|
// Gaze mode: a pulse for each click, and with POINTER_GAZE_DOT=moving, shown only
|
||||||
@@ -2317,10 +2173,12 @@ int main() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (tnow < calPanelUntil) alpha = 0; // the calibration panel is up (see the top)
|
if (tnow < calPanelUntil) alpha = 0; // the calibration panel is up (see the top)
|
||||||
show.Alpha(float(alpha));
|
overlay->SetOverlayAlpha(show, float(alpha));
|
||||||
show.Place(at, eye, float(2 * dist * std::tan(scale * cursorDeg * M_PI / 360)));
|
overlay->SetOverlayWidthInMeters(show, float(2 * dist * std::tan(scale * cursorDeg * M_PI / 360)));
|
||||||
show.Show(true);
|
auto m = Billboard(at, eye);
|
||||||
hide.Show(false);
|
overlay->SetOverlayTransformAbsolute(show, vr::TrackingUniverseStanding, &m);
|
||||||
|
overlay->ShowOverlay(show);
|
||||||
|
overlay->HideOverlay(hide);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Controller ray: from the eye, aimed at the cursor point, converted from the
|
// Controller ray: from the eye, aimed at the cursor point, converted from the
|
||||||
@@ -2365,15 +2223,10 @@ int main() {
|
|||||||
std::snprintf(msg, sizeof msg, "posq %.5f %.5f %.5f %.6f %.6f %.6f %.6f", oRaw.x, oRaw.y, oRaw.z, q[0],
|
std::snprintf(msg, sizeof msg, "posq %.5f %.5f %.5f %.6f %.6f %.6f %.6f", oRaw.x, oRaw.y, oRaw.z, q[0],
|
||||||
q[1], q[2], q[3]);
|
q[1], q[2], q[3]);
|
||||||
SendTo(out, "ft_pointer", msg);
|
SendTo(out, "ft_pointer", msg);
|
||||||
posed.valid = false;
|
} else {
|
||||||
} else if (!posed.valid || tnow - posed.at >= std::chrono::milliseconds(100) ||
|
|
||||||
Length(eyeRaw - posed.origin) >= 0.0002 || std::fabs(std::remainder(ayaw - posed.yaw, 360.0)) >= 0.04 ||
|
|
||||||
std::fabs(apitch - posed.pitch) >= 0.04) {
|
|
||||||
// The driver keeps the last pose: only a change goes out (see "Unchanged frames" at the top).
|
|
||||||
char msg[160];
|
char msg[160];
|
||||||
std::snprintf(msg, sizeof msg, "pose %.5f %.5f %.5f %.4f %.4f", eyeRaw.x, eyeRaw.y, eyeRaw.z, ayaw, apitch);
|
std::snprintf(msg, sizeof msg, "pose %.5f %.5f %.5f %.4f %.4f", eyeRaw.x, eyeRaw.y, eyeRaw.z, ayaw, apitch);
|
||||||
SendTo(out, "ft_pointer", msg);
|
SendTo(out, "ft_pointer", msg);
|
||||||
posed = {true, tnow, eyeRaw, ayaw, apitch};
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -2422,12 +2275,6 @@ int main() {
|
|||||||
|
|
||||||
vr::VREvent_t ev;
|
vr::VREvent_t ev;
|
||||||
while (sys->PollNextEvent(&ev, sizeof ev)) {
|
while (sys->PollNextEvent(&ev, sizeof ev)) {
|
||||||
// The dashboard's overlays come and go with it, and a game brings its own.
|
|
||||||
if (ev.eventType == vr::VREvent_DashboardActivated || ev.eventType == vr::VREvent_DashboardDeactivated ||
|
|
||||||
ev.eventType == vr::VREvent_DashboardOverlayCreated || ev.eventType == vr::VREvent_SceneApplicationChanged)
|
|
||||||
overlays.Kick();
|
|
||||||
if (ev.eventType == vr::VREvent_TrackedDeviceActivated || ev.eventType == vr::VREvent_TrackedDeviceDeactivated)
|
|
||||||
ours = vr::k_unTrackedDeviceIndexInvalid;
|
|
||||||
if (ev.eventType == vr::VREvent_Quit) {
|
if (ev.eventType == vr::VREvent_Quit) {
|
||||||
sys->AcknowledgeQuit_Exiting();
|
sys->AcknowledgeQuit_Exiting();
|
||||||
|
|
||||||
@@ -2436,15 +2283,6 @@ int main() {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Idle (see the top): wait for a command instead. Not with anything still to finish (the
|
std::this_thread::sleep_for(std::chrono::milliseconds(8));
|
||||||
// claim pulse, a click's release, a press).
|
|
||||||
const bool idle = !active && !handsOn && !claimPending && !claimHeld && !clickRelease && !leftHeld &&
|
|
||||||
hold.src == Src::None;
|
|
||||||
if (idle) {
|
|
||||||
pollfd p{in, POLLIN, 0};
|
|
||||||
poll(&p, 1, controllerButtons.Watching(inGame) ? 20 : 250);
|
|
||||||
} else {
|
|
||||||
std::this_thread::sleep_for(std::chrono::milliseconds(8));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -111,14 +111,6 @@ class ControllerButtons {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Whether Poll reads any button now (the main loop can't sleep long while it does).
|
|
||||||
bool Watching(bool inGame) const {
|
|
||||||
if (!ok_ || (inGame && !games_ && !capture_)) return false;
|
|
||||||
for (int i = 0; i < kCount; ++i)
|
|
||||||
if (bound_[i]) return true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
// {"manifest":true,"global":false,"bound":[...],"active":[...]}: active = bound and
|
// {"manifest":true,"global":false,"bound":[...],"active":[...]}: active = bound and
|
||||||
// delivered (a controller that has the button is on, and SteamVR lets us have it).
|
// delivered (a controller that has the button is on, and SteamVR lets us have it).
|
||||||
std::string Status() const {
|
std::string Status() const {
|
||||||
|
|||||||
Reference in new issue
Block a user