First sweep
This commit is contained in:
@@ -582,10 +582,14 @@
|
||||
#define LCD_SERIAL_PORT 0
|
||||
#define LCD_BAUDRATE 115200
|
||||
#define SERIAL_CATCHALL -1
|
||||
#elif ANY(MachineCR10SPro, MachineCRX, MachineEnder5Plus, MachineCR10Max) && NONE(GraphicLCD, MachineEnder3V2)
|
||||
#elif ANY(MachineCR10SPro, MachineCRX, MachineEnder5Plus, MachineCR10Max) && NONE(GraphicLCD, MachineEnder3V2, Creality422, Creality427)
|
||||
#define LCD_SERIAL_PORT 2
|
||||
#define LCD_BAUDRATE 115200
|
||||
#define SERIAL_CATCHALL 0
|
||||
#elif ANY(MachineCR10SPro, MachineCRX, MachineEnder5Plus, MachineCR10Max) && DISABLED(GraphicLCD)
|
||||
#define LCD_SERIAL_PORT 3
|
||||
#define LCD_BAUDRATE 115200
|
||||
#define SERIAL_CATCHALL 1
|
||||
#elif ANY(Creality422, Creality427) && DISABLED(MachineEnder3V2)
|
||||
#define SERIAL_PORT_2 3
|
||||
#endif
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
#include "Creality_DWIN.h"
|
||||
#include "FileNavigator.h"
|
||||
#include <HardwareSerial.h>
|
||||
#include <WString.h>
|
||||
#include <stdio.h>
|
||||
@@ -7,6 +8,8 @@
|
||||
#if ENABLED(EXTENSIBLE_UI)
|
||||
namespace ExtUI
|
||||
{
|
||||
static uint16_t fileIndex = 0;
|
||||
uint8_t recordcount = 0;
|
||||
uint8_t waitway_lock = 0;
|
||||
const float manual_feedrate_mm_m[] = MANUAL_FEEDRATE;
|
||||
uint8_t startprogress = 0;
|
||||
@@ -586,84 +589,6 @@ void RTSSHOW::RTS_SndData(unsigned long n, unsigned long addr, unsigned char cmd
|
||||
RTS_SndData();
|
||||
}
|
||||
|
||||
void RTSSHOW::RTS_SDCardUpate(bool removed, bool inserted)
|
||||
{
|
||||
SERIAL_ECHOLNPGM_P(PSTR("SDUpdate"));
|
||||
bool shouldCheck;
|
||||
if(!removed && !inserted)
|
||||
shouldCheck = isMediaInserted();
|
||||
else
|
||||
shouldCheck = false;
|
||||
|
||||
if (inserted || shouldCheck)
|
||||
{
|
||||
ExtUI::FileList files;
|
||||
files.count();
|
||||
|
||||
int addrnum = 0;
|
||||
int num = 0;
|
||||
for (uint16_t i = 0; i < files.count() && i < (uint16_t)MaxFileNumber + addrnum; i++)
|
||||
{
|
||||
files.seek(i);
|
||||
files.filename();
|
||||
const char *pointFilename = files.longFilename();
|
||||
int filenamelen = strlen(files.longFilename());
|
||||
int j = 1;
|
||||
while ((strncmp(&pointFilename[j], ".gcode", 6) && strncmp(&pointFilename[j], ".GCODE", 6)) && (j++) < filenamelen)
|
||||
;
|
||||
if (j >= filenamelen)
|
||||
{
|
||||
addrnum++;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (j >= TEXTBYTELEN)
|
||||
{
|
||||
//strncpy(&files.longFilename[TEXTBYTELEN -3],"~~",2);
|
||||
//files.longFilename()[TEXTBYTELEN-1] = '\0';
|
||||
j = TEXTBYTELEN - 1;
|
||||
}
|
||||
|
||||
strncpy(CardRecbuf.Cardshowfilename[num], files.longFilename(), j);
|
||||
|
||||
strcpy(CardRecbuf.Cardfilename[num], files.shortFilename());
|
||||
CardRecbuf.addr[num] = SDFILE_ADDR + num * 10;
|
||||
rtscheck.RTS_SndData(CardRecbuf.Cardshowfilename[num], CardRecbuf.addr[num]);
|
||||
CardRecbuf.Filesum = (++num);
|
||||
//SERIAL_ECHO(" CardRecbuf.Filesum ==");
|
||||
//SERIAL_ECHO(CardRecbuf.Filesum);
|
||||
rtscheck.RTS_SndData(1, FilenameIcon + CardRecbuf.Filesum);
|
||||
}
|
||||
rtscheck.RTS_SndData(17, IconPrintstatus);
|
||||
return;
|
||||
}
|
||||
|
||||
if(removed || !shouldCheck)
|
||||
{
|
||||
for (int i = 0; i < MaxFileNumber; i++)
|
||||
{
|
||||
for (int j = 0; j < 10; j++)
|
||||
rtscheck.RTS_SndData(0, SDFILE_ADDR + i * 10 + j);
|
||||
}
|
||||
|
||||
for (int j = 0; j < 10; j++)
|
||||
{
|
||||
rtscheck.RTS_SndData(0, Printfilename + j); //clean screen.
|
||||
rtscheck.RTS_SndData(0, Choosefilename + j); //clean filename
|
||||
}
|
||||
for (int j = 0; j < 8; j++)
|
||||
rtscheck.RTS_SndData(0, FilenameCount + j);
|
||||
for (int j = 1; j <= MaxFileNumber; j++)
|
||||
{
|
||||
rtscheck.RTS_SndData(10, FilenameIcon + j);
|
||||
rtscheck.RTS_SndData(10, FilenameIcon1 + j);
|
||||
}
|
||||
SERIAL_ECHOLNPGM_P(PSTR("***Card Removed***"));
|
||||
rtscheck.RTS_SndData(18, IconPrintstatus);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
void RTSSHOW::RTS_HandleData()
|
||||
{
|
||||
int Checkkey = -1;
|
||||
@@ -767,7 +692,7 @@ SERIAL_ECHOLNPGM_P(PSTR("BeginSwitch"));
|
||||
{
|
||||
InforShowStatus = false;
|
||||
CardRecbuf.recordcount = -1;
|
||||
RTS_SDCardUpate(false, false);
|
||||
filenavigator.getFiles(0);
|
||||
SERIAL_ECHOLNPGM_P(PSTR("Handle Data PrintFile 1 Setting Screen "));
|
||||
RTS_SndData(ExchangePageBase + 46, ExchangepageAddr);
|
||||
}
|
||||
@@ -1593,43 +1518,32 @@ SERIAL_ECHOLNPGM_P(PSTR("BeginSwitch"));
|
||||
break;
|
||||
|
||||
case Filename:
|
||||
SERIAL_ECHOLNPGM_P(PSTR("Filename"));
|
||||
SERIAL_ECHOLNPGM_P(PSTR("Filename Selected"));
|
||||
if (isMediaInserted() && recdat.addr == FilenameChs)
|
||||
{
|
||||
SERIAL_ECHOLNPGM_P(PSTR("Filename-Media"));
|
||||
if (recdat.data[0] > (uint8_t)CardRecbuf.Filesum)
|
||||
break;
|
||||
SERIAL_ECHOLNPGM_P(PSTR("Has Media"));
|
||||
|
||||
SERIAL_ECHOLNPGM_P(PSTR("Recdata"));
|
||||
CardRecbuf.recordcount = recdat.data[0] - 1;
|
||||
for (int j = 0; j < 10; j++)
|
||||
RTS_SndData(0, Choosefilename + j);
|
||||
int filelen = strlen(CardRecbuf.Cardshowfilename[(int)CardRecbuf.recordcount]);
|
||||
filelen = (TEXTBYTELEN - filelen) / 2;
|
||||
if (filelen > 0)
|
||||
{
|
||||
char buf[20];
|
||||
memset(buf, 0, sizeof(buf));
|
||||
strncpy(buf, " ", filelen);
|
||||
strcpy(&buf[filelen], CardRecbuf.Cardshowfilename[(int)CardRecbuf.recordcount]);
|
||||
RTS_SndData(buf, Choosefilename);
|
||||
recordcount = recdat.data[0] - 1;
|
||||
if(filenavigator.currentindex == 0 && filenavigator.folderdepth > 0 && recordcount == 0) {
|
||||
filenavigator.upDIR();
|
||||
filenavigator.getFiles(0);
|
||||
return;
|
||||
}
|
||||
else
|
||||
RTS_SndData(CardRecbuf.Cardshowfilename[(int)CardRecbuf.recordcount], Choosefilename);
|
||||
|
||||
for (int j = 0; j < 8; j++)
|
||||
RTS_SndData(0, FilenameCount + j);
|
||||
char buf[20];
|
||||
memset(buf, 0, sizeof(buf));
|
||||
sprintf(buf, "%d/%d", (int)recdat.data[0], CardRecbuf.Filesum);
|
||||
RTS_SndData(buf, FilenameCount);
|
||||
delay_ms(2);
|
||||
for (int j = 1; j <= CardRecbuf.Filesum; j++)
|
||||
for (int j = 1; j <= CardRecbuf.Filesum; j++) // Clear filename BG Color and Frame
|
||||
{
|
||||
RTS_SndData((unsigned long)0xFFFF, FilenameNature + j * 16); // white
|
||||
RTS_SndData(10, FilenameIcon1 + j); //clean
|
||||
}
|
||||
|
||||
if(filenavigator.getIndexisDir(fileIndex + recordcount))
|
||||
filenavigator.changeDIR((char *)filenavigator.getIndexName(fileIndex + recordcount));
|
||||
else{
|
||||
for (int j = 0; j < 10; j++) // clear current filename
|
||||
RTS_SndData(0, Choosefilename + j);
|
||||
RTS_SndData(filenavigator.getIndexName(fileIndex + recordcount), Choosefilename);
|
||||
}
|
||||
|
||||
RTS_SndData((unsigned long)0x87F0, FilenameNature + recdat.data[0] * 16); // Change BG of selected line to Light Green
|
||||
RTS_SndData(6, FilenameIcon1 + recdat.data[0]); // show frame
|
||||
}
|
||||
@@ -1639,31 +1553,14 @@ SERIAL_ECHOLNPGM_P(PSTR("BeginSwitch"));
|
||||
{
|
||||
if (CardRecbuf.recordcount < 0)
|
||||
break;
|
||||
printFile(CardRecbuf.Cardfilename[(int)CardRecbuf.recordcount]);
|
||||
printFile(filenavigator.getIndexName(fileIndex + recordcount));
|
||||
|
||||
for (int j = 0; j < 10; j++) //clean screen.
|
||||
RTS_SndData(0, Printfilename + j);
|
||||
|
||||
int filelen = strlen(CardRecbuf.Cardshowfilename[(int)CardRecbuf.recordcount]);
|
||||
filelen = (TEXTBYTELEN - filelen) / 2;
|
||||
if (filelen > 0)
|
||||
{
|
||||
char buf[20];
|
||||
memset(buf, 0, sizeof(buf));
|
||||
strncpy(buf, " ", filelen);
|
||||
strcpy(&buf[filelen], CardRecbuf.Cardshowfilename[(int)CardRecbuf.recordcount]);
|
||||
RTS_SndData(buf, Printfilename);
|
||||
}
|
||||
else
|
||||
RTS_SndData(CardRecbuf.Cardshowfilename[(int)CardRecbuf.recordcount], Printfilename);
|
||||
RTS_SndData(filenavigator.getIndexName(fileIndex + recordcount), Printfilename);
|
||||
delay_ms(2);
|
||||
|
||||
#if FAN_COUNT > 0
|
||||
for (uint8_t i = 0; i < FAN_COUNT; i++)
|
||||
setTargetFan_percent(FanOn, (fan_t)i);
|
||||
#endif
|
||||
FanStatus = false;
|
||||
|
||||
RTS_SndData(1 + CEIconGrap, IconPrintstatus); // 1 for Heating
|
||||
delay_ms(2);
|
||||
RTS_SndData(ExchangePageBase + 53, ExchangepageAddr);
|
||||
@@ -1720,18 +1617,56 @@ void onPrinterKilled(PGM_P killMsg, PGM_P component) {
|
||||
void onMediaInserted()
|
||||
{
|
||||
SERIAL_ECHOLNPGM_P(PSTR("***Initing card is OK***"));
|
||||
rtscheck.RTS_SDCardUpate(false, true);
|
||||
filenavigator.getFiles(0);
|
||||
}
|
||||
|
||||
void onMediaError()
|
||||
{
|
||||
rtscheck.RTS_SDCardUpate(true, false);
|
||||
for (int i = 0; i < MaxFileNumber; i++)
|
||||
{
|
||||
for (int j = 0; j < 10; j++)
|
||||
rtscheck.RTS_SndData(0, SDFILE_ADDR + i * 10 + j);
|
||||
}
|
||||
|
||||
for (int j = 0; j < 10; j++)
|
||||
{
|
||||
rtscheck.RTS_SndData(0, Printfilename + j); //clean screen.
|
||||
rtscheck.RTS_SndData(0, Choosefilename + j); //clean filename
|
||||
}
|
||||
for (int j = 0; j < 8; j++)
|
||||
rtscheck.RTS_SndData(0, FilenameCount + j);
|
||||
for (int j = 1; j <= MaxFileNumber; j++)
|
||||
{
|
||||
rtscheck.RTS_SndData(10, FilenameIcon + j);
|
||||
rtscheck.RTS_SndData(10, FilenameIcon1 + j);
|
||||
}
|
||||
rtscheck.RTS_SndData(18, IconPrintstatus);
|
||||
return;
|
||||
SERIAL_ECHOLNPGM_P(PSTR("***Initing card fails***"));
|
||||
}
|
||||
|
||||
void onMediaRemoved()
|
||||
{
|
||||
rtscheck.RTS_SDCardUpate(true, false);
|
||||
for (int i = 0; i < MaxFileNumber; i++)
|
||||
{
|
||||
for (int j = 0; j < 10; j++)
|
||||
rtscheck.RTS_SndData(0, SDFILE_ADDR + i * 10 + j);
|
||||
}
|
||||
|
||||
for (int j = 0; j < 10; j++)
|
||||
{
|
||||
rtscheck.RTS_SndData(0, Printfilename + j); //clean screen.
|
||||
rtscheck.RTS_SndData(0, Choosefilename + j); //clean filename
|
||||
}
|
||||
for (int j = 0; j < 8; j++)
|
||||
rtscheck.RTS_SndData(0, FilenameCount + j);
|
||||
for (int j = 1; j <= MaxFileNumber; j++)
|
||||
{
|
||||
rtscheck.RTS_SndData(10, FilenameIcon + j);
|
||||
rtscheck.RTS_SndData(10, FilenameIcon1 + j);
|
||||
}
|
||||
rtscheck.RTS_SndData(18, IconPrintstatus);
|
||||
return;
|
||||
SERIAL_ECHOLN("***Card Removed***");
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,144 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||
*
|
||||
* Based on Sprinter and grbl.
|
||||
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
|
||||
/* ****************************************
|
||||
* lcd/extui/lib/nextion/FileNavigator.cpp
|
||||
* ****************************************
|
||||
* Extensible_UI implementation for Nextion
|
||||
* https://github.com/Skorpi08
|
||||
* ***************************************/
|
||||
|
||||
#include "../../../../inc/MarlinConfigPre.h"
|
||||
|
||||
|
||||
|
||||
#include "FileNavigator.h"
|
||||
|
||||
using namespace ExtUI;
|
||||
|
||||
#define DEBUG_OUT NEXDEBUGLEVEL
|
||||
#include "../../../../core/debug_out.h"
|
||||
|
||||
FileList FileNavigator::filelist; // Instance of the Marlin file API
|
||||
char FileNavigator::currentfoldername[MAX_PATH_LEN]; // Current folder path
|
||||
uint16_t FileNavigator::lastindex;
|
||||
uint8_t FileNavigator::folderdepth;
|
||||
uint16_t FileNavigator::currentindex; // override the panel request
|
||||
|
||||
FileNavigator filenavigator;
|
||||
|
||||
FileNavigator::FileNavigator() { reset(); }
|
||||
|
||||
void FileNavigator::reset() {
|
||||
currentfoldername[0] = '\0';
|
||||
folderdepth = 0;
|
||||
currentindex = 0;
|
||||
lastindex = 0;
|
||||
// Start at root folder
|
||||
while (!filelist.isAtRootDir()) filelist.upDir();
|
||||
refresh();
|
||||
}
|
||||
|
||||
void FileNavigator::refresh() { filelist.refresh(); }
|
||||
|
||||
|
||||
bool FileNavigator::getIndexisDir(uint16_t index){
|
||||
filelist.seek(index);
|
||||
return filelist.isDir();
|
||||
}
|
||||
|
||||
const char *FileNavigator::getIndexName(uint16_t index){
|
||||
filelist.seek(index);
|
||||
return filelist.shortFilename();
|
||||
}
|
||||
|
||||
void FileNavigator::getFiles(uint16_t index) {
|
||||
uint16_t files = DISPLAY_FILES, fseek = 0, fcnt = 0;
|
||||
if (index == 0)
|
||||
currentindex = 0;
|
||||
else {
|
||||
// Each time we change folder we reset the file index to 0 and keep track
|
||||
// of the current position as the TFT panel isn't aware of folder trees.
|
||||
--currentindex; // go back a file to take account of the .. added to the root.
|
||||
if (index > lastindex)
|
||||
currentindex += files + 1;
|
||||
else if (currentindex >= files)
|
||||
currentindex -= files - 1;
|
||||
else
|
||||
currentindex = 0;
|
||||
}
|
||||
lastindex = index;
|
||||
|
||||
DEBUG_ECHOLNPAIR("index=", index, " currentindex=", currentindex);
|
||||
|
||||
if (currentindex == 0 && folderdepth > 0) { // Add a link to go up a folder
|
||||
files--;
|
||||
rtscheck.RTS_SndData(filelist.shortFilename(), SDFILE_ADDR);
|
||||
fcnt++;
|
||||
}
|
||||
|
||||
for (uint16_t seek = currentindex; seek < currentindex + files; seek++) {
|
||||
if (filelist.seek(seek)) {
|
||||
rtscheck.RTS_SndData(filelist.shortFilename(), (SDFILE_ADDR + (fcnt * 10)));
|
||||
if (filelist.isDir())
|
||||
rtscheck.RTS_SndData((unsigned long)0x1A2B, (FilenameNature + (fcnt * 16))); // Change BG of selected line to Light Green
|
||||
else
|
||||
rtscheck.RTS_SndData((unsigned long)0xFFFF, FilenameNature + fcnt * 16); // white
|
||||
rtscheck.RTS_SndData(1, FilenameIcon + ++fcnt);
|
||||
fcnt++;
|
||||
fseek = seek;
|
||||
DEBUG_ECHOLNPAIR("-", seek, " '", filelist.longFilename(), "' '", currentfoldername, "", filelist.shortFilename(), "'\n");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void FileNavigator::changeDIR(char *folder) {
|
||||
DEBUG_ECHOLNPAIR("currentfolder: ", currentfoldername, " New: ", folder);
|
||||
if (folderdepth >= MAX_FOLDER_DEPTH) return; // limit the folder depth
|
||||
strcat(currentfoldername, folder);
|
||||
strcat(currentfoldername, "/");
|
||||
filelist.changeDir(folder);
|
||||
refresh();
|
||||
folderdepth++;
|
||||
currentindex = 0;
|
||||
}
|
||||
|
||||
void FileNavigator::upDIR() {
|
||||
filelist.upDir();
|
||||
refresh();
|
||||
folderdepth--;
|
||||
currentindex = 0;
|
||||
// Remove the last child folder from the stored path
|
||||
if (folderdepth == 0) {
|
||||
currentfoldername[0] = '\0';
|
||||
reset();
|
||||
}
|
||||
else {
|
||||
char *pos = nullptr;
|
||||
for (uint8_t f = 0; f < folderdepth; f++)
|
||||
pos = strchr(currentfoldername, '/');
|
||||
pos[1] = '\0';
|
||||
}
|
||||
DEBUG_ECHOLNPAIR("depth: ", folderdepth, " currentfoldername: ", currentfoldername);
|
||||
}
|
||||
|
||||
char* FileNavigator::getCurrentFolderName() { return currentfoldername; }
|
||||
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
* Marlin 3D Printer Firmware
|
||||
* Copyright (c) 2021 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
|
||||
*
|
||||
* Based on Sprinter and grbl.
|
||||
* Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
/* ****************************************
|
||||
* lcd/extui/lib/nextion/FileNavigator.cpp
|
||||
* ****************************************
|
||||
* Extensible_UI implementation for Nextion
|
||||
* https://github.com/Skorpi08
|
||||
* ***************************************/
|
||||
|
||||
#include "../../ui_api.h"
|
||||
#include "Creality_DWIN.h"
|
||||
|
||||
#define MAX_FOLDER_DEPTH 4 // Limit folder depth TFT has a limit for the file path
|
||||
#define MAX_CMND_LEN 16 * MAX_FOLDER_DEPTH // Maximum Length for a Panel command
|
||||
#define MAX_PATH_LEN 16 * MAX_FOLDER_DEPTH // Maximum number of characters in a SD file path
|
||||
#define DISPLAY_FILES 5
|
||||
|
||||
using namespace ExtUI;
|
||||
|
||||
class FileNavigator {
|
||||
public:
|
||||
FileNavigator();
|
||||
static void reset();
|
||||
static void getFiles(uint16_t);
|
||||
static void upDIR();
|
||||
static void changeDIR(char *);
|
||||
static void refresh();
|
||||
static char* getCurrentFolderName();
|
||||
static uint8_t folderdepth;
|
||||
static uint16_t currentindex;
|
||||
static bool getIndexisDir(uint16_t);
|
||||
const char *getIndexName(uint16_t);
|
||||
private:
|
||||
static FileList filelist;
|
||||
static char currentfoldername[MAX_PATH_LEN];
|
||||
static uint16_t lastindex;
|
||||
};
|
||||
|
||||
extern FileNavigator filenavigator;
|
||||
Reference in New Issue
Block a user