コード例 #1
0
ファイル: boardpanel.py プロジェクト: pezr/Teacup_Firmware
    def saveConfigFile(self, path):
        if os.path.basename(path) in protectedFiles:
            dlg = wx.MessageDialog(
                self, "It's not allowed to overwrite files "
                "distributed by Teacup. Choose another name.",
                "Protected file error", wx.OK + wx.ICON_ERROR)
            dlg.ShowModal()
            dlg.Destroy()
            return False

        if not os.path.basename(path).startswith("board."):
            dlg = wx.MessageDialog(
                self, "Illegal file name: %s.\n"
                "File name must begin with \"board.\"" % path,
                "Illegal file name", wx.OK + wx.ICON_ERROR)
            dlg.ShowModal()
            dlg.Destroy()
            return False

        ext = os.path.splitext(os.path.basename(path))[1]
        self.dir = os.path.dirname(path)

        if ext == "":
            path += ".h"

        try:
            fp = file(path, 'w')
        except:
            dlg = wx.MessageDialog(self, "Unable to write to file %s." % path,
                                   "File error", wx.OK + wx.ICON_ERROR)
            dlg.ShowModal()
            dlg.Destroy()
            return False

        self.configFile = path

        values = {}

        for pg in self.pages:
            v1 = pg.getValues()
            for k in v1.keys():
                values[k] = v1[k]

        skipToSensorEnd = False
        skipToHeaterEnd = False
        candThermPinsWritten = False
        candHeatPinsWritten = False
        candProcessorsWritten = False
        candCPUClocksWritten = False

        for ln in self.cfgBuffer:
            m = reStartSensors.match(ln)
            if m:
                fp.write(ln)
                fp.write("//                 name      type           pin    "
                         "additional\n")
                ttString = "\n"
                ttString += "// Beta algorithm      r0      beta  r2    vadc\n"
                ttString += "// Steinhart-Hart      rp      t0    r0      t1    "
                ttString += "r1      t2    r2\n"
                for s in self.sensors:
                    sstr = "%-10s%-15s%-7s" % ((s[0] + ","), (s[1] + ","),
                                               (s[2] + ","))
                    if s[3] is None:
                        sstr += "0"
                    else:
                        sstr += "THERMISTOR_%s" % s[0].upper()
                        tt = s[3]
                        if len(tt) == 4:
                            ttString += "//TEMP_TABLE %-8s (%-8s%-6s%-6s%s)\n" % \
                                        (s[0].upper(), (tt[0] + ","), (tt[1] + ","),
                                         (tt[2] + ","), tt[3])
                        else:
                            ttString += "//TEMP_TABLE %-8s (%-8s%-6s%-8s%-6s%-8s%-6s%s)\n" % \
                                        (s[0].upper(), (tt[0] + ","), (tt[1] + ","),
                                         (tt[2] + ","), (tt[3] + ","), (tt[4] + ","),
                                         (tt[5] + ","), tt[6])
                    fp.write("DEFINE_TEMP_SENSOR(%s)\n" % sstr)
                fp.write(ttString)
                skipToSensorEnd = True
                continue

            if skipToSensorEnd:
                m = reEndSensors.match(ln)
                if m:
                    fp.write(ln)
                    skipToSensorEnd = False
                continue

            m = reStartHeaters.match(ln)
            if m:
                fp.write(ln)
                fp.write("//            name      pin      invert  pwm\n")
                for s in self.heaters:
                    sstr = "%-10s%-9s%-8s%s" % ((s[0] + ","), (s[1] + ","),
                                                (s[2] + ","), s[3])
                    fp.write("DEFINE_HEATER(%s)\n" % sstr)
                fp.write("\n")
                for s in self.heaters:
                    fp.write(defineHeaterFormat % (s[0].upper(), s[0]))
                skipToHeaterEnd = True
                continue

            if skipToHeaterEnd:
                m = reEndHeaters.match(ln)
                if m:
                    fp.write(ln)
                    skipToHeaterEnd = False
                continue

            if reCandThermPins.match(ln):
                if not candThermPinsWritten:
                    for pin in self.candThermPins:
                        fp.write("//#define TEMP_SENSOR_PIN " + pin + "\n")
                    candThermPinsWritten = True
                continue

            if reCandHeatPins.match(ln):
                if not candHeatPinsWritten:
                    for pin in self.candHeatPins:
                        fp.write("//#define HEATER_PIN " + pin + "\n")
                    candHeatPinsWritten = True
                continue

            if reCandProcessors.match(ln):
                if not candProcessorsWritten:
                    for pin in self.candProcessors:
                        fp.write("//#define CPU_TYPE " + pin + "\n")
                    candProcessorsWritten = True
                continue

            if reCandCPUClocks.match(ln):
                if not candCPUClocksWritten:
                    for pin in self.candClocks:
                        fp.write("//#define F_CPU_OPT " + pin + "\n")
                    candCPUClocksWritten = True
                continue

            m = reDefine.match(ln)
            if m:
                t = m.groups()
                if len(t) == 2 and t[0] in values.keys():
                    v = values[t[0]]
                    self.cfgValues[t[0]] = v
                    if v[1] == False:
                        fp.write("//")
                    fp.write(defineValueFormat % (t[0], v[0]))
                else:
                    print "Value key " + t[0] + " not found in GUI."

                continue

            m = reDefBoolBL.match(ln)
            if m:
                t = m.groups()
                if len(t) == 1 and t[0] in values.keys():
                    v = values[t[0]]
                    self.cfgValues[t[0]] = v
                    if v == "" or v == False:
                        fp.write("//")
                    fp.write(defineBoolFormat % t[0])
                else:
                    if t[0] == 'MOTHERBOARD':
                        # Known to be absent in the GUI, also won't be added anytime soon.
                        fp.write(ln)
                    else:
                        print "Boolean key " + t[0] + " not found in GUI."

                continue

            fp.write(ln)

        fp.close()
        return self.generateTempTables()
