Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion docs/device-service-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -4613,7 +4613,10 @@ and returns `timing.completion:"queued"`.
Keys go down in list order and up in reverse order through the
board's keyboard controller, followed by `settle_seconds`. For Fn+Left,
send `["fn", "comma"]`. Use `dot`, `slash` and `semicolon` for
Fn+Down, Fn+Right and Fn+Up.
Fn+Down, Fn+Right and Fn+Up. Direct `kind:"key"` or `kind:"keyboard"`
inputs for `esc`, the arrow keys and `delete` use the mapped Fn chord.
Use `tap`, `click` or `hold` for these actions. Raw physical edges
continue to use their physical key names, such as `grave_accent` or `del`.
- Dial `encoder` accepts a signed nonzero integer between -128 and 128 and
changes the native quadrature controller's detent target. A second
request while movement is pending returns HTTP 409 `input_busy`. A
Expand Down
8 changes: 4 additions & 4 deletions docs/project-snapshot.md
Original file line number Diff line number Diff line change
Expand Up @@ -155,11 +155,11 @@

## 代码与文档规模

- `platform/tools`:`105` 个 Python 模块,`63248` 行;规模最大的模块如下。
- `platform/tools`:`105` 个 Python 模块,`63268` 行;规模最大的模块如下。

| 模块 | 行数 |
| --- | ---: |
| `device_service.py` | 16564 |
| `device_service.py` | 16578 |
| `firmware_manifest.py` | 3640 |
| `user_firmware_matrix.py` | 2347 |
| `network_sandbox.py` | 2171 |
Expand All @@ -168,11 +168,11 @@

- `tests/`:`184` 个可执行 Python 测试文件,分布在 `85` 个目录;`253` 个 evidence JSON。
- `patches/`:`17` 个补丁组,`386` 个 patch 文件。
- 文档:`762` 个 Markdown 页面;除本生成页外共 `84338` 行。
- 文档:`762` 个 Markdown 页面;除本生成页外共 `84341` 行。

## 文档与测试

- 平台测试:`2617` 项。
- 平台测试:`2620` 项。
- Docs 新鲜度登记:`290` 行;其中非历史页 `269` 行,历史固定页 `21` 行。
- 文档职责分布:待办 `3`,契约 `9`,证据/差异 `135`,历史固定 `21`,实现/设计 `15`,参考 `101`,工作流/导航 `6`。
- 全量文档盘点:`762` 个 Markdown 页面;职责分布:权威/专题页 `290`,设备档案 `41`,示例 `1`,治理/入口 `9`,文档导航 `1`,其他 `10`,补丁说明 `22`,平台说明 `26`,仓内历史记录 `5`,测试/用例说明 `249`,未登记 docs 页面 `4`,第三方来源说明 `104`。
Expand Down
54 changes: 54 additions & 0 deletions platform/tests/test_device_service_esp32sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,60 @@ def test_cardputer_keyboard_chords_use_physical_key_edges(self):
(code, 400 if code == "invalid_input" else 409))
session.control.request.assert_not_called()

def test_cardputer_direct_navigation_uses_keyboard_matrix_edges(self):
punctuation = {"esc": "`", "escape": "`", "left": ",", "right": "/",
"up": ";", "down": ".", "delete": "del"}
for device in ("cardputer", "cardputer-adv"):
for key, physical in punctuation.items():
with self.subTest(device=device, key=key):
session = self._input_session(device)
payload = {"kind": "key", "key": key, "action": "tap", "settle_seconds": 1.0}
receipt = session.inject(payload)
self.assertTrue(receipt["accepted"])
self.assertEqual(receipt["action"], "tap")
self.assertEqual(receipt["timing"], {
"clock": "host", "completion": "events_sent", "hold_seconds": 0.12, "presses": 1,
})
self.assertEqual([call.args for call in session.control.request.call_args_list], [
("key-edge", ("fn", 1)), ("key-edge", (physical, 1)),
("key-edge", (physical, 0)), ("key-edge", ("fn", 0)),
])
self.assertEqual([call.args for call in session._stop_event.wait.call_args_list],
[(0.12,), (1.0,)])
self.assertNotIn("qcodes", receipt["input"])

