Enable and disable RPM reading when showing or hiding the live panel via events. Also fix an error when trying to switch to a panel whic hasn't had the href attribute added yet. (#40)

This commit is contained in:
DeionSi 2024-03-25 03:30:03 +01:00 committed by GitHub
parent a168faafe4
commit 2d186e5b4a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 26 additions and 4 deletions

View File

@ -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;

View File

@ -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 -->

View File

@ -313,7 +313,6 @@ function refreshPattern(data)
modalLoading.remove();
//Move to the Live tab
window.location.hash = '#live';
enableRPM();
initComplete = true;
}
@ -463,6 +462,7 @@ function animateGauges() {
var RPMInterval = 0;
function enableRPM()
{
console.log("Enabling RPM reads");
if(RPMInterval == 0)
{
RPMInterval = setInterval(updateRPM, 100);
@ -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();
@ -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);
};