Commits

iorodeo committed f7e9e59

Added line edit widget so that users can enter their own capillary calibration in nL/mm.

Comments (0)

Files changed (4)

array_sensor_gui/array_reader.py

         super(ArrayReader,self).__init__(**kwargs)
         time.sleep(2.0)
 
+    def getFakeData(self):
+        fakeData = 800*pylab.ones((768,))
+        fakeData[:200] = 0.0*fakeData[:200]
+        return fakeData
+
     def getData(self):
         self.write('x\n')
         line_list = []

array_sensor_gui/array_sensor.py

 from array_sensor_ui import Ui_ArraySensorMainWindow
 from array_reader import ArrayReader
 
+FAKE_DATA_DEBUG = False
+
 # Conversions
-MM2NL = 5.0e3/54.8
+#MM2NL = 5.0e3/54.8
+DEFAULT_CALIBRATION = 5.0e3/54.8
 PIXEL2MM = 63.5e-3
 ADC2VOLTS = 5.0/1024.0
 
 BASELINE_PIXEL_LEVEL = 1.0
 DEFAULT_THRESHOLD = 1.5
 DETECTION_WINDOW = 15
-SENSOR_RANGE_NL = NUM_PIXEL*PIXEL2MM*MM2NL
+#SENSOR_RANGE_NL = NUM_PIXEL*PIXEL2MM*MM2NL
+#SENSOR_RANGE_NL = NUM_PIXEL*PIXEL2MM*DEFAULT_CALIBRATION
 
 class Sensor_MainWindow(QtGui.QMainWindow, Ui_ArraySensorMainWindow):
 
         self.startLogPushButton.clicked.connect(self.startLog_Callback)
         self.debugRadioButton.clicked.connect(self.debug_Callback)
         self.stopLogPushButton.clicked.connect(self.stopLog_Callback)
+        self.calibrationLineEdit.editingFinished.connect(self.calibrationLineEdit_Callback)
 
     def setupTimer(self):
         """
             self.port = 'com1'
         self.serialPortLineEdit.setText(self.port)
 
+        # Set capillary calibration
+        self.calibration = DEFAULT_CALIBRATION 
+        self.calibrationLineEdit.setText('%1.3f'%(self.calibration,))
+
+
         #  Initialize plot
         self.pixelPlot, = self.mpl.canvas.ax.plot([],[],linewidth=2)
         self.levelPlot, = self.mpl.canvas.ax.plot([0],[0],'or')
 
         # Get time and sensor data
         currentTime  = time.time()
-        data = self.sensor.getData()
+
+        if FAKE_DATA_DEBUG: 
+            data = self.sensor.getFakeData()
+        else:
+            data = self.sensor.getData()
+
         if data is None:
             return 
 
         if rval:
             ind, value = rval
             pixel_pos = ind*PIXEL2MM
-            fluid_level = SENSOR_RANGE_NL - pixel_pos*MM2NL
+            #fluid_level = SENSOR_RANGE_NL - pixel_pos*MM2NL
+            fluid_level = self.getSensorRange() - pixel_pos*self.calibration
             self.levelLabel.setText('Fluid Level: %1.0f(nl)'%(fluid_level,))
             self.levelPlot.set_visible(True)
             self.levelPlot.set_data([pixel_pos],[value])
             return
         self.thresholdLineEdit.setText('%1.2f'%(self.threshold,))
 
+    def calibrationLineEdit_Callback(self):
+        """
+        Set capillary calibration
+        """
+        calibrationStr = str(self.calibrationLineEdit.text())
+        try:
+            calibration = float(calibrationStr)
+            self.calibration = calibration
+        except ValueError, e:
+            QtGui.QMessageBox.critical(self,'Error', 'Input must be a float, %s'%(e,))
+            return
+        self.calibrationLineEdit.setText('%1.3f'%(self.calibration,))
+
+
     def debug_Callback(self):
         """
         For setting up debuging data
         self.logging = False
         self.enableDisableWidgets()
 
+    def getSensorRange(self):
+        return NUM_PIXEL*PIXEL2MM*self.calibration
+        
+
     def main(self):
         self.show()
 