def test_cardputer_review_setup_uses_direct_navigation_hold(self):
for device in ("cardputer", "cardputer-adv"):
with self.subTest(device=device):
session = self._input_session(device)
step = {"kind": "keyboard", "key": "Esc", "action": "hold",
"seconds": 0.4, "settle_seconds": 0.25}
receipt = session._inject_review_setup(step)
self.assertTrue(receipt["accepted"])
self.assertEqual([call.args for call in session.control.request.call_args_list], [
("key-edge", ("fn", 1)), ("key-edge", ("`", 1)),
("key-edge", ("`", 0)), ("key-edge", ("fn", 0)),
])
self.assertEqual([call.args for call in session._stop_event.wait.call_args_list],
[(0.4,), (0.25,)])

def test_cardputer_navigation_rejects_unmapped_keys_without_edges(self):
for device in ("cardputer", "cardputer-adv"):
with self.subTest(device=device):
session = self._input_session(device)
with self.assertRaises(ServiceError) as error:
session.inject({"kind": "key", "key": "f24"})
self.assertEqual((error.exception.code, error.exception.status), ("not_supported_on_runtime", 409))
self.assertIn("f24", error.exception.message)
with patch("device_service.board_controls", return_value={"keyboard": []}):
with self.assertRaises(ServiceError) as error:
session.inject({"kind": "key", "key": "esc"})
self.assertEqual((error.exception.code, error.exception.status), ("unsupported_input", 409))
self.assertIn("esc", error.exception.message)
session.control.request.assert_not_called()
session.inject({"kind": "key", "key": "delete", "action": "down"})
session.control.request.assert_called_once_with("key-edge", ("del", 1))

def test_esp32sim_chords_check_every_qemu_profile_key(self):
for device in ("cardputer", "cardputer-adv"):
session = self._input_session(device)
Expand Down
32 changes: 23 additions & 9 deletions platform/tools/device_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,12 @@
)
from device_service_input import ( # noqa: E402
CLICK_SECONDS,
KEYBOARD_BOARDS,
NAVIGATION_KEYS,
SEMANTIC_INPUT_KINDS,
action_seconds,
board_controls,
keyboard_code,
normalize_semantic_input,
send_semantic_input,
)
Expand Down Expand Up @@ -11794,6 +11797,24 @@ def _decode_frame_metrics(self, data, *, analyze):
return result

