|
1 | | -### Sample code for python |
2 | | - |
3 | | -### Prerequisite |
| 1 | +# bHaptics Python Library |
| 2 | +## Prerequisite |
4 | 3 | * bHaptics Player has to be installed (Windows) |
5 | 4 | * The app can be found in |
6 | 5 | bHaptics webpage: [http://www.bhaptics.com](http://bhaptics.com/) |
| 6 | +* To play predefined haptic patterns [bHaptics Designer](https://designer1.bhaptics.com/) |
| 7 | +## Quick Start |
| 8 | + |
| 9 | +```python |
| 10 | +from bhaptics import better_haptic_player as player |
| 11 | +from bhaptics.better_haptic_player import BhapticsPosition |
| 12 | +from time import sleep |
| 13 | + |
| 14 | +# Initialize the haptic player |
| 15 | +player.initialize() |
| 16 | + |
| 17 | +# Register tact files (exported from bHaptics Designer - https://designer1.bhaptics.com/) |
| 18 | +player.register("CenterX", "CenterX.tact") |
| 19 | +player.register("Circle", "Circle.tact") |
| 20 | + |
| 21 | +# Play a registered pattern |
| 22 | +player.submit_registered("CenterX") |
| 23 | + |
| 24 | +# Play with options (rotation, intensity) |
| 25 | +player.submit_registered_with_option("Circle", "alt", |
| 26 | + scale_option={"intensity": 1, "duration": 1}, |
| 27 | + rotation_option={"offsetAngleX": 180, "offsetY": 0}) |
| 28 | +``` |
| 29 | + |
| 30 | +## Core Functions |
| 31 | + |
| 32 | +### Initialization |
| 33 | + |
| 34 | +```python |
| 35 | +player.initialize() |
| 36 | +``` |
| 37 | + |
| 38 | +### Pattern Registration |
| 39 | + |
| 40 | +```python |
| 41 | +# Register tact files (exported from bHaptics Designer) |
| 42 | +player.register("effect_name", "effect_file.tact") |
| 43 | +``` |
| 44 | + |
| 45 | +### Playing Effects |
| 46 | + |
| 47 | +```python |
| 48 | +# Play a registered effect |
| 49 | +player.submit_registered("effect_name") |
| 50 | + |
| 51 | +# Play with options (alternate key, scale, rotation) |
| 52 | +player.submit_registered_with_option("effect_name", "alternate_key", |
| 53 | + scale_option={"intensity": 1, "duration": 1}, |
| 54 | + rotation_option={"offsetAngleX": 180, "offsetY": 0}) |
| 55 | + |
| 56 | +## Direct Device Control |
| 57 | + |
| 58 | +### Submit Dot Pattern |
| 59 | + |
| 60 | +Play haptic feedback by specifying dot indices: |
| 61 | + |
| 62 | +```python |
| 63 | +# Play pattern on vest back (dots are indexed 0-19) |
| 64 | +player.submit_dot("feedback_id", BhapticsPosition.VestBack.value, |
| 65 | + [{"index": 0, "intensity": 100}], duration_millis=100) |
| 66 | +``` |
| 67 | + |
| 68 | +### Submit Path Pattern |
| 69 | + |
| 70 | +Play haptic feedback by specifying exact positions: |
| 71 | + |
| 72 | +```python |
| 73 | +# Path on the vest front using coordinates (x, y from 0-1) |
| 74 | +player.submit_path("feedback_id", BhapticsPosition.VestFront.value, [ |
| 75 | + {"x": 0.5, "y": 0.5, "intensity": 100}, # Center |
| 76 | + {"x": 0.7, "y": 0.7, "intensity": 100}, # Upper right |
| 77 | +], duration_millis=1000) |
| 78 | +``` |
| 79 | + |
| 80 | +## Device Positions |
| 81 | + |
| 82 | +The library supports the following device positions: |
| 83 | + |
| 84 | +- `BhapticsPosition.Vest` |
| 85 | +- `BhapticsPosition.VestFront` |
| 86 | +- `BhapticsPosition.VestBack` |
| 87 | +- `BhapticsPosition.ForearmL` |
| 88 | +- `BhapticsPosition.ForearmR` |
| 89 | +- `BhapticsPosition.GloveL` |
| 90 | +- `BhapticsPosition.GloveR` |
| 91 | + |
7 | 92 |
|
8 | | -### Dependencies |
| 93 | +## Dependencies |
9 | 94 | * websocket-client |
10 | 95 |
|
0 commit comments