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:
parent
a168faafe4
commit
2d186e5b4a
|
@ -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;
|
||||
|
|
|
@ -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 -->
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue