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

Iss119 add fade slider control #149

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
4 changes: 3 additions & 1 deletion app/css/dmx.css
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,6 @@ div.section {
padding-bottom: 8px;
}


.slider {
width: 80%;
}
4 changes: 4 additions & 0 deletions app/html/dmx.html
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ <h4>Sets all channels on or off</h4>
<h4>Toggle a continuous fade on all channels</h4>
<button id='fadeOn'>Fade On</button>
<button id='fadeOff'>Fade Off</button>
<div>
<label for="fadeDuration">Fade Speed:</label>
<input type="range" min="0.01" max="10" value="5" class="slider" id="fadeDuration" step="0.01">
</div>
</div>

</body>
Expand Down
19 changes: 11 additions & 8 deletions app/js/dmx.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ const DMX = parent.require('dmx');
/* Fading setup */
let isFading = false;
let currentFade = 0;
const fadeDuration = 5000;
const fadeInterval = 50;
let fadeChange = 255.0 * fadeInterval / fadeDuration;
let fadeDelta = 1;

const fadeInterval = 25; // (ms), the maximum(ish) framerate of DMX

// Limits
const MAX_CHANNEL = 512; // Inclusive
Expand Down Expand Up @@ -39,15 +39,14 @@ function setAll(value) {
// Updates the current fade amount. Only changes if isFading is set
function updateFade() {
if (isFading) {
currentFade += fadeChange;
currentFade += Number(fadeDelta);

if (currentFade < 0) {
currentFade = 0;
fadeChange = -fadeChange;
}
if (currentFade > 255) {
fadeDelta = -fadeDelta;
} else if (currentFade > 255) {
currentFade = 255;
fadeChange = -fadeChange;
fadeDelta = -fadeDelta;
}

// Divide by 1 to make it an int
Expand Down Expand Up @@ -173,6 +172,10 @@ function setupButtons() {
document.getElementById('rangeStart').oninput = function rangeStartOnChange() { onInputChange('rangeStart'); };
document.getElementById('rangeEnd').oninput = function rangeEndOnChange() { onInputChange('rangeEnd'); };
document.getElementById('boxNumber').oninput = function boxNumberOnChange() { onInputChange('boxNumber'); };

document.getElementById('fadeDuration').oninput = function fadeDurationChange() {
fadeDelta = document.getElementById('fadeDuration').value * Math.sign(fadeDelta);
};
}

// Sets up the page
Expand Down