コード例 #2
0
    def saveConfigFile(self, path, values):
        if not values:
            values = self.cfgValues

        if self.settings.verbose >= 1:
            print("Saving board: %s." % path)
        if self.settings.verbose >= 2:
            print(values)

        fp = open(path, "w")
        self.configFile = path

        skipToSensorEnd = False
        skipToHeaterEnd = False
        candThermPinsWritten = False
        candHeatPinsWritten = False
        candProcessorsWritten = False
        candCPUClocksWritten = False

        for ln in self.cfgBuffer:
            m = reStartSensors.match(ln)
            if m:
                fp.write(ln)
                fp.write(
                    "//                 name      type           pin    " "additional\n"
                )
                ttString = "\n"
                ttString += "// Beta algorithm      r0      beta  r2    vadc\n"
                ttString += "// Steinhart-Hart      rp      t0    r0      t1    "
                ttString += "r1      t2    r2\n"
                for s in self.sensors:
                    sstr = "%-10s%-15s%-7s" % ((s[0] + ","), (s[1] + ","), (s[2] + ","))
                    if s[3] is None:
                        sstr += "0"
                    else:
                        sstr += "THERMISTOR_%s" % s[0].upper()
                        tt = s[3]
                        if len(tt) == 4:
                            ttString += "//TEMP_TABLE %-8s (%-8s%-6s%-6s%s)\n" % (
                                s[0].upper(),
                                (tt[0] + ","),
                                (tt[1] + ","),
                                (tt[2] + ","),
                                tt[3],
                            )
                        else:
                            ttString += (
                                "//TEMP_TABLE %-8s (%-8s%-6s%-8s%-6s%-8s%-6s%s)\n"
                                % (
                                    s[0].upper(),
                                    (tt[0] + ","),
                                    (tt[1] + ","),
                                    (tt[2] + ","),
                                    (tt[3] + ","),
                                    (tt[4] + ","),
                                    (tt[5] + ","),
                                    tt[6],
                                )
                            )
                    fp.write("DEFINE_TEMP_SENSOR(%s)\n" % sstr)
                fp.write(ttString)
                skipToSensorEnd = True
                continue

            if skipToSensorEnd:
                m = reEndSensors.match(ln)
                if m:
                    fp.write(ln)
                    skipToSensorEnd = False
                continue

            m = reStartHeaters.match(ln)
            if m:
                fp.write(ln)
                fp.write("//            name      pin      invert  pwm     max_pwm\n")
                for s in self.heaters:
                    sstr = "%-10s%-9s%-8s%-7s%s" % (
                        (s[0] + ","),
                        (s[1] + ","),
                        (s[2] + ","),
                        s[3] + ",",
                        s[4],
                    )
                    fp.write("DEFINE_HEATER(%s)\n" % sstr)
                fp.write("\n")
                for s in self.heaters:
                    fp.write(defineHeaterFormat % (s[0].upper(), s[0]))
                skipToHeaterEnd = True
                continue

            if skipToHeaterEnd:
                m = reEndHeaters.match(ln)
                if m:
                    fp.write(ln)
                    skipToHeaterEnd = False
                continue

            if reCandThermPins.match(ln):
                if not candThermPinsWritten:
                    for pin in self.candThermPins:
                        fp.write("//#define TEMP_SENSOR_PIN " + pin + "\n")
                    candThermPinsWritten = True
                continue

            if reCandHeatPins.match(ln):
                if not candHeatPinsWritten:
                    for pin in self.candHeatPins:
                        fp.write("//#define HEATER_PIN " + pin + "\n")
                    candHeatPinsWritten = True
                continue

            if reCandProcessors.match(ln):
                if not candProcessorsWritten:
                    for pin in self.candProcessors:
                        fp.write("//#define CPU_TYPE " + pin + "\n")
                    candProcessorsWritten = True
                continue

            if reCandCPUClocks.match(ln):
                if not candCPUClocksWritten:
                    for pin in self.candClocks:
                        fp.write("//#define F_CPU_OPT " + pin + "\n")
                    candCPUClocksWritten = True
                continue

            m = reDefine.match(ln)
            if m:
                t = m.groups()
                if len(t) == 2 and t[0] in values.keys():
                    v = values[t[0]]
                    self.cfgValues[t[0]] = v
                    if v[1] == False:
                        fp.write("//")
                    fp.write(defineValueFormat % (t[0], v[0]))
                else:
                    if t[0] == "RX_ENABLE_PIN" or t[0] == "TX_ENABLE_PIN":
                        # Known to be absent in the GUI, also won't be added anytime soon.
                        fp.write(ln)
                    else:
                        print("Value key " + t[0] + " not found in GUI.")

                continue

            m = reDefBoolBL.match(ln)
            if m:
                t = m.groups()
                if len(t) == 1 and t[0] in values.keys():
                    v = values[t[0]]
                    self.cfgValues[t[0]] = v
                    if v == "" or v == False:
                        fp.write("//")
                    fp.write(defineBoolFormat % t[0])
                else:
                    if t[0] == "MOTHERBOARD":
                        # Known to be absent in the GUI, also won't be added anytime soon.
                        fp.write(ln)
                    else:
                        print("Boolean key " + t[0] + " not found in GUI.")

                continue

            fp.write(ln)

        fp.close()

        return True
