Use features¶
Recipes for TapSDK2 (TapXR developer firmware and TapBand). Prefer await connect() so firmware detection picks TapSDK2 automatically; or construct TapSDK2() when you know the firmware.
There is no set_input_mode. Enable streams with DeviceFeatures.
Connect and enable features¶
import asyncio
from tapsdk import DeviceFeatures, TapSDK2, connect
from tapsdk.enumerations import (
ImuAcclSensitivity,
ImuGyroSensitivity,
ModelTypes,
VisionSensorOpModes,
)
async def main():
sdk = await connect()
assert isinstance(sdk, TapSDK2)
sdk.register_tap_events(lambda id, code: print("tap", code))
sdk.register_air_gesture_events(lambda id, data: print("air", data))
sdk.register_imu_motion_data_events(lambda id, motion: print("motion", motion))
sdk.register_raw_imu_data_events(lambda id, packets: print("raw", len(packets)))
sdk.register_standby_state_events(lambda id, s: print("standby", s))
await sdk.start()
# Turn unrelated streams off first (example pattern)
for feature in DeviceFeatures:
await sdk.set_feature(feature, False)
await sdk.set_feature(DeviceFeatures.MODEL_DETECTION, True)
await sdk.set_vision_sensor_model(ModelTypes.AIR_GESTURE)
await sdk.set_vision_sensor_op_mode(VisionSensorOpModes.STREAM)
await asyncio.Event().wait()
asyncio.run(main())
Receive air gestures¶
The TapXR developer firmware supports the full set: thumb swipes, pinches with hold, fist with hold. TapBand uses the same BLE API. Python, Web, iOS, and Android all receive these raw detections. In Python that is register_air_gesture_events. iOS and Android also add a processed click/drag/drop layer.
from tapsdk import UnifiedAirGestures
def on_air_gesture(identifier, data):
gesture = UnifiedAirGestures(int(data[0]))
print(gesture.name)
sdk.register_air_gesture_events(on_air_gesture)
await sdk.start()
await sdk.set_feature(DeviceFeatures.MODEL_DETECTION, True)
await sdk.set_vision_sensor_model(ModelTypes.AIR_GESTURE)
await sdk.set_vision_sensor_op_mode(VisionSensorOpModes.STREAM)
Codes: COMBINED_GESTURE_LEFT / RIGHT / UP / DOWN (swipes), AB–AE (pinches), AB_HOLD–AE_HOLD, FIST / FIST_HOLD, NONE (release). See Enumerations.
Stream IMU motion¶
await sdk.set_feature(DeviceFeatures.IMU_MOTION_DATA, True)
# callback: (identifier, (dx, dy, is_mouse, [roll, pitch, yaw]))
Stream raw IMU¶
await sdk.set_feature(DeviceFeatures.RAW_IMU_DATA, True)
await sdk.set_imu_sensitivity(
xl_sensitivity=ImuAcclSensitivity.G2,
gyro_sensitivity=ImuGyroSensitivity.DPS125,
scaled=True,
)
Packet dicts use type / ts / payload. See Events.
Standby¶
await sdk.set_feature(DeviceFeatures.STANDBY_GESTURE_DETECTION, True)
await sdk.set_standby_state(False)
is_standby = await sdk.get_standby_state()
Haptics¶
Full demo that cycles features: examples/features.py. API surface: TapSDK2 reference.