Skip to content

Commit

Permalink
Updated UI, added loop function, improved FPP sync functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrej Chrcek authored and Andrej Chrcek committed Mar 3, 2025
1 parent 0de772e commit dad3c4e
Show file tree
Hide file tree
Showing 4 changed files with 334 additions and 188 deletions.
2 changes: 1 addition & 1 deletion usermods/FSEQ/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ build_flags =
To integrate the new FSEQ functionality into the WLED UI, add a new button to the navigation area in your `wled00/data/index.htm` file. For example:

<!-- New button for SD & FSEQ Manager -->
<button onclick="window.location.href=getURL('/sd/ui');">
<button onclick="window.location.href=getURL('/fsequi');">
<i class="icons">&#xe0d2;</i>
<p class="tab-label">Fseq</p>
</button>
Expand Down
51 changes: 29 additions & 22 deletions usermods/FSEQ/fseq_player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,13 @@ void FSEQPlayer::processFrameData() {
bool FSEQPlayer::stopBecauseAtTheEnd() {
if (!recordingFile.available()) {
if (recordingRepeats == RECORDING_REPEAT_LOOP) {
// Reset file pointer and frame counter for continuous loop
recordingFile.seek(0);
frame = 0;
} else if (recordingRepeats > 0) {
recordingFile.seek(0);
recordingRepeats--;
frame = 0;
DEBUG_PRINTF("Repeat recording again for: %d\n", recordingRepeats);
} else {
DEBUG_PRINTLN("Finished playing recording, disabling realtime mode");
Expand Down Expand Up @@ -187,7 +190,12 @@ void FSEQPlayer::loadRecording(const char* filepath, uint16_t startLed, uint16_t
if (frame >= file_header.frame_count) {
frame = file_header.frame_count - 1;
}
recordingRepeats = RECORDING_REPEAT_DEFAULT;
// Set loop mode if secondsElapsed is exactly 1.0f
if (secondsElapsed == 1.0f) {
recordingRepeats = RECORDING_REPEAT_LOOP;
} else {
recordingRepeats = RECORDING_REPEAT_DEFAULT;
}
playNextRecordingFrame();
}

Expand All @@ -198,29 +206,28 @@ void FSEQPlayer::clearLastPlayback() {
frame = 0;
}

bool FSEQPlayer::isPlaying() {
return recordingFile && recordingFile.available();
}

bool FSEQPlayer::isPlaying() {
return recordingFile && recordingFile.available();
void FSEQPlayer::syncPlayback(float secondsElapsed) {
if (!isPlaying()) {
DEBUG_PRINTLN("[FSEQ] Sync: Playback not active, cannot sync.");
return;
}

void FSEQPlayer::syncPlayback(float secondsElapsed) {
if (!isPlaying()) {
DEBUG_PRINTLN("[FSEQ] Sync: Playback not active, cannot sync.");
return;
}

uint32_t expectedFrame = (uint32_t)((secondsElapsed * 1000.0f) / file_header.step_time);
int32_t diff = (int32_t)expectedFrame - (int32_t)frame;

if (abs(diff) > 2) {
frame = expectedFrame;
uint32_t offset = file_header.channel_data_offset + file_header.channel_count * frame;
if (recordingFile.seek(offset)) {
DEBUG_PRINTF("[FSEQ] Sync: Adjusted frame to %lu (diff=%ld)\n", expectedFrame, diff);
} else {
DEBUG_PRINTLN("[FSEQ] Sync: Failed to seek to new frame");
}
uint32_t expectedFrame = (uint32_t)((secondsElapsed * 1000.0f) / file_header.step_time);
int32_t diff = (int32_t)expectedFrame - (int32_t)frame;

if (abs(diff) > 2) {
frame = expectedFrame;
uint32_t offset = file_header.channel_data_offset + file_header.channel_count * frame;
if (recordingFile.seek(offset)) {
DEBUG_PRINTF("[FSEQ] Sync: Adjusted frame to %lu (diff=%ld)\n", expectedFrame, diff);
} else {
DEBUG_PRINTF("[FSEQ] Sync: No adjustment needed (current frame: %lu, expected: %lu)\n", frame, expectedFrame);
DEBUG_PRINTLN("[FSEQ] Sync: Failed to seek to new frame");
}
}
} else {
DEBUG_PRINTF("[FSEQ] Sync: No adjustment needed (current frame: %lu, expected: %lu)\n", frame, expectedFrame);
}
}
2 changes: 1 addition & 1 deletion usermods/FSEQ/usermod_fseq.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class UsermodFseq : public Usermod {
JsonArray arr = user.createNestedArray("Usermod FSEQ UI");

String ip = WiFi.localIP().toString();
arr.add("http://" + ip + "/sd/ui"); // value
arr.add("http://" + ip + "/fsequi"); // value
}

// Save your SPI pins to WLED config JSON
Expand Down
Loading

0 comments on commit dad3c4e

Please sign in to comment.