コード例 #3
0
ファイル: boardpanel.py プロジェクト: benj919/Teacup_Firmware
  def saveConfigFile(self, path):
    if os.path.basename(path) in protectedFiles:
      dlg = wx.MessageDialog(self, "It's not allowed to overwrite files "
                             "distributed by Teacup. Choose another name.",
                             "Protected file error", wx.OK + wx.ICON_ERROR)
      dlg.ShowModal()
      dlg.Destroy()
      return False

    if not os.path.basename(path).startswith("board."):
      dlg = wx.MessageDialog(self, "Illegal file name: %s.\n"
                                   "File name must begin with \"board.\"" % path,
                             "Illegal file name", wx.OK + wx.ICON_ERROR)
      dlg.ShowModal()
      dlg.Destroy()
      return False

    ext = os.path.splitext(os.path.basename(path))[1]
    self.dir = os.path.dirname(path)

    if ext == "":
      path += ".h"

    try:
      fp = file(path, 'w')
    except:
      dlg = wx.MessageDialog(self, "Unable to write to file %s." % path,
                             "File error", wx.OK + wx.ICON_ERROR)
      dlg.ShowModal()
      dlg.Destroy()
      return False

    self.configFile = path

    values = {}

    for pg in self.pages:
      v1 = pg.getValues()
      for k in v1.keys():
        values[k] = v1[k]

    skipToSensorEnd = False
    skipToHeaterEnd = False
    tempTables = {}
    candThermPinsWritten = False
    candHeatPinsWritten = False
    candProcessorsWritten = False
    candCPUClocksWritten = False
    for ln in self.cfgBuffer:
      m = reStartSensors.match(ln)
      if m:
        fp.write(ln)
        fp.write("//                 name      type           pin    "
                 "additional\n");
        ttString = "\n"
        ttString += "// Beta algorithm      r0      beta  r2    vadc\n"
        ttString += "// Steinhart-Hart      rp      t0    r0      t1    "
        ttString += "r1      t2    r2\n"
        for s in self.sensors:
          sstr = "%-10s%-15s%-7s" % ((s[0] + ","), (s[1] + ","), (s[2] + ","))
          if s[3] is None:
            sstr += "0"
          else:
            sstr += "THERMISTOR_%s" % s[0].upper()
            tt = s[3]
            if len(tt) == 4:
              ttString += "//TEMP_TABLE %-8s (%-8s%-6s%-6s%s)\n" % \
                          (s[0].upper(), (tt[0] + ","), (tt[1] + ","),
                           (tt[2] + ","), tt[3])
            else:
              ttString += "//TEMP_TABLE %-8s (%-8s%-6s%-8s%-6s%-8s%-6s%s)\n" % \
                          (s[0].upper(), (tt[0] + ","), (tt[1] + ","),
                           (tt[2] + ","), (tt[3] + ","), (tt[4] + ","),
                           (tt[5] + ","), tt[6])
          fp.write("DEFINE_TEMP_SENSOR(%s)\n" % sstr)
        fp.write(ttString)
        skipToSensorEnd = True
        continue

      if skipToSensorEnd:
        m = reEndSensors.match(ln)
        if m:
          fp.write(ln)
          skipToSensorEnd = False
        continue

      m = reStartHeaters.match(ln)
      if m:
        fp.write(ln)
        fp.write("//            name      port   pwm\n")
        for s in self.heaters:
          sstr = "%-10s%-7s%s" % ((s[0] + ","), (s[1] + ","), s[2])
          fp.write("DEFINE_HEATER(%s)\n" % sstr)
        fp.write("\n")
        for s in self.heaters:
          fp.write(defineHeaterFormat % (s[0].upper(), s[0]))
        skipToHeaterEnd = True
        continue

      if skipToHeaterEnd:
        m = reEndHeaters.match(ln)
        if m:
          fp.write(ln)
          skipToHeaterEnd = False
        continue

      if reCandThermPins.match(ln):
        if not candThermPinsWritten:
          for pin in self.candThermPins:
            fp.write("//#define TEMP_SENSOR_PIN " + pin + "\n")
          candThermPinsWritten = True
        continue

      if reCandHeatPins.match(ln):
        if not candHeatPinsWritten:
          for pin in self.candHeatPins:
            fp.write("//#define HEATER_PIN " + pin + "\n")
          candHeatPinsWritten = True
        continue

      if reCandProcessors.match(ln):
        if not candProcessorsWritten:
          for pin in self.candProcessors:
            fp.write("//#define CPU_TYPE " + pin + "\n")
          candProcessorsWritten = True
        continue

      if reCandCPUClocks.match(ln):
        if not candCPUClocksWritten:
          for pin in self.candClocks:
            fp.write("//#define F_CPU_OPT " + pin + "\n")
          candCPUClocksWritten = True
        continue

      m = reDefine.match(ln)
      if m:
        t = m.groups()
        if len(t) == 2 and t[0] in values.keys():
          v = values[t[0]]
          self.cfgValues[t[0]] = v
          if v[1] == False:
            fp.write("//")
          fp.write(defineValueFormat % (t[0], v[0]))
        else:
            if t[0] == 'TX_ENABLE_PIN' or t[0] == 'RX_ENABLE_PIN':
                # Known to be absent in the GUI, probably won't be added anytime soon.
                fp.write(ln)
            else:
                print "Value key " + t[0] + " not found in GUI."

        continue

      m = reDefBoolBL.match(ln)
      if m:
        t = m.groups()
        if len(t) == 1 and t[0] in values.keys():
          v = values[t[0]]
          self.cfgValues[t[0]] = v
          if v == "" or v == False:
            fp.write("//")
          fp.write(defineBoolFormat % t[0])
        else:
          if t[0] == 'MOTHERBOARD':
            # Known to be absent in the GUI, also won't be added anytime soon.
            fp.write(ln)
          else:
            print "Boolean key " + t[0] + " not found in GUI."

        continue

      fp.write(ln)

    fp.close()
    return self.generateTempTables()