def validate_input(self, payload):
if (self.spec.id in KEYBOARD_BOARDS and isinstance(payload, dict)
and payload.get("kind") in ("key", "keyboard")):
key = payload.get("key")
name = key.strip().lower() if isinstance(key, str) else None
action = payload.get("action", "tap")
if isinstance(action, str):
action = action.lower()
if (name in NAVIGATION_KEYS or name == "escape") and action in ("tap", "click", "hold"):
seconds = CLICK_SECONDS
if action == "hold":
seconds = action_seconds(payload, "seconds", 1)
elif payload["kind"] == "key":
seconds = action_seconds(payload, "hold_seconds", CLICK_SECONDS)
settle = action_seconds(payload, "settle_seconds", 0.3, minimum=0)
qcodes = keyboard_code(self.spec, board_controls(self.spec), name)
return {"kind": payload["kind"], "op": "key-edges", "target": "keyboard",
"names": [name], "qcodes": qcodes, "action": action,
"seconds": seconds, "settle_seconds": settle}
if isinstance(payload, dict) and (
payload.get("kind") == "chord"
or (payload.get("kind") == "button" and payload.get("action") == "double_click")
Expand Down Expand Up @@ -11831,7 +11852,7 @@ def inject(self, payload):
409) from error
receipt = (
{key: value for key, value in command.items() if key not in {"op", "qcodes"}}
if command["kind"] == "chord" else command
if command["kind"] == "chord" or command["op"] == "key-edges" else command
)
presses = 2 if command["action"] == "double_click" else 1
timing = {"clock": "host", "completion": "events_sent",
Expand Down Expand Up @@ -11885,20 +11906,13 @@ def inject(self, payload):
return {**self.snapshot(), "input": command, "accepted": True}

def _inject_review_setup(self, step: dict) -> dict:
key = step.get("key")
nav = NAVIGATION_KEYS.get(key.lower()) if isinstance(key, str) else None
if (nav and step["kind"] in {"key", "keyboard"} and self.spec.id in {"cardputer", "cardputer-adv"}
and step.get("action", "tap") in {"tap", "click", "hold"}):
duration = step.get("seconds", 1) if step.get("action") == "hold" else 0.12
step = {"kind": "chord", "target": "keyboard", "keys": ["fn", nav],
"settle_seconds": step.get("settle_seconds", 0.3), "seconds": duration}
if step["kind"] != "chord":
return self.inject(step)
self._require_runtime_permission("input.write")
keys = step.get("keys")
if not isinstance(keys, list) or not 2 <= len(keys) <= 4:
raise ServiceError("invalid_input", "chord keys must be an array of 2 to 4 names", 400)
target = step.get("target", "keyboard" if self.spec.id in {"cardputer", "cardputer-adv"} else "button")
target = step.get("target", "keyboard" if self.spec.id in KEYBOARD_BOARDS else "button")
if target not in {"keyboard", "button"}:
raise ServiceError("invalid_input", "chord target must be button or keyboard", 400)
field = "key" if target == "keyboard" else "control"
Expand Down
6 changes: 4 additions & 2 deletions platform/tools/device_service_esp32sim.py
Original file line number Diff line number Diff line change
Expand Up @@ -543,8 +543,10 @@ def input_command(device, payload, *, board=None):
return "pmic-key", ("long" if action == "hold" else "short",), settle
if kind != "button" and device in {"cardputer", "cardputer-adv"}:
key = KEY_ALIASES.get(name, name)
if key in KEYS:
return "key", (key, hold), settle
if key not in KEYS:
raise ServiceError("not_supported_on_runtime",
f"Keyboard key {name!r} has no esp32sim mapping for {device}", 409)
return "key", (key, hold), settle
if kind == "imu":
accel = vector(payload, "accel", 32)
gyro = vector(payload, "gyro", 4000)
Expand Down
6 changes: 5 additions & 1 deletion platform/tools/device_service_input.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,11 @@ def keyboard_code(spec, controls, key, *, in_chord=False):
if key in NAVIGATION_KEYS and spec.id in KEYBOARD_BOARDS:
if in_chord:
raise ServiceError("invalid_input", "chords require physical keys; use Fn with the physical key", 400)
return [fn, NAVIGATION_KEYS[key]]
nav = NAVIGATION_KEYS[key]
keyboard = controls.get("keyboard", ())
if fn not in keyboard or nav not in keyboard:
raise unavailable(f"keyboard navigation key {key} has no physical mapping on this board")
return [fn, nav]
if key not in controls.get("keyboard", ()):
raise unavailable(f"keyboard key {key} has no model input on this board")
return [key]
Expand Down
4 changes: 2 additions & 2 deletions scripts/esp32sim-runtime.lock.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"repository": "https://github.com/m5agent/esp32sim.git",
"ref": "refs/tags/m5-milestone-papers3-fastepd-20261201",
"commit": "aafa4dfa7da9e36e9deacdbf2683b47d7d4588c9",
"ref": "refs/tags/m5-milestone-fastepd-clippy-20261202",
"commit": "a62c8769c144a402da672682bc4400e95988332b",
"roms": {
"esp32s3_rev0_rom.elf": "c0ce0f338d1de1bdc6efbef1591779a2a42c1ab7d759d3c6ae8ae63a7dd34cfd",
"esp32p4_rev0_rom.elf": "948f2c7d108d04a9c3a982f9c1c498fb17f2c4a68abc51f87782592034d7ce44",
Expand Down
Loading