How to use the able.BluetoothDispatcher 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 / testapps / bletest / main.py View on Github external
from kivy.clock import Clock
from kivy.config import Config
from kivy.properties import BooleanProperty, StringProperty
from kivy.uix.boxlayout import BoxLayout
from kivy.storage.jsonstore import JsonStore

Config.set('kivy', 'log_level', 'debug')
Config.set('kivy', 'log_enable', '1')


class MainLayout(BoxLayout):
    pass


class BLETestApp(App):
    ble = BluetoothDispatcher()
    state = StringProperty('')
    test_string = StringProperty('')
    rssi = StringProperty('')
    notification_value = StringProperty('')
    counter_value = StringProperty('')
    increment_count_value = StringProperty('')
    incremental_interval = StringProperty('100')
    counter_max = StringProperty('128')
    counter_value = StringProperty('')
    counter_state = StringProperty('')
    counter_total_time = StringProperty('')
    queue_timeout_enabled = BooleanProperty(True)
    queue_timeout = StringProperty('1000')
    device_name = StringProperty('KivyBLETest')
    device_address = StringProperty('')
github slinger360 / NineRiFt-Lite / py9b / link / droidble.py View on Github external
class Fifo():
    def __init__(self):
        self.q = queue.Queue()

    def write(self, data): # put bytes
        for b in data:
            self.q.put(b)

    def read(self, size=1, timeout=None): # but read string
        res = ''
        for i in range(size):
            res += chr(self.q.get(True, timeout))
        return res


class ScootBT(BluetoothDispatcher):
    def __init__(self):
        super(ScootBT, self).__init__()
        self.rx_fifo = Fifo()
        self.ble_device = None
        self.state = StringProperty()
        self.dump = True
        self.tx_characteristic = None
        self.rx_characteristic = None
        self.timeout = SCAN_TIMEOUT
        self.set_queue_timeout(self.timeout)


    def __enter__(self):
        return self
github slinger360 / NineRiFt-Lite / py9b / link / bleandroid.py View on Github external
class Fifo():
	def __init__(self):
		self.q = Queue.Queue()

	def write(self, data): # put bytes
		for b in data:
			self.q.put(b)

	def read(self, size=1, timeout=None): # but read string
		res = ''
		for i in xrange(size):
			res += chr(self.q.get(True, timeout))
		return res

class NineBLE(BluetoothDispatcher):
	device = client_characteristic = receive_characteristic = transmit_characteristic = None
	address = ''

	def setaddr(self, a):
		global address
		address = a

	def discover(self):
		self.start_scan()
        self.state = 'scan'

	def on_device(self, device, rssi, advertisement):
		if self.state != 'scan':
			return
		Logger.debug("on_device event {}".format(list(advertisement)))
        scoot_found = False
github b3b / able / examples / alert / main.py View on Github external
"""Turn the alert on Mi Band device
"""
from kivy.app import App
from kivy.uix.button import Button

from able import BluetoothDispatcher, GATT_SUCCESS
from error_message import install_exception_handler


class BLE(BluetoothDispatcher):
    device = alert_characteristic = None

    def start_alert(self, *args, **kwargs):
        if self.alert_characteristic:  # alert service is already discovered
            self.alert(self.alert_characteristic)
        elif self.device:  # device is already founded during the scan
            self.connect_gatt(self.device)  # reconnect
        else:
            self.stop_scan()  # stop previous scan
            self.start_scan()  # start a scan for devices

    def on_device(self, device, rssi, advertisement):
        # some device is found during the scan
        name = device.getName()
        if name and name.startswith('MI'):  # is a Mi Band device
            self.device = device