コード例 #4
0
ファイル: printer.py プロジェクト: yo2mpn/Teacup_Firmware
    def saveConfigFile(self, path, values):
        if not values:
            values = self.cfgValues

        if self.settings.verbose >= 1:
            print("Saving printer: %s." % path)
        if self.settings.verbose >= 2:
            print values

        fp = file(path, 'w')
        self.configFile = path

        for ln in self.cfgBuffer:
            m = reDefine.match(ln)
            if m:
                t = m.groups()
                if len(t) == 2 and t[0] in values.keys():
                    v = values[t[0]]
                    self.cfgValues[t[0]] = v
                    if v[1] == False:
                        fp.write("//")
                    fp.write(defineValueFormat % (t[0], v[0]))
                else:
                    if t[0] == 'CANNED_CYCLE':
                        # Known to be absent in the GUI. Worse, this value is replaced
                        # by the one in the metadata file.
                        #
                        # TODO: make value reading above recognize wether this value is
                        #       commented out or not. Reading the value its self works
                        #       already. Hint: it's the rule using reDefQS, reDefQSm, etc.
                        #
                        # TODO: add a multiline text field in the GUI to deal with this.
                        #
                        # TODO: write this value out properly. In /* comments */, if
                        #       disabled.
                        #
                        # TODO: currently, the lines beyond the ones with the #define are
                        #       treated like arbitrary comments. Having the former TODOs
                        #       done, this will lead to duplicates.
                        fp.write(ln)
                    else:
                        print "Value key " + t[0] + " not found in GUI."

                continue

            m = reDefBoolBL.match(ln)
            if m:
                t = m.groups()
                if len(t) == 1 and t[0] in values.keys():
                    v = values[t[0]]
                    self.cfgValues[t[0]] = v
                    if v == "" or v == False:
                        fp.write("//")
                    fp.write(defineBoolFormat % t[0])
                else:
                    print "Boolean key " + t[0] + " not found in GUI."

                continue

            fp.write(ln)

        fp.close()

        return True
