From 6371c6cd50c4e214ca393d2958010caaee2714d7 Mon Sep 17 00:00:00 2001 From: Luc <8822552+luc-github@users.noreply.github.com> Date: Mon, 11 Jan 2021 13:56:16 +0100 Subject: [PATCH] Add subdir support and device support in command line upload --- esp3d/src/include/version.h | 2 +- .../modules/http/handles/upload-SD-files.cpp | 8 +++++ .../src/modules/http/handles/upload-files.cpp | 8 +++++ .../modules/http/handles/upload-mks-files.cpp | 30 +++++++++++++++++-- 4 files changed, 44 insertions(+), 4 deletions(-) diff --git a/esp3d/src/include/version.h b/esp3d/src/include/version.h index f7ad9c7a..c5d96415 100644 --- a/esp3d/src/include/version.h +++ b/esp3d/src/include/version.h @@ -22,7 +22,7 @@ #define _VERSION_ESP3D_H //version and sources location -#define FW_VERSION "3.0.0.a82" +#define FW_VERSION "3.0.0.a83" #define REPOSITORY "https://github.com/luc-github/ESP3D/tree/3.0" #endif //_VERSION_ESP3D_H diff --git a/esp3d/src/modules/http/handles/upload-SD-files.cpp b/esp3d/src/modules/http/handles/upload-SD-files.cpp index 5417cedf..ac3cde04 100644 --- a/esp3d/src/modules/http/handles/upload-SD-files.cpp +++ b/esp3d/src/modules/http/handles/upload-SD-files.cpp @@ -53,6 +53,14 @@ void HTTP_Server::SDFileupload () } else { filename = upload.filename; } + if (_webserver->hasArg ("rpath") ) { + upload_filename = _webserver->arg ("rpath") + filename; + if (upload_filename[0] != '/') { + filename = "/" + upload_filename; + } else { + filename = upload_filename; + } + } //Sanity check if (ESP_SD::exists (filename.c_str()) ) { ESP_SD::remove (filename.c_str()); diff --git a/esp3d/src/modules/http/handles/upload-files.cpp b/esp3d/src/modules/http/handles/upload-files.cpp index 92cdf06a..325b6e9e 100644 --- a/esp3d/src/modules/http/handles/upload-files.cpp +++ b/esp3d/src/modules/http/handles/upload-files.cpp @@ -52,6 +52,14 @@ void HTTP_Server::FSFileupload () } else { filename = upload.filename; } + if (_webserver->hasArg ("rpath") ) { + upload_filename = _webserver->arg ("rpath") + filename; + if (upload_filename[0] != '/') { + filename = "/" + upload_filename; + } else { + filename = upload_filename; + } + } //Sanity check if (ESP_FileSystem::exists (filename.c_str()) ) { ESP_FileSystem::remove (filename.c_str()); diff --git a/esp3d/src/modules/http/handles/upload-mks-files.cpp b/esp3d/src/modules/http/handles/upload-mks-files.cpp index cfb2849b..21fc1552 100644 --- a/esp3d/src/modules/http/handles/upload-mks-files.cpp +++ b/esp3d/src/modules/http/handles/upload-mks-files.cpp @@ -28,6 +28,7 @@ #endif //ARDUINO_ARCH_ESP8266 #include "../../mks/mks_service.h" #include "../../authentication/authentication_service.h" + //MKS files uploader handle void HTTP_Server::MKSFileupload () { @@ -50,10 +51,33 @@ void HTTP_Server::MKSFileupload () String filename = upload.filename; String sfilename = "s"+filename; //No / in filename - int p = filename.lastIndexOf("/"); + if (filename[0]=='/') { + filename.remove(0,1); + } + //for remote path or device + //if USB on TFT 0: + //if SD on TFT 1: + //if SD on Robin 0: or just - if(p!=-1) { - filename.remove(0,p+1); + if (_webserver->hasArg ("rpath") ) { + String upload_filename = _webserver->arg ("rpath") + "/" + filename; + filename = upload_filename; + if (filename[0]=='/') { + filename.remove(0,1); + } + //this is target device + if (filename.startsWith("USB:") || filename.startsWith("SD:")) { + String cmd = "M998 "; + if (filename.startsWith("USB:")) { + cmd += "0"; + filename.remove(0,strlen("USB:")); + } else { + cmd += "1"; + filename.remove(0,strlen("SD:")); + } + MKSService::sendGcodeFrame(cmd.c_str()); + Hal::wait(10); + } } if (_webserver->hasArg(sfilename)) { fileSize = _webserver->arg(sfilename).toInt();