Skip to main content

Python SDK for Mudra with native library support

Project description

Mudra API Python

Python SDK for Mudra with native library support. This SDK enables you to connect to and interact with Mudra devices via Bluetooth Low Energy (BLE).

For more detailed documentation, visit: https://wearable-devices.github.io/#welcome

Features

  • 🔌 Bluetooth Low Energy (BLE) Support - Connect to Mudra devices wirelessly
  • 📱 Cross-Platform - Supports Windows, macOS
  • 🎯 Device Discovery - Scan and discover nearby Mudra devices
  • 📊 Multiple Sensor Data Types - SNC, IMU (Accelerometer/Gyroscope), Pressure, Navigation, Gestures
  • 🎮 Firmware Targets - Control where data is sent (App, HID)
  • 🤚 Hand Configuration - Set device for left or right hand
  • 🔄 Event-Driven Architecture - Use delegates for handling device events
  • 🔐 Cloud License Management - Retrieve licenses from cloud

Requirements

  • Python 3.7 or higher
  • Bluetooth-enabled computer
  • Mudra device

Installation

pip install mudra-sdk

Platform Support

The SDK includes native libraries for the following platforms:

  • Windows
  • macOS

The appropriate library is automatically loaded based on your platform.

API Reference

Mudra Class

Main entry point for the SDK.

  • scan() - Start scanning for Mudra devices (async)
  • stop_scan() - Stop scanning for devices (async)
  • set_delegate(delegate: MudraDelegate) - Set the delegate for handling device events
  • get_license_for_email_from_cloud(email: str) - Retrieve licenses from cloud for the given email
  • connect(device: MudraDevice) - Connect to a device (async)
  • disconnect(device: MudraDevice) - Disconnect from a device (async)
  • ble_service.discover_services_and_characteristics(device: MudraDevice) - Discover GATT services and characteristics (async)

MudraDevice Class

Represents a discovered or connected Mudra device.

Connection Methods

  • connect() - Connect to the device (async)
  • disconnect() - Disconnect from the device (async)

Data Feature Callbacks

All data callbacks can be enabled by passing a callback function, or disabled by passing None.

  • set_on_snc_ready(callback) - Enable/disable SNC (Sensor Neural Control) data (async)

    • Callback signature: (timestamp: int, data_list: List[float], frequency: int, frequency_std: float, rms_list: List[float]) -> None
  • set_on_imu_acc_ready(callback) - Enable/disable IMU Accelerometer data (async)

    • Callback signature: (timestamp: int, data_list: List[float], frequency: int, frequency_std: float, rms_list: List[float]) -> None
  • set_on_imu_gyro_ready(callback) - Enable/disable IMU Gyroscope data (async)

    • Callback signature: (timestamp: int, data_list: List[float], frequency: int, frequency_std: float, rms_list: List[float]) -> None
  • set_on_pressure_ready(callback) - Enable/disable pressure sensing (async)

    • Callback signature: (pressure_data: int) -> None
    • Pressure values range from 0 to 100
  • set_on_navigation_ready(callback) - Enable/disable navigation delta data (async)

    • Callback signature: (delta_x: int, delta_y: int) -> None
  • set_on_gesture_ready(callback) - Enable/disable gesture recognition (async)

    • Callback signature: (gesture_type: GestureType) -> None
  • set_on_button_changed(callback) - Enable/disable Air Touch Button change notifications (async)

    • Callback signature: (air_touch_button: AirMouseButton) -> None

Firmware Configuration

  • set_firmware_target(target: FirmwareTarget, active: bool) - Enable/disable firmware targets (async)

    • Targets: FirmwareTarget.navigation_to_app, FirmwareTarget.gesture_to_hid, FirmwareTarget.navigation_to_hid
  • set_hand(hand_type: HandType) - Set device hand configuration (async)

    • Options: HandType.left, HandType.right
  • set_air_touch_active(active: bool) - Enable/disable embedded AirTouch feature (async)

Device Properties

  • firmware_status - Access to FirmwareStatus object with current device state
    • Properties include: is_snc_enabled, is_acc_enabled, is_gyro_enabled, is_pressure_enabled, is_navigation_enabled, is_gesture_enabled, is_air_touch_enabled, is_sends_navigation_to_app_enabled, is_sends_gesture_to_hid_enabled, is_sends_navigation_to_hid_enabled

MudraDelegate Interface