コード例 #5
0
    def saveConfigFile(self, path):
        if os.path.basename(path) in protectedFiles:
            dlg = wx.MessageDialog(
                self, "It's not allowed to overwrite files "
                "distributed by Teacup. Choose another name.",
                "Protected file error", wx.OK + wx.ICON_ERROR)
            dlg.ShowModal()
            dlg.Destroy()
            return False

        if not os.path.basename(path).startswith("printer."):
            dlg = wx.MessageDialog(
                self, "Illegal file name: %s.\n"
                "File name must begin with \"printer.\"" % path,
                "Illegal file name", wx.OK + wx.ICON_ERROR)
            dlg.ShowModal()
            dlg.Destroy()
            return False

        ext = os.path.splitext(os.path.basename(path))[1]
        self.dir = os.path.dirname(path)

        if ext == "":
            path += ".h"

        try:
            fp = file(path, 'w')
        except:
            dlg = wx.MessageDialog(self, "Unable to write to file %s." % path,
                                   "File error", wx.OK + wx.ICON_ERROR)
            dlg.ShowModal()
            dlg.Destroy()
            return False

        self.configFile = path

        values = {}

        for pg in self.pages:
            v1 = pg.getValues()
            for k in v1.keys():
                values[k] = v1[k]

        for ln in self.cfgBuffer:
            m = reDefine.match(ln)
            if m:
                t = m.groups()
                if len(t) == 2 and t[0] in values.keys():
                    v = values[t[0]]
                    self.cfgValues[t[0]] = v
                    if v[1] == False:
                        fp.write("//")
                    fp.write(defineValueFormat % (t[0], v[0]))
                else:
                    if t[0] == 'CANNED_CYCLE':
                        # Known to be absent in the GUI. Worse, this value is replaced
                        # by the one in the metadata file.
                        #
                        # TODO: make value reading above recognize wether this value is
                        #       commented out or not. Reading the value its self works
                        #       already. Hint: it's the rule using reDefQS, reDefQSm, etc.
                        #
                        # TODO: add a multiline text field in the GUI to deal with this.
                        #
                        # TODO: write this value out properly. In /* comments */, if
                        #       disabled.
                        #
                        # TODO: currently, the lines beyond the ones with the #define are
                        #       treated like arbitrary comments. Having the former TODOs
                        #       done, this will lead to duplicates.
                        fp.write(ln)
                    else:
                        print "Value key " + t[0] + " not found in GUI."

                continue

            m = reDefBoolBL.match(ln)
            if m:
                t = m.groups()
                if len(t) == 1 and t[0] in values.keys():
                    v = values[t[0]]
                    self.cfgValues[t[0]] = v
                    if v == "" or v == False:
                        fp.write("//")
                    fp.write(defineBoolFormat % t[0])
                else:
                    print "Boolean key " + t[0] + " not found in GUI."

                continue

            fp.write(ln)

        fp.close()

        return True
