airhand 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.
- airhand-0.1.0/.gitignore +12 -0
- airhand-0.1.0/LICENSE +202 -0
- airhand-0.1.0/PKG-INFO +159 -0
- airhand-0.1.0/README.md +137 -0
- airhand-0.1.0/docs/protocol.md +66 -0
- airhand-0.1.0/firmware/CMakeLists.txt +7 -0
- airhand-0.1.0/firmware/prj.conf +52 -0
- airhand-0.1.0/firmware/src/main.c +342 -0
- airhand-0.1.0/firmware/src/proto.c +747 -0
- airhand-0.1.0/firmware/src/proto.h +38 -0
- airhand-0.1.0/firmware/tests/fake_radio.c +95 -0
- airhand-0.1.0/pyproject.toml +48 -0
- airhand-0.1.0/src/airhand/__init__.py +33 -0
- airhand-0.1.0/src/airhand/_dongle.py +373 -0
- airhand-0.1.0/src/airhand/py.typed +0 -0
- airhand-0.1.0/src/airhand/testing.py +117 -0
- airhand-0.1.0/tests/conftest.py +37 -0
- airhand-0.1.0/tests/test_dongle.py +111 -0
- airhand-0.1.0/tests/test_firmware.py +186 -0
airhand-0.1.0/.gitignore
ADDED
airhand-0.1.0/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
1
|
+
|
|
2
|
+
Apache License
|
|
3
|
+
Version 2.0, January 2004
|
|
4
|
+
http://www.apache.org/licenses/
|
|
5
|
+
|
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
7
|
+
|
|
8
|
+
1. Definitions.
|
|
9
|
+
|
|
10
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
11
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
12
|
+
|
|
13
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
14
|
+
the copyright owner that is granting the License.
|
|
15
|
+
|
|
16
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
17
|
+
other entities that control, are controlled by, or are under common
|
|
18
|
+
control with that entity. For the purposes of this definition,
|
|
19
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
20
|
+
direction or management of such entity, whether by contract or
|
|
21
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
22
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
23
|
+
|
|
24
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
25
|
+
exercising permissions granted by this License.
|
|
26
|
+
|
|
27
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
28
|
+
including but not limited to software source code, documentation
|
|
29
|
+
source, and configuration files.
|
|
30
|
+
|
|
31
|
+
"Object" form shall mean any form resulting from mechanical
|
|
32
|
+
transformation or translation of a Source form, including but
|
|
33
|
+
not limited to compiled object code, generated documentation,
|
|
34
|
+
and conversions to other media types.
|
|
35
|
+
|
|
36
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
37
|
+
Object form, made available under the License, as indicated by a
|
|
38
|
+
copyright notice that is included in or attached to the work
|
|
39
|
+
(an example is provided in the Appendix below).
|
|
40
|
+
|
|
41
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
42
|
+
form, that is based on (or derived from) the Work and for which the
|
|
43
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
44
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
45
|
+
of this License, Derivative Works shall not include works that remain
|
|
46
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
47
|
+
the Work and Derivative Works thereof.
|
|
48
|
+
|
|
49
|
+
"Contribution" shall mean any work of authorship, including
|
|
50
|
+
the original version of the Work and any modifications or additions
|
|
51
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
52
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
53
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
54
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
55
|
+
means any form of electronic, verbal, or written communication sent
|
|
56
|
+
to the Licensor or its representatives, including but not limited to
|
|
57
|
+
communication on electronic mailing lists, source code control systems,
|
|
58
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
59
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
60
|
+
excluding communication that is conspicuously marked or otherwise
|
|
61
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
62
|
+
|
|
63
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
64
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
65
|
+
subsequently incorporated within the Work.
|
|
66
|
+
|
|
67
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
68
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
69
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
70
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
71
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
72
|
+
Work and such Derivative Works in Source or Object form.
|
|
73
|
+
|
|
74
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
(except as stated in this section) patent license to make, have made,
|
|
78
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
79
|
+
where such license applies only to those patent claims licensable
|
|
80
|
+
by such Contributor that are necessarily infringed by their
|
|
81
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
82
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
83
|
+
institute patent litigation against any entity (including a
|
|
84
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
85
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
86
|
+
or contributory patent infringement, then any patent licenses
|
|
87
|
+
granted to You under this License for that Work shall terminate
|
|
88
|
+
as of the date such litigation is filed.
|
|
89
|
+
|
|
90
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
91
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
92
|
+
modifications, and in Source or Object form, provided that You
|
|
93
|
+
meet the following conditions:
|
|
94
|
+
|
|
95
|
+
(a) You must give any other recipients of the Work or
|
|
96
|
+
Derivative Works a copy of this License; and
|
|
97
|
+
|
|
98
|
+
(b) You must cause any modified files to carry prominent notices
|
|
99
|
+
stating that You changed the files; and
|
|
100
|
+
|
|
101
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
102
|
+
that You distribute, all copyright, patent, trademark, and
|
|
103
|
+
attribution notices from the Source form of the Work,
|
|
104
|
+
excluding those notices that do not pertain to any part of
|
|
105
|
+
the Derivative Works; and
|
|
106
|
+
|
|
107
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
108
|
+
distribution, then any Derivative Works that You distribute must
|
|
109
|
+
include a readable copy of the attribution notices contained
|
|
110
|
+
within such NOTICE file, excluding those notices that do not
|
|
111
|
+
pertain to any part of the Derivative Works, in at least one
|
|
112
|
+
of the following places: within a NOTICE text file distributed
|
|
113
|
+
as part of the Derivative Works; within the Source form or
|
|
114
|
+
documentation, if provided along with the Derivative Works; or,
|
|
115
|
+
within a display generated by the Derivative Works, if and
|
|
116
|
+
wherever such third-party notices normally appear. The contents
|
|
117
|
+
of the NOTICE file are for informational purposes only and
|
|
118
|
+
do not modify the License. You may add Your own attribution
|
|
119
|
+
notices within Derivative Works that You distribute, alongside
|
|
120
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
121
|
+
that such additional attribution notices cannot be construed
|
|
122
|
+
as modifying the License.
|
|
123
|
+
|
|
124
|
+
You may add Your own copyright statement to Your modifications and
|
|
125
|
+
may provide additional or different license terms and conditions
|
|
126
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
127
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
128
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
129
|
+
the conditions stated in this License.
|
|
130
|
+
|
|
131
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
132
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
133
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
134
|
+
this License, without any additional terms or conditions.
|
|
135
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
136
|
+
the terms of any separate license agreement you may have executed
|
|
137
|
+
with Licensor regarding such Contributions.
|
|
138
|
+
|
|
139
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
140
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
141
|
+
except as required for reasonable and customary use in describing the
|
|
142
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
143
|
+
|
|
144
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
145
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
146
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
147
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
148
|
+
implied, including, without limitation, any warranties or conditions
|
|
149
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
150
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
151
|
+
appropriateness of using or redistributing the Work and assume any
|
|
152
|
+
risks associated with Your exercise of permissions under this License.
|
|
153
|
+
|
|
154
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
155
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
156
|
+
unless required by applicable law (such as deliberate and grossly
|
|
157
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
158
|
+
liable to You for damages, including any direct, indirect, special,
|
|
159
|
+
incidental, or consequential damages of any character arising as a
|
|
160
|
+
result of this License or out of the use or inability to use the
|
|
161
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
162
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
163
|
+
other commercial damages or losses), even if such Contributor
|
|
164
|
+
has been advised of the possibility of such damages.
|
|
165
|
+
|
|
166
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
167
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
168
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
169
|
+
or other liability obligations and/or rights consistent with this
|
|
170
|
+
License. However, in accepting such obligations, You may act only
|
|
171
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
172
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
173
|
+
defend, and hold each Contributor harmless for any liability
|
|
174
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
175
|
+
of your accepting any such warranty or additional liability.
|
|
176
|
+
|
|
177
|
+
END OF TERMS AND CONDITIONS
|
|
178
|
+
|
|
179
|
+
APPENDIX: How to apply the Apache License to your work.
|
|
180
|
+
|
|
181
|
+
To apply the Apache License to your work, attach the following
|
|
182
|
+
boilerplate notice, with the fields enclosed by brackets "[]"
|
|
183
|
+
replaced with your own identifying information. (Don't include
|
|
184
|
+
the brackets!) The text should be enclosed in the appropriate
|
|
185
|
+
comment syntax for the file format. We also recommend that a
|
|
186
|
+
file or class name and description of purpose be included on the
|
|
187
|
+
same "printed page" as the copyright notice for easier
|
|
188
|
+
identification within third-party archives.
|
|
189
|
+
|
|
190
|
+
Copyright [yyyy] [name of copyright owner]
|
|
191
|
+
|
|
192
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
193
|
+
you may not use this file except in compliance with the License.
|
|
194
|
+
You may obtain a copy of the License at
|
|
195
|
+
|
|
196
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
197
|
+
|
|
198
|
+
Unless required by applicable law or agreed to in writing, software
|
|
199
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
200
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
201
|
+
See the License for the specific language governing permissions and
|
|
202
|
+
limitations under the License.
|
airhand-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
Metadata-Version: 2.5
|
|
2
|
+
Name: airhand
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Drive any device that accepts a Bluetooth keyboard and mouse from Python, through an nRF52840 dongle.
|
|
5
|
+
Project-URL: Homepage, https://github.com/chinmayajha/airhand
|
|
6
|
+
Project-URL: Issues, https://github.com/chinmayajha/airhand/issues
|
|
7
|
+
Author: Chinmay Jha
|
|
8
|
+
License-Expression: Apache-2.0
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Keywords: automation,ble,bluetooth,hid,keyboard,mouse,nrf52840,testing
|
|
11
|
+
Classifier: Development Status :: 4 - Beta
|
|
12
|
+
Classifier: Intended Audience :: Developers
|
|
13
|
+
Classifier: Operating System :: MacOS
|
|
14
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
15
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
16
|
+
Classifier: Programming Language :: Python :: 3
|
|
17
|
+
Classifier: Topic :: Software Development :: Testing
|
|
18
|
+
Classifier: Topic :: System :: Hardware
|
|
19
|
+
Requires-Python: >=3.10
|
|
20
|
+
Requires-Dist: pyserial>=3.5
|
|
21
|
+
Description-Content-Type: text/markdown
|
|
22
|
+
|
|
23
|
+
# airhand
|
|
24
|
+
|
|
25
|
+
Drive any device that accepts a Bluetooth keyboard and mouse: phones, tablets, computers and TVs. Nothing is installed on the device. A $10 nRF52840 USB dongle pairs with it as a keyboard, mouse and media remote, and your computer sends it commands over USB serial.
|
|
26
|
+
|
|
27
|
+
```
|
|
28
|
+
your computer ──USB serial──▶ nRF52840 dongle ──Bluetooth LE HID──▶ phone · tablet · computer · TV
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
Use it to automate devices that you cannot or do not want to instrument: real phones without developer mode, locked-down apps, kiosks, set-top boxes. Add a camera over the screen if your automation needs to see.
|
|
32
|
+
|
|
33
|
+
## What it can send
|
|
34
|
+
|
|
35
|
+
| Input | Commands |
|
|
36
|
+
|---|---|
|
|
37
|
+
| Pointer at an exact position | tap, double tap, right click, long press, hover, swipe, drag |
|
|
38
|
+
| Scroll wheel | vertical and horizontal |
|
|
39
|
+
| Keyboard | text on a US layout, any key with `ctrl` / `shift` / `alt` / `cmd`, F1 to F24, the numpad |
|
|
40
|
+
| Media and system keys | home, back, search, volume, mute, play/pause, next, previous, brightness |
|
|
41
|
+
|
|
42
|
+
Positions are fractions of the screen, `0.0` to `1.0`, so the same script works at any resolution.
|
|
43
|
+
|
|
44
|
+
## Hardware
|
|
45
|
+
|
|
46
|
+
- A **Nordic nRF52840 Dongle** (PCA10059). It costs about $10.
|
|
47
|
+
- A device with Bluetooth LE that accepts a Bluetooth keyboard and mouse.
|
|
48
|
+
|
|
49
|
+
## Quick start
|
|
50
|
+
|
|
51
|
+
1. **Flash the firmware.** Download `airhand-firmware-<version>.zip` from the [releases](https://github.com/chinmayajha/airhand/releases). Press the dongle's RESET button (the red LED pulses), then:
|
|
52
|
+
|
|
53
|
+
```sh
|
|
54
|
+
pip install nrfutil
|
|
55
|
+
nrfutil install nrf5sdk-tools
|
|
56
|
+
nrfutil nrf5sdk-tools dfu usb-serial -pkg airhand-firmware-<version>.zip -p <serial port>
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
2. **Pair.** Open the device's Bluetooth settings and select **airhand**. Pairing needs no code.
|
|
60
|
+
|
|
61
|
+
- **iPhone and iPad:** turn on Settings > Accessibility > Touch > AssistiveTouch to use the pointer.
|
|
62
|
+
- **Android, computers and TVs:** no extra settings.
|
|
63
|
+
|
|
64
|
+
3. **Send input.**
|
|
65
|
+
|
|
66
|
+
```sh
|
|
67
|
+
pip install airhand
|
|
68
|
+
```
|
|
69
|
+
|
|
70
|
+
```python
|
|
71
|
+
from airhand import Dongle
|
|
72
|
+
|
|
73
|
+
with Dongle() as dongle:
|
|
74
|
+
dongle.media("home")
|
|
75
|
+
dongle.tap(0.5, 0.3)
|
|
76
|
+
dongle.type_text("hello\n")
|
|
77
|
+
dongle.swipe((0.5, 0.8), (0.5, 0.3), ms=400)
|
|
78
|
+
dongle.key("cmd+space")
|
|
79
|
+
```
|
|
80
|
+
|
|
81
|
+
`Dongle()` opens the one plugged-in dongle. With several, give a USB serial number from `airhand.serial_numbers()`: `Dongle("<serial>")`. A dongle found by serial number is found again after a replug. Use `Dongle(port="/dev/ttyACM0")` for a fixed port.
|
|
82
|
+
|
|
83
|
+
## Python API
|
|
84
|
+
|
|
85
|
+
| Method | Does |
|
|
86
|
+
|---|---|
|
|
87
|
+
| `tap(x, y, button="left", count=1)` | Click. `count=2` is a double click; `button` is `left`, `right` or `middle`. |
|
|
88
|
+
| `hold(x, y, ms, button="left")` | Press and hold: a long press. |
|
|
89
|
+
| `move(x, y)` | Move the pointer without pressing. |
|
|
90
|
+
| `swipe(start, end, ms, hold_ms=0)` | Press, move, release. With `hold_ms`, a drag that starts with a long press. |
|
|
91
|
+
| `wheel(lines, pan=0)` | Turn the scroll wheel by detents. Positive turns it up and right; natural scrolling reverses the content. |
|
|
92
|
+
| `type_text(text)` | Type text. |
|
|
93
|
+
| `key(combo)` | Press a key or a combination, such as `enter`, `a` or `ctrl+shift+t`. |
|
|
94
|
+
| `media(name)` | Press a media or system key. |
|
|
95
|
+
| `status()` | The link state, such as `{"conn": "yes", "sec": "2", "interval_ms": "45"}`. |
|
|
96
|
+
| `unpair()` | Forget every paired device. |
|
|
97
|
+
|
|
98
|
+
`airhand.serial_numbers()` lists the plugged-in dongles. `airhand.KEYS`, `MODIFIERS`, `MEDIA` and `BUTTONS` list every name the firmware accepts.
|
|
99
|
+
|
|
100
|
+
Errors all derive from `airhand.AirhandError`:
|
|
101
|
+
|
|
102
|
+
| Error | Means |
|
|
103
|
+
|---|---|
|
|
104
|
+
| `HostUnavailable` | No device took the command within 10 s: it is not connected, or never encrypted the link. Its `reason` says which. |
|
|
105
|
+
| `DongleLost` | The dongle is not plugged in or stopped answering. The command may or may not have run. |
|
|
106
|
+
| `Unsupported` | The input cannot be sent: a character, key, button or position outside what the firmware supports. |
|
|
107
|
+
| `Refused` | The firmware refused the command and sent nothing. Its `reason` holds the firmware's words. |
|
|
108
|
+
| `WrongFirmware` | The port answers, but not with airhand firmware of the client's series: client 0.1.x needs firmware 0.1.x. |
|
|
109
|
+
|
|
110
|
+
The client keeps commands safe across a lost reply. Every request carries an id, and a reply that goes missing is asked for again with `result <id>`, so a tap is never sent twice.
|
|
111
|
+
|
|
112
|
+
`airhand.testing.FakeDongle` answers the protocol on a pseudo-terminal (macOS and Linux), so you can test your code without hardware:
|
|
113
|
+
|
|
114
|
+
```python
|
|
115
|
+
from airhand import Dongle
|
|
116
|
+
from airhand.testing import FakeDongle
|
|
117
|
+
|
|
118
|
+
with FakeDongle() as fake:
|
|
119
|
+
Dongle(port=fake.port).tap(0.5, 0.5)
|
|
120
|
+
assert fake.commands == [("tap", "0.5000", "0.5000")]
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## Serial protocol
|
|
124
|
+
|
|
125
|
+
Every language can use the dongle: it is one line per request on a USB serial port. See [docs/protocol.md](docs/protocol.md).
|
|
126
|
+
|
|
127
|
+
## Platform notes
|
|
128
|
+
|
|
129
|
+
| Device | Notes |
|
|
130
|
+
|---|---|
|
|
131
|
+
| iPhone, iPad | Turn on AssistiveTouch for the pointer. A slow drag can count as a tap: move at least 0.75 screen heights per second. iOS has no Back key. |
|
|
132
|
+
| Android | Back, Home and the pointer work with no setup. |
|
|
133
|
+
| macOS, Windows, Linux | Use the wheel to scroll; a drag selects text on a computer. |
|
|
134
|
+
| TVs and set-top boxes | Use arrow keys, `enter` and the media keys. |
|
|
135
|
+
|
|
136
|
+
Tested on an iPhone 12 with iOS 26. Results from other devices are welcome as issues or pull requests.
|
|
137
|
+
|
|
138
|
+
## Build the firmware
|
|
139
|
+
|
|
140
|
+
The firmware is a Zephyr app for nRF Connect SDK v3.4.1, in [firmware/](firmware/):
|
|
141
|
+
|
|
142
|
+
```sh
|
|
143
|
+
west build -b nrf52840dongle/nrf52840 -d build firmware
|
|
144
|
+
nrfutil nrf5sdk-tools pkg generate --hw-version 52 --application-version 1 --sd-req=0x00 \
|
|
145
|
+
--application build/firmware/zephyr/zephyr.hex airhand-firmware.zip
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
The protocol core, `firmware/src/proto.c`, has no Zephyr dependency. The tests build it for your computer and drive it through the Python client:
|
|
149
|
+
|
|
150
|
+
```sh
|
|
151
|
+
pip install -e . pytest
|
|
152
|
+
pytest
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
## License
|
|
156
|
+
|
|
157
|
+
Apache-2.0. See [LICENSE](LICENSE).
|
|
158
|
+
|
|
159
|
+
The released firmware image also contains Zephyr (Apache-2.0) and parts of the nRF Connect SDK, such as the Bluetooth LE controller and the HID service, under the [Nordic 5-Clause license](https://github.com/nrfconnect/sdk-nrf/blob/main/LICENSE). Those parts may only be used with Nordic Semiconductor chips.
|
airhand-0.1.0/README.md
ADDED
|
@@ -0,0 +1,137 @@
|
|
|
1
|
+
# airhand
|
|
2
|
+
|
|
3
|
+
Drive any device that accepts a Bluetooth keyboard and mouse: phones, tablets, computers and TVs. Nothing is installed on the device. A $10 nRF52840 USB dongle pairs with it as a keyboard, mouse and media remote, and your computer sends it commands over USB serial.
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
your computer ──USB serial──▶ nRF52840 dongle ──Bluetooth LE HID──▶ phone · tablet · computer · TV
|
|
7
|
+
```
|
|
8
|
+
|
|
9
|
+
Use it to automate devices that you cannot or do not want to instrument: real phones without developer mode, locked-down apps, kiosks, set-top boxes. Add a camera over the screen if your automation needs to see.
|
|
10
|
+
|
|
11
|
+
## What it can send
|
|
12
|
+
|
|
13
|
+
| Input | Commands |
|
|
14
|
+
|---|---|
|
|
15
|
+
| Pointer at an exact position | tap, double tap, right click, long press, hover, swipe, drag |
|
|
16
|
+
| Scroll wheel | vertical and horizontal |
|
|
17
|
+
| Keyboard | text on a US layout, any key with `ctrl` / `shift` / `alt` / `cmd`, F1 to F24, the numpad |
|
|
18
|
+
| Media and system keys | home, back, search, volume, mute, play/pause, next, previous, brightness |
|
|
19
|
+
|
|
20
|
+
Positions are fractions of the screen, `0.0` to `1.0`, so the same script works at any resolution.
|
|
21
|
+
|
|
22
|
+
## Hardware
|
|
23
|
+
|
|
24
|
+
- A **Nordic nRF52840 Dongle** (PCA10059). It costs about $10.
|
|
25
|
+
- A device with Bluetooth LE that accepts a Bluetooth keyboard and mouse.
|
|
26
|
+
|
|
27
|
+
## Quick start
|
|
28
|
+
|
|
29
|
+
1. **Flash the firmware.** Download `airhand-firmware-<version>.zip` from the [releases](https://github.com/chinmayajha/airhand/releases). Press the dongle's RESET button (the red LED pulses), then:
|
|
30
|
+
|
|
31
|
+
```sh
|
|
32
|
+
pip install nrfutil
|
|
33
|
+
nrfutil install nrf5sdk-tools
|
|
34
|
+
nrfutil nrf5sdk-tools dfu usb-serial -pkg airhand-firmware-<version>.zip -p <serial port>
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
2. **Pair.** Open the device's Bluetooth settings and select **airhand**. Pairing needs no code.
|
|
38
|
+
|
|
39
|
+
- **iPhone and iPad:** turn on Settings > Accessibility > Touch > AssistiveTouch to use the pointer.
|
|
40
|
+
- **Android, computers and TVs:** no extra settings.
|
|
41
|
+
|
|
42
|
+
3. **Send input.**
|
|
43
|
+
|
|
44
|
+
```sh
|
|
45
|
+
pip install airhand
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
```python
|
|
49
|
+
from airhand import Dongle
|
|
50
|
+
|
|
51
|
+
with Dongle() as dongle:
|
|
52
|
+
dongle.media("home")
|
|
53
|
+
dongle.tap(0.5, 0.3)
|
|
54
|
+
dongle.type_text("hello\n")
|
|
55
|
+
dongle.swipe((0.5, 0.8), (0.5, 0.3), ms=400)
|
|
56
|
+
dongle.key("cmd+space")
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
`Dongle()` opens the one plugged-in dongle. With several, give a USB serial number from `airhand.serial_numbers()`: `Dongle("<serial>")`. A dongle found by serial number is found again after a replug. Use `Dongle(port="/dev/ttyACM0")` for a fixed port.
|
|
60
|
+
|
|
61
|
+
## Python API
|
|
62
|
+
|
|
63
|
+
| Method | Does |
|
|
64
|
+
|---|---|
|
|
65
|
+
| `tap(x, y, button="left", count=1)` | Click. `count=2` is a double click; `button` is `left`, `right` or `middle`. |
|
|
66
|
+
| `hold(x, y, ms, button="left")` | Press and hold: a long press. |
|
|
67
|
+
| `move(x, y)` | Move the pointer without pressing. |
|
|
68
|
+
| `swipe(start, end, ms, hold_ms=0)` | Press, move, release. With `hold_ms`, a drag that starts with a long press. |
|
|
69
|
+
| `wheel(lines, pan=0)` | Turn the scroll wheel by detents. Positive turns it up and right; natural scrolling reverses the content. |
|
|
70
|
+
| `type_text(text)` | Type text. |
|
|
71
|
+
| `key(combo)` | Press a key or a combination, such as `enter`, `a` or `ctrl+shift+t`. |
|
|
72
|
+
| `media(name)` | Press a media or system key. |
|
|
73
|
+
| `status()` | The link state, such as `{"conn": "yes", "sec": "2", "interval_ms": "45"}`. |
|
|
74
|
+
| `unpair()` | Forget every paired device. |
|
|
75
|
+
|
|
76
|
+
`airhand.serial_numbers()` lists the plugged-in dongles. `airhand.KEYS`, `MODIFIERS`, `MEDIA` and `BUTTONS` list every name the firmware accepts.
|
|
77
|
+
|
|
78
|
+
Errors all derive from `airhand.AirhandError`:
|
|
79
|
+
|
|
80
|
+
| Error | Means |
|
|
81
|
+
|---|---|
|
|
82
|
+
| `HostUnavailable` | No device took the command within 10 s: it is not connected, or never encrypted the link. Its `reason` says which. |
|
|
83
|
+
| `DongleLost` | The dongle is not plugged in or stopped answering. The command may or may not have run. |
|
|
84
|
+
| `Unsupported` | The input cannot be sent: a character, key, button or position outside what the firmware supports. |
|
|
85
|
+
| `Refused` | The firmware refused the command and sent nothing. Its `reason` holds the firmware's words. |
|
|
86
|
+
| `WrongFirmware` | The port answers, but not with airhand firmware of the client's series: client 0.1.x needs firmware 0.1.x. |
|
|
87
|
+
|
|
88
|
+
The client keeps commands safe across a lost reply. Every request carries an id, and a reply that goes missing is asked for again with `result <id>`, so a tap is never sent twice.
|
|
89
|
+
|
|
90
|
+
`airhand.testing.FakeDongle` answers the protocol on a pseudo-terminal (macOS and Linux), so you can test your code without hardware:
|
|
91
|
+
|
|
92
|
+
```python
|
|
93
|
+
from airhand import Dongle
|
|
94
|
+
from airhand.testing import FakeDongle
|
|
95
|
+
|
|
96
|
+
with FakeDongle() as fake:
|
|
97
|
+
Dongle(port=fake.port).tap(0.5, 0.5)
|
|
98
|
+
assert fake.commands == [("tap", "0.5000", "0.5000")]
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
## Serial protocol
|
|
102
|
+
|
|
103
|
+
Every language can use the dongle: it is one line per request on a USB serial port. See [docs/protocol.md](docs/protocol.md).
|
|
104
|
+
|
|
105
|
+
## Platform notes
|
|
106
|
+
|
|
107
|
+
| Device | Notes |
|
|
108
|
+
|---|---|
|
|
109
|
+
| iPhone, iPad | Turn on AssistiveTouch for the pointer. A slow drag can count as a tap: move at least 0.75 screen heights per second. iOS has no Back key. |
|
|
110
|
+
| Android | Back, Home and the pointer work with no setup. |
|
|
111
|
+
| macOS, Windows, Linux | Use the wheel to scroll; a drag selects text on a computer. |
|
|
112
|
+
| TVs and set-top boxes | Use arrow keys, `enter` and the media keys. |
|
|
113
|
+
|
|
114
|
+
Tested on an iPhone 12 with iOS 26. Results from other devices are welcome as issues or pull requests.
|
|
115
|
+
|
|
116
|
+
## Build the firmware
|
|
117
|
+
|
|
118
|
+
The firmware is a Zephyr app for nRF Connect SDK v3.4.1, in [firmware/](firmware/):
|
|
119
|
+
|
|
120
|
+
```sh
|
|
121
|
+
west build -b nrf52840dongle/nrf52840 -d build firmware
|
|
122
|
+
nrfutil nrf5sdk-tools pkg generate --hw-version 52 --application-version 1 --sd-req=0x00 \
|
|
123
|
+
--application build/firmware/zephyr/zephyr.hex airhand-firmware.zip
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
The protocol core, `firmware/src/proto.c`, has no Zephyr dependency. The tests build it for your computer and drive it through the Python client:
|
|
127
|
+
|
|
128
|
+
```sh
|
|
129
|
+
pip install -e . pytest
|
|
130
|
+
pytest
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
## License
|
|
134
|
+
|
|
135
|
+
Apache-2.0. See [LICENSE](LICENSE).
|
|
136
|
+
|
|
137
|
+
The released firmware image also contains Zephyr (Apache-2.0) and parts of the nRF Connect SDK, such as the Bluetooth LE controller and the HID service, under the [Nordic 5-Clause license](https://github.com/nrfconnect/sdk-nrf/blob/main/LICENSE). Those parts may only be used with Nordic Semiconductor chips.
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
# Serial protocol
|
|
2
|
+
|
|
3
|
+
The dongle is a USB serial port (CDC ACM; the baud rate does not matter). A client sends one request per line and gets exactly one reply line.
|
|
4
|
+
|
|
5
|
+
```
|
|
6
|
+
request: <id> <verb> [args]\n
|
|
7
|
+
reply: <id> ok [data]\n
|
|
8
|
+
<id> err <reason>\n
|
|
9
|
+
```
|
|
10
|
+
|
|
11
|
+
- `<id>` is a decimal number of up to 10 digits. A request without an id gets a reply with id `0`.
|
|
12
|
+
- A request line can be up to 255 bytes. A longer line gets `err line too long`.
|
|
13
|
+
- The dongle also writes event lines, such as `evt connected`, and echo is not guaranteed to be off. A client takes a line as its reply only when it starts with its own id, followed by `ok` or `err`.
|
|
14
|
+
|
|
15
|
+
## Verbs
|
|
16
|
+
|
|
17
|
+
Positions are fractions of the screen from `0.0000` to `1.0000`, with `0 0` at the top left. Times are in milliseconds.
|
|
18
|
+
|
|
19
|
+
| Verb | Arguments | Does |
|
|
20
|
+
|---|---|---|
|
|
21
|
+
| `version` | | Replies `ok airhand <version> id=<chip id>`. The chip id is the same as the USB serial number. |
|
|
22
|
+
| `tap` | `x y [button] [count]` | Moves the pointer, waits 100 ms, then clicks `count` times (1 to 5, default 1). `button` is `left` (default), `right` or `middle`. |
|
|
23
|
+
| `hold` | `x y ms [button]` | Moves the pointer, waits 100 ms, presses for `ms` (up to 10000), releases. |
|
|
24
|
+
| `move` | `x y` | Moves the pointer with no button pressed. |
|
|
25
|
+
| `swipe` | `x1 y1 x2 y2 ms [hold_ms]` | Presses at the start, waits `hold_ms` (up to 10000), moves to the end in steps of 15 ms over `ms`, releases. |
|
|
26
|
+
| `wheel` | `lines [pan]` | Turns the wheel by -127 to 127 detents each, one report per detent every 15 ms. Positive `lines` turn it up, away from the user; positive `pan` turns it right. A host with natural scrolling moves the content the other way. |
|
|
27
|
+
| `text` | a JSON string | Types it on a US layout. Only ASCII 32 to 126, `\n` and `\t`. |
|
|
28
|
+
| `key` | `[modifier+...]key` | Presses and releases. Modifiers: `ctrl`/`control`, `shift`, `alt`/`option`, `cmd`/`command`/`gui`/`meta`/`win`. A key is one typable character, or a name: `enter`/`return`, `escape`/`esc`, `backspace`, `tab`, `space`, `insert`, `delete`, `home`, `end`, `pageup`, `pagedown`, `up`, `down`, `left`, `right`, `capslock`, `menu`/`application`, `printscreen`, `scrolllock`, `pause`, `numlock`, `f1` to `f24`, `numpad0` to `numpad9`, `numpaddivide`, `numpadmultiply`, `numpadminus`, `numpadplus`, `numpadenter`, `numpaddecimal`/`numpadperiod`. Names are not case sensitive. |
|
|
29
|
+
| `media` | name | Presses and releases a consumer key: `home`, `back`, `search`, `volup`, `voldown`, `mute`, `playpause`, `next`, `previous`, `stop`, `brightnessup`, `brightnessdown`. |
|
|
30
|
+
| `pointer` | `buttons x y` | Sends one raw absolute pointer report; `x` and `y` are 0 to 32767. `a` is a short form. |
|
|
31
|
+
| `reset` | | Releases every key and button. Send it before you close the port. |
|
|
32
|
+
| `result` | `<id>` | Sends the reply to an earlier request again. The dongle keeps the last 8. |
|
|
33
|
+
| `status` | | Replies `ok conn=yes\|no sec=<level> interval_ms=<n> hid_init=<err> uptime_s=<n>`. |
|
|
34
|
+
| `unpair` | | Forgets every paired device. |
|
|
35
|
+
|
|
36
|
+
A line of numbers with no verb is a raw report: 1 number is a consumer usage, 3 numbers a relative mouse report (`buttons dx dy`), 8 numbers a keyboard report.
|
|
37
|
+
|
|
38
|
+
## Refusals
|
|
39
|
+
|
|
40
|
+
A command that sends reports does nothing in these cases:
|
|
41
|
+
|
|
42
|
+
| Reply | Means | What a client does |
|
|
43
|
+
|---|---|---|
|
|
44
|
+
| `err not connected` | No device is connected. | Retry for a while: a device reconnects by itself after a Bluetooth drop. |
|
|
45
|
+
| `err not secure` | A device is connected but has not encrypted the link yet. | Retry: this lasts a moment after every reconnect. If it does not end, pair again. |
|
|
46
|
+
| `err unsupported char\|key\|media` | The input is outside the tables above. | Report it; do not retry. |
|
|
47
|
+
| `err bad args`, `err bad json`, `err unknown verb`, `err line too long` | The request is malformed. | Report it. |
|
|
48
|
+
|
|
49
|
+
When a report fails after the first one went out, the reply is `err partial <done>/<total> failed <errno>`, so the client knows the command ran in part. `err busy <errno>` means the first report did not go out.
|
|
50
|
+
|
|
51
|
+
## A lost reply
|
|
52
|
+
|
|
53
|
+
When a reply does not arrive in time, ask for it with `result <id>` instead of sending the command again. If that also gets no answer, the link is lost and the command may or may not have run.
|
|
54
|
+
|
|
55
|
+
## Reports
|
|
56
|
+
|
|
57
|
+
The dongle is one Bluetooth LE HID device with these input reports:
|
|
58
|
+
|
|
59
|
+
| ID | Report | Bytes |
|
|
60
|
+
|---|---|---|
|
|
61
|
+
| 1 | Keyboard | modifiers, reserved, 6 key codes |
|
|
62
|
+
| 2 | Relative mouse | buttons, dx, dy, wheel, pan |
|
|
63
|
+
| 3 | Consumer control | 16-bit usage |
|
|
64
|
+
| 4 | Absolute pointer | buttons, x (16 bits), y (16 bits), 0 to 32767 |
|
|
65
|
+
|
|
66
|
+
A device caches this layout when it pairs. Firmware that changes it adds a report, so paired devices read the layout again on their next connection.
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
# SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
# The board brings up its USB serial port (CDC ACM) as the console at boot: requests come in there
|
|
3
|
+
# and printk sends the replies back the same way. Clients find the dongle by its USB product name.
|
|
4
|
+
CONFIG_CDC_ACM_SERIAL_MANUFACTURER_STRING="airhand"
|
|
5
|
+
CONFIG_CDC_ACM_SERIAL_PRODUCT_STRING="airhand"
|
|
6
|
+
|
|
7
|
+
CONFIG_BT=y
|
|
8
|
+
CONFIG_BT_PERIPHERAL=y
|
|
9
|
+
CONFIG_BT_MAX_CONN=1
|
|
10
|
+
CONFIG_BT_MAX_PAIRED=4
|
|
11
|
+
# With a full bond table a new pairing request gets no reply; Android shows that as a wrong PIN.
|
|
12
|
+
CONFIG_BT_KEYS_OVERWRITE_OLDEST=y
|
|
13
|
+
CONFIG_BT_DEVICE_NAME="airhand"
|
|
14
|
+
# Generic HID
|
|
15
|
+
CONFIG_BT_DEVICE_APPEARANCE=960
|
|
16
|
+
|
|
17
|
+
# The host starts security and PHY changes; starting them from both sides at once drops the link.
|
|
18
|
+
CONFIG_BT_GATT_AUTO_SEC_REQ=n
|
|
19
|
+
CONFIG_BT_AUTO_PHY_UPDATE=n
|
|
20
|
+
|
|
21
|
+
# Just Works pairing; bonds survive a reboot, so the host reconnects by itself.
|
|
22
|
+
CONFIG_BT_SMP=y
|
|
23
|
+
CONFIG_BT_SETTINGS=y
|
|
24
|
+
CONFIG_SETTINGS=y
|
|
25
|
+
CONFIG_FLASH=y
|
|
26
|
+
CONFIG_FLASH_PAGE_LAYOUT=y
|
|
27
|
+
CONFIG_FLASH_MAP=y
|
|
28
|
+
CONFIG_NVS=y
|
|
29
|
+
|
|
30
|
+
CONFIG_BT_HIDS=y
|
|
31
|
+
CONFIG_BT_HIDS_INPUT_REP_MAX=5
|
|
32
|
+
CONFIG_BT_HIDS_OUTPUT_REP_MAX=0
|
|
33
|
+
CONFIG_BT_HIDS_FEATURE_REP_MAX=0
|
|
34
|
+
CONFIG_BT_HIDS_ATTR_MAX=40
|
|
35
|
+
CONFIG_BT_HIDS_MAX_CLIENT_COUNT=1
|
|
36
|
+
CONFIG_BT_HIDS_DEFAULT_PERM_RW_ENCRYPT=y
|
|
37
|
+
CONFIG_BT_GATT_UUID16_POOL_SIZE=56
|
|
38
|
+
CONFIG_BT_GATT_CHRC_POOL_SIZE=28
|
|
39
|
+
CONFIG_BT_CONN_CTX=y
|
|
40
|
+
|
|
41
|
+
CONFIG_BT_DIS=y
|
|
42
|
+
CONFIG_BT_DIS_PNP=y
|
|
43
|
+
CONFIG_BT_DIS_PNP_VID_SRC=2
|
|
44
|
+
CONFIG_BT_DIS_PNP_VID=0x1915
|
|
45
|
+
CONFIG_BT_DIS_PNP_PID=0xEEEE
|
|
46
|
+
CONFIG_BT_DIS_PNP_VER=0x0100
|
|
47
|
+
|
|
48
|
+
CONFIG_MAIN_STACK_SIZE=2048
|
|
49
|
+
CONFIG_SYSTEM_WORKQUEUE_STACK_SIZE=2048
|
|
50
|
+
|
|
51
|
+
# The chip id in the version reply.
|
|
52
|
+
CONFIG_HWINFO=y
|