Implement this interface to handle device events:

  • on_device_discovered(device: MudraDevice) - Called when a device is discovered
  • on_mudra_device_connected(device: MudraDevice) - Called when a device connects
  • on_mudra_device_disconnected(device: MudraDevice) - Called when a device disconnects
  • on_mudra_device_connecting(device: MudraDevice) - Called when a device is connecting
  • on_mudra_device_disconnecting(device: MudraDevice) - Called when a device is disconnecting
  • on_mudra_device_connection_failed(device: MudraDevice, error: str) - Called when connection fails
  • on_bluetooth_state_changed(state: bool) - Called when Bluetooth state changes

Enums

  • FirmwareTarget - Firmware target options: navigation_to_app, gesture_to_hid, navigation_to_hid
  • HandType - Hand configuration: left, right
  • GestureType - Gesture recognition types
  • AirMouseButton - Air Touch Button states

Getting Started

Basic Setup

import asyncio
from mudra_sdk import Mudra, MudraDevice
from mudra_sdk.models.callbacks import MudraDelegate

# Create Mudra instance
mudra = Mudra()

# Retrieve license from cloud (required for full functionality)
mudra.get_license_for_email_from_cloud("your-email@example.com")

# Implement delegate to handle device events
class MyMudraDelegate(MudraDelegate):
    def on_device_discovered(self, device: MudraDevice):
        print(f"Discovered: {device.name} ({device.address})")

    def on_mudra_device_connected(self, device: MudraDevice):
        print(f"Device connected: {device.name}")

    def on_mudra_device_disconnected(self, device: MudraDevice):
        print(f"Device disconnected: {device.name}")

    def on_mudra_device_connecting(self, device: MudraDevice):
        print(f"Device connecting: {device.name}...")

    def on_mudra_device_disconnecting(self, device: MudraDevice):
        print(f"Device disconnecting: {device.name}...")

    def on_mudra_device_connection_failed(self, device: MudraDevice, error: str):
        print(f"Connection failed: {device.name}, Error: {error}")

    def on_bluetooth_state_changed(self, state: bool):
        print(f"Bluetooth state changed: {'On' if state else 'Off'}")

# Set the delegate
mudra.set_delegate(MyMudraDelegate())

Scanning for Devices

mudra = Mudra()

async def start():
    mudra.set_delegate(MyMudraDelegate())
    
    # Start scanning for Mudra devices
    await mudra.scan()
    
    # Wait for devices to be discovered
    await asyncio.sleep(10)

async def stop():
    # Stop scanning when done
    await mudra.stop_scan()

Connecting to a Device

# Store discovered devices
discovered_devices = []

class MyMudraDelegate(MudraDelegate):
    def on_device_discovered(self, device: MudraDevice):
        discovered_devices.append(device)
        print(f"Discovered: {device.name}")

async def main():
    mudra = Mudra()
    mudra.set_delegate(MyMudraDelegate())
    
    # Start scanning
    await mudra.scan()
    await asyncio.sleep(5)  # Wait for discovery
    
    # Connect to the first discovered device
    if discovered_devices:
        device = discovered_devices[0]
        await device.connect()
        print(f"Connected to {device.name}")
        
        # ... use the device ...
        
        # Disconnect when done
        await device.disconnect()

asyncio.run(main())

Usage Examples

SNC (Sensor Neural Control) Data

Enable SNC data to receive neural control signals with RMS values:

def on_snc_ready(timestamp: int, data_list: list, frequency: int, frequency_std: float, rms_list: list):
    print(f"SNC - Frequency: {frequency} Hz, RMS: {rms_list}")

async def enable_snc():
    await device.set_on_snc_ready(on_snc_ready)

async def disable_snc():
    await device.set_on_snc_ready(None)

IMU Data (Accelerometer & Gyroscope)

Enable IMU data to receive motion sensor information:

def on_imu_acc_ready(timestamp: int, data_list: list, frequency: int, frequency_std: float, rms_list: list):
    print(f"IMU Acc - Frequency: {frequency:.2f} Hz")

def on_imu_gyro_ready(timestamp: int, data_list: list, frequency: int, frequency_std: float, rms_list: list):
    print(f"IMU Gyro - Frequency: {frequency:.2f} Hz")

async def enable_imu():
    await device.set_on_imu_acc_ready(on_imu_acc_ready)
    await device.set_on_imu_gyro_ready(on_imu_gyro_ready)

async def disable_imu():
    await device.set_on_imu_acc_ready(None)
    await device.set_on_imu_gyro_ready(None)

Pressure Data

Enable pressure sensing to receive real-time pressure data from the device:

def on_pressure_ready(pressure_data: int):
    print(f"Pressure: {pressure_data}")  # Range: 0-100

async def enable_pressure():    
    await device.set_on_pressure_ready(on_pressure_ready)