コード例 #6
0
ファイル: board.py プロジェクト: Traumflug/Teacup_Firmware
  def saveConfigFile(self, path, values):
    if not values:
      values = self.cfgValues

    if self.settings.verbose >= 1:
      print("Saving board: %s." % path)
    if self.settings.verbose >= 2:
      print values

    fp = file(path, 'w')
    self.configFile = path

    skipToSensorEnd = False
    skipToHeaterEnd = False
    candThermPinsWritten = False
    candHeatPinsWritten = False
    candProcessorsWritten = False
    candCPUClocksWritten = False

    for ln in self.cfgBuffer:
      m = reStartSensors.match(ln)
      if m:
        fp.write(ln)
        fp.write("//                 name      type           pin    "
                 "additional\n");
        ttString = "\n"
        ttString += "// Beta algorithm      r0      beta  r2    vadc\n"
        ttString += "// Steinhart-Hart      rp      t0    r0      t1    "
        ttString += "r1      t2    r2\n"
        for s in self.sensors:
          sstr = "%-10s%-15s%-7s" % ((s[0] + ","), (s[1] + ","), (s[2] + ","))
          if s[3] is None:
            sstr += "0"
          else:
            sstr += "THERMISTOR_%s" % s[0].upper()
            tt = s[3]
            if len(tt) == 4:
              ttString += "//TEMP_TABLE %-8s (%-8s%-6s%-6s%s)\n" % \
                          (s[0].upper(), (tt[0] + ","), (tt[1] + ","),
                           (tt[2] + ","), tt[3])
            else:
              ttString += "//TEMP_TABLE %-8s (%-8s%-6s%-8s%-6s%-8s%-6s%s)\n" % \
                          (s[0].upper(), (tt[0] + ","), (tt[1] + ","),
                           (tt[2] + ","), (tt[3] + ","), (tt[4] + ","),
                           (tt[5] + ","), tt[6])
          fp.write("DEFINE_TEMP_SENSOR(%s)\n" % sstr)
        fp.write(ttString)
        skipToSensorEnd = True
        continue

      if skipToSensorEnd:
        m = reEndSensors.match(ln)
        if m:
          fp.write(ln)
          skipToSensorEnd = False
        continue

      m = reStartHeaters.match(ln)
      if m:
        fp.write(ln)
        fp.write("//            name      pin      invert  pwm     max_pwm\n")
        for s in self.heaters:
          sstr = "%-10s%-9s%-8s%-7s%s" % ((s[0] + ","), (s[1] + ","),
                                      (s[2] + ","), s[3] + ",", s[4])
          fp.write("DEFINE_HEATER(%s)\n" % sstr)
        fp.write("\n")
        for s in self.heaters:
          fp.write(defineHeaterFormat % (s[0].upper(), s[0]))
        skipToHeaterEnd = True
        continue

      if skipToHeaterEnd:
        m = reEndHeaters.match(ln)
        if m:
          fp.write(ln)
          skipToHeaterEnd = False
        continue

      if reCandThermPins.match(ln):
        if not candThermPinsWritten:
          for pin in self.candThermPins:
            fp.write("//#define TEMP_SENSOR_PIN " + pin + "\n")
          candThermPinsWritten = True
        continue

      if reCandHeatPins.match(ln):
        if not candHeatPinsWritten:
          for pin in self.candHeatPins:
            fp.write("//#define HEATER_PIN " + pin + "\n")
          candHeatPinsWritten = True
        continue

      if reCandProcessors.match(ln):
        if not candProcessorsWritten:
          for pin in self.candProcessors:
            fp.write("//#define CPU_TYPE " + pin + "\n")
          candProcessorsWritten = True
        continue

      if reCandCPUClocks.match(ln):
        if not candCPUClocksWritten:
          for pin in self.candClocks:
            fp.write("//#define F_CPU_OPT " + pin + "\n")
          candCPUClocksWritten = True
        continue

      m = reDefine.match(ln)
      if m:
        t = m.groups()
        if len(t) == 2 and t[0] in values.keys():
          v = values[t[0]]
          self.cfgValues[t[0]] = v
          if v[1] == False:
            fp.write("//")
          fp.write(defineValueFormat % (t[0], v[0]))
        else:
          if t[0] == 'RX_ENABLE_PIN' or t[0] == 'TX_ENABLE_PIN':
            # Known to be absent in the GUI, also won't be added anytime soon.
            fp.write(ln)
          else:
            print("Value key " + t[0] + " not found in GUI.")

        continue

      m = reDefBoolBL.match(ln)
      if m:
        t = m.groups()
        if len(t) == 1 and t[0] in values.keys():
          v = values[t[0]]
          self.cfgValues[t[0]] = v
          if v == "" or v == False:
            fp.write("//")
          fp.write(defineBoolFormat % t[0])
        else:
          if t[0] == 'MOTHERBOARD':
            # Known to be absent in the GUI, also won't be added anytime soon.
            fp.write(ln)
          else:
            print "Boolean key " + t[0] + " not found in GUI."

        continue

      fp.write(ln)

    fp.close()

    return True
