Skip to content

Commit 0de772e

Browse files
Andrej ChrcekAndrej Chrcek
authored andcommitted
maybe functional version of FSEQ usermod
1 parent 6df59a0 commit 0de772e

File tree

8 files changed

+373
-236
lines changed

8 files changed

+373
-236
lines changed

usermods/FSEQ/README.md

Lines changed: 79 additions & 115 deletions
Original file line numberDiff line numberDiff line change
@@ -1,153 +1,117 @@
1-
### Configure PlatformIO
2-
3-
Add the following configuration to your `platformio_override.ini` (or `platformio.ini`) to enable the necessary build flags and define the usermod:
4-
5-
```ini
6-
[env:esp32dev_V4]
7-
build_flags =
8-
-D WLED_DEBUG
9-
-D WLED_USE_SD_SPI
10-
-D USERMOD_FPP
11-
-D USERMOD_FSEQ
12-
-I wled00/src/dependencies/json
13-
14-
### 3. Update the WLED Web Interface / optional
15-
16-
To integrate the new FSEQ functionality into the WLED UI, add a new button in your wled00/data/index.htm file. For example, insert the following button into the navigation area:
17-
18-
<!-- New button for SD & FSEQ Manager -->
19-
<button onclick="window.location.href=getURL('/sd/ui');"><i class="icons">&#xe0d2;</i><p class="tab-label">Fseq</p></button>
20-
21-
22-
23-
### 1. Modify `usermods_list.cpp`
24-
25-
Add the following lines to register the FSEQ usermod. Make sure that you **do not** include any conflicting modules (e.g. `usermod_sd_card.h`):
26-
27-
```cpp
28-
#ifdef USERMOD_FSEQ
29-
#include "../usermods/FSEQ/usermod_fseq.h"
30-
#endif
31-
32-
#ifdef USERMOD_FSEQ
33-
UsermodManager::add(new UsermodFseq());
34-
#endif
35-
36-
delete or uncoment
37-
//#include "../usermods/sd_card/usermod_sd_card.h"
38-
39-
//#ifdef SD_ADAPTER
40-
//UsermodManager::add(new UsermodSdCard());
41-
//#endif
42-
43-
44-
45-
46-
47-
Below is a list of the HTTP endpoints (commands) included in the code along with their descriptions and usage:
48-
• GET /sd/ui
49-
Description: Returns an HTML page with a user interface for managing SD files and FSEQ files.
50-
Usage: Open this URL in a browser to view the SD & FSEQ Manager interface.
51-
• GET /sd/list
52-
Description: Displays an HTML page listing all files on the SD card. It also includes options to delete files and a form to upload new files.
53-
Usage: Access this endpoint via a browser or an HTTP GET request to list the SD card files.
54-
• POST /sd/upload
55-
Description: Handles file uploads to the SD card. The file is sent as part of a multipart/form-data POST request.
56-
Usage: Use a file upload form or an HTTP client to send a POST request with the file data to this endpoint.
57-
• GET /sd/delete
58-
Description: Deletes a specified file from the SD card. It requires a query parameter named path which specifies the file to delete.
59-
Usage: Example: /sd/delete?path=/example.fseq to delete the file named example.fseq.
60-
• GET /fseq/list
61-
Description: Returns an HTML page listing all FSEQ files (files ending with .fseq or .FSEQ) available on the SD card. Each file is accompanied by a button to play it.
62-
Usage: Navigate to this URL in a browser to view and interact with the FSEQ file list.
63-
• GET /fseq/start
64-
Description: Starts the playback of a selected FSEQ file. This endpoint requires a file query parameter for the file path and optionally a t parameter (in seconds) to specify a starting time offset.
65-
Usage: Example: /fseq/start?file=/animation.fseq&t=10 starts the playback of animation.fseq from 10 seconds into the sequence.
66-
• GET /fseq/stop
67-
Description: Stops the current FSEQ playback and clears the active playback session.
68-
Usage: Simply send an HTTP GET request to this endpoint to stop the playback.
69-
70-
71-
72-
73-
74-
75-
1+
# ✨ Usermod FSEQ ✨
762

3+
> **Created by: Andrej Chrcek**
774
5+
Welcome to the **Usermod FSEQ** project! This innovative module empowers your WLED setup by enabling FSEQ file playback from an SD card, complete with a sleek web UI and UDP remote control. Dive into a world where creativity meets functionality and transform your lighting experience.
786

7+
# SWEB UI http://yourIP/sd/ui
798

809
# SD & FSEQ Usermod for WLED
8110

