Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added SD card statistics to the File Admin page. #402

Merged
merged 5 commits into from
Oct 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion ESPixelStick/src/FileMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,13 @@ void c_FileMgr::GetListOfSdFiles (String & Response)
break;
}

#ifdef ARDUINO_ARCH_ESP32
ResponseJsonDoc[F ("totalBytes")] = SD.cardSize ();
#else
ResponseJsonDoc[F ("totalBytes")] = SD.size64 ();
#endif
uint64_t usedBytes = 0;

File dir = SDFS.open ("/", CN_r);

while (true)
Expand All @@ -618,6 +625,8 @@ void c_FileMgr::GetListOfSdFiles (String & Response)
break;
}

usedBytes += entry.size ();

String EntryName = String (entry.name ());
EntryName = EntryName.substring ((('/' == EntryName[0]) ? 1 : 0));
// DEBUG_V ("EntryName: " + EntryName);
Expand All @@ -639,10 +648,12 @@ void c_FileMgr::GetListOfSdFiles (String & Response)
entry.close ();
}

ResponseJsonDoc[F ("usedBytes")] = usedBytes;

} while (false);

serializeJson (ResponseJsonDoc, Response);
// DEBUG_V (Response);
// DEBUG_V (String ("Response: ") + Response);

// DEBUG_END;

Expand Down
96 changes: 3 additions & 93 deletions ESPixelStick/src/input/InputFPPRemotePlayFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@ void c_InputFPPRemotePlayFile::Poll (uint8_t * _Buffer, size_t _BufferSize)
Buffer = _Buffer;
BufferSize = _BufferSize;

InitTimeCorrectionFactor ();
pCurrentFsmState->Poll ();

// Show that we have received a poll
Expand Down Expand Up @@ -140,17 +139,14 @@ void c_InputFPPRemotePlayFile::GetStatus (JsonObject& JsonStatus)
{
// xDEBUG_START;

// uint32_t mseconds = millis () - StartTimeMS;
time_t AdjustedFrameStepTimeMS = time_t (float (FrameControl.FrameStepTimeMS) * SyncControl.TimeCorrectionFactor);
uint32_t mseconds = AdjustedFrameStepTimeMS * FrameControl.LastPlayedFrameId;
uint32_t mseconds = FrameControl.FrameStepTimeMS * FrameControl.LastPlayedFrameId;
uint32_t msecondsTotal = FrameControl.FrameStepTimeMS * FrameControl.TotalNumberOfFramesInSequence;

uint32_t secs = mseconds / 1000;
uint32_t secsTot = msecondsTotal / 1000;

JsonStatus[F ("SyncCount")] = SyncControl.SyncCount;
JsonStatus[F ("SyncAdjustmentCount")] = SyncControl.SyncAdjustmentCount;
JsonStatus[F ("TimeOffset")] = SyncControl.TimeCorrectionFactor;

String temp = GetFileName ();

Expand Down Expand Up @@ -202,7 +198,7 @@ uint32_t c_InputFPPRemotePlayFile::CalculateFrameId (int32_t SyncOffsetMS)
break;
}

CurrentFrameId = (AdjustedPlayTime / SyncControl.AdjustedFrameStepTimeMS);
CurrentFrameId = (AdjustedPlayTime / FrameControl.FrameStepTimeMS);
// DEBUG_V (String (" CurrentFrameId: ") + String (CurrentFrameId));

} while (false);
Expand All @@ -218,10 +214,9 @@ void c_InputFPPRemotePlayFile::CalculatePlayStartTime (uint32_t StartingFrameId)
{
// DEBUG_START;

FrameControl.ElapsedPlayTimeMS = uint32_t ((float (FrameControl.FrameStepTimeMS) * SyncControl.TimeCorrectionFactor) * float (StartingFrameId));
FrameControl.ElapsedPlayTimeMS = FrameControl.FrameStepTimeMS * StartingFrameId;

// DEBUG_V (String (" FrameStepTimeMS: ") + String (FrameControl.FrameStepTimeMS));
// DEBUG_V (String ("TimeCorrectionFactor: ") + String (SyncControl.TimeCorrectionFactor));
// DEBUG_V (String (" StartingFrameId: ") + String (StartingFrameId));
// DEBUG_V (String (" ElapsedPlayTIme: ") + String (FrameControl.ElapsedPlayTimeMS));

Expand Down Expand Up @@ -314,7 +309,6 @@ bool c_InputFPPRemotePlayFile::ParseFseqFile ()

FrameControl.FrameStepTimeMS = max ((uint8_t)25, fsqParsedHeader.stepTime);
FrameControl.TotalNumberOfFramesInSequence = fsqParsedHeader.TotalNumberOfFramesInSequence;
SyncControl.AdjustedFrameStepTimeMS = uint32_t (float (FrameControl.FrameStepTimeMS) * SyncControl.TimeCorrectionFactor);

FrameControl.DataOffset = fsqParsedHeader.dataOffset;
FrameControl.ChannelsPerFrame = fsqParsedHeader.channelCount;
Expand Down Expand Up @@ -410,90 +404,6 @@ bool c_InputFPPRemotePlayFile::ParseFseqFile ()

} // ParseFseqFile

