Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
29 changes: 22 additions & 7 deletions wled00/data/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,21 @@ function onLoad()
sl.addEventListener('touchstart', toggleBubble);
sl.addEventListener('touchend', toggleBubble);
});
// limter for all number inputs: limit inputs instantly
d.addEventListener("input", function(e) {
const t = e.target;
if (t.tagName === "INPUT" && t.type === "number") {
let val = parseFloat(t.value);
const max = parseFloat(t.max);
const min = parseFloat(t.min);

if (!isNaN(val)) {
if (val > max) t.value = max;
if (val < min) t.value = min;
if (t.oninput) t.oninput(); // refresh UI labels
}
}
}, false);
Comment thread
DedeHai marked this conversation as resolved.
Outdated
}

function updateTablinks(tabI)
Expand Down Expand Up @@ -1957,11 +1972,11 @@ function pleTr(p,i,field)
{
const du = gId(`pl${p}du${i}`);
const dv = parseFloat(du.value);
if (dv > 0) {
field.max = dv;
if (parseFloat(field.value) > dv)
field.value = du.value;
}
const max = parseFloat(field.max);
let val = parseFloat(field.value);
if (isNaN(val)) return;
val = Math.min(val, max, dv > 0 ? dv : max); // limit to max or duration, whichever is smaller
field.value = val;
Comment thread
DedeHai marked this conversation as resolved.
if (field.validity.valid)
plJson[p].transition[i] = Math.floor(field.value*10);
}
Expand Down Expand Up @@ -2117,8 +2132,8 @@ function makePlEntry(p,i)
<td class="c">#${i+1}</td>
</tr>
<tr>
<td class="c" width="40%"><input class="segn" type="number" placeholder="Duration" max=6553.0 min=0.0 step=0.1 oninput="pleDur(${p},${i},this)" value="${plJson[p].dur[i]/10.0}" id="pl${p}du${i}" ${man?"readonly":""}>s</td>
<td class="c" width="40%"><input class="segn" type="number" placeholder="Transition" max=65.0 min=0.0 step=0.1 oninput="pleTr(${p},${i},this)" onfocus="pleTr(${p},${i},this)" value="${plJson[p].transition[i]/10.0}">s</td>
<td class="c" width="40%"><input class="segn" type="number" style="width:7ch" placeholder="Duration" max=4294967 min=0.0 step=0.1 oninput="pleDur(${p},${i},this)" value="${plJson[p].dur[i]/10.0}" id="pl${p}du${i}" ${man?"readonly":""}>s</td>
Comment thread
DedeHai marked this conversation as resolved.
<td class="c" width="40%"><input class="segn" type="number" style="width:4ch" placeholder="Transition" max=65.5 min=0.0 step=0.1 oninput="pleTr(${p},${i},this)" onfocus="pleTr(${p},${i},this)" value="${plJson[p].transition[i]/10.0}">s</td>
<td class="c"><button class="btn btn-pl-del" onclick="delPl(${p},${i})"><i class="icons btn-icon">&#xe037;</i></button></div></td>
</tr>
</table>
Expand Down
21 changes: 13 additions & 8 deletions wled00/playlist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

typedef struct PlaylistEntry {
uint8_t preset; //ID of the preset to apply
uint16_t dur; //Duration of the entry (in tenths of seconds)
uint16_t tr; //Duration of the transition TO this entry (in tenths of seconds)
uint32_t dur; //Duration of the entry (in milliseconds)
} ple;

static byte playlistRepeat = 1; //how many times to repeat the playlist (0 = infinitely)
Expand All @@ -17,7 +17,7 @@ static byte playlistOptions = 0; //bit 0: shuffle playlist after
static PlaylistEntry *playlistEntries = nullptr;
static byte playlistLen; //number of playlist entries
static int8_t playlistIndex = -1;
static uint16_t playlistEntryDur = 0; //duration of the current entry in tenths of seconds
static uint32_t playlistEntryDur = 0; //duration of the current entry in milliseconds

//values we need to keep about the parent playlist while inside sub-playlist
static int16_t parentPlaylistIndex = -1;
Expand Down Expand Up @@ -48,7 +48,9 @@ void unloadPlaylist() {
playlistEntries = nullptr;
}
currentPlaylist = playlistIndex = -1;
playlistLen = playlistEntryDur = playlistOptions = 0;
playlistLen = 0;
playlistOptions = 0;
playlistEntryDur = 0;
DEBUG_PRINTLN(F("Playlist unloaded."));
}

Expand Down Expand Up @@ -80,12 +82,15 @@ int16_t loadPlaylist(JsonObject playlistObj, byte presetId) {
it = 0;
JsonArray durations = playlistObj["dur"];
if (durations.isNull()) {
playlistEntries[0].dur = playlistObj["dur"] | 100; //10 seconds as fallback
uint32_t durMs = playlistObj["dur"] | 100; // 10 seconds as fallback (tenths)
durMs = constrain(durMs, 0L, 42949672L) * 100UL; // limit to max value and convert to ms
playlistEntries[0].dur = (uint32_t)durMs;
it = 1;
} else {
for (int dur : durations) {
if (it >= playlistLen) break;
playlistEntries[it].dur = constrain(dur, 0, 65530);
uint32_t durMs = constrain(dur, 0L, 42949672L) * 100UL; // limit to max value and convert to ms
playlistEntries[it].dur = (uint32_t)durMs;
it++;
}
}
Expand Down Expand Up @@ -147,7 +152,7 @@ void handlePlaylist() {
static unsigned long presetCycledTime = 0;
if (currentPlaylist < 0 || playlistEntries == nullptr) return;

if ((playlistEntryDur < UINT16_MAX && millis() - presetCycledTime > 100 * playlistEntryDur) || doAdvancePlaylist) {
if ((playlistEntryDur < UINT32_MAX && millis() - presetCycledTime > playlistEntryDur) || doAdvancePlaylist) {
presetCycledTime = millis();
if (bri == 0 || nightlightActive) return;

Expand All @@ -170,7 +175,7 @@ void handlePlaylist() {

jsonTransitionOnce = true;
strip.setTransition(playlistEntries[playlistIndex].tr * 100);
playlistEntryDur = playlistEntries[playlistIndex].dur > 0 ? playlistEntries[playlistIndex].dur : UINT16_MAX;
playlistEntryDur = playlistEntries[playlistIndex].dur > 0 ? playlistEntries[playlistIndex].dur : UINT32_MAX; // UINT32_MAX means infinite
applyPresetFromPlaylist(playlistEntries[playlistIndex].preset);
doAdvancePlaylist = false;
}
Expand All @@ -187,7 +192,7 @@ void serializePlaylist(JsonObject sObj) {
playlist["r"] = playlistOptions & PL_OPTION_SHUFFLE;
for (int i=0; i<playlistLen; i++) {
ps.add(playlistEntries[i].preset);
dur.add(playlistEntries[i].dur);
dur.add((playlistEntries[i].dur) / 100); // convert ms back to tenths of seconds (backwards compatibility)
transition.add(playlistEntries[i].tr);
}
}
Loading