From 739d1fede4861d2842681382fa97abd014b605ac Mon Sep 17 00:00:00 2001 From: Sergey Date: Thu, 2 Dec 2021 17:36:25 +0300 Subject: [PATCH] m992 and m944 support --- Marlin/src/gcode/gcode.cpp | 2 ++ .../src/module/mks_wifi/mks_wifi_gcodes.cpp | 29 ++++++++++++++++++ Marlin/src/module/mks_wifi/mks_wifi_gcodes.h | 2 ++ Marlin/src/sd/cardreader.cpp | 30 +++++++++++++++++++ Marlin/src/sd/cardreader.h | 5 ++++ 5 files changed, 68 insertions(+) diff --git a/Marlin/src/gcode/gcode.cpp b/Marlin/src/gcode/gcode.cpp index e534a5d465..3a9436ca97 100644 --- a/Marlin/src/gcode/gcode.cpp +++ b/Marlin/src/gcode/gcode.cpp @@ -1070,6 +1070,8 @@ void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) { #if ENABLED(MKS_WIFI) case 991: if(port.index == MKS_WIFI_SERIAL_NUM){mks_m991();}; return; + case 992: if(port.index == MKS_WIFI_SERIAL_NUM){mks_m992();}; return; + case 994: if(port.index == MKS_WIFI_SERIAL_NUM){mks_m994();}; return; #endif #if ENABLED(MKS_WIFI) diff --git a/Marlin/src/module/mks_wifi/mks_wifi_gcodes.cpp b/Marlin/src/module/mks_wifi/mks_wifi_gcodes.cpp index 2913ef11ed..caa3f4a18d 100644 --- a/Marlin/src/module/mks_wifi/mks_wifi_gcodes.cpp +++ b/Marlin/src/module/mks_wifi/mks_wifi_gcodes.cpp @@ -1,5 +1,9 @@ #include "mks_wifi_gcodes.h" #ifdef MKS_WIFI +#include "../../module/printcounter.h" +#include "../../libs/duration_t.h" + + const uint8_t pak[5]={0xA5,0x07,0x00,0x00,0xFC}; @@ -63,6 +67,31 @@ void mks_m115(void){ mks_wifi_out_add((uint8_t *)m115_firmware,strlen(m115_firmware)); } + +void mks_m992(void){ + char buffer[30]; + uint32_t duration_sec = print_job_timer.duration(); + uint16_t hours = duration_sec / 3600; + uint16_t minutes = (duration_sec - hours*3600) / 60; + uint16_t seconds = (duration_sec - hours*3600 - minutes*60); + + sprintf((char *)buffer, "M992 %02d:%02d:%02d\r\n", hours, minutes, seconds); + mks_wifi_out_add((uint8_t *)buffer,strlen(buffer)); +} + +void mks_m994(void){ + char buffer[150]; + char filename[101]; + + if(CardReader::isPrinting()){ + CardReader::GetSelectedFilename(filename); + sprintf((char *)buffer, ("M994 %s;%ld\n"), filename, CardReader::GetSelectedFilesize()); + mks_wifi_out_add((uint8_t *)buffer,strlen(buffer)); + } + +} + + void mks_m27(void){ // if (CardReader::isPrinting()) { diff --git a/Marlin/src/module/mks_wifi/mks_wifi_gcodes.h b/Marlin/src/module/mks_wifi/mks_wifi_gcodes.h index 7cea204df8..1a9645bcbb 100644 --- a/Marlin/src/module/mks_wifi/mks_wifi_gcodes.h +++ b/Marlin/src/module/mks_wifi/mks_wifi_gcodes.h @@ -10,6 +10,8 @@ #ifdef MKS_WIFI void mks_m991(void); +void mks_m992(void); +void mks_m994(void); void mks_m997(void); void mks_m115(void); void mks_m105(void); diff --git a/Marlin/src/sd/cardreader.cpp b/Marlin/src/sd/cardreader.cpp index 72c62aabb6..9b4533454e 100644 --- a/Marlin/src/sd/cardreader.cpp +++ b/Marlin/src/sd/cardreader.cpp @@ -1375,4 +1375,34 @@ void CardReader::fileHasFinished() { #endif // POWER_LOSS_RECOVERY + +#if ENABLED(MKS_WIFI) +void CardReader::GetSelectedFilename(char *filename) { + if (file.isOpen()) { + char dosFilename[FILENAME_LENGTH]; + file.getDosName(dosFilename); + #if ENABLED(LONG_FILENAME_HOST_SUPPORT) + selectFileByName(dosFilename); + if (longFilename[0]) { + strncpy(filename,longFilename,100); + }else{ + strncpy(filename,dosFilename,100); + } + #else + strncpy(filename,dosFilename,100); + #endif + } + else + SERIAL_ECHOPGM("(no file)"); + + SERIAL_EOL(); +} + + +uint32_t CardReader::GetSelectedFilesize(void) { + return filesize; +} + +#endif + #endif // SDSUPPORT diff --git a/Marlin/src/sd/cardreader.h b/Marlin/src/sd/cardreader.h index 97003e1d13..10f1d0451a 100644 --- a/Marlin/src/sd/cardreader.h +++ b/Marlin/src/sd/cardreader.h @@ -109,6 +109,11 @@ public: CardReader(); +#if ENABLED(MKS_WIFI) + static void GetSelectedFilename(char *filename); + static uint32_t GetSelectedFilesize(void); +#endif + static void changeMedia(DiskIODriver *_driver) { driver = _driver; } static SdFile getroot() { return root; }