SHARE
TWEET

Untitled

a guest Sep 22nd, 2019 18 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. from network import Bluetooth
  2.  
  3. class BLEGATTSCharacteristic:
  4.     def __init__(self, name, uuid, prop, static_read=0, dynamic_read=None, dynamic_write=None):
  5.         self.name = name
  6.         self.uuid = uuid
  7.         self.static_read = static_read
  8.         self.dynamic_read = dynamic_read
  9.         self.dynamic_write = dynamic_write
  10.         self.prop = prop
  11.         self.bt_char_inst = None
  12.         self.bt_char_cb = None
  13.  
  14.     def _characteristic_callback(self,char):
  15.         events = char.events()
  16.         if events & Bluetooth.CHAR_WRITE_EVENT:
  17.             if self.dynamic_write:
  18.                 self.dynamic_write(self.name,self.uuid,char.value())
  19.         elif events & Bluetooth.CHAR_READ_EVENT:
  20.             if self.dynamic_read:
  21.                 return self.dynamic_read(self.name,self.uuid)
  22.             else:
  23.                 return self.static_read
  24.  
  25.     def setInstance(self, bt_char_inst):
  26.         self.bt_char_inst = bt_char_inst
  27.         if self.dynamic_read or self.dynamic_write:
  28.             self.bt_char_cb = self.bt_char_inst.callback(trigger=Bluetooth.CHAR_READ_EVENT|Bluetooth.CHAR_WRITE_EVENT, handler=self._characteristic_callback)
  29.  
  30.     def setValue(self, value):
  31.         if self.bt_char_inst:
  32.             #print ('char uuid 0x%02x = %s' % (self.uuid,str(value)))
  33.             self.bt_char_inst.value(value)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top