Skip to content

Commit c325971

Browse files
authored
Merge pull request #25 from TapWithUs/unified-client
Unified backends with bleak
2 parents 9c18485 + e33be6d commit c325971

27 files changed

Lines changed: 372 additions & 390 deletions

.flake8

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[flake8]
2+
max-line-length = 120

.github/workflows/test.yml

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: CI
2+
3+
on:
4+
pull_request:
5+
push:
6+
branches: [master]
7+
8+
jobs:
9+
build:
10+
runs-on: ${{ matrix.os }}
11+
strategy:
12+
matrix:
13+
os: [ubuntu-latest, windows-latest, macos-latest]
14+
python-version: ["3.9", "3.10", "3.11"]
15+
steps:
16+
- uses: actions/checkout@v3
17+
- name: Set up Python
18+
uses: actions/setup-python@v4
19+
with:
20+
python-version: ${{ matrix.python-version }}
21+
- name: Install dependencies
22+
run: |
23+
python -m pip install --upgrade pip
24+
pip install -e .[dev]
25+
- name: Lint with flake8
26+
run: |
27+
pip install flake8
28+
flake8 examples tapsdk tests
29+
- name: Run tests
30+
run: pytest -v

History.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ ______________________
1313
* Spatial features are still not available for Windows backend.
1414
* MacOS & Linux backends -
1515
* Doesn't support multiple Tap strap connections.
16-
* OnConnect and OnDisconnect events are not implemented
1716
* Raw sensor data is given unscaled (i.e. unitless), thereforein order to scale to physical units need to multiply by the relevant scale factor
1817

1918
## 0.5.1 (2024-01-01)

Readme.md

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,14 @@
33
### What Is This ?
44

55
TAP python SDK allows you to build python app that can establish BLE connection with Tap Strap and TapXR, send commands and receive events and data - Thus allowing TAP to act as a controller for your app!
6-
The library is developed with Python >= 3.7 and is **currently in beta**.
6+
The library is developed with Python >= 3.9 and is **currently in beta**.
77

88

