Skip to content

Commit fcaf135

Browse files
committed
Fix physical transport readiness and reconnect handling
1 parent 190fe00 commit fcaf135

11 files changed

Lines changed: 234 additions & 28 deletions

File tree

‎CHANGELOG.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,14 @@
22

33
## Unreleased
44

5+
- Keep the transport daemon alive while the selected USB backend is absent or
6+
disconnected; publish a PID-checked readiness marker for framebuffer clients.
7+
- Mark readiness with the backend's physical-transport capability so diagnostic
8+
null/PPM backends cannot activate the real second-screen consumer.
9+
- Rate-limit missing-adapter diagnostics through the daemon's retry reporting
10+
instead of emitting backend discovery and empty-close messages every retry.
11+
- Add explicit reconnect and virtual-device path handling to the systemd service
12+
so a missing UGREEN adapter cannot be mistaken for a ready display.
513
- Add the experimental Actions Micro `185b:2d1d` live backend with replay-
614
derived initialization and heartbeat templates, FFmpeg H.264 encoding, and
715
dual-hidraw video delivery.

‎README.md‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,14 @@ sudo rmmod usbdisplay
113113
Do not assume the secondary nodes are always numbered `1`; discover them by
114114
the `usbdisplay` framebuffer name and DRM driver name in production scripts.
115115

116+
The daemon writes `/run/usbdisplay/ready` after the selected backend has opened
117+
successfully. The marker contains `pid`, `backend`, and `physical`; only
118+
`physical=1` is a valid gate for a real HDMI consumer. The null and PPM
119+
diagnostic backends intentionally publish `physical=0`. The daemon removes the
120+
marker on disconnect and waits inside the same process for reconnect. The
121+
virtual framebuffer can exist without a USB adapter. `--ready-file PATH` and
122+
`--retry-ms N` customize the marker and retry interval.
123+
116124
## Application examples
117125

118126
Run only one producer at a time. Both LVGL examples render the same dashboard:

‎README.zh-CN.md‎

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,13 @@ sudo rmmod usbdisplay
9999
第二设备的编号不保证为 `1`。生产脚本应通过 sysfs 中的 `usbdisplay`
100100
framebuffer 名称和 DRM 驱动名称发现节点。
101101

102+
生产守护进程在后端打开成功后写入包含 `pid`、`backend` 和 `physical` 的
103+
`/run/usbdisplay/ready`;只有 `physical=1` 才表示真实物理传输已就绪,`null`
104+
和 `ppm` 诊断后端会明确写入 `physical=0`。HID 断开时清理该文件,并在同一
105+
进程内等待重连。第二屏程序必须校验该文件和守护进程 PID,不能仅凭 `/dev/fb1`
106+
存在就认为 HDMI 已连接。可通过 `--ready-file PATH` 和 `--retry-ms N` 调整路径
107+
与重连间隔。
108+
102109
## 应用示例
103110

104111
同一时间只运行一个渲染生产者。两个 LVGL 示例显示同一套仪表盘:

‎backends/actions-micro/actions_micro_backend.c‎

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -545,12 +545,6 @@ static int open_hidraw(const char *configured_path, int expected_input,
545545
close(descriptor);
546546
descriptor = -1;
547547
}
548-
if (result != 0) {
549-
fprintf(stderr,
550-
"actions-micro: cannot find 185b:2d1d input%d: %s\n",
551-
expected_input, strerror(-result));
552-
}
553-
554548
return result == 0 ? descriptor : result;
555549
}
556550

