Skip to content

Commit

Permalink
Added ability to accept zipped fseq files when using ESP32 CPU
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinMueller2003 committed Jan 10, 2025
1 parent ee88e72 commit db99c03
Show file tree
Hide file tree
Showing 6 changed files with 168 additions and 15 deletions.
2 changes: 1 addition & 1 deletion html/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ $(function () {
uploadMultiple: false,
createImageThumbnails: false,
dictDefaultMessage: 'Drag an image here to upload, or click to select one',
acceptedFiles: '.fseq,.pl',
acceptedFiles: '.fseq,.pl,.zip',
timeout: 99999999, /*milliseconds*/
init: function () {
this.on('success', function (file, resp) {
Expand Down
2 changes: 1 addition & 1 deletion include/ESPixelStick.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
#define STRINGIFY(X) #X
#define STRING(X) STRINGIFY(X)

extern void RequestReboot(uint32_t LoopDelay);
extern void RequestReboot(uint32_t LoopDelay, bool SkipDisable = false);
extern bool RebootInProgress();

/// Core configuration structure
Expand Down
7 changes: 5 additions & 2 deletions include/FileMgr.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,13 @@ class c_FileMgr
void GetListOfSdFiles (std::vector<String> & Response, bool LockStatus = false);
uint64_t GetSdFileSize (const String & FileName, bool LockStatus = false);
uint64_t GetSdFileSize (const FileId & FileHandle, bool LockStatus = false);
void BuildFseqList (bool LockStatus = false);
void BuildFseqList (bool LockStatus, bool DisplayFileNames);
bool SeekSdFile (const FileId & FileHandle, size_t position, SeekMode Mode);

void GetDriverName (String& Name) { Name = "FileMgr"; }
void NetworkStateChanged (bool NewState);
size_t GetDefaultFseqFileList(uint8_t * buffer, size_t maxlen);
size_t GetDefaultFseqFileList (uint8_t * buffer, size_t maxlen);
void FindFirstZipFile (String &FileName, bool LockStatus);

#define FSEQFILELIST "fseqfilelist.json"
// Configuration file params
Expand Down Expand Up @@ -141,6 +143,7 @@ class c_FileMgr
bool FtpEnabled = true;
uint64_t SdCardSizeMB = 0;
uint32_t MaxSdSpeed = MaxSdTransSpeedMHz;
bool FoundZipFile = false;

public: struct __attribute__((__packed__, aligned(4))) CSD {
public: union {
Expand Down
3 changes: 3 additions & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ lib_deps =
https://github.com/MartinMueller2003/Artnet
https://github.com/MartinMueller2003/Espalexa
https://github.com/MartinMueller2003/SimpleFTPServer
https://github.com/bitbank2/unzipLIB
extra_scripts =
.scripts/download_fs.py
.scripts/CopyTargets.py
Expand Down Expand Up @@ -104,6 +105,8 @@ build_flags =
${env.build_flags}
-D DEFAULT_FTP_SERVER_NETWORK_TYPE_ESP32=6
-D DEFAULT_STORAGE_TYPE_ESP32=2
-D SUPPORT_UNZIP=1
-D DYNAMIC_CRC_TABLE=1 ; unzip uses this
-Wl,-Map=firmware.map
-Wl,--cref
-mtext-section-literals
Expand Down
167 changes: 157 additions & 10 deletions src/FileMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "FileMgr.hpp"
#include "network/NetworkMgr.hpp"
#include "output/OutputMgr.hpp"
#include "UnzipFiles.hpp"

SdFs sd;
const int8_t DISABLE_CS_PIN = -1;
Expand Down Expand Up @@ -61,7 +62,7 @@ void ftp_callback(FtpOperation ftpOperation, unsigned int freeSpace, unsigned in

case FTP_FREE_SPACE_CHANGE:
{
FileMgr.BuildFseqList(false);
FileMgr.BuildFseqList(false, false);
LOG_PORT.printf("FTP: Free space change, free %u of %u! Rebuilding FSEQ file list\n", freeSpace, totalSpace);
break;
}
Expand Down Expand Up @@ -181,6 +182,18 @@ void c_FileMgr::Begin ()

SetSpiIoPins ();

#ifdef SUPPORT_UNZIP
if(FoundZipFile)
{
FeedWDT();
UnzipFiles * Unzipper = new(UnzipFiles);
Unzipper->Run();
delete Unzipper;
logcon("Requesting reboot after unzipping files");
RequestReboot(1, true);
}
#endif // def SUPPORT_UNZIP

} while (false);

// DEBUG_END;
Expand Down Expand Up @@ -427,7 +440,7 @@ void c_FileMgr::SetSpiIoPins ()

DescribeSdCardToUser ();
// DEBUG_V();
BuildFseqList(false);
BuildFseqList(false, true);
// DEBUG_V();
}
}
Expand Down Expand Up @@ -1021,7 +1034,7 @@ void c_FileMgr::DeleteSdFile (const String & FileName, bool LockStatus)
ESP_SD.remove (FileName);
if(!FileName.equals(FSEQFILELIST))
{
BuildFseqList(true);
BuildFseqList(true, false);
}
}
UnLockSd(LockStatus);
Expand Down Expand Up @@ -1677,6 +1690,8 @@ uint64_t c_FileMgr::GetSdFileSize (const String& FileName, bool LockStatus)
//-----------------------------------------------------------------------------
uint64_t c_FileMgr::GetSdFileSize (const FileId& FileHandle, bool LockStatus)
{
// DEBUG_START;

LockSd(LockStatus);
uint64_t response = 0;
int FileListIndex;
Expand All @@ -1688,14 +1703,16 @@ uint64_t c_FileMgr::GetSdFileSize (const FileId& FileHandle, bool LockStatus)
{
logcon (String (F ("GetSdFileSize::ERROR::Invalid File Handle: ")) + String (FileHandle));
}
// DEBUG_V(String("response: ") + String(response));

UnLockSd(LockStatus);
// DEBUG_END;
return response;

} // GetSdFileSize

//-----------------------------------------------------------------------------
void c_FileMgr::BuildFseqList(bool LockStatus)
void c_FileMgr::BuildFseqList(bool LockStatus, bool DisplayFileNames)
{
// DEBUG_START;
char entryName [256];
Expand Down Expand Up @@ -1769,6 +1786,13 @@ void c_FileMgr::BuildFseqList(bool LockStatus)
!EntryName.equals(FSEQFILELIST))
)
{
// is this a zipped file?
if((-1 != EntryName.indexOf(F(".zip"))) ||
(-1 != EntryName.indexOf(F(".ZIP"))))
{
FoundZipFile = true;
}

// do we need to add a separator?
if(numFiles)
{
Expand All @@ -1780,9 +1804,9 @@ void c_FileMgr::BuildFseqList(bool LockStatus)
usedBytes += CurrentEntry.size ();
++numFiles;

if(IsBooting)
if(DisplayFileNames)
{
logcon (String(F("SD File: '")) + EntryName + "'");
logcon (String(F("SD File: '")) + EntryName + "' " + String(CurrentEntry.size ()));
}
uint16_t Date;
uint16_t Time;
Expand Down Expand Up @@ -1845,6 +1869,79 @@ void c_FileMgr::BuildFseqList(bool LockStatus)

} // BuildFseqList

//-----------------------------------------------------------------------------
void c_FileMgr::FindFirstZipFile(String &FileName, bool LockStatus)
{
// DEBUG_START;
char entryName [256];
LockSd(LockStatus);

do // once
{
if(!SdCardIsInstalled())
{
// DEBUG_V("No SD card installed.");
break;
}

FeedWDT();

FsFile InputFile;
ESP_SD.chdir(); // Set to sd root
if(!InputFile.open ("/", O_READ))
{
logcon(F("ERROR: Could not open SD card for Reading FSEQ List."));
break;
}

// open output file, erase old data
ESP_SD.chdir(); // Set to sd root

FsFile CurrentEntry;
while (CurrentEntry.openNext (&InputFile, O_READ))
{
// DEBUG_V("Process a file entry");
FeedWDT();

if(CurrentEntry.isDirectory() || CurrentEntry.isHidden())
{
// DEBUG_V("Skip embedded directory and hidden files");
CurrentEntry.close();
continue;
}

memset(entryName, 0x0, sizeof(entryName));
CurrentEntry.getName (entryName, sizeof(entryName)-1);
String EntryName = String (entryName);
// DEBUG_V ( "EntryName: " + EntryName);
// DEBUG_V ("EntryName.length(): " + String(EntryName.length ()));
// DEBUG_V (" entry.size(): " + int64String(CurrentEntry.size ()));

// is this a zipped file?
if((-1 != EntryName.indexOf(F(".zip"))) ||
(-1 != EntryName.indexOf(F(".ZIP"))))
{
FileName = EntryName;
CurrentEntry.close();
InputFile.close();
break;
}
else
{
// DEBUG_V("Skipping File");
}
CurrentEntry.close();
} // end while true

InputFile.close();
} while(false);

UnLockSd(LockStatus);

// DEBUG_END;

} // FindFirstZipFile

//-----------------------------------------------------------------------------
bool c_FileMgr::handleFileUpload (
const String & filename,
Expand Down Expand Up @@ -1884,7 +1981,7 @@ bool c_FileMgr::handleFileUpload (
DeleteSdFile (fsUploadFileName, false);
fsUploadFileHandle = INVALID_FILE_HANDLE;
delay(1000);
BuildFseqList(false);
BuildFseqList(false, false);
expectedIndex = 0;
fsUploadFileName = emptyString;
}
Expand Down Expand Up @@ -1914,8 +2011,6 @@ bool c_FileMgr::handleFileUpload (
CloseSdFile(fsUploadFileHandle, false);
DeleteSdFile (fsUploadFileName, false);
fsUploadFileHandle = INVALID_FILE_HANDLE;
delay(1000);
BuildFseqList(false);
expectedIndex = 0;
fsUploadFileName = emptyString;
break;
Expand Down Expand Up @@ -1943,7 +2038,7 @@ bool c_FileMgr::handleFileUpload (

expectedIndex = 0;
delay(1000);
BuildFseqList(false);
BuildFseqList(false, false);

// DEBUG_V(String("Expected: ") + String(totalLen));
// DEBUG_V(String(" Got: ") + String(GetSdFileSize(fsUploadFileName)));
Expand Down Expand Up @@ -2012,6 +2107,58 @@ size_t c_FileMgr::GetDefaultFseqFileList(uint8_t * buffer, size_t maxlen)
return strlen((char*)&buffer[0]);
} // GetDefaultFseqFileList

//-----------------------------------------------------------------------------
bool c_FileMgr::SeekSdFile(const FileId & FileHandle, size_t position, SeekMode Mode)
{
// DEBUG_START;

// DEBUG_V(String("FileHandle: ") + String(FileHandle));
// DEBUG_V(String(" position: ") + String(position));
// DEBUG_V(String(" Mode: ") + String(uint32_t(Mode)));

uint64_t response = false;
int FileListIndex;

do // once
{
if (-1 == (FileListIndex = FileListFindSdFileHandle (FileHandle)))
{
logcon (String (F ("SeekSdFile::ERROR::Invalid File Handle: ")) + String (FileHandle));
break;
}

switch(Mode)
{
case SeekMode::SeekSet:
{
response = FileList[FileListIndex].fsFile.seek (position);
break;
}
case SeekMode::SeekEnd:
{
uint64_t EndPosition = FileList[FileListIndex].fsFile.size();
response = FileList[FileListIndex].fsFile.seek (EndPosition - position);
break;
}
case SeekMode::SeekCur:
{
uint64_t CurrentPosition = FileList[FileListIndex].fsFile.position();
response = FileList[FileListIndex].fsFile.seek (CurrentPosition + position);
break;
}
default:
{
logcon("Procedural error. Cannot set seek value");
break;
}
} // end switch mode
} while(false);

// DEBUG_END;
return response;

} // SeekSdFile

//-----------------------------------------------------------------------------
void c_FileMgr::LockSd(bool CurrentLockState)
{
Expand Down
2 changes: 1 addition & 1 deletion src/WebMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -702,7 +702,7 @@ size_t c_WebMgr::GetFseqFileListChunk(uint8_t *buffer, size_t maxlen, size_t ind
logcon(F("ERROR: Could not open List of Fseq files for reading"));
response = FileMgr.GetDefaultFseqFileList(buffer, maxlen);
delay(500);
FileMgr.BuildFseqList();
FileMgr.BuildFseqList(false, false);

break;
}
Expand Down

0 comments on commit db99c03

Please sign in to comment.