From e1277e4f4a250e245345d2471c6171c85079ec65 Mon Sep 17 00:00:00 2001 From: jbernardis Date: Tue, 19 May 2015 18:36:27 -0400 Subject: [PATCH] Configtool: move thermistor presets into distribution file. The problem was, that settings distributed in configtool.default.ini were overridden once a configtool.ini was created. Accordingly, users upgrading sources wouldn't see changes in this file. The solution is to move settings set by the distribution into a separate file which isn't replaced by a user-saved one. This should fix issue #142. --- configtool.default.ini | 20 -------------------- configtool/addsensordlg.py | 20 ++++++++++---------- configtool/boardpanel.py | 4 +--- configtool/sensorpage.py | 3 +-- configtool/settings.py | 21 --------------------- configtool/thermistorpresets.py | 18 ++++++++++++++++++ 6 files changed, 30 insertions(+), 56 deletions(-) create mode 100644 configtool/thermistorpresets.py diff --git a/configtool.default.ini b/configtool.default.ini index 97d1bf5..5c887ab 100644 --- a/configtool.default.ini +++ b/configtool.default.ini @@ -46,23 +46,3 @@ r1 = 0 numtemps = 25 maxadc = 1023 minadc = 0 - - -# Define thermistor presets. These can either be defined to use the -# beta argorithm by specifying 4 parameters: -# R0, beta, Rp, Vadc -# -# or to use the Steinhart-Hart algorithm by specifying 7 parameters: -# Rp, T0, R0, T1, R1, T2, R2 -# -# TODO: this should be moved into a file which isn't overridden by a local -# file (here: configtool.ini). Similar to config/protectedfiles.py. -[thermistors] -EPCOS 100K (B5754061104) = 100000, 4066, 4700, 5.0 -EPCOS 100K (B57560G1104F) = 100000, 4092, 4700, 5.0 -EPCOS 100K (B57560G104F) = 100000, 4036, 4700, 5.0 -RRRF 100K = 100000, 3960, 4700, 5.0 -RRRF 10K = 10000, 3964, 1600, 5.0 -RS 10K = 10000, 3480, 1600, 5.0 -Honeywell 100K = 100000, 3974, 4700, 5.0 -ATC Semitec 104GT-2 = 100000, 4267, 4700, 5.0 diff --git a/configtool/addsensordlg.py b/configtool/addsensordlg.py index cdd5df3..f68c369 100644 --- a/configtool/addsensordlg.py +++ b/configtool/addsensordlg.py @@ -2,6 +2,7 @@ import wx from configtool.data import (pinNames, BSIZESMALL, sensorTypes, offsetTcLabel, offsetChLabel, reInteger, reFloat) +from configtool.thermistorpresets import thermistorPresets MODE_NONTHERM = 0 MODE_THERMISTOR = 1 @@ -27,7 +28,6 @@ class AddSensorDlg(wx.Dialog): self.names = names self.choices = pins self.modify = modify - self.presets = parent.thermistorpresets if len(params) == 0: self.currentMethod = METHOD_BETA @@ -245,7 +245,7 @@ class AddSensorDlg(wx.Dialog): st.SetFont(font) lsz.Add(st, 1, wx.TOP, offsetTcLabel) - choices = [""] + sorted(self.presets.keys()) + choices = [""] + sorted(thermistorPresets.keys()) ch = wx.Choice(self, wx.ID_ANY, choices = choices) ch.SetFont(font) ch.Enable(False) @@ -621,14 +621,14 @@ class AddSensorDlg(wx.Dialog): s = ch.GetSelection() label = ch.GetString(s) if s != 0: - self.param0.SetValue(self.presets[label][0]) - self.param1.SetValue(self.presets[label][1]) - self.param2.SetValue(self.presets[label][2]) - self.param3.SetValue(self.presets[label][3]) - if len(self.presets[label]) == 7: - self.param4.SetValue(self.presets[label][4]) - self.param5.SetValue(self.presets[label][5]) - self.param6.SetValue(self.presets[label][5]) + self.param0.SetValue(thermistorPresets[label][0]) + self.param1.SetValue(thermistorPresets[label][1]) + self.param2.SetValue(thermistorPresets[label][2]) + self.param3.SetValue(thermistorPresets[label][3]) + if len(thermistorPresets[label]) == 7: + self.param4.SetValue(thermistorPresets[label][4]) + self.param5.SetValue(thermistorPresets[label][5]) + self.param6.SetValue(thermistorPresets[label][5]) self.currentMethod = METHOD_SH else: self.currentMethod = METHOD_BETA diff --git a/configtool/boardpanel.py b/configtool/boardpanel.py index f78c643..603705c 100644 --- a/configtool/boardpanel.py +++ b/configtool/boardpanel.py @@ -67,8 +67,7 @@ class BoardPanel(wx.Panel): self.pageValid.append(True) self.pgSensors = SensorsPage(self, self.nb, len(self.pages), - self.settings.font, - self.settings.thermistorpresets) + self.settings.font) text = "Temperature Sensors" self.nb.AddPage(self.pgSensors, text) self.pages.append(self.pgSensors) @@ -200,7 +199,6 @@ class BoardPanel(wx.Panel): if path is None: return - self.dir = os.path.dirname(path) rc = self.loadConfigFile(path) diff --git a/configtool/sensorpage.py b/configtool/sensorpage.py index 900fe93..4bf645d 100644 --- a/configtool/sensorpage.py +++ b/configtool/sensorpage.py @@ -7,12 +7,11 @@ from addsensordlg import AddSensorDlg class SensorsPage(wx.Panel, Page): - def __init__(self, parent, nb, idPg, font, thermistorpresets): + def __init__(self, parent, nb, idPg, font): wx.Panel.__init__(self, nb, wx.ID_ANY) Page.__init__(self, font) self.parent = parent self.font = font - self.thermistorpresets = thermistorpresets self.id = idPg self.sensorTypeKeys = {'TT_MAX6675': 'TEMP_MAX6675', diff --git a/configtool/settings.py b/configtool/settings.py index 0864e79..09ab8e9 100644 --- a/configtool/settings.py +++ b/configtool/settings.py @@ -29,8 +29,6 @@ class Settings: self.maxAdc = 1023 self.minAdc = 1 - self.thermistorpresets = {} - self.cfg = ConfigParser.ConfigParser() self.cfg.optionxform = str @@ -72,16 +70,6 @@ class Settings: else: print "Missing %s section - assuming defaults." % self.section - section = "thermistors" - if self.cfg.has_section(section): - for opt, value in self.cfg.items(section): - value = value.strip().replace(" ", "") - vl = value.split(",") - if len(vl) != 4 and len(vl) != 7: - print "Invalid entry for thermistor %s." % opt - else: - self.thermistorpresets[opt] = vl - def saveSettings(self): self.section = "configtool" try: @@ -102,15 +90,6 @@ class Settings: self.cfg.set(self.section, "minadc", str(self.minAdc)) self.cfg.set(self.section, "uploadspeed", str(self.uploadspeed)) - section = "thermistors" - try: - self.cfg.add_section(section) - except ConfigParser.DuplicateSectionError: - pass - - for t in self.thermistorpresets.keys(): - self.cfg.set(section, t, ", ".join(self.thermistorpresets[t])) - try: cfp = open(self.inifile, 'wb') except: diff --git a/configtool/thermistorpresets.py b/configtool/thermistorpresets.py new file mode 100644 index 0000000..b296eea --- /dev/null +++ b/configtool/thermistorpresets.py @@ -0,0 +1,18 @@ + +# Define thermistor presets. These can either be defined to use the +# beta argorithm by specifying 4 parameters: +# R0, beta, Rp, Vadc +# +# or to use the Steinhart-Hart algorithm by specifying 7 parameters: +# Rp, T0, R0, T1, R1, T2, R2 +# +thermistorPresets = { + "RS 10K": ['10000', '3480', '1600', '5.0'], + "RRRF 10K": ['10000', '3964', '1600', '5.0'], + "ATC Semitec 104GT-2": ['100000', '4267', '4700', '5.0'], + "EPCOS 100K (B57560G1104F)": ['100000', '4092', '4700', '5.0'], + "EPCOS 100K (B5754061104)": ['100000', '4066', '4700', '5.0'], + "EPCOS 100K (B57560G104F)": ['100000', '4036', '4700', '5.0'], + "Honeywell 100K": ['100000', '3974', '4700', '5.0'], + "RRRF 100K": ['100000', '3960', '4700', '5.0'], +}