diff --git a/docs/api/printer.rst b/docs/api/printer.rst index 1c8483a55..82f86cc91 100644 --- a/docs/api/printer.rst +++ b/docs/api/printer.rst @@ -22,6 +22,11 @@ Bed corresponding resource returns temperature information including an optional history. Note that Bed commands are only available if the currently selected printer profile has a heated bed. See :ref:`sec-api-printer-bedcommand`. +Chamber + Chamber commands allow setting the temperature and temperature offset for the printer's heated chamber. Querying + the corresponding resource returns temperature information including an option history. Note that Chamber commands + are only available if the currently selected printer profile has a heated chamber. + See :ref:`sec-api-printer-chambercommand`. SD card SD commands allow initialization, refresh and release of the printer's SD card (if available). Querying the corresponding resource returns the current SD card state. @@ -623,12 +628,12 @@ Issue a bed command are: target - Sets the given target temperature on the printer's tools. Additional parameters: + Sets the given target temperature on the printer's bed. Additional parameters: * ``target``: Target temperature to set. offset - Sets the given temperature offset on the printer's tools. Additional parameters: + Sets the given temperature offset on the printer's bed. Additional parameters: * ``offset``: Offset to set. @@ -710,7 +715,7 @@ Retrieve the current bed state an :http:statuscode:`409`. .. note:: - If you want both tool and bed temperature information at the same time, take a look at + If you want tool, bed and chamber temperature information at the same time, take a look at :ref:`Retrieve the current printer state `. **Example** @@ -760,6 +765,154 @@ Retrieve the current bed state :statuscode 409: If the printer is not operational or the selected printer profile does not have a heated bed. +.. _sec-api-printer-chambercommand: + +Issue a chamber command +======================= + +.. http:post:: /api/printer/bed + + Chamber commands allow setting the temperature and temperature offsets for the printer's heated chamber. Available commands + are: + + target + Sets the given target temperature on the printer's chamber. Additional parameters: + + * ``target``: Target temperature to set. + + offset + Sets the given temperature offset on the printer's chamber. Additional parameters: + + * ``offset``: Offset to set. + + All of these commands may only be sent if the printer is currently operational. Otherwise a :http:statuscode:`409` + is returned. + + Upon success, a status code of :http:statuscode:`204` and an empty body is returned. + + If no heated chambed is configured for the currently selected printer profile, the resource will return + an :http:statuscode:`409`. + + Requires user rights. + + **Example Target Temperature Request** + + Set the target temperature for the printer's heated chamber to 50°C. + + .. sourcecode:: http + + POST /api/printer/chamber HTTP/1.1 + Host: example.com + Content-Type: application/json + X-Api-Key: abcdef... + + { + "command": "target", + "target": 50 + } + + .. sourcecode:: http + + HTTP/1.1 204 No Content + + **Example Offset Temperature Request** + + Set the temperature offset for the heated chamber to -5°C. + + .. sourcecode:: http + + POST /api/printer/chamber HTTP/1.1 + Host: example.com + Content-Type: application/json + X-Api-Key: abcdef... + + { + "command": "offset", + "offset": -5 + } + + .. sourcecode:: http + + HTTP/1.1 204 No Content + + :json string command: The command to issue, either ``target`` or ``offset``. + :json object target: ``target`` command: The target temperature to set. + :json object offset: ``offset`` command: The offset temperature to set. + :statuscode 204: No error + :statuscode 400: If ``target`` or ``offset`` is not a valid number or outside of the supported range, or if the + request is otherwise invalid. + :statuscode 409: If the printer is not operational or the selected printer profile + does not have a heated chamber. + +.. _sec-api-printer-chamberstate: + +Retrieve the current chamber state +================================== + +.. http:get:: /api/printer/chamber + + Retrieves the current temperature data (actual, target and offset) plus optionally a (limited) history (actual, target, + timestamp) for the printer's heated chamber. + + It's also possible to retrieve the temperature history by supplying the ``history`` query parameter set to ``true``. The + amount of returned history data points can be limited using the ``limit`` query parameter. + + Returns a :http:statuscode:`200` with a Temperature Response in the body upon success. + + If no heated chamber is configured for the currently selected printer profile, the resource will return + an :http:statuscode:`409`. + + .. note:: + If you want tool, bed and chamber temperature information at the same time, take a look at + :ref:`Retrieve the current printer state `. + + **Example** + + Query the chamber temperature data and also include the temperature history but limit it to two entries. + + .. sourcecode:: http + + GET /api/printer/chamber?history=true&limit=2 HTTP/1.1 + Host: example.com + X-Api-Key: abcdef... + + .. sourcecode:: http + + HTTP/1.1 200 OK + Content-Type: application/json + + { + "chamber": { + "actual": 50.221, + "target": 70.0, + "offset": 5 + }, + "history": [ + { + "time": 1395651928, + "chamber": { + "actual": 50.221, + "target": 70.0 + } + }, + { + "time": 1395651926, + "chamber": { + "actual": 49.1123, + "target": 70.0 + } + } + ] + } + + :query history: If set to ``true`` (or: ``yes``, ``y``, ``1``), history information will be included in the response + too. If no ``limit`` parameter is given, all available temperature history data will be returned. + :query limit: If set to an integer (``n``), only the last ``n`` data points from the printer's temperature history + will be returned. Will be ignored if ``history`` is not enabled. + :statuscode 200: No error + :statuscode 409: If the printer is not operational or the selected printer profile + does not have a heated chamber. + .. _sec-api-printer-sdcommand: Issue an SD command diff --git a/docs/api/printerprofiles.rst b/docs/api/printerprofiles.rst index 8db1b51ae..9f2f163e2 100644 --- a/docs/api/printerprofiles.rst +++ b/docs/api/printerprofiles.rst @@ -52,6 +52,7 @@ Retrieve all printer profiles "height": 200 }, "heatedBed": true, + "heatedChamber": false, "axes": { "x": { "speed": 6000, @@ -93,6 +94,7 @@ Retrieve all printer profiles "height": 200 }, "heatedBed": true, + "heatedChamber": true, "axes": { "x": { "speed": 6000, @@ -184,6 +186,7 @@ Add a new printer profile "height": 200 }, "heatedBed": true, + "heatedChamber": false, "axes": { "x": { "speed": 6000, @@ -267,6 +270,7 @@ Add a new printer profile "height": 300 }, "heatedBed": false, + "heatedChamber": false, "axes": { "x": { "speed": 6000, @@ -352,6 +356,7 @@ Update an existing printer profile "height": 200 }, "heatedBed": true, + "heatedChamber": false, "axes": { "x": { "speed": 6000, @@ -578,6 +583,10 @@ Profile - 0..1 - ``boolean`` - Whether the printer has a heated bed (``true``) or not (``false``) + * - ``heatedChamber`` + - 0..1 + - ``boolean`` + - Whether the printer has a heated chamber (``true``) or not (``false``) * - ``axes`` - 0..1 - Object diff --git a/docs/configuration/config_yaml.rst b/docs/configuration/config_yaml.rst index fd25a4d8c..7ab22da07 100644 --- a/docs/configuration/config_yaml.rst +++ b/docs/configuration/config_yaml.rst @@ -323,6 +323,9 @@ The following settings are only relevant to you if you want to do OctoPrint deve # Whether the simulated printer should also simulate a heated bed or not hasBed: true + # Whether the simulated printer should also simulate a heated chamber or not + hasChamber: false + # If enabled, reports the set target temperatures as separate messages from the firmware # # True: > M109 S220.0 diff --git a/docs/jsclientlib/printer.rst b/docs/jsclientlib/printer.rst index 14df29834..d79d3d6de 100644 --- a/docs/jsclientlib/printer.rst +++ b/docs/jsclientlib/printer.rst @@ -210,6 +210,64 @@ :param object opts: Additional options for the request :returns Promise: A `jQuery Promise `_ for the request's response +.. js:function:: OctoPrintClient.printer.getChamberState(data, opts) + + Retrieves the current printer chamber state/temperature information, and optionally also the temperature + history. + + The ``flags`` object can be used to specify the data to retrieve further via the following + properties: + + * ``history``: a boolean value to specify whether the temperature history should be included (``true``) + or not (``false``), defaults to it not being included + * ``limit``: an integer value to specify how many history entries to include + + See :ref:`Retrieve the current bed state ` for more details. + + :param object flags: Flags that further specify which data to retrieve, see above for details + :param object opts: Additional options for the request + :returns Promise: A `jQuery Promise `_ for the request's response + +.. js:function:: OctoPrintClient.printer.setChamberTargetTemperature(target, opts) + + Sets the given temperature on the printer's heated chamber (if available). + + ``target`` is expected to be the target temperature as a float value. + + **Example:** + + Set the chamber to 50°C. + + .. code-block:: javascript + + OctoPrint.printer.setChamberTargetTemperature(50.0); + + See the ``target`` command in :ref:`Issue a chamber command ` for more details. + + :param float target: The target to set + :param object opts: Additional options for the request + :returns Promise: A `jQuery Promise `_ for the request's response + +.. js:function:: OctoPrintClient.printer.setChamberTemperatureOffset(offset, opts) + + Sets the given temperature offset for the printer's heated chamber (if available). + + ``offset`` is expected to be the temperature offset to set. + + **Example:** + + Set the offset for the chamber to -5°C. + + .. code-block:: javascript + + OctoPrint.printer.setChamberTemperatureOffset(-5); + + See the ``offset`` command in :ref:`Issue a chamber command ` for more details. + + :param object offsets: The offsets to set + :param object opts: Additional options for the request + :returns Promise: A `jQuery Promise `_ for the request's response + .. js:function:: OctoPrintClient.printer.jog(amounts, opts) Jogs the specified axes by the specified ``amounts``. diff --git a/src/octoprint/plugins/virtual_printer/virtual.py b/src/octoprint/plugins/virtual_printer/virtual.py index 5720daa6f..c44de6b0e 100644 --- a/src/octoprint/plugins/virtual_printer/virtual.py +++ b/src/octoprint/plugins/virtual_printer/virtual.py @@ -84,6 +84,8 @@ class VirtualPrinter(object): self.targetTemp = [0.0] * self.temperatureCount self.bedTemp = self._ambient_temperature self.bedTargetTemp = 0.0 + self.chamberTemp = self._ambient_temperature + self.chamberTargetTemp = 0.0 self.lastTempAt = monotonic_time() self._relative = True @@ -459,6 +461,12 @@ class VirtualPrinter(object): def _gcode_M190(self, data): self._parseBedCommand(data, wait=True, support_r=True) + def _gcode_M141(self, data): + self._parseChamberCommand(data) + + def _gcode_M191(self, data): + self._parseChamberCommand(data, wait=True, support_r=True) + def _gcode_M105(self, data): self._processTemperatureQuery() return True @@ -930,6 +938,12 @@ class VirtualPrinter(object): else: allTempsString = "B:%.2f %s" % (self.bedTemp, allTempsString) + if settings().getBoolean(["devel", "virtualPrinter", "hasChamber"]): + if includeTarget: + allTempsString = "C:%.2f /%.2f %s" % (self.chamberTemp, self.chamberTargetTemp, allTempsString) + else: + allTempsString = "C:%.2f %s" % (self.chamberTemp, allTempsString) + if settings().getBoolean(["devel", "virtualPrinter", "includeCurrentToolInTemps"]): if includeTarget: output = "T:%.2f /%.2f %s" % (self.temp[self.currentExtruder], self.targetTemp[self.currentExtruder], allTempsString) @@ -939,9 +953,28 @@ class VirtualPrinter(object): output = allTempsString else: if includeTarget: - output = "T:%.2f /%.2f B:%.2f /%.2f" % (self.temp[0], self.targetTemp[0], self.bedTemp, self.bedTargetTemp) + t = "T:%.2f /%.2f" % (self.temp[0], self.targetTemp[0]) else: - output = "T:%.2f B:%.2f" % (self.temp[0], self.bedTemp) + t = "T:%.2f" % self.temp[0] + + if settings().getBoolean(["devel", "virtualPrinter", "hasBed"]): + if includeTarget: + b = "B:%.2f /%.2f" % (self.bedTemp, self.bedTargetTemp) + else: + b = "B:%.2f" % self.bedTemp + else: + b = "" + + if settings().getBoolean(["devel", "virtualPrinter", "hasChamber"]): + if includeTarget: + c = "C:%.2f /%.2f" % (self.chamberTemp, self.chamberTargetTemp) + else: + c = "C:%.2f" % self.chamberTemp + else: + c = "" + + output = t + " " + b + " " + c + output = output.strip() output += " @:64\n" return output @@ -985,6 +1018,9 @@ class VirtualPrinter(object): self._send("TargetExtr%d:%d" % (tool, self.targetTemp[tool])) def _parseBedCommand(self, line, wait=False, support_r=False): + if not settings().getBoolean(["devel", "virtualPrinter", "hasBed"]): + return + only_wait_if_higher = True try: self.bedTargetTemp = float(re.search('S([0-9]+)', line).group(1)) @@ -1001,6 +1037,24 @@ class VirtualPrinter(object): if settings().getBoolean(["devel", "virtualPrinter", "repetierStyleTargetTemperature"]): self._send("TargetBed:%d" % self.bedTargetTemp) + def _parseChamberCommand(self, line, wait=False, support_r=False): + if not settings().getBoolean(["devel", "virtualPrinter", "hasChamber"]): + return + + only_wait_if_higher = True + try: + self.chamberTargetTemp = float(re.search('S([0-9]+)', line).group(1)) + except: + if support_r: + try: + self.chamberTargetTemp = float(re.search('R([0-9]+)', line).group(1)) + only_wait_if_higher = False + except: + pass + + if wait: + self._waitForHeatup("chamber", only_wait_if_higher) + def _performMove(self, line): matchX = re.search("X([0-9.]+)", line) matchY = re.search("Y([0-9.]+)", line) @@ -1210,6 +1264,9 @@ class VirtualPrinter(object): elif heater == "bed": test = lambda: self.bedTemp < self.bedTargetTemp - delta or (not only_wait_if_higher and self.bedTemp > self.bedTargetTemp + delta) output = lambda: "B:%0.2f" % self.bedTemp + elif heater == "chamber": + test = lambda: self.chamberTemp < self.chamberTargetTemp - delta or (not only_wait_if_higher and self.chamberTemp > self.chamberTargetTemp + delta) + output = lambda: "C:%0.2f" % self.chamberTemp else: return @@ -1261,6 +1318,7 @@ class VirtualPrinter(object): continue self.temp[i] = simulate(self.temp[i], self.targetTemp[i], self._ambient_temperature) self.bedTemp = simulate(self.bedTemp, self.bedTargetTemp, self._ambient_temperature) + self.chamberTemp = simulate(self.chamberTemp, self.chamberTargetTemp, self._ambient_temperature) def _processBuffer(self): while self.buffered is not None: diff --git a/src/octoprint/printer/__init__.py b/src/octoprint/printer/__init__.py index d2899d142..ea8880b42 100644 --- a/src/octoprint/printer/__init__.py +++ b/src/octoprint/printer/__init__.py @@ -47,7 +47,7 @@ class PrinterInterface(object): valid_tool_regex = re.compile("^(tool\d+)$") """Regex for valid tool identifiers.""" - valid_heater_regex = re.compile("^(tool\d+|bed)$") + valid_heater_regex = re.compile("^(tool\d+|bed|chamber)$") """Regex for valid heater identifiers.""" @classmethod diff --git a/src/octoprint/printer/profile.py b/src/octoprint/printer/profile.py index 191207087..b846f1e20 100644 --- a/src/octoprint/printer/profile.py +++ b/src/octoprint/printer/profile.py @@ -66,6 +66,9 @@ A printer profile is a ``dict`` of the following structure: * - ``heatedBed`` - ``bool`` - Whether the printer has a heated bed (``True``) or not (``False``) + * - ``heatedChamber`` + - ``bool`` + - Whether the printer has a heated chamber (``True``) or not (``False``) * - ``extruder`` - ``dict`` - Information about the printer's extruders @@ -218,6 +221,7 @@ class PrinterProfileManager(object): custom_box = False ), heatedBed = True, + heatedChamber = False, extruder=dict( count = 1, offsets = [ @@ -509,6 +513,10 @@ class PrinterProfileManager(object): profile["extruder"]["offsets"] = [(0.0, 0.0)] modified = True + if not "heatedChamber" in profile: + profile["heatedChamber"] = False + modified = True + return modified def _ensure_valid_profile(self, profile): diff --git a/src/octoprint/printer/standard.py b/src/octoprint/printer/standard.py index dc4459ae5..bc69480f2 100644 --- a/src/octoprint/printer/standard.py +++ b/src/octoprint/printer/standard.py @@ -394,11 +394,13 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback): def set_temperature(self, heater, value, *args, **kwargs): if not PrinterInterface.valid_heater_regex.match(heater): - raise ValueError("heater must match \"tool[0-9]+\" or \"bed\": {heater}".format(heater=heater)) + raise ValueError("heater must match \"tool[0-9]+\", \"bed\" or \"chamber\": {heater}".format(heater=heater)) if not isinstance(value, (int, long, float)) or value < 0: raise ValueError("value must be a valid number >= 0: {value}".format(value=value)) + tags = kwargs.get("tags", set()) | {"trigger:printer.set_temperature"} + if heater.startswith("tool"): printer_profile = self._printerProfileManager.get_current_or_default() extruder_count = printer_profile["extruder"]["count"] @@ -406,14 +408,18 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback): if extruder_count > 1 and not shared_nozzle: toolNum = int(heater[len("tool"):]) self.commands("M104 T{} S{}".format(toolNum, value), - tags=kwargs.get("tags", set()) | {"trigger:printer.set_temperature"}) + tags=tags) else: self.commands("M104 S{}".format(value), - tags=kwargs.get("tags", set()) | {"trigger:printer.set_temperature"}) + tags=tags) elif heater == "bed": self.commands("M140 S{}".format(value), - tags=kwargs.get("tags", set()) | {"trigger:printer.set_temperature"}) + tags=tags) + + elif heater == "chamber": + self.commands("M141 S{}".format(value), + tags=tags) def set_temperature_offset(self, offsets=None, *args, **kwargs): if offsets is None: @@ -614,6 +620,12 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback): "target": self._bedTemp[1], "offset": offsets["bed"] if "bed" in offsets and offsets["bed"] is not None else 0 } + if self._chamberTemp is not None: + result["chamber"] = { + "actual": self._chamberTemp[0], + "target": self._chamberTemp[1], + "offset": offsets["chamber"] if "chamber" in offsets and offsets["chamber"] is not None else 0 + } return result @@ -853,7 +865,7 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback): printTimeLeft=int(printTimeLeft) if printTimeLeft is not None else None, printTimeLeftOrigin=printTimeLeftOrigin) - def _addTemperatureData(self, tools=None, bed=None): + def _addTemperatureData(self, tools=None, bed=None, chamber=None): if tools is None: tools = dict() @@ -862,11 +874,14 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback): data["tool%d" % tool] = self._dict(actual=tools[tool][0], target=tools[tool][1]) if bed is not None and isinstance(bed, tuple): data["bed"] = self._dict(actual=bed[0], target=bed[1]) + if chamber is not None and isinstance(chamber, tuple): + data["chamber"] = self._dict(actual=chamber[0], target=chamber[1]) self._temps.append(data) self._temp = tools self._bedTemp = bed + self._chamberTemp = chamber self._stateMonitor.add_temperature(self._dict(**data)) @@ -1015,8 +1030,8 @@ class Printer(PrinterInterface, comm.MachineComPrintCallback): """ self._addLog(to_unicode(message, "utf-8", errors="replace")) - def on_comm_temperature_update(self, temp, bedTemp): - self._addTemperatureData(tools=copy.deepcopy(temp), bed=copy.deepcopy(bedTemp)) + def on_comm_temperature_update(self, temp, bedTemp, chamberTemp): + self._addTemperatureData(tools=copy.deepcopy(temp), bed=copy.deepcopy(bedTemp), chamber=copy.deepcopy(chamberTemp)) def on_comm_position_update(self, position, reason=None): payload = dict(reason=reason) diff --git a/src/octoprint/server/api/printer.py b/src/octoprint/server/api/printer.py index 561efcfde..5616954cb 100644 --- a/src/octoprint/server/api/printer.py +++ b/src/octoprint/server/api/printer.py @@ -211,7 +211,71 @@ def printerBedState(): if not printerProfileManager.get_current_or_default()["heatedBed"]: return make_response("Printer does not have a heated bed", 409) - data = _get_temperature_data(_delete_tools) + data = _get_temperature_data(_keep_bed) + if isinstance(data, Response): + return data + else: + return jsonify(data) + + +##~~ Heated chamber + + +@api.route("/printer/chamber", methods=["POST"]) +@restricted_access +def printerChamberCommand(): + if not printer.is_operational(): + return make_response("Printer is not operational", 409) + + if not printerProfileManager.get_current_or_default()["heatedChamber"]: + return make_response("Printer does not have a heated chamber", 409) + + valid_commands = { + "target": ["target"], + "offset": ["offset"] + } + command, data, response = get_json_command_from_request(request, valid_commands) + if response is not None: + return response + + tags = {"source:api", "api:printer.chamber"} + + ##~~ temperature + if command == "target": + target = data["target"] + + # make sure the target is a number + if not isinstance(target, (int, long, float)): + return make_response("Not a number: %r" % target, 400) + + # perform the actual temperature command + printer.set_temperature("chamber", target, tags=tags) + + ##~~ temperature offset + elif command == "offset": + offset = data["offset"] + + # make sure the offset is valid + if not isinstance(offset, (int, long, float)): + return make_response("Not a number: %r" % offset, 400) + if not -50 <= offset <= 50: + return make_response("Offset not in range [-50, 50]: %f" % offset, 400) + + # set the offsets + printer.set_temperature_offset({"chamber": offset}) + + return NO_CONTENT + + +@api.route("/printer/chamber", methods=["GET"]) +def printerChamberState(): + if not printer.is_operational(): + return make_response("Printer is not operational", 409) + + if not printerProfileManager.get_current_or_default()["heatedChamber"]: + return make_response("Printer does not have a heated chamber", 409) + + data = _get_temperature_data(_keep_chamber) if isinstance(data, Response): return data else: @@ -412,12 +476,16 @@ def _get_temperature_data(preprocessor): return preprocessor(tempData) -def _delete_tools(x): - return _delete_from_data(x, lambda k: k.startswith("tool")) +def _keep_tools(x): + return _delete_from_data(x, lambda k: not k.startswith("tool")) -def _delete_bed(x): - return _delete_from_data(x, lambda k: k == "bed") +def _keep_bed(x): + return _delete_from_data(x, lambda k: k != "bed") + + +def _keep_chamber(x): + return _delete_from_data(x, lambda k: k != "chamber") def _delete_from_data(x, key_matcher): diff --git a/src/octoprint/settings.py b/src/octoprint/settings.py index b448da7c5..03b0de911 100644 --- a/src/octoprint/settings.py +++ b/src/octoprint/settings.py @@ -397,6 +397,7 @@ default_settings = { "includeCurrentToolInTemps": True, "includeFilenameInOpened": True, "hasBed": True, + "hasChamber": False, "repetierStyleTargetTemperature": False, "okBeforeCommandOutput": False, "smoothieTemperatureReporting": False, diff --git a/src/octoprint/static/js/app/client/printer.js b/src/octoprint/static/js/app/client/printer.js index a1fe43d16..b55267d74 100644 --- a/src/octoprint/static/js/app/client/printer.js +++ b/src/octoprint/static/js/app/client/printer.js @@ -9,6 +9,7 @@ var printheadUrl = url + "/printhead"; var toolUrl = url + "/tool"; var bedUrl = url + "/bed"; + var chamberUrl = url + "/chamber"; var sdUrl = url + "/sd"; var OctoPrintPrinterClient = function(base) { @@ -27,6 +28,10 @@ return this.base.issueCommand(bedUrl, command, payload, opts); }; + OctoPrintPrinterClient.prototype.issueChamberCommand = function (command, payload, opts) { + return this.base.issueCommand(chamberUrl, command, payload, opts); + }; + OctoPrintPrinterClient.prototype.issueSdCommand = function (command, payload, opts) { return this.base.issueCommand(sdUrl, command, payload, opts); }; @@ -90,6 +95,23 @@ return this.base.get(getUrl, opts); }; + OctoPrintPrinterClient.prototype.getChamberState = function (flags, opts) { + flags = flags || {}; + + var history = flags.history || undefined; + var limit = flags.limit || undefined; + + var getUrl = chamberUrl; + if (history) { + getUrl += "?history=true"; + if (limit) { + getUrl += "&limit=" + limit; + } + } + + return this.base.get(getUrl, opts); + }; + OctoPrintPrinterClient.prototype.getSdState = function (opts) { return this.base.get(sdUrl, opts); }; @@ -198,6 +220,26 @@ return this.issueBedCommand("offset", payload, opts); }; + OctoPrintPrinterClient.prototype.setChamberTargetTemperature = function (target, opts) { + target = target || 0; + + var payload = { + target: target + }; + + return this.issueChamberCommand("target", payload, opts); + }; + + OctoPrintPrinterClient.prototype.setChamberTemperatureOffset = function (offset, opts) { + offset = offset || 0; + + var payload = { + offset: offset + }; + + return this.issueChamberCommand("offset", payload, opts); + }; + OctoPrintPrinterClient.prototype.initSd = function (opts) { return this.issueSdCommand("init", {}, opts); }; diff --git a/src/octoprint/static/js/app/viewmodels/printerprofiles.js b/src/octoprint/static/js/app/viewmodels/printerprofiles.js index ad9a95897..556063848 100644 --- a/src/octoprint/static/js/app/viewmodels/printerprofiles.js +++ b/src/octoprint/static/js/app/viewmodels/printerprofiles.js @@ -14,6 +14,7 @@ $(function() { custom_box: false }, heatedBed: true, + heatedChamber: false, axes: { x: {speed: 6000, inverted: false}, y: {speed: 6000, inverted: false}, @@ -60,6 +61,7 @@ $(function() { }); self.heatedBed = ko.observable(); + self.heatedChamber = ko.observable(); self.nozzleDiameter = ko.observable(); self.extruders = ko.observable(); @@ -209,6 +211,7 @@ $(function() { } self.heatedBed(data.heatedBed); + self.heatedChamber(data.heatedChamber); self.nozzleDiameter(data.extruder.nozzleDiameter); self.sharedNozzle(data.extruder.sharedNozzle); @@ -269,6 +272,7 @@ $(function() { origin: self.volumeOrigin() }, heatedBed: self.heatedBed(), + heatedChamber: self.heatedChamber(), extruder: { count: parseInt(self.extruders()), offsets: [ diff --git a/src/octoprint/static/js/app/viewmodels/settings.js b/src/octoprint/static/js/app/viewmodels/settings.js index 42eaf5bfd..637370671 100644 --- a/src/octoprint/static/js/app/viewmodels/settings.js +++ b/src/octoprint/static/js/app/viewmodels/settings.js @@ -297,7 +297,7 @@ $(function() { }); self.addTemperatureProfile = function() { - self.temperature_profiles.push({name: "New", extruder:0, bed:0}); + self.temperature_profiles.push({name: "New", extruder:0, bed:0, chamber:0}); }; self.removeTemperatureProfile = function(profile) { @@ -818,7 +818,8 @@ $(function() { result.push({ name: profile.name, extruder: Math.floor(_.isNumber(profile.extruder) ? profile.extruder : parseInt(profile.extruder)), - bed: Math.floor(_.isNumber(profile.bed) ? profile.bed : parseInt(profile.bed)) + bed: Math.floor(_.isNumber(profile.bed) ? profile.bed : parseInt(profile.bed)), + chamber: Math.floor(_.isNumber(profile.chamber) ? profile.chamber : (_.isNumber(parseInt(profile.chamber)) ? parseInt(profile.chamber) : 0)) }); } catch (ex) { // ignore diff --git a/src/octoprint/static/js/app/viewmodels/temperature.js b/src/octoprint/static/js/app/viewmodels/temperature.js index 7c1e43b55..f78a4b9cd 100644 --- a/src/octoprint/static/js/app/viewmodels/temperature.js +++ b/src/octoprint/static/js/app/viewmodels/temperature.js @@ -70,11 +70,16 @@ $(function() { self.tools = ko.observableArray([]); self.hasBed = ko.observable(true); + self.hasChamber = ko.observable(false); self.bedTemp = self._createToolEntry(); self.bedTemp["name"](gettext("Bed")); self.bedTemp["key"]("bed"); + self.chamberTemp = self._createToolEntry(); + self.chamberTemp["name"](gettext("Chamber")); + self.chamberTemp["key"]("chamber"); + self.isErrorOrClosed = ko.observable(undefined); self.isOperational = ko.observable(undefined); self.isPrinting = ko.observable(undefined); @@ -135,6 +140,14 @@ $(function() { self.hasBed(false); } + // heated chamber + if (currentProfileData && currentProfileData.heatedChamber()) { + self.hasChamber(true); + heaterOptions["chamber"] = {name: gettext("Chamber"), color: "black"}; + } else { + self.hasChamber(false); + } + // write back self.heaterOptions(heaterOptions); self.tools(tools); @@ -149,6 +162,7 @@ $(function() { self.settingsViewModel.printerProfiles.currentProfileData().extruder.count.subscribe(self._printerProfileUpdated); self.settingsViewModel.printerProfiles.currentProfileData().extruder.sharedNozzle.subscribe(self._printerProfileUpdated); self.settingsViewModel.printerProfiles.currentProfileData().heatedBed.subscribe(self._printerProfileUpdated); + self.settingsViewModel.printerProfiles.currentProfileData().heatedChamber.subscribe(self._printerProfileUpdated); }); self.temperatures = []; @@ -224,6 +238,14 @@ $(function() { self.bedTemp["target"](0); } + if (lastData.hasOwnProperty("chamber")) { + self.chamberTemp["actual"](lastData.chamber.actual); + self.chamberTemp["target"](lastData.chamber.target); + } else { + self.chamberTemp["actual"](0); + self.chamberTemp["target"](0); + } + if (!CONFIG_TEMPERATURE_GRAPH) return; self.temperatures = self._processTemperatureData(serverTime, data, self.temperatures); @@ -250,6 +272,12 @@ $(function() { } else { self.bedTemp["offset"](0); } + + if (data.hasOwnProperty("chamber")) { + self.chamberTemp["offset"](data["chamber"]); + } else { + self.chamberTemp["offset"](0); + } }; self._processTemperatureData = function(serverTime, data, result) { @@ -295,6 +323,27 @@ $(function() { return result; }; + self.profileText = function(heater, profile) { + var text = gettext("Set %(name)s (%(value)s)"); + + var value; + if (heater.key() === "bed") { + value = profile.bed; + } else if (heater.key() === "chamber") { + value = profile.chamber; + } else { + value = profile.extruder; + } + + if (value === 0 || value === undefined) { + value = gettext("Off"); + } else { + value = "" + value + "°C"; + } + + return _.sprintf(text, {name: profile.name, value: value}); + }; + self.updatePlot = function() { var graph = $("#temperature-graph"); if (!graph.length) return; // no graph @@ -560,7 +609,18 @@ $(function() { if (!profile) return OctoPrintClient.createRejectedDeferred(); self.clearAutosendTarget(item); - return self.setTargetToValue(item, (item.key() === "bed" ? profile.bed : profile.extruder)); + + var target; + if (item.key() === "bed") { + target = profile.bed; + } else if (item.key() === "chamber") { + target = profile.chamber; + } else { + target = profile.extruder; + } + + if (target === undefined) target = 0; + return self.setTargetToValue(item, target); }; self.setTargetToZero = function(item) { @@ -587,6 +647,9 @@ $(function() { if (item.key() === "bed") { return self._setBedTemperature(value) .done(onSuccess); + } else if (item.key() === "chamber") { + return self._setChamberTemperature(value) + .done(onSuccess); } else { return self._setToolTemperature(item.key(), value) .done(onSuccess); @@ -674,6 +737,9 @@ $(function() { if (item.key() === "bed") { return self._setBedOffset(value) .done(onSuccess); + } else if (item.key() === "chamber") { + return self._setChamberOffset(value) + .done(onSuccess); } else { return self._setToolOffset(item.key(), value) .done(onSuccess); @@ -700,6 +766,14 @@ $(function() { return OctoPrint.printer.setBedTemperatureOffset(parseInt(offset)); }; + self._setChamberTemperature = function(temperature) { + return OctoPrint.printer.setChamberTargetTemperature(parseInt(temperature)); + }; + + self._setChamberOffset = function(offset) { + return OctoPrint.printer.setChamberTemperatureOffset(parseInt(offset)); + }; + self._replaceLegendLabel = function(index, series, value, emph) { var showFahrenheit = self._shallShowFahrenheit(); diff --git a/src/octoprint/templates/snippets/settings/printerprofiles/profileEditorBuildvolume.jinja2 b/src/octoprint/templates/snippets/settings/printerprofiles/profileEditorBuildvolume.jinja2 index 763e3aeb2..eb5dcd65c 100644 --- a/src/octoprint/templates/snippets/settings/printerprofiles/profileEditorBuildvolume.jinja2 +++ b/src/octoprint/templates/snippets/settings/printerprofiles/profileEditorBuildvolume.jinja2 @@ -23,6 +23,12 @@ +
+ +
+ +
+
diff --git a/src/octoprint/templates/tabs/temperature.jinja2 b/src/octoprint/templates/tabs/temperature.jinja2 index 7bdceffe2..aa726cefd 100644 --- a/src/octoprint/templates/tabs/temperature.jinja2 +++ b/src/octoprint/templates/tabs/temperature.jinja2 @@ -16,6 +16,7 @@ +