//-----------------------------------------------------------------------------
void c_InputFPPRemotePlayFile::InitTimeCorrectionFactor ()
{
// DEBUG_START;

do // once
{
if (INVALID_TIME_CORRECTION_FACTOR != SyncControl.SavedTimeCorrectionFactor)
{
break;
}

// only do this once after boot.
SyncControl.TimeCorrectionFactor = SyncControl.SavedTimeCorrectionFactor = INITIAL_TIME_CORRECTION_FACTOR;

String FileData;
FileMgr.ReadSdFile (String (CN_time), FileData);

if (0 == FileData.length ())
{
// DEBUG_V ("No data in file");
break;
}

// DEBUG_V (String ("FileData: ") + FileData);

DynamicJsonDocument jsonDoc (64);
DeserializationError error = deserializeJson (jsonDoc, FileData);
if (error)
{
logcon (CN_Heap_colon + String (ESP.getFreeHeap ()));
logcon (String (F ("Time Factor Deserialzation Error. Error code = ")) + error.c_str ());
}
// DEBUG_V ("");

JsonObject JsonData = jsonDoc.as<JsonObject> ();

// extern void PrettyPrint (JsonObject & jsonStuff, String Name);
// PrettyPrint (JsonData, String ("InitTimeCorrectionFactor"));

setFromJSON (SyncControl.TimeCorrectionFactor, JsonData, CN_time);
SyncControl.SavedTimeCorrectionFactor = SyncControl.TimeCorrectionFactor;
// DEBUG_V (String ("TimeCorrectionFactor: ") + String (TimeCorrectionFactor, 10));

} while (false);

// DEBUG_END;

} // InitTimeCorrectionFactor

//-----------------------------------------------------------------------------
void c_InputFPPRemotePlayFile::SaveTimeCorrectionFactor ()
{
// DEBUG_START;

do // once
{
if (fabs (SyncControl.SavedTimeCorrectionFactor - SyncControl.TimeCorrectionFactor) < 0.000005F )
{
// DEBUG_V ("Nothing to save");
break;
}

DynamicJsonDocument jsonDoc (64);
JsonObject JsonData = jsonDoc.createNestedObject ("x");
// JsonObject JsonData = jsonDoc.as<JsonObject> ();

JsonData[CN_time] = SyncControl.TimeCorrectionFactor;
SyncControl.SavedTimeCorrectionFactor = SyncControl.TimeCorrectionFactor;

// extern void PrettyPrint (JsonObject & jsonStuff, String Name);
// PrettyPrint (JsonData, String ("SaveTimeCorrectionFactor"));

String JsonFileData;
serializeJson (JsonData, JsonFileData);
// DEBUG_V (String ("JsonFileData: ") + JsonFileData);
FileMgr.SaveSdFile (String(CN_time), JsonFileData);

} while (false);

// DEBUG_END;

} // SaveTimeCorrectionFactor