82-
This usermod adds support for playing FSEQ files from an SD card and provides a web interface for managing SD files and FSEQ playback. Follow the instructions below to install and use this usermod.
11+
This usermod adds support for playing FSEQ files from an SD card and provides a web interface for managing SD files and controlling FSEQ playback via HTTP and UDP. It also supports configurable SPI pin settings for SD SPI. The usermod exposes several HTTP endpoints for file management and playback control.
8312

8413
---
8514

86-
## Installation
87-
88-
### 1. Modify `usermods_list.cpp`
89-
90-
Add the following lines to register the FSEQ usermod. Make sure that you **do not** include any conflicting modules (e.g. `usermod_sd_card.h`):
15+
## Features
9116

92-
```cpp
93-
#ifdef USERMOD_FSEQ
94-
#include "../usermods/FSEQ/usermod_fseq.h"
95-
#endif
96-
97-
#ifdef USERMOD_FSEQ
98-
UsermodManager::add(new UsermodFseq());
99-
#endif
100-
101-
delete or uncoment
102-
//#include "../usermods/sd_card/usermod_sd_card.h"
103-
104-
//#ifdef SD_ADAPTER
105-
//UsermodManager::add(new UsermodSdCard());
106-
//#endif
17+
- **FSEQ Playback:** Play FSEQ files from an SD card.
18+
- **Web UI:** Manage SD files (list, upload, delete) and control FSEQ playback.
19+
- **UDP Synchronization:** Remote control via UDP packets.
20+
- **Configurable SPI Pins:** SPI pin assignments are configurable through WLED’s configuration JSON.
10721

22+
---
10823

109-
### 2. Configure PlatformIO
24+
## Installation
11025

111-
Add the following configuration to your platformio_override.ini (or platformio.ini) to enable the necessary build flags and define the usermod:
26+
### 1. Configure PlatformIO
11227

28+
Add the following configuration to your `platformio_override.ini` (or `platformio.ini`) file:
11329

30+
```ini
11431
[env:esp32dev_V4]
11532
build_flags =
116-
-D WLED_DEBUG
11733
-D WLED_USE_SD_SPI
118-
-D WLED_PIN_SCK=18 ; CLK
119-
-D WLED_PIN_MISO=19 ; Data Out (POCI)
120-
-D WLED_PIN_MOSI=23 ; Data In (PICO)
121-
-D WLED_PIN_SS=5 ; Chip Select (CS)
34+
-D USERMOD_FPP
12235
-D USERMOD_FSEQ
123-
-std=gnu++17
124-
36+
-I wled00/src/dependencies/json
37+
; optional:
38+
; -D WLED_DEBUG
12539

12640

127-
### 3. Update the WLED Web Interface
41+
### 2. Update the WLED Web Interface (Optional)
12842

129-
To integrate the new FSEQ functionality into the WLED UI, add a new button in your index.htm file. For example, insert the following button into the navigation area:
43+
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:
13044

13145
<!-- New button for SD & FSEQ Manager -->
13246
<button onclick="window.location.href=getURL('/sd/ui');">
13347
<i class="icons">&#xe0d2;</i>
13448
<p class="tab-label">Fseq</p>
13549
</button>
13650

51+
### 3. Modify usermods_list.cpp
13752

138-
This button will take you to the SD & FSEQ Manager interface.
53+
Register the FSEQ usermod by adding the following lines to `usermods_list.cpp`. Ensure no conflicting modules are included:
13954