array_sensor_gui/array_sensor.ui

    <rect>
     <x>0</x>
     <y>0</y>
-    <width>751</width>
-    <height>684</height>
+    <width>700</width>
+    <height>699</height>
    </rect>
   </property>
   <property name="sizePolicy">
         </spacer>
        </item>
        <item>
-        <widget class="QLabel" name="label_2">
-         <property name="text">
-          <string>Threshold</string>
-         </property>
-        </widget>
-       </item>
-       <item>
-        <widget class="QLineEdit" name="thresholdLineEdit">
-         <property name="sizePolicy">
-          <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
-           <horstretch>0</horstretch>
-           <verstretch>0</verstretch>
-          </sizepolicy>
-         </property>
-         <property name="maximumSize">
-          <size>
-           <width>80</width>
-           <height>16777215</height>
-          </size>
-         </property>
-        </widget>
-       </item>
-       <item>
         <spacer name="horizontalSpacer">
          <property name="orientation">
           <enum>Qt::Horizontal</enum>
      </widget>
     </item>
     <item>
+     <widget class="QFrame" name="frame_5">
+      <property name="frameShape">
+       <enum>QFrame::StyledPanel</enum>
+      </property>
+      <property name="frameShadow">
+       <enum>QFrame::Raised</enum>
+      </property>
+      <layout class="QHBoxLayout" name="horizontalLayout_4">
+       <item>
+        <widget class="QLabel" name="label_2">
+         <property name="text">
+          <string>Threshold</string>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <widget class="QLineEdit" name="thresholdLineEdit">
+         <property name="sizePolicy">
+          <sizepolicy hsizetype="Fixed" vsizetype="Fixed">
+           <horstretch>0</horstretch>
+           <verstretch>0</verstretch>
+          </sizepolicy>
+         </property>
+         <property name="maximumSize">
+          <size>
+           <width>80</width>
+           <height>16777215</height>
+          </size>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <spacer name="horizontalSpacer_7">
+         <property name="orientation">
+          <enum>Qt::Horizontal</enum>
+         </property>
+         <property name="sizeType">
+          <enum>QSizePolicy::Fixed</enum>
+         </property>
+         <property name="sizeHint" stdset="0">
+          <size>
+           <width>65</width>
+           <height>20</height>
+          </size>
+         </property>
+        </spacer>
+       </item>
+       <item>
+        <widget class="QLabel" name="label_3">
+         <property name="text">
+          <string>Calibration (nL/mm)</string>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <widget class="QLineEdit" name="calibrationLineEdit">
+         <property name="maximumSize">
+          <size>
+           <width>80</width>
+           <height>16777215</height>
+          </size>
+         </property>
+        </widget>
+       </item>
+       <item>
+        <spacer name="horizontalSpacer_8">
+         <property name="orientation">
+          <enum>Qt::Horizontal</enum>
+         </property>
+         <property name="sizeHint" stdset="0">
+          <size>
+           <width>40</width>
+           <height>20</height>
+          </size>
+         </property>
+        </spacer>
+       </item>
+      </layout>
+     </widget>
+    </item>
+    <item>
      <widget class="QFrame" name="frame_2">
       <property name="sizePolicy">
        <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
     <rect>
      <x>0</x>
      <y>0</y>
-     <width>751</width>
+     <width>700</width>
      <height>23</height>
     </rect>
    </property>

array_sensor_gui/array_sensor_ui.py

 
 # Form implementation generated from reading ui file 'array_sensor.ui'
 #
-# Created: Mon Aug 15 12:39:32 2011
+# Created: Wed Aug 17 13:58:57 2011
 #      by: PyQt4 UI code generator 4.7.2
 #
 # WARNING! All changes made in this file will be lost!
 class Ui_ArraySensorMainWindow(object):
     def setupUi(self, ArraySensorMainWindow):
         ArraySensorMainWindow.setObjectName("ArraySensorMainWindow")
