How to use the able.dispatcher.BluetoothDispatcherBase function in able

To help you get started, we’ve selected a few able examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github b3b / able / able / android / dispatcher.py View on Github external
from able.android.jni import PythonBluetooth
from able.dispatcher import BluetoothDispatcherBase


Activity = autoclass('android.app.Activity')
BLE = autoclass('org.able.BLE')

BluetoothGattDescriptor = autoclass('android.bluetooth.BluetoothGattDescriptor')
BluetoothAdapter = autoclass('android.bluetooth.BluetoothAdapter')
ENABLE_NOTIFICATION_VALUE = BluetoothGattDescriptor.ENABLE_NOTIFICATION_VALUE
ENABLE_INDICATION_VALUE = BluetoothGattDescriptor.ENABLE_INDICATION_VALUE
DISABLE_NOTIFICATION_VALUE = BluetoothGattDescriptor.DISABLE_NOTIFICATION_VALUE


class BluetoothDispatcher(BluetoothDispatcherBase):

    def _set_ble_interface(self):
        self._events_interface = PythonBluetooth(self)
        self._ble = BLE(self._events_interface)
        activity.bind(on_activity_result=self.on_activity_result)

    def _check_runtime_permissions(self):
        # Either ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION permission
        # is needed to obtain BLE scan results
        return check_permission(Permission.ACCESS_COARSE_LOCATION) or \
            check_permission(Permission.ACCESS_FINE_LOCATION)

    def _request_runtime_permissions(self):
        request_permission(Permission.ACCESS_COARSE_LOCATION,
                           self.on_runtime_permissions)
github b3b / able / able / dispatcher.py View on Github external
def __init__(self, queue_timeout=0.5, enable_ble_code=0xab1e):
        super(BluetoothDispatcherBase, self).__init__()
        self.queue_timeout = queue_timeout
        self.enable_ble_code = enable_ble_code
        self._remote_device_address = None
        self._set_ble_interface()
        self._set_queue()