magichid 0.1.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (125) hide show
  1. magichid-0.1.0/.github/workflows/ci.yml +21 -0
  2. magichid-0.1.0/.gitignore +219 -0
  3. magichid-0.1.0/.python-version +1 -0
  4. magichid-0.1.0/LICENSE +21 -0
  5. magichid-0.1.0/PKG-INFO +105 -0
  6. magichid-0.1.0/README.md +60 -0
  7. magichid-0.1.0/README_ja.md +62 -0
  8. magichid-0.1.0/examples/_horipad.py +52 -0
  9. magichid-0.1.0/examples/_keyboard.py +68 -0
  10. magichid-0.1.0/examples/hello_keyboard.py +66 -0
  11. magichid-0.1.0/hut1_7.ocr.md +10259 -0
  12. magichid-0.1.0/pyproject.toml +47 -0
  13. magichid-0.1.0/spec/PROTOCOL.md +189 -0
  14. magichid-0.1.0/spec/horipad.md +95 -0
  15. magichid-0.1.0/spec/mh_protocol.h +115 -0
  16. magichid-0.1.0/spec/protocol.yaml +86 -0
  17. magichid-0.1.0/spec/protocol_vectors.txt +12 -0
  18. magichid-0.1.0/spec/reports.json +336 -0
  19. magichid-0.1.0/spec/universal_reports.yaml +1834 -0
  20. magichid-0.1.0/src/cli/__init__.py +5 -0
  21. magichid-0.1.0/src/cli/__main__.py +5 -0
  22. magichid-0.1.0/src/cli/_common.py +35 -0
  23. magichid-0.1.0/src/cli/_context.py +255 -0
  24. magichid-0.1.0/src/cli/_digitizer.py +58 -0
  25. magichid-0.1.0/src/cli/_horipad.py +91 -0
  26. magichid-0.1.0/src/cli/_keyboard.py +70 -0
  27. magichid-0.1.0/src/cli/_mouse.py +77 -0
  28. magichid-0.1.0/src/cli/_soc.py +54 -0
  29. magichid-0.1.0/src/cli/_unicode.py +22 -0
  30. magichid-0.1.0/src/cli/main.py +131 -0
  31. magichid-0.1.0/src/core/__init__.py +7 -0
  32. magichid-0.1.0/src/core/codec.py +91 -0
  33. magichid-0.1.0/src/core/connection.py +168 -0
  34. magichid-0.1.0/src/core/events.py +112 -0
  35. magichid-0.1.0/src/core/io/__init__.py +11 -0
  36. magichid-0.1.0/src/core/io/blocking.py +189 -0
  37. magichid-0.1.0/src/core/reports.json +336 -0
  38. magichid-0.1.0/src/core/reports.py +150 -0
  39. magichid-0.1.0/src/core/wire.py +63 -0
  40. magichid-0.1.0/src/hid/__init__.py +85 -0
  41. magichid-0.1.0/src/hid/_client.py +21 -0
  42. magichid-0.1.0/src/hid/_tables/__init__.py +0 -0
  43. magichid-0.1.0/src/hid/_tables/keycode.py +275 -0
  44. magichid-0.1.0/src/hid/horipad/__init__.py +9 -0
  45. magichid-0.1.0/src/hid/horipad/controller.py +361 -0
  46. magichid-0.1.0/src/hid/universal/__init__.py +72 -0
  47. magichid-0.1.0/src/hid/universal/arcade.py +106 -0
  48. magichid-0.1.0/src/hid/universal/aux_display.py +97 -0
  49. magichid-0.1.0/src/hid/universal/barcode_scanner.py +119 -0
  50. magichid-0.1.0/src/hid/universal/battery_system.py +135 -0
  51. magichid-0.1.0/src/hid/universal/braille.py +112 -0
  52. magichid-0.1.0/src/hid/universal/button_panel.py +110 -0
  53. magichid-0.1.0/src/hid/universal/camera_control.py +49 -0
  54. magichid-0.1.0/src/hid/universal/consumer_control.py +145 -0
  55. magichid-0.1.0/src/hid/universal/digitizer.py +158 -0
  56. magichid-0.1.0/src/hid/universal/eye_tracker.py +76 -0
  57. magichid-0.1.0/src/hid/universal/fido.py +80 -0
  58. magichid-0.1.0/src/hid/universal/gamepad.py +87 -0
  59. magichid-0.1.0/src/hid/universal/gaming_device.py +66 -0
  60. magichid-0.1.0/src/hid/universal/generic_device.py +100 -0
  61. magichid-0.1.0/src/hid/universal/haptics.py +108 -0
  62. magichid-0.1.0/src/hid/universal/keyboard.py +308 -0
  63. magichid-0.1.0/src/hid/universal/led.py +104 -0
  64. magichid-0.1.0/src/hid/universal/lighting.py +122 -0
  65. magichid-0.1.0/src/hid/universal/medical.py +114 -0
  66. magichid-0.1.0/src/hid/universal/monitor.py +72 -0
  67. magichid-0.1.0/src/hid/universal/monitor_enum.py +46 -0
  68. magichid-0.1.0/src/hid/universal/mouse.py +156 -0
  69. magichid-0.1.0/src/hid/universal/msr.py +76 -0
  70. magichid-0.1.0/src/hid/universal/ordinal.py +78 -0
  71. magichid-0.1.0/src/hid/universal/pid.py +83 -0
  72. magichid-0.1.0/src/hid/universal/power_device.py +138 -0
  73. magichid-0.1.0/src/hid/universal/scale.py +116 -0
  74. magichid-0.1.0/src/hid/universal/sensor.py +116 -0
  75. magichid-0.1.0/src/hid/universal/simulation.py +114 -0
  76. magichid-0.1.0/src/hid/universal/soc_control.py +70 -0
  77. magichid-0.1.0/src/hid/universal/sport.py +91 -0
  78. magichid-0.1.0/src/hid/universal/telephony.py +166 -0
  79. magichid-0.1.0/src/hid/universal/unicode_input.py +64 -0
  80. magichid-0.1.0/src/hid/universal/vesa_vc.py +137 -0
  81. magichid-0.1.0/src/hid/universal/vr_controls.py +109 -0
  82. magichid-0.1.0/tests/__init__.py +0 -0
  83. magichid-0.1.0/tests/fake_device.py +88 -0
  84. magichid-0.1.0/tests/protocol_vectors.txt +12 -0
  85. magichid-0.1.0/tests/test_arcade.py +109 -0
  86. magichid-0.1.0/tests/test_aux_display.py +123 -0
  87. magichid-0.1.0/tests/test_barcode_scanner.py +130 -0
  88. magichid-0.1.0/tests/test_battery_system.py +32 -0
  89. magichid-0.1.0/tests/test_braille.py +100 -0
  90. magichid-0.1.0/tests/test_button_panel.py +169 -0
  91. magichid-0.1.0/tests/test_camera_control.py +63 -0
  92. magichid-0.1.0/tests/test_connection.py +168 -0
  93. magichid-0.1.0/tests/test_consumer_control.py +142 -0
  94. magichid-0.1.0/tests/test_digitizer.py +134 -0
  95. magichid-0.1.0/tests/test_eye_tracker.py +28 -0
  96. magichid-0.1.0/tests/test_fido.py +134 -0
  97. magichid-0.1.0/tests/test_gamepad.py +94 -0
  98. magichid-0.1.0/tests/test_gaming_device.py +112 -0
  99. magichid-0.1.0/tests/test_generic_device.py +31 -0
  100. magichid-0.1.0/tests/test_haptics.py +89 -0
  101. magichid-0.1.0/tests/test_horipad.py +522 -0
  102. magichid-0.1.0/tests/test_io.py +95 -0
  103. magichid-0.1.0/tests/test_keyboard.py +60 -0
  104. magichid-0.1.0/tests/test_keyboard_hid.py +303 -0
  105. magichid-0.1.0/tests/test_led.py +60 -0
  106. magichid-0.1.0/tests/test_lighting.py +78 -0
  107. magichid-0.1.0/tests/test_medical.py +74 -0
  108. magichid-0.1.0/tests/test_monitor.py +108 -0
  109. magichid-0.1.0/tests/test_monitor_enum.py +30 -0
  110. magichid-0.1.0/tests/test_mouse.py +223 -0
  111. magichid-0.1.0/tests/test_msr.py +92 -0
  112. magichid-0.1.0/tests/test_ordinal.py +66 -0
  113. magichid-0.1.0/tests/test_pid.py +68 -0
  114. magichid-0.1.0/tests/test_power_device.py +109 -0
  115. magichid-0.1.0/tests/test_reports.py +76 -0
  116. magichid-0.1.0/tests/test_scale.py +75 -0
  117. magichid-0.1.0/tests/test_sensor.py +81 -0
  118. magichid-0.1.0/tests/test_simulation.py +86 -0
  119. magichid-0.1.0/tests/test_soc_control.py +77 -0
  120. magichid-0.1.0/tests/test_sport.py +76 -0
  121. magichid-0.1.0/tests/test_telephony.py +136 -0
  122. magichid-0.1.0/tests/test_unicode_input.py +144 -0
  123. magichid-0.1.0/tests/test_vectors.py +99 -0
  124. magichid-0.1.0/tests/test_vesa_vc.py +114 -0
  125. magichid-0.1.0/tests/test_vr_controls.py +83 -0