async def disable_pressure():
    await device.set_on_pressure_ready(None)

Navigation Data

Enable navigation to receive cursor movement deltas:

def on_navigation_ready(delta_x: int, delta_y: int):
    print(f"Navigation delta: X={delta_x}, Y={delta_y}")

async def enable_navigation():
    await device.set_on_navigation_ready(on_navigation_ready)

async def disable_navigation():
    await device.set_on_navigation_ready(None)

Gesture Recognition

Enable gesture recognition to detect hand gestures:

from mudra_sdk.models.enums import GestureType

def on_gesture_ready(gesture_type: GestureType):
    print(f"Gesture detected: {gesture_type}")

async def enable_gesture():
    await device.set_on_gesture_ready(on_gesture_ready)

async def disable_gesture():
    await device.set_on_gesture_ready(None)

Air Touch Button

Monitor Air Touch Button state changes:

from mudra_sdk.models.enums import AirMouseButton

def on_button_changed(air_touch_button: AirMouseButton):
    print(f"Air Touch Button: {air_touch_button}")

async def enable_button_monitoring():
    await device.set_on_button_changed(on_button_changed)

async def disable_button_monitoring():
    await device.set_on_button_changed(None)

Firmware Targets

Control where firmware sends data (to your app or to HID):

from mudra_sdk.models.enums import FirmwareTarget

async def configure_firmware_targets():
    # Enable navigation data to be sent to your app
    await device.set_firmware_target(FirmwareTarget.navigation_to_app, True)
    
    # Enable gesture data to be sent to HID (Human Interface Device)
    await device.set_firmware_target(FirmwareTarget.gesture_to_hid, True)
    
    # Enable navigation data to be sent to HID
    await device.set_firmware_target(FirmwareTarget.navigation_to_hid, True)

async def disable_firmware_targets():
    await device.set_firmware_target(FirmwareTarget.navigation_to_app, False)
    await device.set_firmware_target(FirmwareTarget.gesture_to_hid, False)
    await device.set_firmware_target(FirmwareTarget.navigation_to_hid, False)

Hand Configuration

Set the device for left or right hand:

from mudra_sdk.models.enums import HandType

async def set_hand_configuration():
    # Set for left hand
    await device.set_hand(HandType.left)
    
    # Or set for right hand
    await device.set_hand(HandType.right)

Embedded AirTouch

Enable/disable the embedded AirTouch feature:

async def enable_embedded_airtouch():
    await device.set_air_touch_active(True)

async def disable_embedded_airtouch():
    await device.set_air_touch_active(False)

Device Discovery

Discover GATT services and characteristics on a connected device:

async def discover_device():
    await mudra.ble_service.discover_services_and_characteristics(device)
    print("Device discovery completed")

Checking Device Status

Access the device's firmware status to check which features are enabled:

# After connecting to a device
if device.firmware_status.is_pressure_enabled:
    print("Pressure sensing is enabled")

if device.firmware_status.is_navigation_enabled:
    print("Navigation is enabled")

if device.firmware_status.is_sends_navigation_to_app_enabled:
    print("Navigation data is being sent to app")

Complete Usage Example

Here's a complete example that demonstrates the full workflow:

import asyncio
from mudra_sdk import Mudra, MudraDevice
from mudra_sdk.models.callbacks import MudraDelegate
from mudra_sdk.models.enums import FirmwareTarget, HandType, GestureType, AirMouseButton

discovered_devices = []
connected_device = None

class MyMudraDelegate(MudraDelegate):
    def on_device_discovered(self, device: MudraDevice):
        print(f"✓ Discovered: {device.name} ({device.address})")
        discovered_devices.append(device)

    def on_mudra_device_connected(self, device: MudraDevice):
        global connected_device
        connected_device = device
        print(f"✓ Connected to: {device.name}")

    def on_mudra_device_disconnected(self, device: MudraDevice):
        print(f"✓ Disconnected from: {device.name}")

    def on_mudra_device_connecting(self, device: MudraDevice):
        print(f"→ Connecting to: {device.name}...")

    def on_mudra_device_disconnecting(self, device: MudraDevice):
        print(f"→ Disconnecting from: {device.name}...")

    def on_mudra_device_connection_failed(self, device: MudraDevice, error: str):
        print(f"✗ Connection failed: {device.name}, Error: {error}")

    def on_bluetooth_state_changed(self, state: bool):
        print(f"Bluetooth: {'On' if state else 'Off'}")

# Data callbacks
def on_snc_ready(timestamp, data_list, frequency, frequency_std, rms_list):
    print(f"SNC - Frequency: {frequency} Hz, RMS: {rms_list}")