-        ArraySensorMainWindow.resize(751, 684)
+        ArraySensorMainWindow.resize(700, 699)
         sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Preferred)
         sizePolicy.setHorizontalStretch(0)
         sizePolicy.setVerticalStretch(0)
         self.horizontalLayout_3.addWidget(self.serialPortLineEdit)
         spacerItem2 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
         self.horizontalLayout_3.addItem(spacerItem2)
-        self.label_2 = QtGui.QLabel(self.frame_3)
-        self.label_2.setObjectName("label_2")
-        self.horizontalLayout_3.addWidget(self.label_2)
-        self.thresholdLineEdit = QtGui.QLineEdit(self.frame_3)
-        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
-        sizePolicy.setHorizontalStretch(0)
-        sizePolicy.setVerticalStretch(0)
-        sizePolicy.setHeightForWidth(self.thresholdLineEdit.sizePolicy().hasHeightForWidth())
-        self.thresholdLineEdit.setSizePolicy(sizePolicy)
-        self.thresholdLineEdit.setMaximumSize(QtCore.QSize(80, 16777215))
-        self.thresholdLineEdit.setObjectName("thresholdLineEdit")
-        self.horizontalLayout_3.addWidget(self.thresholdLineEdit)
         spacerItem3 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
         self.horizontalLayout_3.addItem(spacerItem3)
         self.startPushButton = QtGui.QPushButton(self.frame_3)
         self.stopPushButton.setObjectName("stopPushButton")
         self.horizontalLayout_3.addWidget(self.stopPushButton)
         self.verticalLayout_3.addWidget(self.frame_3)
+        self.frame_5 = QtGui.QFrame(self.centralwidget)
+        self.frame_5.setFrameShape(QtGui.QFrame.StyledPanel)
+        self.frame_5.setFrameShadow(QtGui.QFrame.Raised)
+        self.frame_5.setObjectName("frame_5")
+        self.horizontalLayout_4 = QtGui.QHBoxLayout(self.frame_5)
+        self.horizontalLayout_4.setObjectName("horizontalLayout_4")
+        self.label_2 = QtGui.QLabel(self.frame_5)
+        self.label_2.setObjectName("label_2")
+        self.horizontalLayout_4.addWidget(self.label_2)
+        self.thresholdLineEdit = QtGui.QLineEdit(self.frame_5)
+        sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Fixed)
+        sizePolicy.setHorizontalStretch(0)
+        sizePolicy.setVerticalStretch(0)
+        sizePolicy.setHeightForWidth(self.thresholdLineEdit.sizePolicy().hasHeightForWidth())
+        self.thresholdLineEdit.setSizePolicy(sizePolicy)
+        self.thresholdLineEdit.setMaximumSize(QtCore.QSize(80, 16777215))
+        self.thresholdLineEdit.setObjectName("thresholdLineEdit")
+        self.horizontalLayout_4.addWidget(self.thresholdLineEdit)
+        spacerItem4 = QtGui.QSpacerItem(65, 20, QtGui.QSizePolicy.Fixed, QtGui.QSizePolicy.Minimum)
+        self.horizontalLayout_4.addItem(spacerItem4)
+        self.label_3 = QtGui.QLabel(self.frame_5)
+        self.label_3.setObjectName("label_3")
+        self.horizontalLayout_4.addWidget(self.label_3)
+        self.calibrationLineEdit = QtGui.QLineEdit(self.frame_5)
+        self.calibrationLineEdit.setMaximumSize(QtCore.QSize(80, 16777215))
+        self.calibrationLineEdit.setObjectName("calibrationLineEdit")
+        self.horizontalLayout_4.addWidget(self.calibrationLineEdit)
+        spacerItem5 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
+        self.horizontalLayout_4.addItem(spacerItem5)
+        self.verticalLayout_3.addWidget(self.frame_5)
         self.frame_2 = QtGui.QFrame(self.centralwidget)
         sizePolicy = QtGui.QSizePolicy(QtGui.QSizePolicy.Preferred, QtGui.QSizePolicy.Fixed)
         sizePolicy.setHorizontalStretch(0)
         self.saveBackgroundPushButton.setObjectName("saveBackgroundPushButton")
         self.verticalLayout_5.addWidget(self.saveBackgroundPushButton)
         self.horizontalLayout_5.addLayout(self.verticalLayout_5)
