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

Merge upstream #5

Merged
merged 830 commits into from
Dec 5, 2021
Merged
Changes from 3 commits
Commits
Show all changes
830 commits
Select commit Hold shift + click to select a range
52b60fd
Added elekstube env to examples in platformio.ini
RedNax67 Jun 4, 2021
29c9e5c
Merge pull request #2015 from RedNax67/master
Aircoookie Jun 4, 2021
131625b
Endless playlist fix.
blazoncek Jun 7, 2021
8fdf840
Optimisations.
blazoncek Jun 7, 2021
73d6cc1
Merge pull request #2020 from blazoncek/endless-playlist-fix
Aircoookie Jun 7, 2021
7885ddd
Create FUNDING.yml
Aircoookie Jun 9, 2021
374457d
A few small fixes
Aircoookie Jun 9, 2021
623694a
Playlist additions
Aircoookie Jun 10, 2021
dc4e439
Bump normalize-url from 4.5.0 to 4.5.1
dependabot[bot] Jun 11, 2021
51db653
Bump glob-parent from 5.1.1 to 5.1.2
dependabot[bot] Jun 11, 2021
7610ab7
Update logo
Aircoookie Jun 13, 2021
7d2f5f0
Fixed div by 0 when using palette on single LED segment
Aircoookie Jun 15, 2021
bde70a2
Merge pull request #2025 from Aircoookie/dependabot/npm_and_yarn/glob…
Aircoookie Jun 15, 2021
0b26417
Merge pull request #2024 from Aircoookie/dependabot/npm_and_yarn/norm…
Aircoookie Jun 15, 2021
dfdb22f
Optimized JSON buffer usage (pre-serialized color arrays)
Aircoookie Jun 17, 2021
16216b9
made sn_photorisistor configarable
Jun 18, 2021
495f7f1
Fixed DOS on Chrome tab restore causing reboot
Aircoookie Jun 18, 2021
f43bf03
Merge pull request #2031 from DickSwart/dickdev
Aircoookie Jun 18, 2021
1539e70
Use sprintf_P for color array generation
Aircoookie Jun 19, 2021
c831d62
Added 2 Ethernet boards and split Ethernet configs into separate file
Aircoookie Jun 19, 2021
b73aaec
Fix 4MB 1MB FS partition table
Aircoookie Jun 21, 2021
660de0b
Auto-create segments based on configured busses
Aircoookie Jun 24, 2021
1e5420e
readFromConfig() update
Aircoookie Jun 24, 2021
4cd3a61
Fixed preset only disabling on second effect/color change (fixes #2038 )
Aircoookie Jun 25, 2021
af9aa7d
Do not compile in example usermod
Aircoookie Jun 25, 2021
0ae0f40
Fixed four line display usermod compilation
Aircoookie Jun 25, 2021
9e8aadb
Usermod settings v2
blazoncek Jun 27, 2021
04b4ef6
Regenerate html_settings.h
Aircoookie Jun 27, 2021
9b2a010
Merge pull request #2043 from blazoncek/v2-usermod-settings
Aircoookie Jun 27, 2021
bc0a3f8
Better number handling in Usermod settings.
blazoncek Jun 29, 2021
0b23bf6
Merge pull request #2045 from blazoncek/better-num-handling
Aircoookie Jun 29, 2021
a58c5cc
Merge pull request #1967 from poelzi/max_segments
Aircoookie Jun 29, 2021
7233c55
Segment Offset
Aircoookie Jun 29, 2021
4b46502
Playlist UI (#2046)
Aircoookie Jun 29, 2021
599a456
Version bump to 0.13.0-b0 "Toki"
Aircoookie Jun 29, 2021
2009608
Removed preset cycle
Aircoookie Jun 29, 2021
8b6cc70
Fixed a problem with disabled buttons reverting to pin 0 causing conf…
Aircoookie Jun 30, 2021
7483d3b
Fixed settings page broken by using "%" in input fields (fixes #1516 )
Aircoookie Jun 30, 2021
4aa53aa
Adjust input field widths
Aircoookie Jun 30, 2021
4c73df4
Shorten input size class names
Aircoookie Jun 30, 2021
c4f084a
Merge JSON ircodes (#2048)
Aircoookie Jun 30, 2021
3754088
Updated [env] for Universal Wemos Shield board (#2049)
srg74 Jul 1, 2021
4c678a5
Fixed a minor visual issue with slider trail not reaching thumb on lo…
Aircoookie Jul 1, 2021
e16a672
Merge pull request #2011 from blazoncek/multi-button-update
Aircoookie Jul 1, 2021
0197d89
Added MQTT button option
Aircoookie Jul 1, 2021
801df94
Update libraries
Aircoookie Jul 1, 2021
dc01c90
Send websockets on every state change
Aircoookie Jul 1, 2021
40c8fdb
Added WebSockets support to UI
Aircoookie Jul 1, 2021
793a01f
Bus wrapper simplification (#2054)
Aircoookie Jul 3, 2021
1bb7e36
More compact playlist entries
Aircoookie Jul 3, 2021
c879351
JSON IR improvements
Aircoookie Jul 4, 2021
5903e82
Fixed preset immediately deselecting when set via HTTP API PL=
Aircoookie Jul 4, 2021
ec05215
Update ArduinoJSON to 6.18.1
Aircoookie Jul 4, 2021
8c44147
Usermod Settings polishing/documentation (#2061)
embedded-creations Jul 5, 2021
f27b31b
Quick fix fro paltformio.ini (#2060)
srg74 Jul 6, 2021
14b7ec2
Added support for ESP32 S2. (#2067)
blazoncek Jul 6, 2021
17d2fb8
More robust initial resource loading in UI
Aircoookie Jul 7, 2021
e04b965
Peek uses the main websocket connection
Aircoookie Jul 8, 2021
5da4763
Busses extend total configured LEDs if required (closes #2056 )
Aircoookie Jul 9, 2021
2c6850f
Fixed presets using wrong call mode (e.g. causing buttons to send UDP…
Aircoookie Jul 9, 2021
a17f83c
Renamed `NOTIFIER_CALL_MODE_` to `CALL_MODE_`
Aircoookie Jul 9, 2021
3ad336a
Bug 2064, 2063 - PinManager usage (#2066)
henrygab Jul 9, 2021
0862859
New usermod: Support for RGB Rotary Encoder Board (#2068)
ezcGman Jul 9, 2021
6a8ed11
Accept hex color strings in individual LED API
Aircoookie Jul 10, 2021
123bd0b
v0.13.0-b2
Aircoookie Jul 11, 2021
02b6d53
Rotary Encoder Compilation fix. (#2085)
blazoncek Jul 20, 2021
9ba7e5d
Fix for not honouring enabled state for PIR usermod. (#2090)
blazoncek Jul 22, 2021
e1527fc
White slider fix.
blazoncek Jul 22, 2021
f702e1a
Merge pull request #2091 from blazoncek/white-slider-fix
Aircoookie Jul 22, 2021
9f0f618
Added PIR option to trigger only if WLED is off.
blazoncek Jul 23, 2021
b058fb8
Merge pull request #2093 from blazoncek/PIR-sensor-update
Aircoookie Jul 23, 2021
2e9bd47
Upload files & skinning (#2084)
blazoncek Jul 25, 2021
07d11c8
Fix for missing off-only MQTT messages.
blazoncek Jul 28, 2021
f7191c0
Fix ordering platformio_override.ini.sample
tschundler Aug 2, 2021
8159409
Merge pull request #2113 from tschundler/master
Aircoookie Aug 3, 2021
bd13336
Fixed undesirable boot color transition
Aircoookie Aug 6, 2021
7fea0c3
Add new palettes from SR branch
scottrbailey Aug 12, 2021
4b81720
Added application level pong websockets reply (#2139)
Aircoookie Aug 17, 2021
e541d86
Merge pull request #2140 from Aircoookie/ws-ping
Aircoookie Aug 17, 2021
441416b
Fixed edge case with transition 0
Aircoookie Aug 17, 2021
91e758f
Fixed JSON IR remote not working with codes greater than 0xFFFFFF (fi…
Aircoookie Aug 18, 2021
aec998a
Fix formatting of the first title
coliss86 Aug 18, 2021
3eb1fe0
Merge pull request #2144 from coliss86/patch-1
Aircoookie Aug 19, 2021
2ecc53b
UDP Signal color correction (#1902)
ahmed-shehata Aug 19, 2021
f04c9d1
Added usermod "battery status basic" (#2127)
itCarl Aug 20, 2021
72e001b
Bash and Wnindows CMD scripts for updating multiple WLEDs.
blazoncek Aug 20, 2021
50aeee2
Merge branch 'master' of https://github.com/aircoookie/WLED
blazoncek Aug 20, 2021
530e8b3
Added SSD1306 SPI display option to 4 Line Display
blazoncek Aug 20, 2021
ff8145b
Merge pull request #2101 from blazoncek/fix-mqtt-pir
blazoncek Aug 21, 2021
1d4487b
Ethernet configuration fix, improve PinManager (#2123)
henrygab Aug 23, 2021
77c0ba9
Bugfix for calling FX=~ from within playlist preset.
blazoncek Aug 24, 2021
b481c13
Sync groups (#2150)
blazoncek Aug 25, 2021
d8240bb
Changing some palette names
scottrbailey Aug 25, 2021
e968917
rename palette arrays
scottrbailey Aug 25, 2021
dbc67e0
Merge pull request #2134 from scottrbailey/sr_palettes
blazoncek Aug 26, 2021
54f4658
Added JSON API over serial support (#2156)
Aircoookie Aug 26, 2021
021c4ba
Revert changes from PR1902
henrygab Aug 29, 2021
f368bbe
added MQTT support, Battery voltage to Info, circuit diagram to readm…
itCarl Sep 2, 2021
88ceba5
Fix error 12 issues
scottrbailey Sep 3, 2021
a839809
change random mode choice on presetFallback
scottrbailey Sep 3, 2021
e26299b
Revert some small syntactical changes
Aircoookie Sep 4, 2021
83c6f72
Fix segment runtime not reset on FX change via HTTP API
Aircoookie Sep 4, 2021
e80594d
Bugfix (sclPin, sdaPin).
blazoncek Sep 7, 2021
4d89ed7
FX optimisations.
blazoncek Sep 8, 2021
f1e2439
Slight IR JSON simplefication
Aircoookie Sep 9, 2021
6a01658
Use pbolduc fork of AsyncTCP
Aircoookie Sep 9, 2021
c24ab1b
Auto create segments setting (#2183)
Aircoookie Sep 10, 2021
f59c6e7
Replace wiki link in readme to knoWLEDge
Aircoookie Sep 11, 2021
8d4636b
Merge pull request #2170 from scottrbailey/error-12-fix
Aircoookie Sep 11, 2021
d044012
Bugfix for AutoSave & 4LD.
blazoncek Sep 11, 2021
c8610b8
Small improvements to segment names
Aircoookie Sep 11, 2021
bd23942
Fixed IR JSON cmd string (closes #2187 )
Aircoookie Sep 11, 2021
3d51d1e
Merge pull request #2175 from henrygab/revert_pr1902
Aircoookie Sep 13, 2021
d7e3765
Fix segment creation
Aircoookie Sep 14, 2021
4bc4012
add env for sp511
scottrbailey Sep 16, 2021
3cefb14
Merge pull request #2195 from scottrbailey/sp511
blazoncek Sep 16, 2021
bc18eda
Segment name UI changes
Aircoookie Sep 17, 2021
c5eac29
Do not delete name if segment bounds are unchanged
Aircoookie Sep 17, 2021
6dbed30
Updated Web UI dev docs reference
laserguru Sep 18, 2021
72d04a0
Updated reference to docs on readme to knoWLEDge
laserguru Sep 18, 2021
10a52f8
Updated cdata.js so generated files point to knoWLEDge
laserguru Sep 18, 2021
a899666
Merge branch 'master' of https://github.com/protoplasma-mx/WLED
laserguru Sep 18, 2021
b8e8028
Merge pull request #2184 from Aircoookie/fx-mods
Aircoookie Sep 19, 2021
3577da0
Avoid redundant localIP calls, each call takes 0.700 us on ESP32 240M…
pbolduc Sep 19, 2021
baf49b8
Semi-working segment on/off transition
Aircoookie Sep 20, 2021
8fae964
Allocate segment data based on currently active segments (#2217)
Aircoookie Sep 20, 2021
5eb4ffb
Fix for missing inverted analog.
blazoncek Sep 21, 2021
e416ec9
Removed dev types.
blazoncek Sep 21, 2021
f2043dc
Merge pull request #2219 from blazoncek/analog-invert
blazoncek Sep 21, 2021
96422de
0.13.0-b3
Aircoookie Sep 21, 2021
267f515
Wled math bugfix.
blazoncek Sep 23, 2021
51a4f61
Add "on":true to playlist JSON
blazoncek Sep 24, 2021
476ac26
Merge pull request #2227 from blazoncek/master
blazoncek Sep 24, 2021
a94269c
Novosibirsk time-zone.
blazoncek Sep 26, 2021
f85f2d5
Merge pull request #2203 from protoplasma-mx/master
blazoncek Sep 26, 2021
2ac90bb
Fixed sunrise/set UTC offset
Aircoookie Sep 27, 2021
f62e56b
Merge branch 'master' of https://github.com/Aircoookie/WLED
Aircoookie Sep 27, 2021
8453cd8
Fixed DMXmap
Aircoookie Sep 27, 2021
3a874bc
Add colorUpdated call
scottrbailey Sep 28, 2021
7d929dc
Merge pull request #2236 from scottrbailey/ir_bri_fix
blazoncek Sep 29, 2021
ccd3152
Add Basic Overlay support to Usermods.
Sep 30, 2021
22fc58d
Add seven segment overlay usermod
Sep 30, 2021
3ac772b
Add seven_seg debug build
Sep 30, 2021
dc9dedf
Fixed pin reservations. (#2214)
blazoncek Sep 30, 2021
17c2027
Make sbuff local
Aircoookie Oct 1, 2021
7a129e6
Add new Usermod
Proto-molecule Oct 2, 2021
d00b433
Add scrolling message to seven seg um
Oct 2, 2021
46b66c7
Merge pbolduc/WLED/feature/upd-ddp-send into network-bus
blazoncek Oct 2, 2021
c1b0877
Bus implementation.
blazoncek Oct 2, 2021
0b0d18f
Fix preset variable
Aircoookie Oct 2, 2021
05b532b
Add new Usermod (#2244)
Proto-molecule Oct 2, 2021
a28345d
Merge branch 'Aircoookie:master' into master
Proto-molecule Oct 2, 2021
772c80a
PWM fan with temperature control usermod
blazoncek Oct 3, 2021
91598cb
Remove Total LEDs field
Aircoookie Oct 3, 2021
6ddcba8
Change currentPreset to byte
Aircoookie Oct 3, 2021
b5c15d9
Fix for incorrect RPM reported.
blazoncek Oct 3, 2021
9e5d45d
Optional custom start indices
Aircoookie Oct 3, 2021
330da13
Fixed virtual getPixelColor() returning scaled values
Aircoookie Oct 3, 2021
b003ed3
PWM fan with temperature control usermod (#2246)
blazoncek Oct 3, 2021
84f4e3e
Merge branch 'Aircoookie:master' into master
Proto-molecule Oct 4, 2021
6457314
Glyph fix for 4 line
Proto-molecule Oct 4, 2021
5c9405f
Added configurable PWM fan parameters:
blazoncek Oct 4, 2021
75fe1a1
Merge master
blazoncek Oct 4, 2021
5d14716
Merge pull request #2251 from blazoncek/pwm-fan-usermod
blazoncek Oct 4, 2021
b750f82
Merge pull request #2168 from itCarl/usermod_battery_status
blazoncek Oct 4, 2021
caa9cc3
Removed double buffer.
blazoncek Oct 4, 2021
8f1cee2
Fixed mem calculation.
blazoncek Oct 4, 2021
0775ace
Merge pull request #2250 from Proto-molecule/master
blazoncek Oct 4, 2021
cf87da0
Minor UI fixes.
blazoncek Oct 6, 2021
7d6d9ed
Change virtual bus type range
Aircoookie Oct 6, 2021
3f0eb0a
Code optimization, updated URL links.
blazoncek Oct 6, 2021
fb2e556
Allow playlist as end preset in playlist.
blazoncek Oct 6, 2021
cc87ba4
Merge pull request #2245 from Aircoookie/network-bus
Aircoookie Oct 6, 2021
cbb12e1
Updated vid and changelog
Aircoookie Oct 6, 2021
849aa64
Fixed red color on IP address
blazoncek Oct 7, 2021
2ebb837
bh1750
calebmah Oct 7, 2021
b89f718
Merge pull request #2257 from calebmah/bh1750-usermod
Aircoookie Oct 7, 2021
5dac669
Add msg scroll. Add MQTT and Config support
Oct 8, 2021
47d4e73
Merge 'master' of Aircoookie/WLED into overlayum
Oct 8, 2021
355525c
Add readme
Oct 9, 2021
6cd770b
Restore platformio.inii
Oct 9, 2021
de454e8
Edit comments
Aircoookie Oct 10, 2021
8b2145b
Add strip off refresh option in LED settings. (#2259)
blazoncek Oct 11, 2021
f4b47ed
Exclude virtual busses from current calculation (#2262)
Aircoookie Oct 11, 2021
d47157e
Refactor string usage
Oct 11, 2021
a5de66b
Merge branch 'overlayum' of https://github.com/AK5nowman/WLED into ov…
Oct 11, 2021
0327f94
Merge branch 'master' of https://github.com/Aircoookie/WLED into over…
Oct 11, 2021
8afaac1
0.13.0-b4
Aircoookie Oct 11, 2021
445b6ee
Fix MQTT Null publish
Oct 11, 2021
303fc65
Merge branch 'master' of https://github.com/Aircoookie/WLED into over…
Oct 11, 2021
1b50fba
Additional Flash string concat
Oct 11, 2021
3f71d3b
Add AKST/AKDT
Oct 11, 2021
10cfcda
Merge pull request #2264 from AK5nowman/Alaskatime
blazoncek Oct 11, 2021
392bda7
Merge pull request #2261 from AK5nowman/overlayum
blazoncek Oct 13, 2021
c3d48ac
UM RGB-Rotary-Encoder: Properly used PinOwner
ezcGman Oct 16, 2021
00f1b48
Merge pull request #2279 from ezcGman/um-rgb-rotary-encoder
blazoncek Oct 17, 2021
39b7b3a
CCT (color white balance support)
blazoncek Oct 20, 2021
0d77027
Bugfix for white value.
blazoncek Oct 22, 2021
0acca2e
Cycling bugfix.
blazoncek Oct 22, 2021
090e29e
Moved auto white calculation to bus manager.
blazoncek Oct 25, 2021
8ca298b
Removed legacy auto-white calculation.
blazoncek Oct 26, 2021
f55f803
Updated aut-white calculation.
blazoncek Oct 27, 2021
b33e288
New Usermod: QuinLED-An-Penta (#2296)
ezcGman Oct 30, 2021
0023824
JSON in/decrementing (#2258)
Aircoookie Oct 30, 2021
a93f05c
Multirelay button support. (#2284)
blazoncek Oct 31, 2021
7e1920d
Remove ledCount (#2300)
Aircoookie Oct 31, 2021
46e7db6
Add MX-CST/CDT Time Zone
underritoSR Nov 3, 2021
2bdaf53
Merge pull request #2311 from underritoSR/master
Aircoookie Nov 3, 2021
b44ffff
Fixed DDP override
Aircoookie Nov 3, 2021
adeb9bc
Use New Issue Forms for Bug Reports (#2312)
shauneccles Nov 4, 2021
d590e01
Merge branch 'master' into CCT-support
blazoncek Nov 5, 2021
446b4b0
Changed WLED_USE_DMX to WLED_ENABLE_DMX
yoeywire Nov 8, 2021
d6ad089
Merge pull request #2324 from yoeywire/DMXdefine
blazoncek Nov 9, 2021
5784092
Fix settings JS buffer too small (#2323)
Aircoookie Nov 9, 2021
3161f5f
Fix for network 'pin' conflicts.
blazoncek Nov 9, 2021
83753a5
Fixed no gamma correction for JSON individual LED control
Aircoookie Nov 9, 2021
6df64d0
Fix a bug which prevents DMX channel mappings from loading correctly.…
jeffc Nov 9, 2021
eb92c0b
Fix for ACCURATE auto-white mode.
blazoncek Nov 11, 2021
38d8dfe
Improv support (#2334)
Aircoookie Nov 16, 2021
bc40344
0.13.0-b5
Aircoookie Nov 17, 2021
4af1f62
Revert testing PIO changes
Aircoookie Nov 17, 2021
d31e4c7
Added getPinOwner
Aircoookie Nov 17, 2021
0465298
Merge branch 'master' into CCT-support
Aircoookie Nov 18, 2021
31b7cdf
Change effect names to be more consistent
Aircoookie Nov 19, 2021
b3324d2
allowCCT performance improvement
Aircoookie Nov 21, 2021
80a6579
Fixed preset cycle not working from preset called by UI
Aircoookie Nov 22, 2021
c8d5218
Updated outdated wiki links in readme
Aircoookie Nov 22, 2021
b97b6dc
Remove F macro for "ps"
Aircoookie Nov 23, 2021
97b3c3d
Incrementing & random effects, palettes via JSON.
blazoncek Nov 23, 2021
ea0f37f
CCT bus manager logic simplification
Aircoookie Nov 24, 2021
37bd525
Improve link contrast
Aircoookie Nov 24, 2021
02fb255
Shorter link color
Aircoookie Nov 24, 2021
3dec4a6
UI slider and CCT adjustments
Aircoookie Nov 26, 2021
ba8a007
cctFromRgb option
Aircoookie Nov 26, 2021
624993f
CCT transitions
Aircoookie Nov 27, 2021
9f3e66f
Cleaning up indentations (sorry but my OCD is strong).
blazoncek Nov 27, 2021
3e9aea0
CCT blending setting
Aircoookie Nov 27, 2021
3e6728f
Only do auto white calc for busses with white channel
Aircoookie Nov 28, 2021
16d97d3
Merge branch 'master' into CCT-support
Aircoookie Nov 28, 2021
1973424
Remove JSON ledmap
Aircoookie Nov 28, 2021
11c7ffa
Alexa and UDP sync CCT support
Aircoookie Nov 28, 2021
48339b1
Status LED support in Bus manager
Aircoookie Nov 30, 2021
9547ac3
Save and load the e131 Proxy Universe setting in the DMX menu (#2365)
jeffc Nov 30, 2021
f6e5b67
Merge pull request #2285 from Aircoookie/CCT-support
Aircoookie Nov 30, 2021
33036e7
Fix sliders on page load if black is set
Aircoookie Nov 30, 2021
f740408
Unload playlist on PL=
Aircoookie Nov 30, 2021
a643b56
Fixed no color updated on full JSON state request
Aircoookie Dec 1, 2021
cadda12
Fixed spacing LEDs not blanked if offset is changed
Aircoookie Dec 1, 2021
46ec504
Various fixes
Aircoookie Dec 3, 2021
66bad2b
Single json buffer (#2336)
Aircoookie Dec 4, 2021
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
71 changes: 36 additions & 35 deletions wled00/playlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,95 +10,102 @@ typedef struct PlaylistEntry {
uint16_t tr;
} ple;

int8_t playlistRepeat = 1;
byte playlistEndPreset = 0;
byte *playlistEntries = nullptr;
byte playlistLen;
int8_t playlistIndex = -1;
uint16_t playlistEntryDur = 0;
bool playlistEndless = false;
int8_t playlistRepeat = 1;
byte playlistEndPreset = 0;
PlaylistEntry *playlistEntries = nullptr;
byte playlistLen;
int8_t playlistIndex = -1;
uint16_t playlistEntryDur = 0;


void shufflePlaylist() {
int currentIndex = playlistLen;

PlaylistEntry temporaryValue, *entries = reinterpret_cast<PlaylistEntry*>(playlistEntries);
PlaylistEntry temporaryValue;

// While there remain elements to shuffle...
while (currentIndex--) {
// Pick a random element...
int randomIndex = random(0, currentIndex);
// And swap it with the current element.
temporaryValue = entries[currentIndex];
entries[currentIndex] = entries[randomIndex];
entries[randomIndex] = temporaryValue;
temporaryValue = playlistEntries[currentIndex];
playlistEntries[currentIndex] = playlistEntries[randomIndex];
playlistEntries[randomIndex] = temporaryValue;
}
DEBUG_PRINTLN(F("Playlist shuffle."));
}


void unloadPlaylist() {
if (playlistEntries != nullptr) {
delete[] playlistEntries;
playlistEntries = nullptr;
}
currentPlaylist = playlistIndex = -1;
playlistLen = playlistEntryDur = 0;
DEBUG_PRINTLN(F("Playlist unloaded."));
}


void loadPlaylist(JsonObject playlistObj) {
unloadPlaylist();

JsonArray presets = playlistObj["ps"];
playlistLen = presets.size();
if (playlistLen == 0) return;
if (playlistLen > 100) playlistLen = 100;
uint16_t dataSize = sizeof(ple) * playlistLen;
playlistEntries = new byte[dataSize];
PlaylistEntry* entries = reinterpret_cast<PlaylistEntry*>(playlistEntries);

playlistEntries = new PlaylistEntry[playlistLen];
if (playlistEntries == nullptr) return;

byte it = 0;
for (int ps : presets) {
if (it >= playlistLen) break;
entries[it].preset = ps;
playlistEntries[it].preset = ps;
it++;
}

it = 0;
JsonArray durations = playlistObj["dur"];
if (durations.isNull()) {
entries[0].dur = playlistObj["dur"] | 100;
playlistEntries[0].dur = playlistObj["dur"] | 100;
it = 1;
} else {
for (int dur : durations) {
if (it >= playlistLen) break;
entries[it].dur = dur;
playlistEntries[it].dur = (dur > 0) ? dur : presetCycleTime;
it++;
}
}
for (int i = it; i < playlistLen; i++) entries[i].dur = entries[it -1].dur;
for (int i = it; i < playlistLen; i++) playlistEntries[i].dur = playlistEntries[it -1].dur;

it = 0;
JsonArray tr = playlistObj["transition"];
JsonArray tr = playlistObj[F("transition")];
if (tr.isNull()) {
entries[0].tr = playlistObj["transition"] | (transitionDelay / 100);
playlistEntries[0].tr = playlistObj[F("transition")] | (transitionDelay / 100);
it = 1;
} else {
for (int transition : tr) {
if (it >= playlistLen) break;
entries[it].tr = transition;
playlistEntries[it].tr = transition;
it++;
}
}
for (int i = it; i < playlistLen; i++) entries[i].tr = entries[it -1].tr;
for (int i = it; i < playlistLen; i++) playlistEntries[i].tr = playlistEntries[it -1].tr;

playlistRepeat = playlistObj[F("repeat")] | 0;
playlistEndPreset = playlistObj[F("end")] | 0;

if (playlistRepeat <= 0) playlistRepeat--; // make it endless (-2 == endless & random)

currentPlaylist = 0; //TODO here we need the preset ID where the playlist is saved
DEBUG_PRINTLN(F("Playlist loaded."));
}


void handlePlaylist() {
if (currentPlaylist < 0 || playlistEntries == nullptr || presetCyclingEnabled) return;

if (millis() - presetCycledTime > (100*playlistEntryDur)) {
presetCycledTime = millis();
if (bri == 0 || nightlightActive) return;
Expand All @@ -112,20 +119,14 @@ void handlePlaylist() {
}
// playlist roll-over
if (!playlistIndex) {
if (playlistRepeat > 0) {// playlistRepeat < 0 => endless loop with shuffling presets
playlistRepeat--; // decrease repeat count on each index reset
} else {
shufflePlaylist(); // shuffle playlist and start over
}
// playlistRepeat < 0 => endless loop
if (playlistRepeat > 0) playlistRepeat--; // decrease repeat count on each index reset if not an endless playlist
if (playlistRepeat < -1) shufflePlaylist(); // shuffle playlist and start over
}

PlaylistEntry* entries = reinterpret_cast<PlaylistEntry*>(playlistEntries);

jsonTransitionOnce = true;
transitionDelayTemp = entries[playlistIndex].tr * 100;

applyPreset(entries[playlistIndex].preset);
playlistEntryDur = entries[playlistIndex].dur;
if (playlistEntryDur == 0) playlistEntryDur = 10;
transitionDelayTemp = playlistEntries[playlistIndex].tr * 100;
playlistEntryDur = playlistEntries[playlistIndex].dur;
applyPreset(playlistEntries[playlistIndex].preset);
}
}