Web interface: UART history, receive indicator

This commit is contained in:
SG 2023-08-10 18:41:14 +03:00
parent ab10f0b8b2
commit deba0ed44a
5 changed files with 66 additions and 12 deletions

View File

@ -5,6 +5,7 @@
import TabSys from "./tabs/TabSys.svelte";
import TabPs from "./tabs/TabPS.svelte";
import Reload from "./lib/Reload.svelte";
import Indicator from "./lib/Indicator.svelte";
let current_tab = "WiFi";
if (localStorage.getItem("current_tab") != null) {
@ -16,13 +17,32 @@
localStorage.setItem("current_tab", current_tab);
}
let uart_history_array = [];
function uart_history_array_get() {
return uart_history_array;
}
function uart_history_array_put(data) {
uart_history_array.push(data);
}
let uart_indicatior = undefined;
let uart_terminal = undefined;
function receive_uart(data) {
uart_indicatior.activate();
uart_history_array_put(data);
if (uart_terminal != undefined) {
uart_terminal.push(data);
}
}
function uart_on_mount() {
let uart_data = uart_history_array_get();
for (let i = 0; i < uart_data.length; i++) {
uart_terminal.push(uart_data[i]);
}
}
const tabs = ["WiFi", "SYS", "PS", "UART"];
</script>
@ -55,12 +75,13 @@
</tab-content>
{:else if current_tab == tabs[3]}
<tab-content>
<WebSocket receive={receive_uart} />
<UartTerminal bind:this={uart_terminal} />
<UartTerminal bind:this={uart_terminal} on_mount={uart_on_mount} />
</tab-content>
{/if}
</tabs-content>
<Indicator bind:this={uart_indicatior} />
<WebSocket receive={receive_uart} />
<Reload />
</main>

View File

@ -0,0 +1,35 @@
<script>
let active = false;
let timer = undefined;
export function activate() {
active = true;
if (timer != undefined) {
clearTimeout(timer);
}
timer = setTimeout(() => {
active = false;
}, 100);
}
</script>
<div class="indicatior" class:active>U</div>
<style>
.indicatior {
position: fixed;
top: 0;
right: 0;
background-color: green;
color: white;
padding: 4px;
visibility: hidden;
pointer-events: none;
}
.indicatior.active {
visibility: visible;
}
</style>

View File

@ -13,6 +13,8 @@
last: "",
};
export let on_mount = () => {};
function process_bytes() {
let decoded = new TextDecoder().decode(new Uint8Array(bytes));
let last_line_complete =
@ -35,7 +37,9 @@
ready = ready;
}
onMount(() => {});
onMount(() => {
on_mount();
});
const scrollToBottom = (node) => {
const scroll = () =>

View File

@ -4,8 +4,6 @@
export let receive = () => {};
// const tag = "uart-terminal";
function cleanup_server() {
let url = api.server;
if (url == "") {
@ -19,12 +17,9 @@
let gateway = `ws://${cleanup_server()}/api/v1/uart/websocket`;
let websocket;
function on_open(event) {
console.log("Connection opened");
}
function on_open(event) {}
function on_close(event) {
console.log("Connection closed");
setTimeout(init, 1000);
}
@ -46,7 +41,6 @@
}
function init() {
console.log("Trying to open a WebSocket connection...");
websocket = new WebSocket(gateway);
websocket.onopen = on_open;
websocket.onclose = on_close;
@ -54,7 +48,7 @@
}
function destroy() {
websocket.onclose = function () {}; // disable onclose handler first
websocket.onclose = function () {};
websocket.close();
}

View File

@ -662,7 +662,7 @@ err_fail:
/*************** UART ***************/
#include <stream_buffer.h>
#define WEBSOCKET_STREAM_BUFFER_SIZE_BYTES 1024 * 256
#define WEBSOCKET_STREAM_BUFFER_SIZE_BYTES 1024 * 1024
static uint8_t websocket_stream_storage[WEBSOCKET_STREAM_BUFFER_SIZE_BYTES + 1] EXT_RAM_ATTR;
static StaticStreamBuffer_t websocket_stream_buffer_struct;
static StreamBufferHandle_t websocket_stream = NULL;