Commits

iorodeo committed b1d9f4c

Finished modifications to software so that the colorimeter can be used with the 'custom' LED PCB.

Comments (0)

Files changed (3)

python/Colorimeter/colorimeter/gui/measure/measure.py

         self.actionIncludeUserTestSolutions.setChecked(True)
         self.updateTestSolutionDicts()
         self.populateTestSolutionComboBox()
-        self.testSolutionComboBox.setCurrentIndex(
-                self.testSolutionIndex
-                )
+        self.testSolutionComboBox.setCurrentIndex(self.testSolutionIndex)
 
         self.setSampleUnits('um')
         self.updateWidgetEnabled()
     def updateTestSolution(self,index):
         if index <= 0:
             self.coeffLEDWidget.setEnabled(True)
+            if self.isStandardRgbLEDMode():
+                self.setLEDRadioButtonsEnabled(True)
+            else:
+                self.setLEDRadioButtonsEnabled(False)
             self.sampleUnitsActionGroup.setEnabled(True)
             self.coefficientLineEdit.setText("")
             self.coeff = None
                 self.coefficientLineEdit.setText('{0:1.1f}'.format(1.0e6*self.coeff))
             else:
                 self.coefficientLineEdit.setText(' -- nonlinear --')
-            self.setLEDColor(data['led'])
+            if data['led'] in constants.COLOR2LED_DICT:
+                self.setLEDColor(data['led'])
+            elif data['led'] == 'custom':
+                pass
+            else:
+                raise ValueError, 'unknown LED type {0}'.format(data['led'])
         self.testSolutionIndex = index
         self.updateWidgetEnabled()
 
             absorb = random.random()
             conc = self.getConcentration(absorb) 
         else:
-            freq, trans, absorb = self.dev.getMeasurement()
+            if self.isStandardRgbLEDMode():
+                freq, trans, absorb = self.dev.getMeasurement()
+                absorbValue = absorb[ledNumber]
+            else:
+                freq, trans, absorb = self.dev.getMeasurementBlue()
+                absorbValue = absorb
+
             try:
-                conc = self.getConcentration(absorb[ledNumber])
+                conc = self.getConcentration(absorbValue)
             except ValueError, err:
                 msgTitle = 'Range Error'
                 msgText = str(err)
 
     def getSaveFileHeader(self):
         timeStr = time.strftime('%Y-%m-%d %H:%M:%S %Z') 
+        if self.isStandardRgbLEDMode():
+            currentLED = self.currentColor
+        else:
+            currentLED = 'custom'
         headerList = [ 
                 '# {0}'.format(timeStr), 
                 '# Colorimeter Data', 
-                '# LED {0}'.format(self.currentColor),
+                '# LED {0}'.format(currentLED),
                 '# ----------------------------', 
                 '# Label    |    Concentration ',
                 ]
         plt.draw() 
 
     def updateTestSolutionDicts(self):
+        # User test solutions
         self.user_TestSolutionDict = self.loadUserTestSolutionDict()
+        self.user_TestSolutionDict = self.filterTestSolutionDict(
+                self.user_TestSolutionDict, 
+                self.getLEDMode()
+                )
+        # Default test solutinos
         self.default_TestSolutionDict = self.loadDefaultTestSolutionDict()
+        self.default_TestSolutionDict = self.filterTestSolutionDict(
+                self.default_TestSolutionDict,
+                self.getLEDMode()
+                )
+
+    def filterTestSolutionDict(self,testSolutionDict,mode):
+        newTestSolutionDict = {}
+        for testName,pathName in testSolutionDict.iteritems():
+            data = import_export.importTestSolutionData(pathName)
+            if (mode == 'standard') and (data['led'] in constants.COLOR2LED_DICT):
+                newTestSolutionDict[testName] = pathName
+            if (mode == 'custom') and (data['led'] == 'custom'):
+                newTestSolutionDict[testName] = pathName
+        return newTestSolutionDict
 
     def loadDefaultTestSolutionDict(self):
         return import_export.loadDefaultTestSolutionDict()
             for name in sorted(self.default_TestSolutionDict):
                 self.testSolutionComboBox.addItem(name)
 
-        if includeDflt and includeUser:
-            count = self.testSolutionComboBox.count()+1
-            self.testSolutionComboBox.insertSeparator(count)
-
         # Add user test solutions
         if includeUser:
             for name in sorted(self.user_TestSolutionDict):
             self.sampleUnits = units
         self.tableWidget.setHorizontalHeaderLabels(('Sample', concentrationStr)) 
 
+    def setLEDMode(self,value):
+        super(MeasureMainWindow,self).setLEDMode(value)
+        self.updateTestSolutionDicts()
+        self.populateTestSolutionComboBox()
+        self.updateTestSolution(1)
+
+    def setLEDRadioButtonsEnabled(self,value):
+        for color in constants.COLOR2LED_DICT:
+            button = getattr(self,'{0}RadioButton'.format(color))
+            button.setEnabled(value)
+
 def dataListToLabelAndFloat(dataList):
     dataListNew = []
     for x,y in dataList:

python/Colorimeter/colorimeter/gui/plot/plot.py

         solutionDict = dict(userSolutionDict.items() + dfltSolutionDict.items())
         data = TestSolutionDialog().importData(solutionDict)
         if data is not None:
+            if data['led'] in constants.COLOR2LED_DICT:     
+                self.setLEDMode('standard')
+                self.setLEDColor(data['led'])
+            elif data['led'] == 'custom':
+                self.setLEDMode('custom')
             self.setTableData(data['values'])
-            self.setLEDColor(data['led'])
             self.setFitType(data['fitType'],data['fitParams'])
             self.setConcentrationUnits(data['concentrationUnits'])
         self.updateWidgetEnabled()
                 import_export.deleteTestSolution(self.userHome,solutionName)
 
         dateStr = time.strftime('%Y-%m-%d %H:%M:%S %Z')
+
+        if self.isStandardRgbLEDMode():
+            currentLED = self.currentColor
+        else:
+            currentLED = 'custom'
+
         dataDict = { 
                 'name': solutionName,
                 'date': dateStr,
-                'led': self.currentColor,
+                'led': currentLED,
                 'values': [map(float,x) for x in dataList],
                 'fitType': fitType,
                 'concentrationUnits': self.getConcentrationUnits(),

python/Colorimeter/colorimeter/main_window.py

     def calibrateClicked_Callback(self):
         if not constants.DEVEL_FAKE_MEASURE: 
             try:
-                self.dev.calibrate()
+                if self.isStandardRgbLEDMode():
+                    self.dev.calibrate()
+                else:
+                    self.dev.calibrateBlue()
                 self.isCalibrated = True
             except IOError, e:
                 msgTitle = 'Calibration Error:'
     def isCustomLEDMode(self):
         return self.actionCustomLED.isChecked()
 
+    def getLEDMode(self):
+        if self.isStandardRgbLEDMode():
+            return 'standard'
+        else:
+            return 'custom'
+
     def haveData(self):
         return False