@@ -0,0 +1,21 @@
1
+ name: CI
2
+
3
+ on:
4
+ push:
5
+ branches: [main]
6
+ pull_request:
7
+
8
+ jobs:
9
+ test:
10
+ runs-on: ubuntu-latest
11
+ strategy:
12
+ fail-fast: false
13
+ matrix:
14
+ python-version: ["3.10", "3.11", "3.12", "3.13"]
15
+ steps:
16
+ - uses: actions/checkout@v4
17
+ - uses: actions/setup-python@v5
18
+ with:
19
+ python-version: ${{ matrix.python-version }}
20
+ - run: pip install -e ".[dev]"
21
+ - run: pytest -ra
@@ -0,0 +1,219 @@
1
+ # Byte-compiled / optimized / DLL files
2
+ __pycache__/
3
+ *.py[codz]
4
+ *$py.class
5
+
6
+ # C extensions
7
+ *.so
8
+
9
+ # Distribution / packaging
10
+ .Python
11
+ build/
12
+ develop-eggs/
13
+ dist/
14
+ downloads/
15
+ eggs/
16
+ .eggs/
17
+ lib/
18
+ lib64/
19
+ parts/
20
+ sdist/
21
+ var/
22
+ wheels/
23
+ share/python-wheels/
24
+ *.egg-info/
25
+ .installed.cfg
26
+ *.egg
27
+ MANIFEST
28
+
29
+ # PyInstaller
30
+ # Usually these files are written by a python script from a template
31
+ # before PyInstaller builds the exe, so as to inject date/other infos into it.
32
+ *.manifest
33
+ *.spec
34
+
35
+ # Installer logs
36
+ pip-log.txt
37
+ pip-delete-this-directory.txt
38
+
39
+ # Unit test / coverage reports
40
+ htmlcov/
41
+ .tox/
42
+ .nox/
43
+ .coverage
44
+ .coverage.*
45
+ .cache
46
+ nosetests.xml
47
+ coverage.xml
48
+ *.cover
49
+ *.py.cover
50
+ .hypothesis/
51
+ .pytest_cache/
52
+ cover/
53
+
54
+ # Translations
55
+ *.mo
56
+ *.pot
57
+
58
+ # Django stuff:
59
+ *.log
60
+ local_settings.py
61
+ db.sqlite3
62
+ db.sqlite3-journal
63
+
64
+ # Flask stuff:
65
+ instance/
66
+ .webassets-cache
67
+
68
+ # Scrapy stuff:
69
+ .scrapy
70
+
71
+ # Sphinx documentation
72
+ docs/_build/
73
+
74
+ # PyBuilder
75
+ .pybuilder/
76
+ target/
77
+
78
+ # Jupyter Notebook
79
+ .ipynb_checkpoints
80
+
81
+ # IPython
82
+ profile_default/
83
+ ipython_config.py
84
+
85
+ # pyenv
86
+ # For a library or package, you might want to ignore these files since the code is
87
+ # intended to run in multiple environments; otherwise, check them in:
88
+ # .python-version
89
+
90
+ # pipenv
91
+ # According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
92
+ # However, in case of collaboration, if having platform-specific dependencies or dependencies
93
+ # having no cross-platform support, pipenv may install dependencies that don't work, or not
94
+ # install all needed dependencies.
95
+ # Pipfile.lock
96
+
97
+ # UV
98
+ # Similar to Pipfile.lock, it is generally recommended to include uv.lock in version control.
99
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
100
+ # commonly ignored for libraries.
101
+ # uv.lock
102
+
103
+ # poetry
104
+ # Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
105
+ # This is especially recommended for binary packages to ensure reproducibility, and is more
106
+ # commonly ignored for libraries.
107
+ # https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
108
+ # poetry.lock
109
+ # poetry.toml
110
+
111
+ # pdm
112
+ # Similar to Pipfile.lock, it is generally recommended to include pdm.lock in version control.
113
+ # pdm recommends including project-wide configuration in pdm.toml, but excluding .pdm-python.
114
+ # https://pdm-project.org/en/latest/usage/project/#working-with-version-control
115
+ # pdm.lock
116
+ # pdm.toml
117
+ .pdm-python
118
+ .pdm-build/
119
+
120
+ # pixi
121
+ # Similar to Pipfile.lock, it is generally recommended to include pixi.lock in version control.
122
+ # pixi.lock
123
+ # Pixi creates a virtual environment in the .pixi directory, just like venv module creates one
124
+ # in the .venv directory. It is recommended not to include this directory in version control.
125
+ .pixi
126
+
127
+ # PEP 582; used by e.g. github.com/David-OConnor/pyflow and github.com/pdm-project/pdm
128
+ __pypackages__/
129
+
130
+ # Celery stuff
131
+ celerybeat-schedule
132
+ celerybeat.pid
133
+
134
+ # Redis
135
+ *.rdb
136
+ *.aof
137
+ *.pid
138
+
139
+ # RabbitMQ
140
+ mnesia/
141
+ rabbitmq/
142
+ rabbitmq-data/
143
+
144
+ # ActiveMQ
145
+ activemq-data/
146
+
147
+ # SageMath parsed files
148
+ *.sage.py
149
+
150
+ # Environments
151
+ .env
152
+ .envrc
153
+ .venv
154
+ env/
155
+ venv/
156
+ ENV/
157
+ env.bak/
158
+ venv.bak/
159
+
160
+ # Spyder project settings
161
+ .spyderproject
162
+ .spyproject
163
+
164
+ # Rope project settings
165
+ .ropeproject
166
+
167
+ # mkdocs documentation
168
+ /site
169
+
170
+ # mypy
171
+ .mypy_cache/
172
+ .dmypy.json
173
+ dmypy.json
174
+
175
+ # Pyre type checker
176
+ .pyre/
177
+
178
+ # pytype static type analyzer
179
+ .pytype/
180
+
181
+ # Cython debug symbols
182
+ cython_debug/
183
+
184
+ # PyCharm
185
+ # JetBrains specific template is maintained in a separate JetBrains.gitignore that can
186
+ # be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
187
+ # and can be added to the global gitignore or merged into this file. For a more nuclear
188
+ # option (not recommended) you can uncomment the following to ignore the entire idea folder.
189
+ # .idea/
190
+
191
+ # Abstra
192
+ # Abstra is an AI-powered process automation framework.
193
+ # Ignore directories containing user credentials, local state, and settings.
194
+ # Learn more at https://abstra.io/docs
195
+ .abstra/
196
+
197
+ # Visual Studio Code
198
+ # Visual Studio Code specific template is maintained in a separate VisualStudioCode.gitignore
199
+ # that can be found at https://github.com/github/gitignore/blob/main/Global/VisualStudioCode.gitignore
200
+ # and can be added to the global gitignore or merged into this file. However, if you prefer,
201
+ # you could uncomment the following to ignore the entire vscode folder
202
+ # .vscode/
203
+ # Temporary file for partial code execution
204
+ tempCodeRunnerFile.py
205
+
206
+ # Ruff stuff:
207
+ .ruff_cache/
208
+
209
+ # PyPI configuration file
210
+ .pypirc
211
+
212
+ # Marimo
213
+ marimo/_static/
214
+ marimo/_lsp/
215
+ __marimo__/
216
+
217
+ # Streamlit
218
+ .streamlit/secrets.toml
219
+
@@ -0,0 +1 @@
1
+ 3.13
magichid-0.1.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 YoseiUshida
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,105 @@
1
+ Metadata-Version: 2.4
2
+ Name: magichid
3
+ Version: 0.1.0
4
+ Summary: Python client for the MagicHID transparent USB-HID bridge
5
+ Project-URL: Homepage, https://github.com/youseiushida/magichid
6
+ Project-URL: Repository, https://github.com/youseiushida/magichid
7
+ License: MIT License
8
+
9
+ Copyright (c) 2026 YoseiUshida
10
+
11
+ Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ of this software and associated documentation files (the "Software"), to deal
13
+ in the Software without restriction, including without limitation the rights
14
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
+ copies of the Software, and to permit persons to whom the Software is
16
+ furnished to do so, subject to the following conditions:
17
+
18
+ The above copyright notice and this permission notice shall be included in all
19
+ copies or substantial portions of the Software.
20
+
21
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
+ SOFTWARE.
28
+ License-File: LICENSE
29
+ Classifier: Development Status :: 3 - Alpha
30
+ Classifier: Intended Audience :: Developers
31
+ Classifier: License :: OSI Approved :: MIT License
32
+ Classifier: Operating System :: OS Independent
33
+ Classifier: Programming Language :: Python :: 3
34
+ Classifier: Programming Language :: Python :: 3.10
35
+ Classifier: Programming Language :: Python :: 3.11
36
+ Classifier: Programming Language :: Python :: 3.12
37
+ Classifier: Programming Language :: Python :: 3.13
38
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
39
+ Classifier: Topic :: System :: Hardware
40
+ Requires-Python: >=3.10
41
+ Requires-Dist: pyserial>=3.5
42
+ Provides-Extra: dev
43
+ Requires-Dist: pytest>=8; extra == 'dev'
44
+ Description-Content-Type: text/markdown
45
+
46
+ # magichid
47
+
48
+ Python client for the [MagicHID](https://github.com/youseiushida/magichid).
49
+
50
+ ## Install
51
+
52
+ ```
53
+ pip install magichid
54
+ ```
55
+
56
+ ## Quickstart -- high-level API
57
+
58
+ ```python
59
+ from core.io.blocking import BlockingClient
60
+ from core.reports import ReportTable
61
+ from hid import Keyboard, Keycode, Mouse, MouseButton, Digitizer
62
+
63
+ with BlockingClient("COM5") as c:
64
+ c.handshake()
65
+
66
+ # Keyboard
67
+ kb = Keyboard(c, ReportTable.universal())
68
+ kb.tap(Keycode.A)
69
+ kb.type_text("Hello world")
70
+
71
+ # Mouse
72
+ mouse = Mouse(c, ReportTable.universal())
73
+ mouse.move(x=10, y=-5)
74
+ mouse.click(MouseButton.LEFT)
75
+
76
+ # Touch digitizer
77
+ dig = Digitizer(c, ReportTable.universal())
78
+ dig.down(x=0.5, y=0.5)
79
+ dig.move(x=0.6, y=0.5)
80
+ dig.up()
81
+ ```
82
+
83
+ 35 device classes in `hid.universal`: keyboard, mouse, gamepad, flight sim, VR headset,
84
+ golf club, consumer control, digitizer, haptics, force feedback, unicode input, eye tracker,
85
+ accelerometer, medical ultrasound, braille display, lamp array, monitor, UPS, battery,
86
+ barcode scanner, scale, MSR, camera, arcade I/O, gaming device, FIDO authenticator, and more.
87
+
88
+ Horipad (Nintendo Switch, profile 1) in `hid.horipad`.
89
+
90
+ ## Quickstart -- CLI
91
+
92
+ ```
93
+ magichid --port COM5 keyboard type --text "Hello world"
94
+ magichid --port COM5 mouse move --x 10 --y -5 --json
95
+ magichid --port COM5 digitizer down --x 0.5 --y 0.5
96
+ magichid --port COM5 unicode type --text "Hello (U+1F389)"
97
+ magichid --port COM5 horipad press --button A --json
98
+ magichid --port COM5 soc firmware-chunk --firmware-id 1 --offset 0 --payload-file chunk.bin
99
+
100
+ # Agent introspection
101
+ magichid agent-context | jq .commands.mouse.actions
102
+ ```
103
+
104
+ The CLI is non-interactive by default. `--json` emits structured stdout. Errors go to stderr
105
+ with enumerated valid values. `agent-context` provides a versioned machine-readable schema.
@@ -0,0 +1,60 @@
1
+ # magichid
2
+
3
+ Python client for the [MagicHID](https://github.com/youseiushida/magichid).
4
+
5
+ ## Install
6
+
7
+ ```
8
+ pip install magichid
9
+ ```
10
+
11
+ ## Quickstart -- high-level API
12
+
13
+ ```python
14
+ from core.io.blocking import BlockingClient
15
+ from core.reports import ReportTable
16
+ from hid import Keyboard, Keycode, Mouse, MouseButton, Digitizer
17
+
18
+ with BlockingClient("COM5") as c:
19
+ c.handshake()
20
+
21
+ # Keyboard
22
+ kb = Keyboard(c, ReportTable.universal())
23
+ kb.tap(Keycode.A)
24
+ kb.type_text("Hello world")
25
+
26
+ # Mouse
27
+ mouse = Mouse(c, ReportTable.universal())
28
+ mouse.move(x=10, y=-5)
29
+ mouse.click(MouseButton.LEFT)
30
+
31
+ # Touch digitizer
32
+ dig = Digitizer(c, ReportTable.universal())
33
+ dig.down(x=0.5, y=0.5)
34
+ dig.move(x=0.6, y=0.5)
35
+ dig.up()
36
+ ```
37
+
38
+ 35 device classes in `hid.universal`: keyboard, mouse, gamepad, flight sim, VR headset,
39
+ golf club, consumer control, digitizer, haptics, force feedback, unicode input, eye tracker,
40
+ accelerometer, medical ultrasound, braille display, lamp array, monitor, UPS, battery,
41
+ barcode scanner, scale, MSR, camera, arcade I/O, gaming device, FIDO authenticator, and more.
42
+
43
+ Horipad (Nintendo Switch, profile 1) in `hid.horipad`.
44
+
45
+ ## Quickstart -- CLI
46
+
47
+ ```
48
+ magichid --port COM5 keyboard type --text "Hello world"
49
+ magichid --port COM5 mouse move --x 10 --y -5 --json
50
+ magichid --port COM5 digitizer down --x 0.5 --y 0.5
51
+ magichid --port COM5 unicode type --text "Hello (U+1F389)"
52
+ magichid --port COM5 horipad press --button A --json
53
+ magichid --port COM5 soc firmware-chunk --firmware-id 1 --offset 0 --payload-file chunk.bin
54
+
55
+ # Agent introspection
56
+ magichid agent-context | jq .commands.mouse.actions
57
+ ```
58
+
59
+ The CLI is non-interactive by default. `--json` emits structured stdout. Errors go to stderr
60
+ with enumerated valid values. `agent-context` provides a versioned machine-readable schema.
@@ -0,0 +1,62 @@
1
+ # magichid
2
+
3
+ [MagicHID](https://github.com/youseiushida/magichid) の Python クライアント。
4
+
5
+ ## インストール
6
+
7
+ ```
8
+ pip install magichid
9
+ ```
10
+
11
+ ## クイックスタート -- 高レベル API
12
+
13
+ ```python
14
+ from core.io.blocking import BlockingClient
15
+ from core.reports import ReportTable
16
+ from hid import Keyboard, Keycode, Mouse, MouseButton, Digitizer
17
+
18
+ with BlockingClient("COM5") as c:
19
+ c.handshake()
20
+
21
+ # キーボード
22
+ kb = Keyboard(c, ReportTable.universal())
23
+ kb.tap(Keycode.A)
24
+ kb.type_text("Hello world")
25
+
26
+ # マウス
27
+ mouse = Mouse(c, ReportTable.universal())
28
+ mouse.move(x=10, y=-5)
29
+ mouse.click(MouseButton.LEFT)
30
+
31
+ # タッチパネル
32
+ dig = Digitizer(c, ReportTable.universal())
33
+ dig.down(x=0.5, y=0.5)
34
+ dig.move(x=0.6, y=0.5)
35
+ dig.up()
36
+ ```
37
+
38
+ `hid.universal` には 35 のデバイスクラスがあります。キーボード、マウス、ゲームパッド、
39
+ フライトシム、VR ヘッドセット、ゴルフクラブ、コンシューマ制御、タッチパネル、ハプティクス、
40
+ フォースフィードバック、Unicode 入力、アイトラッカー、加速度センサー、医療用超音波、
41
+ 点字ディスプレイ、LampArray、モニター制御、UPS、バッテリー、バーコードスキャナ、
42
+ 秤、磁気ストライプリーダー、カメラ制御、アーケード I/O、ゲーミングデバイス、
43
+ FIDO 認証器など。
44
+
45
+ Horipad(Nintendo Switch、プロファイル 1)は `hid.horipad` にあります。
46
+
47
+ ## クイックスタート -- CLI
48
+
49
+ ```
50
+ magichid --port COM5 keyboard type --text "Hello world"
51
+ magichid --port COM5 mouse move --x 10 --y -5 --json
52
+ magichid --port COM5 digitizer down --x 0.5 --y 0.5
53
+ magichid --port COM5 unicode type --text "Hello (U+1F389)"
54
+ magichid --port COM5 horipad press --button A --json
55
+ magichid --port COM5 soc firmware-chunk --firmware-id 1 --offset 0 --payload-file chunk.bin
56
+
57
+ # エージェント向け自己記述
58
+ magichid agent-context | jq .commands.mouse.actions
59
+ ```
60
+
61
+ CLI はデフォルトで非対話です。`--json` で構造化出力。エラーは stderr に有効値一覧付きで
62
+ 出力されます。`agent-context` はバージョン付きの機械可読スキーマを提供します。
@@ -0,0 +1,52 @@
1
+ """Convenience builder for the HORIPAD (Nintendo Switch) profile.
2
+
3
+ This is an *example* — not part of the protocol core. The byte layout is the
4
+ contract in ``spec/horipad.md``; this module just encodes it as a Python
5
+ function. Use as-is, copy, or replace.
6
+ """
7
+
8
+ from __future__ import annotations
9
+
10
+ __all__ = [
11
+ "HORIPAD_NEUTRAL", "HORIPAD_BUTTONS", "HORIPAD_DPAD", "horipad_report",
12
+ ]
13
+
14
+ # Neutral: nothing pressed, sticks centered (0x80), hat centered (0x0F).
15
+ HORIPAD_NEUTRAL = bytes([0x00, 0x00, 0x0F, 0x80, 0x80, 0x80, 0x80, 0x00])
16
+
17
+ HORIPAD_BUTTONS = {
18
+ "Y": 0, "B": 1, "A": 2, "X": 3,
19
+ "L": 4, "R": 5, "ZL": 6, "ZR": 7,
20
+ "MINUS": 8, "PLUS": 9,
21
+ "LCLICK": 10, "RCLICK": 11,
22
+ "HOME": 12, "CAPTURE": 13,
23
+ }
24
+
25
+ HORIPAD_DPAD = {
26
+ "UP": 0, "UP_RIGHT": 1, "RIGHT": 2, "DOWN_RIGHT": 3,
27
+ "DOWN": 4, "DOWN_LEFT": 5, "LEFT": 6, "UP_LEFT": 7,
28
+ "CENTER": 0x0F,
29
+ }
30
+
31
+
32
+ def horipad_report(
33
+ buttons: tuple[str, ...] = (),
34
+ dpad: str = "CENTER",
35
+ lx: int = 0x80,
36
+ ly: int = 0x80,
37
+ rx: int = 0x80,
38
+ ry: int = 0x80,
39
+ vendor: int = 0x00,
40
+ ) -> bytes:
41
+ """Bare 8-byte HORIPAD controller state (full-state, no deltas)."""
42
+ bits = 0
43
+ for name in buttons:
44
+ bits |= 1 << HORIPAD_BUTTONS[name]
45
+ return bytes([
46
+ bits & 0xFF,
47
+ (bits >> 8) & 0xFF,
48
+ HORIPAD_DPAD[dpad] & 0x0F,
49
+ lx & 0xFF, ly & 0xFF,
50
+ rx & 0xFF, ry & 0xFF,
51
+ vendor & 0xFF,
52
+ ])
@@ -0,0 +1,68 @@
1
+ """Convenience builders for boot-keyboard and mouse HID reports.
2
+
3
+ These are *examples* of how to construct report payloads — they are not part
4
+ of the protocol core. Use them as-is, copy them, or replace them with your
5
+ own builders for other profiles. All they do is lay out bytes; the actual
6
+ rules (size, relative/reliable) are enforced by :class:`core.reports.ReportTable`.
7
+ """
8
+
9
+ from __future__ import annotations
10
+
11
+ __all__ = [
12
+ "KEY_MOD", "keyboard_report", "mouse_report", "char_to_keycode",
13
+ ]
14
+
15
+
16
+ class KEY_MOD:
17
+ """Keyboard modifier bitmask (HID boot-keyboard byte 0)."""
18
+
19
+ LCTRL = 0x01
20
+ LSHIFT = 0x02
21
+ LALT = 0x04
22
+ LGUI = 0x08
23
+ RCTRL = 0x10
24
+ RSHIFT = 0x20
25
+ RALT = 0x40
26
+ RGUI = 0x80
27
+
28
+
29
+ def keyboard_report(keys: bytes | tuple[int, ...] = (), modifier: int = 0) -> bytes:
30
+ """Boot-keyboard 8-byte INPUT: ``[modifier][reserved=0][k1..k6]``."""
31
+ kc = list(keys)
32
+ if len(kc) > 6:
33
+ raise ValueError("at most 6 simultaneous keycodes")
34
+ kc += [0] * (6 - len(kc))
35
+ return bytes([modifier & 0xFF, 0, *(k & 0xFF for k in kc)])
36
+
37
+
38
+ def mouse_report(buttons: int = 0, x: int = 0, y: int = 0,
39
+ wheel: int = 0, pan: int = 0) -> bytes:
40
+ """5-byte mouse INPUT: ``[buttons][x][y][wheel][pan]`` (signed int8 deltas)."""
41
+ return bytes([buttons & 0xFF, *((v & 0xFF) for v in (x, y, wheel, pan))])
42
+
43
+
44
+ def char_to_keycode(ch: str) -> tuple[int, int]:
45
+ """Single ASCII char -> ``(modifier, keycode)``.
46
+
47
+ Covers a-z, A-Z, 0-9 and a few common symbols — enough for demos.
48
+ US layout only; not a full IME.
49
+ """
50
+ if len(ch) != 1:
51
+ raise ValueError("exactly one character required")
52
+ o = ord(ch)
53
+ if "a" <= ch <= "z":
54
+ return 0, 0x04 + (o - 0x61)
55
+ if "A" <= ch <= "Z":
56
+ return KEY_MOD.LSHIFT, 0x04 + (o - 0x41)
57
+ if "1" <= ch <= "9":
58
+ return 0, 0x1E + (o - 0x31)
59
+ if ch == "0":
60
+ return 0, 0x27
61
+ m = {
62
+ " ": (0, 0x2C), "\n": (0, 0x28), "\t": (0, 0x2B),
63
+ "-": (0, 0x2D), "=": (0, 0x2E), ".": (0, 0x37),
64
+ ",": (0, 0x36), "/": (0, 0x38), ";": (0, 0x33),
65
+ }
66
+ if ch in m:
67
+ return m[ch]
68
+ raise KeyError(f"no keycode for {ch!r}")
@@ -0,0 +1,66 @@
1
+ """Minimal end-to-end demo: type one character through the MagicHID bridge.
2
+
3
+ Flow (spec/PROTOCOL.md §6 recommended session)::
4
+
5
+ open serial (1 Mbps) -> PING -> wait STATUS(MOUNTED|READY)
6
+ -> SEND_REPORT(KEYBOARD, [mod, 0, key, 0,0,0,0,0]) # press
7
+ -> brief hold -> release the key
8
+ -> RELEASE_ALL (automatic on context exit)
9
+
10
+ Usage::
11
+
12
+ python examples/hello_keyboard.py --port COM5 # Windows
13
+ python examples/hello_keyboard.py --port /dev/ttyUSB0 # Linux/macOS
14
+ """
15
+
16
+ from __future__ import annotations
17
+
18
+ import argparse
19
+ import sys
20
+ import time
21
+ from pathlib import Path
22
+
23
+ _ROOT = str(Path(__file__).resolve().parent.parent)
24
+ sys.path.insert(0, _ROOT)
25
+ sys.path.insert(0, _ROOT + "/src")
26
+
27
+ from core.events import HostEventReceived # noqa: E402
28
+ from core.io.blocking import BlockingClient # noqa: E402
29
+ from core.reports import KEYBOARD # noqa: E402
30
+ from examples._keyboard import char_to_keycode, keyboard_report # noqa: E402
31
+
32
+
33
+ def main(argv: list[str] | None = None) -> int:
34
+ ap = argparse.ArgumentParser(description="Type one character via core.")
35
+ ap.add_argument("--port", required=True, help="serial port (e.g. COM5)")
36
+ ap.add_argument("--baud", type=int, default=1_000_000)
37
+ ap.add_argument("--char", default="a", help="character to type")
38
+ ap.add_argument("--hold", type=float, default=0.3, help="hold seconds")
39
+ ap.add_argument("--timeout", type=float, default=10.0, help="handshake timeout")
40
+ args = ap.parse_args(argv)
41
+
42
+ modifier, keycode = char_to_keycode(args.char)
43
+
44
+ with BlockingClient(args.port, baudrate=args.baud) as c:
45
+ print(f"handshaking on {args.port} ...")
46
+ s = c.handshake(timeout=args.timeout)
47
+ print(f"ready: flags={s.flags:#04x} proto_version={s.proto_version}")
48
+
49
+ caps = c.get_caps(timeout=2.0)
50
+ print(f"profile: {len(caps.entries)} reports")
51
+
52
+ print(f"typing {args.char!r} (keycode={keycode:#04x})")
53
+ c.request(0x01, bytes([KEYBOARD]) + keyboard_report([keycode], modifier=modifier))
54
+ time.sleep(args.hold)
55
+ c.request(0x01, bytes([KEYBOARD]) + keyboard_report([]))
56
+
57
+ for e in c.drain_events():
58
+ if isinstance(e, HostEventReceived):
59
+ print(f"[host-event] id={e.report_id} type={e.type_name} data={e.data.hex()}")
60
+
61
+ print("done.")
62
+ return 0
63
+
64
+
65
+ if __name__ == "__main__":
66
+ raise SystemExit(main())