mirror of
https://github.com/jam422470459/EPD-nRF52-hema213.git
synced 2025-12-09 18:08:14 +08:00
optimize addLog performance
This commit is contained in:
@@ -106,6 +106,7 @@ body.debug-mode fieldset legend {
|
|||||||
font-weight: 400;
|
font-weight: 400;
|
||||||
line-height: 1.5;
|
line-height: 1.5;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
|
overflow: hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
.footer {
|
.footer {
|
||||||
@@ -214,17 +215,31 @@ code {
|
|||||||
margin: 0;
|
margin: 0;
|
||||||
padding: 5px;
|
padding: 5px;
|
||||||
background: #DDD;
|
background: #DDD;
|
||||||
overflow: auto;
|
overflow-y: auto;
|
||||||
|
overflow-x: hidden;
|
||||||
font-family: ui-monospace, SFMono-Regular, SF Mono, Menlo, Consolas, Liberation Mono, monospace;
|
font-family: ui-monospace, SFMono-Regular, SF Mono, Menlo, Consolas, Liberation Mono, monospace;
|
||||||
box-sizing: border-box;
|
box-sizing: border-box;
|
||||||
|
word-break: break-word;
|
||||||
|
}
|
||||||
|
|
||||||
|
#log div {
|
||||||
|
padding: 2px 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#log .time,
|
||||||
|
#log .action {
|
||||||
|
display: inline-block;
|
||||||
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
|
|
||||||
#log .time {
|
#log .time {
|
||||||
color: #333;
|
color: #333;
|
||||||
|
margin-right: 0.5em;
|
||||||
}
|
}
|
||||||
|
|
||||||
#log .action {
|
#log .action {
|
||||||
color: #666;
|
color: #666;
|
||||||
|
margin-right: 0.5em;
|
||||||
}
|
}
|
||||||
|
|
||||||
#canvas-box {
|
#canvas-box {
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@@ -41,7 +41,7 @@ async function write(cmd, data, withResponse=true) {
|
|||||||
if (data instanceof Uint8Array) data = Array.from(data);
|
if (data instanceof Uint8Array) data = Array.from(data);
|
||||||
payload.push(...data)
|
payload.push(...data)
|
||||||
}
|
}
|
||||||
addLog(`<span class="action">⇑</span> ${bytes2hex(payload)}`);
|
addLog(bytes2hex(payload), '⇑');
|
||||||
try {
|
try {
|
||||||
if (withResponse)
|
if (withResponse)
|
||||||
await epdCharacteristic.writeValueWithResponse(Uint8Array.from(payload));
|
await epdCharacteristic.writeValueWithResponse(Uint8Array.from(payload));
|
||||||
@@ -240,8 +240,7 @@ function handleNotify(value, idx) {
|
|||||||
filterDitheringOptions();
|
filterDitheringOptions();
|
||||||
} else {
|
} else {
|
||||||
if (textDecoder == null) textDecoder = new TextDecoder();
|
if (textDecoder == null) textDecoder = new TextDecoder();
|
||||||
const msg = textDecoder.decode(data);
|
addLog(textDecoder.decode(data), '⇓');
|
||||||
addLog(`<span class="action">⇓</span> ${msg}`);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -251,11 +250,11 @@ async function connect() {
|
|||||||
try {
|
try {
|
||||||
addLog("正在连接: " + bleDevice.name);
|
addLog("正在连接: " + bleDevice.name);
|
||||||
gattServer = await bleDevice.gatt.connect();
|
gattServer = await bleDevice.gatt.connect();
|
||||||
addLog(' 找到 GATT Server');
|
addLog(' 找到 GATT Server');
|
||||||
epdService = await gattServer.getPrimaryService('62750001-d828-918d-fb46-b6c11c675aec');
|
epdService = await gattServer.getPrimaryService('62750001-d828-918d-fb46-b6c11c675aec');
|
||||||
addLog(' 找到 EPD Service');
|
addLog(' 找到 EPD Service');
|
||||||
epdCharacteristic = await epdService.getCharacteristic('62750002-d828-918d-fb46-b6c11c675aec');
|
epdCharacteristic = await epdService.getCharacteristic('62750002-d828-918d-fb46-b6c11c675aec');
|
||||||
addLog(' 找到 Characteristic');
|
addLog(' 找到 Characteristic');
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
if (e.message) addLog("connect: " + e.message);
|
if (e.message) addLog("connect: " + e.message);
|
||||||
@@ -293,18 +292,32 @@ function setStatus(statusText) {
|
|||||||
document.getElementById("status").innerHTML = statusText;
|
document.getElementById("status").innerHTML = statusText;
|
||||||
}
|
}
|
||||||
|
|
||||||
function addLog(logTXT) {
|
function addLog(logTXT, action = '') {
|
||||||
const log = document.getElementById("log");
|
const log = document.getElementById("log");
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
const time = String(now.getHours()).padStart(2, '0') + ":" +
|
const time = String(now.getHours()).padStart(2, '0') + ":" +
|
||||||
String(now.getMinutes()).padStart(2, '0') + ":" +
|
String(now.getMinutes()).padStart(2, '0') + ":" +
|
||||||
String(now.getSeconds()).padStart(2, '0') + " ";
|
String(now.getSeconds()).padStart(2, '0') + " ";
|
||||||
log.innerHTML += '<span class="time">' + time + '</span>' + logTXT + '<br>';
|
|
||||||
log.scrollTop = log.scrollHeight;
|
const logEntry = document.createElement('div');
|
||||||
while ((log.innerHTML.match(/<br>/g) || []).length > 20) {
|
const timeSpan = document.createElement('span');
|
||||||
var logs_br_position = log.innerHTML.search("<br>");
|
timeSpan.className = 'time';
|
||||||
log.innerHTML = log.innerHTML.substring(logs_br_position + 4);
|
timeSpan.textContent = time;
|
||||||
|
logEntry.appendChild(timeSpan);
|
||||||
|
|
||||||
|
if (action !== '') {
|
||||||
|
const actionSpan = document.createElement('span');
|
||||||
|
actionSpan.className = 'action';
|
||||||
|
actionSpan.innerHTML = action;
|
||||||
|
logEntry.appendChild(actionSpan);
|
||||||
|
}
|
||||||
|
logEntry.appendChild(document.createTextNode(logTXT));
|
||||||
|
|
||||||
|
log.appendChild(logEntry);
|
||||||
log.scrollTop = log.scrollHeight;
|
log.scrollTop = log.scrollHeight;
|
||||||
|
|
||||||
|
while (log.childNodes.length > 20) {
|
||||||
|
log.removeChild(log.firstChild);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -368,17 +381,21 @@ function convert_dithering() {
|
|||||||
function filterDitheringOptions() {
|
function filterDitheringOptions() {
|
||||||
const driver = document.getElementById('epddriver').value;
|
const driver = document.getElementById('epddriver').value;
|
||||||
const dithering = document.getElementById('dithering');
|
const dithering = document.getElementById('dithering');
|
||||||
|
let currentOptionStillValid = false;
|
||||||
|
|
||||||
for (let optgroup of dithering.getElementsByTagName('optgroup')) {
|
for (let optgroup of dithering.getElementsByTagName('optgroup')) {
|
||||||
const drivers = optgroup.getAttribute('data-driver').split('|');
|
const drivers = optgroup.getAttribute('data-driver').split('|');
|
||||||
const show = drivers.includes(driver);
|
const show = drivers.includes(driver);
|
||||||
for (option of optgroup.getElementsByTagName('option')) {
|
for (option of optgroup.getElementsByTagName('option')) {
|
||||||
if (show)
|
if (show) {
|
||||||
option.removeAttribute('disabled');
|
option.removeAttribute('disabled');
|
||||||
else
|
if (option.value == dithering.value) currentOptionStillValid = true;
|
||||||
|
} else {
|
||||||
option.setAttribute('disabled', 'disabled');
|
option.setAttribute('disabled', 'disabled');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
dithering.value = '';
|
}
|
||||||
|
if (!currentOptionStillValid) dithering.value = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkDebugMode() {
|
function checkDebugMode() {
|
||||||
|
|||||||
Reference in New Issue
Block a user