def on_imu_acc_ready(timestamp, data_list, frequency, frequency_std, rms_list):
    print(f"IMU Acc - Frequency: {frequency:.2f} Hz")

def on_imu_gyro_ready(timestamp, data_list, frequency, frequency_std, rms_list):
    print(f"IMU Gyro - Frequency: {frequency:.2f} Hz")

def on_pressure_ready(pressure_data: int):
    print(f"Pressure: {pressure_data}")

def on_navigation_ready(delta_x: int, delta_y: int):
    print(f"Navigation: ΔX={delta_x}, ΔY={delta_y}")

def on_gesture_ready(gesture_type: GestureType):
    print(f"Gesture: {gesture_type}")

def on_button_changed(air_touch_button: AirMouseButton):
    print(f"Air Touch Button: {air_touch_button}")

async def main():
    mudra = Mudra()
    mudra.set_delegate(MyMudraDelegate())
    
    # Retrieve license from cloud
    mudra.get_license_for_email_from_cloud("your-email@example.com")
    
    print("Scanning for Mudra devices...")
    await mudra.scan()
    
    # Wait for devices to be discovered
    await asyncio.sleep(5)
    
    if discovered_devices:
        device = discovered_devices[0]
        print(f"\nConnecting to {device.name}...")
        await device.connect()
        
        # Discover GATT services and characteristics
        await mudra.ble_service.discover_services_and_characteristics(device)
        
        # Set hand configuration
        await device.set_hand(HandType.right)
        
        # Enable data features
        await device.set_on_snc_ready(on_snc_ready)
        await device.set_on_imu_acc_ready(on_imu_acc_ready)
        await device.set_on_imu_gyro_ready(on_imu_gyro_ready)
        await device.set_on_pressure_ready(on_pressure_ready)
        await device.set_on_navigation_ready(on_navigation_ready)
        await device.set_on_gesture_ready(on_gesture_ready)
        await device.set_on_button_changed(on_button_changed)
        
        # Configure firmware targets
        await device.set_firmware_target(FirmwareTarget.navigation_to_app, True)
        await device.set_firmware_target(FirmwareTarget.gesture_to_hid, True)
        
        # Enable embedded AirTouch
        await device.set_air_touch_active(True)
        
        print("\nDevice ready! Interacting with device for 30 seconds...")
        await asyncio.sleep(30)
        
        # Cleanup - disable all features
        await device.set_on_snc_ready(None)
        await device.set_on_imu_acc_ready(None)
        await device.set_on_imu_gyro_ready(None)
        await device.set_on_pressure_ready(None)
        await device.set_on_navigation_ready(None)
        await device.set_on_gesture_ready(None)
        await device.set_on_button_changed(None)
        await device.set_air_touch_active(False)
        await device.set_firmware_target(FirmwareTarget.navigation_to_app, False)
        await device.set_firmware_target(FirmwareTarget.gesture_to_hid, False)
        
        await device.disconnect()
    else:
        print("No devices found.")
    
    await mudra.stop_scan()

if __name__ == "__main__":
    asyncio.run(main())

Support

For issues, questions, or contributions please contact foad.k@wearabledevices.co.il

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mudra_sdk-0.1.6.tar.gz (1.9 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mudra_sdk-0.1.6-py3-none-any.whl (1.9 MB view details)

Uploaded Python 3

File details

Details for the file mudra_sdk-0.1.6.tar.gz.

File metadata

  • Download URL: mudra_sdk-0.1.6.tar.gz
  • Upload date:
  • Size: 1.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for mudra_sdk-0.1.6.tar.gz
Algorithm Hash digest
SHA256 7a66a46d54180fa20ece3c68226c4472a133d5e4e7461dab8f55cb73d17ccf9a
MD5 e42df64f5fc3f59ed1afca8aa2d43254
BLAKE2b-256 207272c798f95a5a1f987f7c537802277f41b215447b5a9299e533f855c3b855

See more details on using hashes here.

File details

Details for the file mudra_sdk-0.1.6-py3-none-any.whl.

File metadata

  • Download URL: mudra_sdk-0.1.6-py3-none-any.whl
  • Upload date:
  • Size: 1.9 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.5

File hashes

Hashes for mudra_sdk-0.1.6-py3-none-any.whl
Algorithm Hash digest
SHA256 cfa78835d605a5b21748c3def0397306c8a6e710c9d3ecdf85037386af9453f1
MD5 1e50d32ee4423554a33848950610cb3c
BLAKE2b-256 373a2f85642777d08c0a482a29d840b59f2559a226e9914027eb319a36200f2a

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page