//-----------------------------------------------------------------------------
void c_InputFPPRemotePlayFile::ClearFileInfo()
{
Expand Down
11 changes: 1 addition & 10 deletions ESPixelStick/src/input/InputFPPRemotePlayFile.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,10 @@ class c_InputFPPRemotePlayFile : public c_InputFPPRemotePlayItem
void TimerPoll ();

uint32_t GetLastFrameId () { return FrameControl.LastPlayedFrameId; }
float GetTimeCorrectionFactor () { return SyncControl.TimeCorrectionFactor; }

private:
#define INVALID_TIME_CORRECTION_FACTOR -1.0
#define INITIAL_TIME_CORRECTION_FACTOR 1.0
#define ELAPSED_PLAY_TIMER_INTERVAL_MS 10

void InitTimeCorrectionFactor ();
void SaveTimeCorrectionFactor ();
void ClearFileInfo ();

friend class fsm_PlayFile_state_Idle;
Expand All @@ -71,7 +66,7 @@ class c_InputFPPRemotePlayFile : public c_InputFPPRemotePlayItem
{
size_t DataOffset = 0;
uint32_t ChannelsPerFrame = 0;
time_t FrameStepTimeMS = 1;
uint32_t FrameStepTimeMS = 1;
uint32_t TotalNumberOfFramesInSequence = 0;
uint32_t ElapsedPlayTimeMS = 0;

Expand All @@ -84,10 +79,6 @@ class c_InputFPPRemotePlayFile : public c_InputFPPRemotePlayItem
uint32_t SyncCount = 0;
uint32_t SyncAdjustmentCount = 0;
uint32_t LastRcvdSyncFrameId = 0;

double TimeCorrectionFactor = INITIAL_TIME_CORRECTION_FACTOR;
double SavedTimeCorrectionFactor = INVALID_TIME_CORRECTION_FACTOR;
uint32_t AdjustedFrameStepTimeMS = 0;
} SyncControl;

uint8_t * Buffer = nullptr;
Expand Down
1 change: 0 additions & 1 deletion ESPixelStick/src/input/InputFPPRemotePlayFileFsm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,6 @@ void fsm_PlayFile_state_Stopping::Poll ()

FileMgr.CloseSdFile (p_Parent->FileHandleForFileBeingPlayed);
p_Parent->FileHandleForFileBeingPlayed = 0;
p_Parent->SaveTimeCorrectionFactor ();
p_Parent->fsm_PlayFile_state_Idle_imp.Init (p_Parent);

if (FileName != "")
Expand Down
10 changes: 9 additions & 1 deletion html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,6 @@
<tr><td width="50%">Filename: </td><td><span id="fppremoteFilePlayerFilename"></span></td></tr>
<tr><td width="50%">Time Elapsed: </td><td><span id="fppremoteFilePlayerTimeElapsed"></span></td></tr>
<tr><td width="50%">Time Remaining: </td><td><span id="fppremoteFilePlayerTimeRemaining"></span></td></tr>
<tr><td width="50%">Frame Time Adjustment: </td><td><span id="fppremoteFilePlayerTimeOffset"></span></td></tr>
</table>
</fieldset>
</div>
Expand Down Expand Up @@ -345,6 +344,15 @@
<div id="filemanagement" class="mdiv hidden anchor">
<fieldset>
<legend class="esps-legend">File Management</legend>
<form>
<label class="control-label col-sm-2" for="totalBytes">SD Size (MB):</label>
<output id="totalBytes"></output>
<label class="control-label col-sm-2" for="usedBytes">SD Used (MB):</label>
<output id="usedBytes"></output>
<label class="control-label col-sm-2" for="remainingBytes">SD Remaining (MB):</label>
<output id="remainingBytes"></output>
</form>
<br />
<div>
<a id="FileDeleteButton" class="button">Remove Selected File(s)</a>
<!-- <a id="FileUploadButton" class="button">Upload Selected File(s)</a> -->
Expand Down
11 changes: 10 additions & 1 deletion html/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,12 @@ function RequestListOfFiles()

} // RequestListOfFiles

function BytesToMB(Value)
{
return (Value / (1024 * 1024)).toFixed();

} // BytesToMB

function ProcessGetFileListResponse(JsonConfigData)
{
// console.info("ProcessGetFileListResponse");
Expand All @@ -389,6 +395,10 @@ function ProcessGetFileListResponse(JsonConfigData)
$("#li-filemanagement").addClass("hidden");
}

$("#totalBytes").val(BytesToMB (JsonConfigData.totalBytes));
$("#usedBytes").val(BytesToMB (JsonConfigData.usedBytes));
$("#remainingBytes").val(BytesToMB (JsonConfigData.totalBytes - JsonConfigData.usedBytes) );

Fseq_File_List = JsonConfigData;

clearTimeout(FseqFileListRequestTimer);
Expand Down Expand Up @@ -1594,7 +1604,6 @@ function ProcessReceivedJsonStatusMessage(data)
$('#fppremoteFilePlayerFilename').text(FPPDstatus.current_sequence);
$('#fppremoteFilePlayerTimeElapsed').text(FPPDstatus.time_elapsed);
$('#fppremoteFilePlayerTimeRemaining').text(FPPDstatus.time_remaining);
$('#fppremoteFilePlayerTimeOffset').text(FPPDstatus.TimeOffset);
}
else
{
Expand Down