-        spacerItem4 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
-        self.horizontalLayout_5.addItem(spacerItem4)
+        spacerItem6 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
+        self.horizontalLayout_5.addItem(spacerItem6)
         self.verticalLayout_6 = QtGui.QVBoxLayout()
         self.verticalLayout_6.setObjectName("verticalLayout_6")
         self.setLogPushButton = QtGui.QPushButton(self.frame_2)
         self.logFileLabel = QtGui.QLabel(self.frame_4)
         self.logFileLabel.setObjectName("logFileLabel")
         self.horizontalLayout_2.addWidget(self.logFileLabel)
-        spacerItem5 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
-        self.horizontalLayout_2.addItem(spacerItem5)
+        spacerItem7 = QtGui.QSpacerItem(40, 20, QtGui.QSizePolicy.Expanding, QtGui.QSizePolicy.Minimum)
+        self.horizontalLayout_2.addItem(spacerItem7)
         self.verticalLayout_3.addWidget(self.frame_4)
         ArraySensorMainWindow.setCentralWidget(self.centralwidget)
         self.menubar = QtGui.QMenuBar(ArraySensorMainWindow)
-        self.menubar.setGeometry(QtCore.QRect(0, 0, 751, 23))
+        self.menubar.setGeometry(QtCore.QRect(0, 0, 700, 23))
         self.menubar.setObjectName("menubar")
         ArraySensorMainWindow.setMenuBar(self.menubar)
         self.statusbar = QtGui.QStatusBar(ArraySensorMainWindow)
         self.debugRadioButton.setText(QtGui.QApplication.translate("ArraySensorMainWindow", "debug", None, QtGui.QApplication.UnicodeUTF8))
         self.label.setText(QtGui.QApplication.translate("ArraySensorMainWindow", "Serial Port", None, QtGui.QApplication.UnicodeUTF8))
         self.serialPortLineEdit.setToolTip(QtGui.QApplication.translate("ArraySensorMainWindow", "set serial port address", None, QtGui.QApplication.UnicodeUTF8))
-        self.label_2.setText(QtGui.QApplication.translate("ArraySensorMainWindow", "Threshold", None, QtGui.QApplication.UnicodeUTF8))
         self.startPushButton.setToolTip(QtGui.QApplication.translate("ArraySensorMainWindow", "start acquiring data from sensor", None, QtGui.QApplication.UnicodeUTF8))
         self.startPushButton.setText(QtGui.QApplication.translate("ArraySensorMainWindow", "        Start      ", None, QtGui.QApplication.UnicodeUTF8))
         self.stopPushButton.setToolTip(QtGui.QApplication.translate("ArraySensorMainWindow", "stop acquisition form sensor", None, QtGui.QApplication.UnicodeUTF8))
         self.stopPushButton.setText(QtGui.QApplication.translate("ArraySensorMainWindow", "       Stop        ", None, QtGui.QApplication.UnicodeUTF8))
+        self.label_2.setText(QtGui.QApplication.translate("ArraySensorMainWindow", "Threshold", None, QtGui.QApplication.UnicodeUTF8))
+        self.label_3.setText(QtGui.QApplication.translate("ArraySensorMainWindow", "Calibration (nL/mm)", None, QtGui.QApplication.UnicodeUTF8))
         self.takeBackgroundPushButton.setToolTip(QtGui.QApplication.translate("ArraySensorMainWindow", "take background reading of capillary for equalization", None, QtGui.QApplication.UnicodeUTF8))
         self.takeBackgroundPushButton.setText(QtGui.QApplication.translate("ArraySensorMainWindow", "Take Background", None, QtGui.QApplication.UnicodeUTF8))
         self.loadBackgroundPushButton.setToolTip(QtGui.QApplication.translate("ArraySensorMainWindow", "load background reading from file", None, QtGui.QApplication.UnicodeUTF8))