コード例 #7
0
  def saveConfigFile(self, path):
    if os.path.basename(path) in protectedFiles:
      dlg = wx.MessageDialog(self, "It's not allowed to overwrite files "
                             "distributed by Teacup. Choose another name.",
                             "Protected file error", wx.OK + wx.ICON_ERROR)
      dlg.ShowModal()
      dlg.Destroy()
      return False

    if not os.path.basename(path).startswith("printer."):
      dlg = wx.MessageDialog(self, "Illegal file name: %s.\n"
                             "File name must begin with \"printer.\"" % path,
                             "Illegal file name", wx.OK + wx.ICON_ERROR)
      dlg.ShowModal()
      dlg.Destroy()
      return False

    ext = os.path.splitext(os.path.basename(path))[1]
    self.dir = os.path.dirname(path)

    if ext == "":
      path += ".h"

    try:
      fp = file(path, 'w')
    except:
      dlg = wx.MessageDialog(self, "Unable to write to file %s." % path,
                             "File error", wx.OK + wx.ICON_ERROR)
      dlg.ShowModal()
      dlg.Destroy()
      return False

    self.configFile = path

    values = {}

    for pg in self.pages:
      v1 = pg.getValues()
      for k in v1.keys():
        values[k] = v1[k]

    for ln in self.cfgBuffer:
      m = reDefine.match(ln)
      if m:
        t = m.groups()
        if len(t) == 2 and t[0] in values.keys():
          v = values[t[0]]
          self.cfgValues[t[0]] = v
          if v[1] == False:
            fp.write("//")
          fp.write(defineValueFormat % (t[0], v[0]))
        else:
          if t[0] == 'CANNED_CYCLE':
            # Known to be absent in the GUI. Worse, this value is replaced
            # by the one in the metadata file.
            #
            # TODO: make value reading above recognize wether this value is
            #       commented out or not. Reading the value its self works
            #       already. Hint: it's the rule using reDefQS, reDefQSm, etc.
            #
            # TODO: add a multiline text field in the GUI to deal with this.
            #
            # TODO: write this value out properly. In /* comments */, if
            #       disabled.
            #
            # TODO: currently, the lines beyond the ones with the #define are
            #       treated like arbitrary comments. Having the former TODOs
            #       done, this will lead to duplicates.
            fp.write(ln)
          else:
            print "Value key " + t[0] + " not found in GUI."

        continue

      m = reDefBoolBL.match(ln)
      if m:
        t = m.groups()
        if len(t) == 1 and t[0] in values.keys():
          v = values[t[0]]
          self.cfgValues[t[0]] = v
          if v == "" or v == False:
            fp.write("//")
          fp.write(defineBoolFormat % t[0])
        else:
          print "Boolean key " + t[0] + " not found in GUI."

        continue

      fp.write(ln)

    fp.close()

    return True