55+
```cpp
56+
#ifdef USERMOD_FSEQ
57+
#include "../usermods/FSEQ/usermod_fseq.h"
58+
#endif
14059

60+
#ifdef USERMOD_FSEQ
61+
UsermodManager::add(new UsermodFseq());
62+
#endif
14163

142-
###Usage
143-
• Web Interface:
144-
Access the SD & FSEQ Manager by clicking the Fseq button in the main UI. The interface allows you to view, upload, and delete SD card files as well as control FSEQ playback.
145-
• File Management:
146-
The SD file manager displays all files on the SD card. You can upload new files via the provided form and delete files using the red “Delete” button.
147-
• FSEQ Playback:
148-
Once an FSEQ file is loaded, the usermod will play the sequence on the LED strip. Use the provided web interface to start and stop playback.
64+
// Remove or comment out any conflicting SD card usermod:
65+
// //#include "../usermods/sd_card/usermod_sd_card.h"
66+
// //#ifdef SD_ADAPTER
67+
// //UsermodManager::add(new UsermodSdCard());
68+
// //#endif
69+
70+
HTTP Endpoints
71+
72+
The following endpoints are available:
73+
• GET /sd/ui
74+
Description: Returns an HTML page with the SD & FSEQ Manager interface.
75+
Usage: Open this URL in a browser.
76+
• GET /sd/list
77+
Description: Displays an HTML page listing all files on the SD card, with options to delete files and a form to upload new files.
78+
Usage: Access this URL to view the SD file list.
79+
• POST /sd/upload
80+
Description: Handles file uploads to the SD card using a multipart/form-data POST request.
81+
Usage: Use a file upload form or an HTTP client.
82+
• GET /sd/delete
83+
Description: Deletes a specified file from the SD card. Requires a query parameter path indicating the file path.
84+
Usage: Example: /sd/delete?path=/example.fseq.
85+
• GET /fseq/list
86+
Description: Returns an HTML page listing all FSEQ files (with .fseq or .FSEQ extensions) on the SD card. Each file includes a button to play it.
87+
Usage: Open this URL in a browser to view and interact with the file list.
88+
• GET /fseq/start
89+
Description: Starts playback of a selected FSEQ file. Requires a file query parameter and optionally a t parameter (time offset in seconds).
90+
Usage: Example: /fseq/start?file=/animation.fseq&t=10.
91+
• GET /fseq/stop
92+
Description: Stops the current FSEQ playback and clears the active playback session.
93+
Usage: Send an HTTP GET request to stop playback.
94+
• GET /fseqfilelist
95+
Description: Returns a JSON list of all FSEQ files found on the SD card.
96+
Usage: Open this URL or send an HTTP GET request to retrieve the file list.
97+
98+
99+
Configurable SPI Pin Settings
100+
101+
The default SPI pin assignments for SD SPI are defined as follows:
102+
103+
#ifdef WLED_USE_SD_SPI
104+
int8_t UsermodFseq::configPinSourceSelect = 5;
105+
int8_t UsermodFseq::configPinSourceClock = 18;
106+
int8_t UsermodFseq::configPinPoci = 19;
107+
int8_t UsermodFseq::configPinPico = 23;
108+
#endif
149109

110+
These values can be modified via WLED’s configuration JSON using the addToConfig() and readFromConfig() methods. This allows you to change the pin settings without recompiling the firmware.
150111

112+
Summary
151113

114+
The SD & FSEQ Usermod for WLED enables FSEQ file playback from an SD card with a full-featured web UI and UDP synchronization for remote control. With configurable SPI pin settings, this usermod integrates seamlessly into WLED, providing additional functionality without modifying core code.
152115

116+
For further customization or support, please refer to the project documentation or open an issue on GitHub.
153117

usermods/FSEQ/fseq_player.cpp

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,4 +196,31 @@ void FSEQPlayer::clearLastPlayback() {
196196
setRealtimePixel(i, 0, 0, 0, 0);
197197
}
198198
frame = 0;
199-
}
199+
}
200+
201+
202+
bool FSEQPlayer::isPlaying() {
203+
return recordingFile && recordingFile.available();
204+
}
205+
206+
void FSEQPlayer::syncPlayback(float secondsElapsed) {
207+
if (!isPlaying()) {
208+
DEBUG_PRINTLN("[FSEQ] Sync: Playback not active, cannot sync.");
209+
return;
210+
}
211+
212+
uint32_t expectedFrame = (uint32_t)((secondsElapsed * 1000.0f) / file_header.step_time);
213+
int32_t diff = (int32_t)expectedFrame - (int32_t)frame;
214+
215+
if (abs(diff) > 2) {
216+
frame = expectedFrame;
217+
uint32_t offset = file_header.channel_data_offset + file_header.channel_count * frame;
218+
if (recordingFile.seek(offset)) {
219+
DEBUG_PRINTF("[FSEQ] Sync: Adjusted frame to %lu (diff=%ld)\n", expectedFrame, diff);
220+
} else {
221+
DEBUG_PRINTLN("[FSEQ] Sync: Failed to seek to new frame");
222+
}
223+
} else {
224+
DEBUG_PRINTF("[FSEQ] Sync: No adjustment needed (current frame: %lu, expected: %lu)\n", frame, expectedFrame);
225+
}
226+
}

usermods/FSEQ/fseq_player.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ class FSEQPlayer {
3636
static void loadRecording(const char* filepath, uint16_t startLed, uint16_t stopLed, float secondsElapsed = 0.0f);
3737
static void handlePlayRecording();
3838
static void clearLastPlayback();
39+
static void syncPlayback(float secondsElapsed);
40+
static bool isPlaying();
3941

4042
private:
4143
FSEQPlayer() {}

usermods/FSEQ/sd_manager.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@
1313
class SDManager {
1414
public:
1515
SDManager() {}
16-
bool begin(); // Inicializácia SD
17-
void end(); // Deinitializácia SD
18-
String listFiles(const char* dirname); // Výpis súborov vo forme HTML
16+
bool begin();
17+
void end();
18+
String listFiles(const char* dirname);
1919
bool deleteFile(const char* path);
2020
};
2121

0 commit comments

Comments
 (0)