@@ -1238,10 +1232,12 @@ static void actions_close(void *context)
12381232
if (state->hid[0] >= 0) {
12391233
close(state->hid[0]);
12401234
}
1241-
fprintf(stderr,
1242-
"actions-micro: closed frames=%llu reports=%llu\n",
1243-
(unsigned long long)state->frames,
1244-
(unsigned long long)state->reports);
1235+
if (state->frames != 0 || state->reports != 0) {
1236+
fprintf(stderr,
1237+
"actions-micro: closed frames=%llu reports=%llu\n",
1238+
(unsigned long long)state->frames,
1239+
(unsigned long long)state->reports);
1240+
}
12451241
free(state->encoder.encoded);
12461242
free(state->encoder.packed_frame);
12471243
free(state->bootstrap);
@@ -1327,7 +1323,8 @@ static int actions_open(const struct usbdisplay_backend_config *config,
13271323
static const struct usbdisplay_backend_v1 actions_backend = {
13281324
.abi_version = USBDISPLAY_BACKEND_ABI_VERSION,
13291325
.struct_size = sizeof(struct usbdisplay_backend_v1),
1330-
.capabilities = USBDISPLAY_BACKEND_CAP_TICK,
1326+
.capabilities = USBDISPLAY_BACKEND_CAP_TICK |
1327+
USBDISPLAY_BACKEND_CAP_PHYSICAL,
13311328
.name = "actions-micro-185b-2d1d",
13321329
.open = actions_open,
13331330
.submit = actions_submit,

‎docs/abi.md‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,12 @@ every 100 ms while idle and after frame processing, allowing keepalives and
4545
transport health checks to continue when the displayed image is static. Old
4646
backends whose table ends at `close` remain compatible.
4747
48+
`USBDISPLAY_BACKEND_CAP_PHYSICAL` declares that a backend owns a real display
49+
transport rather than a diagnostic sink. The daemon records this capability as
50+
`physical=1` in its readiness file after `open` succeeds. Consumers that drive
51+
real displays must require that value; the null and PPM backends intentionally
52+
leave the capability clear and publish `physical=0`.
53+
4854
`submit` runs synchronously. A backend should either complete promptly or
4955
implement its own bounded queue. Holding the call indefinitely prevents the
5056
daemon from advancing to newer snapshots.

‎docs/actions-micro-185b-2d1d.md‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ encapsulation, and alternating HID report delivery. On 2026-08-07, after a
1919
physical USB power cycle, `bootstrap=full` handed off from an authorized replay
2020
to newly encoded 1920x1080 LVGL output and the HDMI pixels were visually
2121
confirmed. The backend remains experimental pending repeated reconnect and
22-
long-running tests, so it is installed but is not selected by default.
22+
long-running tests. The host daemon now clears its readiness marker on
23+
disconnect and waits for the same adapter to reappear instead of relying on a
24+
rapid systemd restart loop.
2325

2426
## Observed framing
2527

@@ -124,6 +126,6 @@ restart the complete activation sequence.
124126

125127
## Remaining validation work
126128

127-
- handle hotplug, status input, backpressure, and frame dropping;
129+
- handle status input, backpressure, and frame dropping;
128130
- repeat physical power-cycle and reconnect tests;
129131
- validate long-running behavior.

‎docs/architecture.md‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,13 @@ unrelated backends to change.
5050
Backends may request a periodic `tick` callback. This keeps control traffic
5151
alive even when fbdev or DRM has not published a new frame.
5252

53+
The daemon publishes a PID-bearing readiness file after the backend opens. The
54+
file also carries `physical=1` only for a backend that owns a physical display
55+
transport; diagnostic backends publish `physical=0`. On a backend open or
56+
submit failure it removes the file, closes the backend, and retries in the same
57+
process. Real display consumers must require both a live daemon PID and
58+
`physical=1`; the virtual framebuffer can exist while no USB adapter is present.
59+
5360
A backend owns all protocol-specific work:
5461

5562
- pixel conversion and compression;
@@ -71,8 +78,8 @@ are present in the kernel module or application examples.
7178
## Failure boundaries
7279

7380
- Only one daemon may open `/dev/usbdisplay0` at a time.
74-
- A missing or failed backend terminates the daemon; it does not affect fb0.
75-
- A disconnected USB adapter is a backend error; there is no primary-display
76-
fallback.
81+
- A missing backend library is fatal, but a physical backend open or submit
82+
failure clears readiness and enters the bounded reconnect wait.
83+
- A disconnected USB adapter never falls back to the primary display.
7784
- Module unload unregisters fbdev, the misc device, and DRM before releasing
7885
their memory.

‎include/usbdisplay/backend.h‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
#define USBDISPLAY_BACKEND_ENTRY "usbdisplay_backend_v1"
1212
#define USBDISPLAY_BACKEND_CAP_NONE 0U
1313
#define USBDISPLAY_BACKEND_CAP_TICK (1ULL << 0)
14+
/* The backend owns a physical display transport, not only a diagnostic sink. */
15+
#define USBDISPLAY_BACKEND_CAP_PHYSICAL (1ULL << 1)
1416

1517
struct usbdisplay_backend_config {
1618
uint32_t struct_size;

‎packaging/usb-displayd.default‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# SPDX-License-Identifier: GPL-2.0-only
22

3-
# The null backend verifies frame flow without touching USB hardware.
3+
# The null backend verifies frame flow without touching USB hardware. A real
4+
# adapter backend must be selected explicitly; there is no transport fallback.
45
USBDISPLAY_BACKEND=/usr/lib/usbdisplay/usbdisplay-null.so
56

67
# Example PPM diagnostic output:

‎packaging/usb-displayd.service‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,13 @@ ConditionPathExists=/dev/usbdisplay0
55

66
[Service]
77
Type=simple
8+
RuntimeDirectory=usbdisplay
9+
RuntimeDirectoryMode=0755
810
Environment=USBDISPLAY_BACKEND=/usr/lib/usbdisplay/usbdisplay-null.so
911
Environment=USBDISPLAY_BACKEND_ARGS=
1012
EnvironmentFile=-/etc/default/usb-displayd
11-
ExecStart=/usr/bin/usb-displayd --device /dev/usbdisplay0 --backend ${USBDISPLAY_BACKEND} $USBDISPLAY_BACKEND_ARGS
13+
ExecStartPre=/bin/rm -f /run/usbdisplay/ready
14+
ExecStart=/usr/bin/usb-displayd --device /dev/usbdisplay0 --backend ${USBDISPLAY_BACKEND} $USBDISPLAY_BACKEND_ARGS --ready-file /run/usbdisplay/ready --retry-ms 2000
1215
Restart=on-failure
1316
RestartSec=2
1417
NoNewPrivileges=true

0 commit comments

Comments
 (0)