Skip to content

Commit

Permalink
add write-dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
andete committed Mar 5, 2014
1 parent b321ff1 commit f7fbf5c
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 2 deletions.
5 changes: 5 additions & 0 deletions ble.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,4 +254,9 @@ def handle_attclient_attribute_value(self, sender, args):
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]))

def write_handle(self, handle, chandle, value):
self.send_command(self.ble.ble_cmd_attclient_write_command(handle, chandle, value))
time.sleep(0.1)
self.send_command(self.ble.ble_cmd_attclient_read_by_handle(handle, chandle))

34 changes: 33 additions & 1 deletion data/texas_instruments.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,35 @@
def ti_print_ir_temp(data):
ambient = (data[2] + 256*data[3])/128.0
# TODO target temp
return "%0.2f" % (ambient)


"""
private double extractTargetTemperature(BluetoothGattCharacteristic c, double ambient) {
Integer twoByteValue = shortSignedAtOffset(c, 0);
double Vobj2 = twoByteValue.doubleValue();
Vobj2 *= 0.00000015625;
double Tdie = ambient + 273.15;
double S0 = 5.593E-14; // Calibration factor
double a1 = 1.75E-3;
double a2 = -1.678E-5;
double b0 = -2.94E-5;
double b1 = -5.7E-7;
double b2 = 4.63E-9;
double c2 = 13.4;
double Tref = 298.15;
double S = S0*(1+a1*(Tdie - Tref)+a2*pow((Tdie - Tref),2));
double Vos = b0 + b1*(Tdie - Tref) + b2*pow((Tdie - Tref),2);
double fObj = (Vobj2 - Vos) + c2*pow((Vobj2 - Vos),2);
double tObj = pow(pow(Tdie,4) + (fObj/S),.25);
return tObj - 273.15;
}
"""

service = dict(
ti_st_1 = ([0xF0, 0x00, 0xAA, 0x00, 0x04, 0x51, 0x40, 0x00, 0xB0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], "TI IR Temperature Sensor"),
ti_st_2 = ([0xF0, 0x00, 0xAA, 0x10, 0x04, 0x51, 0x40, 0x00, 0xB0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], "TI Accelerometer"),
Expand All @@ -11,7 +43,7 @@
)

attr = dict(
ti_st_11 = ([0xF0, 0x00, 0xAA, 0x01, 0x04, 0x51, 0x40, 0x00, 0xB0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], "TI IR Temperature Sensor Data"),
ti_st_11 = ([0xF0, 0x00, 0xAA, 0x01, 0x04, 0x51, 0x40, 0x00, 0xB0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], "TI IR Temperature Sensor Data", ti_print_ir_temp),
ti_st_12 = ([0xF0, 0x00, 0xAA, 0x02, 0x04, 0x51, 0x40, 0x00, 0xB0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], "TI IR Temperature Sensor Configuration"),

ti_st_21 = ([0xF0, 0x00, 0xAA, 0x11, 0x04, 0x51, 0x40, 0x00, 0xB0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00], "TI Accelerometer Data"),
Expand Down
31 changes: 30 additions & 1 deletion gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,35 @@
#
# (c) 2014 Joost Yervante Damad <[email protected]>

import sys, time, datetime
import sys, time, datetime, ast

from PySide import QtGui, QtCore
from PySide.QtCore import Qt

import ble
from ble import BLE

class WriteDialog(QtGui.QDialog):

def __init__(self, parent, chandle, value=''):
super(WriteDialog, self).__init__(parent)
self.chandle = chandle
self.setWindowTitle("Write %d" % (chandle))
self.resize(640,160) # TODO, there must be a better way to do this
vbox = QtGui.QVBoxLayout()
fl = QtGui.QFormLayout()
self.value_edit = QtGui.QLineEdit()
self.value_edit.setText(str(value))
fl.addRow("Value:", self.value_edit)
vbox.addLayout(fl)
buttons = QtGui.QDialogButtonBox.Ok | QtGui.QDialogButtonBox.Cancel
self.button_box = QtGui.QDialogButtonBox(buttons, QtCore.Qt.Horizontal)
self.button_box.accepted.connect(self.accept)
self.button_box.rejected.connect(self.reject)
#self.button_box.button(QtGui.QDialogButtonBox.Ok).setDisabled(True)
vbox.addWidget(self.button_box)
self.setLayout(vbox)

class Device:

def __init__(self, ble, handle, mac):
Expand Down Expand Up @@ -73,6 +94,14 @@ def write(self):
if t == 'attr':
chandle = int(parent.child(self.current.row(), 3).data(Qt.DisplayRole))
print "write to ", chandle
try:
value = self.chandle_to_value_item[chandle].data(Qt.DisplayRole)
except:
value = ''
dialog = WriteDialog(self.view, chandle, value)
if dialog.exec_() != QtGui.QDialog.Accepted: return
value = ast.literal_eval(dialog.value_edit.text())
self.ble.write_handle(self.handle, chandle, value)

def primary(self):
self.type = 'primary'
Expand Down

0 comments on commit f7fbf5c

Please sign in to comment.