Browse Source

Авто-старт после загрузки файлов

Отключаемая отправка настроек ESP
pull/1/head
Sergey 4 years ago
parent
commit
44d3475ed7
  1. 22
      Marlin/src/gcode/gcode.cpp
  2. 19
      Marlin/src/module/mks_wifi/mks_wifi.cpp
  3. 41
      Marlin/src/module/mks_wifi/mks_wifi_gcodes.cpp
  4. 1
      Marlin/src/module/mks_wifi/mks_wifi_gcodes.h
  5. 177
      Marlin/src/sd/cardreader.cpp
  6. 4
      Marlin/src/sd/cardreader.h

22
Marlin/src/gcode/gcode.cpp

@ -401,10 +401,28 @@ void GcodeSuite::process_parsed_command(const bool no_ok/*=false*/) {
case 17: M17(); break; // M17: Enable all stepper motors
#if ENABLED(SDSUPPORT)
case 20: M20(); break; // M20: List SD card
case 20:
#if ENABLED(MKS_WIFI)
if(!IS_SD_PRINTING()){
DEBUG("No SD print, proceed cmd");
M20();
}else{
DEBUG("SD print, skip cmd");
}
#else
M20();
#endif
break; // M20: List SD card
case 21: M21(); break; // M21: Init SD card
case 22: M22(); break; // M22: Release SD card
case 23: M23(); break; // M23: Select file
case 23:
#if ENABLED(MKS_WIFI)
mks_m23(parser.string_arg);
#else
M23();
#endif
break; // M23: Select file
case 24: M24(); break; // M24: Start SD print
case 25: M25(); break; // M25: Pause SD print
case 26: M26(); break; // M26: Set SD index

19
Marlin/src/module/mks_wifi/mks_wifi.cpp

@ -29,10 +29,7 @@ void mks_wifi_init(void){
WRITE(MKS_WIFI_IO_RST, HIGH);
safe_delay(1000);
WRITE(MKS_WIFI_IO4, LOW);
// mks_wifi_sd_deinit();
// safe_delay(100);
// mks_wifi_sd_init();
// mks_wifi_sd_deinit();
}
@ -102,7 +99,9 @@ void mks_wifi_out_add(uint8_t *data, uint32_t size){
uint8_t mks_wifi_input(uint8_t data){
ESP_PROTOC_FRAME esp_frame;
#ifdef MKS_WIFI_ENABLED_WIFI_CONFIG
static uint8_t get_packet_from_esp=0;
#endif
static uint8_t packet_start_flag=0;
static uint8_t packet_type=0;
static uint16_t packet_index=0;
@ -135,13 +134,14 @@ uint8_t mks_wifi_input(uint8_t data){
mks_wifi_parse_packet(&esp_frame);
#ifdef MKS_WIFI_ENABLED_WIFI_CONFIG
if(!get_packet_from_esp){
DEBUG("Fisrt packet from ESP, send config");
mks_wifi_set_param();
get_packet_from_esp=1;
}
#endif
packet_start_flag=0;
packet_index=0;
}
@ -164,6 +164,7 @@ uint8_t mks_wifi_input(uint8_t data){
void mks_wifi_parse_packet(ESP_PROTOC_FRAME *packet){
static uint8_t show_ip_once=0;
char str[100];
uint8_t str_len;
switch(packet->type){
case ESP_TYPE_NET:
@ -175,6 +176,14 @@ void mks_wifi_parse_packet(ESP_PROTOC_FRAME *packet){
ui.set_status((const char *)str+2,true);
SERIAL_ECHO_START();
SERIAL_ECHOLN((char*)str);
//Вывод имени сети
str_len = packet->data[8]; //Wifi network name len
memcpy(str,&packet->data[9],str_len);
str[str_len]=0;
SERIAL_ECHO_START();
SERIAL_ECHO("; WIFI: ");
SERIAL_ECHOLN((char*)str);
}
DEBUG("[Net] connected, IP: %d.%d.%d.%d",packet->data[0],packet->data[1],packet->data[2],packet->data[3]);

41
Marlin/src/module/mks_wifi/mks_wifi_gcodes.cpp

@ -84,4 +84,43 @@ void mks_m30(char *filename){
DEBUG("M30: %s",filename);
sd_delete_file(filename);
}
}
void mks_m23(char *filename){
char dosfilename[14];
uint8_t dot_pos;
DEBUG("M23: %s",filename);
// Simplify3D includes the size, so zero out all spaces (#7227)
for (char *fn = filename; *fn; ++fn) if (*fn == ' ') *fn = '\0';
//Имя файла может быть меньше 12 символов, но с расширением .gcode
//С конца имени файла шагаем к началу, считаем сколько символов до точки
dot_pos=0;
for (char *fn = (filename+strlen(filename) - 1); fn > filename; --fn){
dot_pos++;
if (*fn == '.') break;
}
DEBUG("DOT pos: %d",dot_pos);
CardReader::mount();
if((strlen(filename) > 12) || (dot_pos > 4)){
DEBUG("Long file name");
if(CardReader::getDosFilename(filename,dosfilename)){
strcpy(CardReader::longFilename,filename); //Для отображения на экране
DEBUG("DOS file name: %s",dosfilename);
card.openFileRead(dosfilename);
}else{
DEBUG("Can't find dos file name");
}
}else{
DEBUG("DOS file name");
card.openFileRead(filename);
}
}

1
Marlin/src/module/mks_wifi/mks_wifi_gcodes.h

@ -11,6 +11,7 @@ void mks_m991(void);
void mks_m997(void);
void mks_m115(void);
void mks_m105(void);
void mks_m23(char *filename);
void mks_m27(void);
void mks_m30(char *filename);

177
Marlin/src/sd/cardreader.cpp

@ -1167,4 +1167,181 @@ void CardReader::fileHasFinished() {
#endif // POWER_LOSS_RECOVERY
#if ENABLED(MKS_WIFI)
uint8_t CardReader::getDosFilename(char *file, char *dosfile){
dir_t p;
SdFile parent=root;
char f_name_buf[100];
int i, pathLen;
uint8_t retval=0;
parent.rewind();
while (parent.readDir(&p, longFilename) > 0) {
createFilename(filename, p);
pathLen = strlen(filename);
for (i = 0; i < pathLen; i++) if (filename[i] == '/') filename[i] = '\0';
SdFile diveDir = root; // start from the root for segment 1
for (i = 0; i < pathLen;) {
if (filename[i] == '\0') i++; // move past a single nul
char *segment = &filename[i]; // The segment after most slashes
// If a segment is empty (extra-slash) then exit
if (!*segment) break;
// Go to the next segment
while (filename[++i]) { }
diveDir.rewind();
strcpy(f_name_buf,segment);
selectByName(diveDir, f_name_buf);
// Проверка длинного имени:
//DEBUG("F: %s LF %s ",filename,longFilename);
if(!strncmp(longFilename,file,100)){
strncpy(dosfile,filename,13);
retval=1;
break;
}
// If the filename was printed then that's it
if (!flag.filenameIsDir) break;
diveDir.close();
} // while i<pathLen
}
return retval;
}
/*
void CardReader::printLongPath(char * const path) {
#if ENABLED(MKS_WIFI)
char f_name_buf[100];
#endif
int i, pathLen = strlen(path);
// SERIAL_ECHOPGM("Full Path: "); SERIAL_ECHOLN(path);
// Zero out slashes to make segments
for (i = 0; i < pathLen; i++) if (path[i] == '/') path[i] = '\0';
SdFile diveDir = root; // start from the root for segment 1
for (i = 0; i < pathLen;) {
if (path[i] == '\0') i++; // move past a single nul
char *segment = &path[i]; // The segment after most slashes
// If a segment is empty (extra-slash) then exit
if (!*segment) break;
// Go to the next segment
while (path[++i]) { }
// SERIAL_ECHOPGM("Looking for segment: "); SERIAL_ECHOLN(segment);
// Find the item, setting the long filename
diveDir.rewind();
#if ENABLED(MKS_WIFI)
strcpy(f_name_buf,segment);
selectByName(diveDir, f_name_buf);
#else
selectByName(diveDir, segment);
#endif
// Print /LongNamePart to serial output
#if ENABLED(MKS_WIFI)
if(!serial_port_index){
SERIAL_CHAR('/');
};
#else
SERIAL_CHAR('/');
#endif
SERIAL_ECHO(longFilename[0] ? longFilename : "???");
// If the filename was printed then that's it
if (!flag.filenameIsDir) break;
// SERIAL_ECHOPGM("Opening dir: "); SERIAL_ECHOLN(segment);
// Open the sub-item as the new dive parent
SdFile dir;
if (!dir.open(&diveDir, segment, O_READ)) {
SERIAL_EOL();
SERIAL_ECHO_START();
SERIAL_ECHOPAIR(STR_SD_CANT_OPEN_SUBDIR, segment);
break;
}
diveDir.close();
diveDir = dir;
} // while i<pathLen
SERIAL_EOL();
}
void CardReader::printListing(SdFile parent, const char * const prepend) {
dir_t p;
while (parent.readDir(&p, longFilename) > 0) {
if (DIR_IS_SUBDIR(&p)) {
// Get the short name for the item, which we know is a folder
char dosFilename[FILENAME_LENGTH];
createFilename(dosFilename, p);
// Allocate enough stack space for the full path to a folder, trailing slash, and nul
const bool prepend_is_empty = (!prepend || prepend[0] == '\0');
const int len = (prepend_is_empty ? 1 : strlen(prepend)) + strlen(dosFilename) + 1 + 1;
char path[len];
// Append the FOLDERNAME12/ to the passed string.
// It contains the full path to the "parent" argument.
// We now have the full path to the item in this folder.
strcpy(path, prepend_is_empty ? "/" : prepend); // root slash if prepend is empty
strcat(path, dosFilename); // FILENAME_LENGTH characters maximum
strcat(path, "/"); // 1 character
// Serial.print(path);
// Get a new directory object using the full path
// and dive recursively into it.
SdFile child;
if (!child.open(&parent, dosFilename, O_READ)) {
SERIAL_ECHO_START();
SERIAL_ECHOLNPAIR(STR_SD_CANT_OPEN_SUBDIR, dosFilename);
}
printListing(child, path);
// close() is done automatically by destructor of SdFile
}
else if (is_dir_or_gcode(p)) {
createFilename(filename, p);
if (prepend) SERIAL_ECHO(prepend);
#if ENABLED(MKS_WIFI)
if (serial_port_index){
printLongPath(filename);
}else{
SERIAL_ECHO(filename);
SERIAL_CHAR(' ');
SERIAL_ECHOLN(p.fileSize);
}
#else
SERIAL_ECHO(filename);
SERIAL_CHAR(' ');
SERIAL_ECHOLN(p.fileSize);
#endif
}
}
}
*/
#endif
#endif // SDSUPPORT

4
Marlin/src/sd/cardreader.h

@ -156,6 +156,10 @@ public:
static Sd2Card& getSd2Card() { return sd2card; }
#if ENABLED(MKS_WIFI)
static uint8_t getDosFilename(char *file, char *dosfile);
#endif
#if ENABLED(AUTO_REPORT_SD_STATUS)
static void auto_report_sd_status();
static inline void set_auto_report_interval(uint8_t v) {

Loading…
Cancel
Save