コード例 #8
0
ファイル: printer.py プロジェクト: Traumflug/Teacup_Firmware
  def saveConfigFile(self, path, values):
    if not values:
      values = self.cfgValues

    if self.settings.verbose >= 1:
      print("Saving printer: %s." % path)
    if self.settings.verbose >= 2:
      print values

    fp = file(path, 'w')
    self.configFile = path

    skipToHomingEnd = False

    for ln in self.cfgBuffer:
      m = reStartHoming.match(ln)
      if m:
        fp.write(ln)
        sstr = "%s, %s, %s, %s" % ((values['HOMING_STEP1']),
                                   (values['HOMING_STEP2']),
                                   (values['HOMING_STEP3']),
                                   (values['HOMING_STEP4']))
        fp.write("DEFINE_HOMING(%s)\n" % sstr)
        skipToHomingEnd = True
        continue

      if skipToHomingEnd:
        m = reEndHoming.match(ln)
        if m:
          fp.write(ln)
          skipToHomingEnd = False
        continue

      m = reDefine.match(ln)
      if m:
        t = m.groups()
        if len(t) == 2 and t[0] in values.keys():
          v = values[t[0]]
          self.cfgValues[t[0]] = v
          if v[1] == False:
            fp.write("//")
          fp.write(defineValueFormat % (t[0], v[0]))
        else:
          if t[0] == 'CANNED_CYCLE':
            # Known to be absent in the GUI. Worse, this value is replaced
            # by the one in the metadata file.
            #
            # TODO: make value reading above recognize wether this value is
            #       commented out or not. Reading the value its self works
            #       already. Hint: it's the rule using reDefQS, reDefQSm, etc.
            #
            # TODO: add a multiline text field in the GUI to deal with this.
            #
            # TODO: write this value out properly. In /* comments */, if
            #       disabled.
            #
            # TODO: currently, the lines beyond the ones with the #define are
            #       treated like arbitrary comments. Having the former TODOs
            #       done, this will lead to duplicates.
            fp.write(ln)
          else:
            print "Value key " + t[0] + " not found in GUI."

        continue

      m = reDefBoolBL.match(ln)
      if m:
        t = m.groups()
        if len(t) == 1 and t[0] in values.keys():
          v = values[t[0]]
          self.cfgValues[t[0]] = v
          if v == "" or v == False:
            fp.write("//")
          fp.write(defineBoolFormat % t[0])
        else:
          print "Boolean key " + t[0] + " not found in GUI."

        continue

      fp.write(ln)

    fp.close()

    return True
コード例 #9
0
    def saveConfigFile(self, path, values):
        if not values:
            values = self.cfgValues

        if self.settings.verbose >= 1:
            print("Saving printer: %s." % path)
        if self.settings.verbose >= 2:
            print(values)

        fp = open(path, "w")
        self.configFile = path

        homingWritten = False

        for ln in self.cfgBuffer:
            if reDefHoming.match(ln):
                if not homingWritten:
                    home = []
                    for h in self.homingKeys:
                        home.append(values[h][0])
                    while "none" in home:
                        home.remove("none")
                    if not home:
                        home = ["none"]
                    homing_str = "DEFINE_HOMING({})\n".format(", ".join(home))
                    fp.write(homing_str)
                    homingWritten = True
                continue

            m = reDefine.match(ln)
            if m:
                t = m.groups()
                if len(t) == 2 and t[0] in values.keys():
                    v = values[t[0]]
                    self.cfgValues[t[0]] = v
                    if v[1] == False:
                        fp.write("//")
                    fp.write(defineValueFormat % (t[0], v[0]))
                else:
                    if t[0] == "CANNED_CYCLE":
                        # Known to be absent in the GUI. Worse, this value is replaced
                        # by the one in the metadata file.
                        #
                        # TODO: make value reading above recognize wether this value is
                        #       commented out or not. Reading the value its self works
                        #       already. Hint: it's the rule using reDefQS, reDefQSm, etc.
                        #
                        # TODO: add a multiline text field in the GUI to deal with this.
                        #
                        # TODO: write this value out properly. In /* comments */, if
                        #       disabled.
                        #
                        # TODO: currently, the lines beyond the ones with the #define are
                        #       treated like arbitrary comments. Having the former TODOs
                        #       done, this will lead to duplicates.
                        fp.write(ln)
                    else:
                        print("Value key " + t[0] + " not found in GUI.")

                continue

            m = reDefBoolBL.match(ln)
            if m:
                t = m.groups()
                if len(t) == 1 and t[0] in values.keys():
                    v = values[t[0]]
                    self.cfgValues[t[0]] = v
                    if v == "" or v == False:
                        fp.write("//")
                    fp.write(defineBoolFormat % t[0])
                else:
                    print("Boolean key " + t[0] + " not found in GUI.")

                continue

            fp.write(ln)

        fp.close()

        return True