Skip to content

Commit

Permalink
Merge pull request #3 from Salandora/master
Browse files Browse the repository at this point in the history
Sync latest updates
  • Loading branch information
Wotsamatter committed Apr 10, 2021
2 parents 8a4cb61 + 821748c commit 8ddb419
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 16 deletions.
26 changes: 16 additions & 10 deletions octoprint_eeprom_repetier/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def get_full_path(self, filename):
def get_file_url(self, filename):
return flask.url_for("index") + "plugin/eeprom_repetier/download/" + filename

## BlueprintPlugin
## BlueprintPlugin REST API
@octoprint.plugin.BlueprintPlugin.route("/list", methods=["GET"])
def get_list(self):
backup_folder = self.get_backup_folder()
Expand All @@ -86,9 +86,8 @@ def create_backup(self):
response_status = 201

try:
file = open(full_path,"w")
file.write(json.dumps(backup_data, indent=2))
file.close()
with open(full_path,"w") as file:
file.write(json.dumps(backup_data, indent=2))
self._logger.info("Created new EEPROM backup {}".format(filename))
except Exception:
self._logger.exception("Could not create EEPROM backup file {}".format(filename))
Expand All @@ -106,14 +105,12 @@ def get_backup(self, filename):

if (os.path.exists(full_path)):
try:
file = open(full_path,"r")
data = file.read()
file.close()
with open(full_path,"r") as file:
data = file.read()
self._logger.info("Read EEPROM backup {}".format(filename))
except Exception:
self._logger.exception("Could not read {}".format(filename))
response_status = 404
#raise
else:
self._logger.warning("Requested backup file {} not found.".format(filename))
response_status = 204
Expand All @@ -124,7 +121,6 @@ def get_backup(self, filename):

@octoprint.plugin.BlueprintPlugin.route("/backup/<filename>", methods=["DELETE"])
def delete_backup(self, filename):
backup_folder = self.get_backup_folder()
full_path = self.get_full_path(filename)
response_status = 200

Expand All @@ -135,14 +131,24 @@ def delete_backup(self, filename):
except Exception:
self._logger.exception("Could not delete {}".format(filename))
response_status = 404
#raise
else:
self._logger.warning("Backup file {} not found.".format(filename))

response = flask.jsonify(name=filename, data=[])
response.status_code = response_status
return response

@octoprint.plugin.BlueprintPlugin.route("/log", methods=["POST"])
def write_log(self):
data = flask.request.json
log_message = data["message"] if "message" in data else "empty log request"

self._logger.info(log_message)

response = flask.jsonify(message=log_message)
response.status_code = 201
return response

## tornado hooks for static file download
def route_hook(self, *args, **kwargs):
from octoprint.server import app
Expand Down
16 changes: 11 additions & 5 deletions octoprint_eeprom_repetier/static/js/eeprom_repetier.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ $(function() {
self.repetierRegEx = /Repetier_([^\s]*)/i;
self.firmwareVersion = "Unknown";

self.eepromDataRegEx = /EPR:(\d+) (\d+) ([^\s]+) (.+)/;
self.eepromDataRegEx = / EPR:(\d) (\d+) ([^\s]+) (.+)/;

self.pluginUrl = "plugin/eeprom_repetier/";

Expand Down Expand Up @@ -117,11 +117,18 @@ $(function() {
_.each(eepromData, function(data) {
if (data.origValue != data.value) {
self._requestSaveDataToEeprom(data.dataType, data.position, data.value);
data.origValue = data.value;
changed = true;

OctoPrint.postJson(
self.pluginUrl+"log",
{ message: `Updated EEPROM[${data.position}]: value ${data.origValue} changed to ${data.value} for ${data.description}` }
)
.done(function(response) {
});
changed = true;
}
});
if (changed) {
self.loadEeprom()
self.showPopup("success", "All changed values stored to EEPROM.", "");
}
};
Expand Down Expand Up @@ -150,12 +157,11 @@ $(function() {
var cmd = "M206 T" + data_type + " P" + position;
if (data_type == 3) {
cmd += " X" + value;
self.control.sendCustomCommand({ command: cmd });
}
else {
cmd += " S" + value;
self.control.sendCustomCommand({ command: cmd });
}
self.control.sendCustomCommand({ command: cmd });
};

self.showPopup = function(message_type, title, text) {
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
plugin_name = "OctoPrint-EEprom-Repetier"

# The plugin's version. Can be overwritten within OctoPrint's internal data via __plugin_version__ in the plugin module
plugin_version = "0.1.4"
plugin_version = "0.1.5"

# The plugin's description. Can be overwritten within OctoPrint's internal data via __plugin_description__ in the plugin
# module
Expand Down

0 comments on commit 8ddb419

Please sign in to comment.