Skip to content

Commit

Permalink
Enable and disable RPM reading when showing or hiding the live panel …
Browse files Browse the repository at this point in the history
…via events. Also fix an error when trying to switch to a panel whic hasn't had the href attribute added yet. (#40)
  • Loading branch information
DeionSi authored Mar 25, 2024
1 parent a168faa commit 2d186e5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
2 changes: 2 additions & 0 deletions UI/assets/js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@
var href = $(this).attr('href');

// Not a panel link? Bail.
if (typeof href === 'undefined')
return;
if (href.charAt(0) != '#'
|| $panels.filter(href).length == 0)
return;
Expand Down
6 changes: 3 additions & 3 deletions UI/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@

<!-- Nav -->
<nav id="nav">
<a href="#connect" class="icon fa-plug" onClick="disableRPM()"><span>Connect</span></a>
<a id="link_live" class="icon fa-tachometer" onClick="enableRPM()"><span>Dashboard</span></a>
<a id="link_config" class="icon fa-sliders-h" onClick="disableRPM()"><span>Config</span></a>
<a href="#connect" class="icon fa-plug"><span>Connect</span></a>
<a id="link_live" class="icon fa-tachometer"><span>Dashboard</span></a>
<a id="link_config" class="icon fa-sliders-h"><span>Config</span></a>
</nav>

<!-- Main -->
Expand Down
22 changes: 21 additions & 1 deletion UI/renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -313,7 +313,6 @@ function refreshPattern(data)
modalLoading.remove();
//Move to the Live tab
window.location.hash = '#live';
enableRPM();
initComplete = true;
}

Expand Down Expand Up @@ -463,6 +462,7 @@ function animateGauges() {
var RPMInterval = 0;
function enableRPM()
{
console.log("Enabling RPM reads");
if(RPMInterval == 0)
{
RPMInterval = setInterval(updateRPM, 100);
Expand Down Expand Up @@ -529,6 +529,19 @@ async function checkForUpdates()

}

function liveShowHide(mutationsList, observer) {
mutationsList.forEach(mutation => {
if (mutation.attributeName === 'style') {
if (mutation.target.style.display === 'none') {
disableRPM();
}
else {
enableRPM();
}
}
})
}

window.onload = function ()
{
refreshSerialPorts();
Expand All @@ -537,6 +550,13 @@ window.onload = function ()
checkForUpdates();
//animateGauges();

//Enable and disabled retrieval of RPM when viewing live panel
const liveShowHideObserver = new MutationObserver(liveShowHide);
liveShowHideObserver.observe(
document.getElementById('live'),
{ attributes: true }
);

usb.on('attach', refreshSerialPorts);
usb.on('detach', refreshSerialPorts);
};
Expand Down

0 comments on commit 2d186e5

Please sign in to comment.