Skip to content

Commit

Permalink
add client characteristic configuration editing; notifications work
Browse files Browse the repository at this point in the history
  • Loading branch information
andete committed Mar 6, 2014
1 parent a95e4a2 commit ee848cc
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 4 deletions.
1 change: 1 addition & 0 deletions ble.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,7 @@ def read_handles(self, handle, h1, h2):
self.send_command(self.ble.ble_cmd_attclient_read_by_handle(handle, h1))

def handle_attclient_attribute_value(self, sender, args):
print args
chandle = args['atthandle']
handle = args['connection']
t = args['type']
Expand Down
2 changes: 1 addition & 1 deletion data/bluetooth.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

Attr([0x29, 0x00], "Characteristic Extented Properties"),
Attr([0x29, 0x01], "Characteristic User Description", printers.String),
Attr([0x29, 0x02], "Client Characteristic Configuration"),
Attr([0x29, 0x02], "Client Characteristic Configuration", printers.ClientCharConf),
Attr([0x29, 0x03], "Server Characteristic Configuration"),
Attr([0x29, 0x04], "Characteristic Presentation Format"),
Attr([0x29, 0x05], "Characteristic Aggregate Format"),
Expand Down
55 changes: 52 additions & 3 deletions data/printers.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,10 @@ def printv(self, val):

class Bool(Default):

class BoolEditor(QtGui.QCheckBox):
class Editor(QtGui.QCheckBox):

def __init__(self, value):
super(Bool.BoolEditor, self).__init__("Enabled")
super(Bool.Editor, self).__init__("Enabled")
if str(value) == 'True':
self.setCheckState(Qt.Checked)
else:
Expand All @@ -67,4 +67,53 @@ def scanv(self, s):
return [0]

def editor(self):
return Bool.BoolEditor
return Bool.Editor

class ClientCharConf(Default):

n = "Notify"
i = "Indicate"

class Editor(QtGui.QWidget):

def __init__(self, c, value):
super(ClientCharConf.Editor, self).__init__()
self.n = c.n
self.i = c.i
vbox = QtGui.QVBoxLayout()
prop = c.scanv(value)[0]
notify = prop & 0x1 > 0
indicate = prop & 0x2 > 0
self.notify_edit = QtGui.QCheckBox(self.n)
self.indicate_edit = QtGui.QCheckBox(self.i)
self.notify_edit.setCheckState(Qt.Unchecked)
self.indicate_edit.setCheckState(Qt.Unchecked)
if notify:
self.notify_edit.setCheckState(Qt.Checked)
if indicate:
self.indicate_edit.setCheckState(Qt.Checked)
vbox.addWidget(self.notify_edit)
vbox.addWidget(self.indicate_edit)
self.setLayout(vbox)

def value(self):
props = []
if self.notify_edit.isChecked(): props += [self.n]
if self.indicate_edit.isChecked(): props += [self.i]
return '|'.join(props)

def printv(self, val):
prop = val[0]
props = []
if prop & 0x1 > 0: props += [self.n]
if prop & 0x2 > 0: props += [self.i]
return '|'.join(props)

def scanv(self, s):
v = 0
if self.n in s: v += 1
if self.i in s: v += 2
return [v, 0]

def editor(self):
return (lambda v: ClientCharConf.Editor(self, v))

0 comments on commit ee848cc

Please sign in to comment.