99
### Supported Platforms
1010
This package supports the following platforms:
1111
* MacOS (tested on 10.15.2) - using Apple's CoreBluetooth library. The library depends on PyObjC which Apple includes with their Python version on OSX. Note that if you're using a different Python, be sure to install PyObjC for that version of Python.
1212
* Windows 10 - by wrapping the dynamic library (DLL) generated by [tap-standalonewin-sdk](https://github.com/TapWithUs/tap-standalonewin-sdk).
13-
* Linux (testerd on Ubuntu 18.04) - need to install libbluetooth-dev and bluez-tools
13+
* Linux (tested on Ubuntu 18.04) - need to install libbluetooth-dev and bluez-tools
1414
```
1515
sudo apt-get install bluez-tools libbluetooth-dev
1616
```
@@ -166,7 +166,7 @@ Resgister callback to raw sensors data packet received event.
166166
6. ```register_air_gesture_events(self, listener:Callable):```
167167
Resgister callback to air gesture events.
168168
```python
169-
from tapsdk.models import AirGestures
169+
from tapsdk import AirGestures
170170

171171
def on_airgesture(identifier, gesture):
172172
print(identifier + " - gesture: " + str(AirGestures(gesture)))
@@ -239,7 +239,22 @@ The dynamic range of the sensors is determined with the ```set_input_mode``` met
239239

240240
### Examples
241241

242-
You can find OS specific examples on the [examples folder](examples).
242+
You can find some examples in the [examples folder](examples).
243+
244+
### Testing
245+
246+
To run the tests, first install the development dependencies:
247+
248+
```bash
249+
pip install .[dev]
250+
```
251+
252+
Then run the tests using pytest:
253+
254+
```bash
255+
pytest
256+
```
257+
243258

244259
### Known Issues
245260
An up-to-date list of known issues is available [here](History.md).
Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
import asyncio
22
import time
33

4-
from tapsdk import TapInputMode, TapSDK, InputType
5-
from tapsdk.models import AirGestures
4+
from tapsdk import TapInputMode, TapSDK, InputType, AirGestures
5+
6+
7+
def OnDisconnection(identifier):
8+
print("Disconnected. ", identifier)
9+
10+
11+
def OnConnection(identifier):
12+
print("Connected. ", identifier)
613

714

815
def OnMouseModeChange(identifier, mouse_mode):
@@ -28,23 +35,25 @@ def OnRawData(identifier, packets):
2835

2936
async def run(loop):
3037
client = TapSDK(loop=loop)
38+
39+
client.register_disconnection_events(OnDisconnection)
40+
client.register_connection_events(OnConnection)
41+
client.register_air_gesture_events(OnGesture)
42+
client.register_tap_events(OnTapped)
43+
client.register_raw_data_events(OnRawData)
44+
client.register_mouse_events(OnMoused)
45+
client.register_air_gesture_state_events(OnMouseModeChange)
3146
await client.run()
3247
print("Connected: {0}".format(client.client.is_connected))
3348

34-
await client.register_air_gesture_events(OnGesture)
35-
await client.register_tap_events(OnTapped)
36-
await client.register_raw_data_events(OnRawData)
37-
await client.register_mouse_events(OnMoused)
38-
await client.register_air_gesture_state_events(OnMouseModeChange)
39-
4049
print("Set Controller Mode for 5 seconds")
4150
await client.set_input_mode(TapInputMode("controller"))
4251
await asyncio.sleep(5)
4352

4453
print("Force Mouse Mode for 5 seconds")
4554
await client.set_input_type(InputType.MOUSE)
4655
await asyncio.sleep(5)
47-
56+
4857
print("Force keyboard Mode for 5 seconds")
4958
await client.set_input_type(InputType.KEYBOARD)
5059
await asyncio.sleep(5)

examples/example_win.py

Lines changed: 0 additions & 81 deletions
This file was deleted.

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
bleak
2-
setuptools
2+
setuptools

setup.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
REQUIRED = [
2222
# linux reqs
2323
'bleak==0.6.4;platform_system=="Linux"',
24-
# macOS reqs
24+
# macOS reqs
2525
'bleak==0.12.1;platform_system=="Darwin"',
2626
# Windows reqs
2727
'pythonnet;platform_system=="Windows"'
@@ -82,13 +82,13 @@ def run(self):
8282
author_email=EMAIL,
8383
url=URL,
8484
packages=find_packages(exclude=("tests", "examples", "docs")),
85-
# package_data={"tapsdk.backends.dotnet": ["*.dll"]},
8685
install_requires=REQUIRED,
87-
# test_suite="tests",
88-
# tests_require=TEST_REQUIRED,
8986
include_package_data=True,
9087
license="MIT",
91-
python_requires='>=3.7'
88+
python_requires='>=3.9',
89+
extras_require={
90+
"dev": ["pytest", "flake8"]
91+
},
9292
# classifiers=[
9393
# # Trove classifiers
9494
# # Full list: https://pypi.python.org/pypi?%3Aaction=list_classifiers

tapsdk/TapSDK.py

Lines changed: 0 additions & 49 deletions
This file was deleted.

tapsdk/__init__.py

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,3 @@
1-
import platform
2-
from .models.enumerations import InputType
3-
4-
this_platform = platform.system()
5-
6-
if this_platform == "Windows":
7-
from tapsdk.backends.dotnet.TapSDK import TapWindowsSDK as TapSDK
8-
from tapsdk.backends.dotnet.inputmodes import TapInputMode
9-
elif this_platform in ["Darwin", "Linux"]:
10-
from tapsdk.backends.posix.TapSDK import TapPosixSDK as TapSDK
11-
from tapsdk.backends.posix.inputmodes import TapInputMode
12-
13-
else:
14-
raise ValueError("Value for platfrom is unknown: {}".format(this_platform))
1+
from tapsdk.enumerations import InputType, AirGestures # noqa: F401
2+
from tapsdk.inputmodes import TapInputMode # noqa: F401
3+
from tapsdk.tap import TapSDK # noqa: F401

0 commit comments

Comments
 (0)