Skip to content

Commit

Permalink
add support for multi-read
Browse files Browse the repository at this point in the history
  • Loading branch information
andete committed Mar 5, 2014
1 parent 387526b commit b321ff1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
16 changes: 11 additions & 5 deletions ble.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ def __init__(self, baud_rate, packet_mode = False):
self.packet_mode = packet_mode
self.address = None
self.uuid = data.UUID()
self.handles_to_read = []

def address_response(self, sender, args):
self.address = ':'.join(['%02X' % b for b in args['address'][::-1]])
Expand Down Expand Up @@ -88,7 +89,7 @@ def start(self, port = None):
self.ble.packet_mode = self.packet_mode
self.ble.ble_rsp_system_address_get += self.address_response
ble = self.ble
ble.on_timeout += self.timeout
ble.on_timeout += self.on_timeout
ble.ble_evt_gap_scan_response += self.handle_scan_response
self.ser = serial.Serial(port=self.port, baudrate=self.baud_rate, timeout=1)
self.ser.flushInput()
Expand Down Expand Up @@ -129,7 +130,7 @@ def start(self, port = None):
def send_command(self, cmd):
return self.ble.send_command(self.ser, cmd)

def timeout(self, sender, args):
def on_timeout(self, sender, args):
# might want to try the following lines to reset, though it probably
# wouldn't work at this point if it's already timed out:
#ble.send_command(ser, ble.ble_cmd_system_reset(0))
Expand Down Expand Up @@ -239,13 +240,18 @@ def read_handle(self, handle, chandle):
self.send_command(self.ble.ble_cmd_attclient_read_by_handle(handle, chandle))

def read_handles(self, handle, h1, h2):
for x in range(h1, h2+1):
self.send_command(self.ble.ble_cmd_attclient_read_by_handle(handle, x))
self.handles_to_read = range(h1, h2+1)
self.send_command(self.ble.ble_cmd_attclient_read_by_handle(handle, h1))

def handle_attclient_attribute_value(self, sender, args):
chandle = args['atthandle']
handle = args['connection']
t = args['type']
value = args['value']
self.attr_value.emit(handle, chandle, t, value)
self.ble.check_activity(self.ser, 1)
if self.handles_to_read == []: return
if chandle in self.handles_to_read:
self.handles_to_read.remove(chandle)
if self.handles_to_read == []: return
self.send_command(self.ble.ble_cmd_attclient_read_by_handle(handle, self.handles_to_read[0]))

1 change: 1 addition & 0 deletions gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ def main():
QtCore.QCoreApplication.setOrganizationDomain("productize.be")
QtCore.QCoreApplication.setApplicationName("BTLE tool")
app = QtGui.QApplication(["BTLE tool"])
app.setWindowIcon(QtGui.QIcon('productize_icon.png'))
widget = MainWin()
widget.show()
return app.exec_()
Expand Down
Binary file added productize_icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit b321ff1

Please sign in to comment.