From 7e7178eac327852d7494f04a4c9ae93a224869f6 Mon Sep 17 00:00:00 2001 From: spencerkee <spencerkee@users.noreply.github.com> Date: Mon, 24 Mar 2025 21:16:01 +0000 Subject: [PATCH] Add debug button --- app.js | 41 +++++++++++++++++++---------------------- index.html | 5 +++++ 2 files changed, 24 insertions(+), 22 deletions(-) diff --git a/app.js b/app.js index 1c664b0..a97304a 100644 --- a/app.js +++ b/app.js @@ -32,7 +32,7 @@ var canvas = canvasElement.getContext("2d", { willReadFrequently: true }); var loadingMessage = document.getElementById("loadingMessage"); var outputContainer = document.getElementById("output"); var outputData = document.getElementById("outputData"); - +var debugCheckbox = document.getElementById("debug"); const latencyDiv = document.getElementById("latency"); const latencyScan = document.getElementById("scan"); @@ -412,18 +412,20 @@ let datas = {}; recordedData = new Array(recordingButtons.length).fill({}); function renderData() { - let html = "<table><tr><th>Data</th><th>Count</th><th>Buttons</th></tr>"; - const keys = Object.keys(datas); - for (let i = 0; i < keys.length; i++) { - const key = keys[i]; - const val = datas[key]; - const evaluatedButtons = Object.keys(getButtonReadouts(key)); - html += `<tr><td>${key}</td><td>${val.count}</td><td>${evaluatedButtons}</td></tr>`; - } + if (debugCheckbox?.checked) { + let html = "<table><tr><th>Data</th><th>Count</th><th>Buttons</th></tr>"; + const keys = Object.keys(datas); + for (let i = 0; i < keys.length; i++) { + const key = keys[i]; + const val = datas[key]; + const evaluatedButtons = Object.keys(getButtonReadouts(key)); + html += `<tr><td>${key}</td><td>${val.count}</td><td>${evaluatedButtons}</td></tr>`; + } - html += "</table>"; + html += "</table>"; - outputData.innerHTML = html; + outputData.innerHTML = html; + } } function drawLine(begin, end, color) { @@ -512,14 +514,17 @@ function tick() { const end = window.performance.now(); const delta = end - start; - latencyDiv.innerText = `Frame latency: ${delta}ms`; + if (debugCheckbox?.checked) { + latencyDiv.innerText = `Frame latency: ${delta}ms`; + } if (code?.data.length > 0) { // reset qr = getButtonReadouts(code.data); - latencyScan.innerText = `Scan latency: ${delta}ms`; - + if (debugCheckbox?.checked) { + latencyScan.innerText = `Scan latency: ${delta}ms`; + } drawLine( code.location.topLeftCorner, code.location.topRightCorner, @@ -557,14 +562,6 @@ function tick() { } } - // console.log(recordingButtonIsHeldArr); - // console.log(recordedData[0]); - // Log sorted recordedData[0] to the console - // console.log( - // Object.entries(recordedData[0]).sort((a, b) => b[1].count - a[1].count), - // ); - - if (!datas[code.data]) { let buttons = []; for (let i = 0; i < Object.keys(qr).length; i++) { diff --git a/index.html b/index.html index 701b0e0..6b05681 100644 --- a/index.html +++ b/index.html @@ -48,6 +48,11 @@ </div> </div> </div> + <!-- Add debug checkbox --> + <div> + <label for="debug">Debug</label> + <input type="checkbox" id="debug" /> + </div> <div id="output" hidden> <div id="latency"></div> <div id="scan"></div> -- GitLab