Skip to content

Commit

Permalink
Web interface: UART send
Browse files Browse the repository at this point in the history
  • Loading branch information
DrZlo13 committed Sep 22, 2023
1 parent 871e770 commit 9a92f81
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 2 deletions.
10 changes: 8 additions & 2 deletions components/svelte-portal/src/App.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@
let uart_indicatior = undefined;
let uart_terminal = undefined;
let web_socket = undefined;
function receive_uart(data) {
uart_indicatior.activate();
uart_history_array_put(data);
Expand All @@ -43,6 +45,10 @@
}
}
function uart_send(data) {
web_socket.send(data);
}
const tabs = ["WiFi", "SYS", "PS", "UART"];
</script>

Expand Down Expand Up @@ -75,13 +81,13 @@
</tab-content>
{:else if current_tab == tabs[3]}
<tab-content>
<UartTerminal bind:this={uart_terminal} on_mount={uart_on_mount} />
<UartTerminal bind:this={uart_terminal} on_mount={uart_on_mount} send={uart_send}/>
</tab-content>
{/if}
</tabs-content>

<Indicator bind:this={uart_indicatior} />
<WebSocket receive={receive_uart} />
<WebSocket bind:this={web_socket} receive={receive_uart} />
<Reload />
</main>

Expand Down
4 changes: 4 additions & 0 deletions components/svelte-portal/src/lib/Input.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script>
export let value = "";
export let type = "text";
export let input = undefined;
export function set_value(new_value) {
value = new_value;
Expand All @@ -13,6 +14,9 @@
function text_input() {
this.size = this.value.length > 3 ? this.value.length : 3;
value = this.value;
if (input != undefined) {
input(value);
}
}
</script>

Expand Down
31 changes: 31 additions & 0 deletions components/svelte-portal/src/lib/UartTerminal.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
export let on_mount = () => {};
export let send;
function process_bytes() {
let decoded = new TextDecoder().decode(new Uint8Array(bytes));
let last_line_complete =
Expand Down Expand Up @@ -94,6 +96,19 @@
}
});
}
let tx = {
popup: null,
data: "",
eol: "\\r\\n",
};
async function uart_send() {
tx.popup.close();
let eol = tx.eol.replaceAll("\\r", "\r").replaceAll("\\n", "\n");
let data = tx.data + eol;
send("s" + data);
}
</script>

<div class="terminal-wrapper">
Expand All @@ -108,6 +123,7 @@
{/if}
</div>
<div class="config">
<Button value="S" on:click={tx.popup.show} />
<Button value="#" on:click={config.popup.show} />
</div>
<Popup bind:this={config.popup}>
Expand Down Expand Up @@ -160,6 +176,21 @@
<Spinner />
{/if}
</Popup>

<Popup bind:this={tx.popup}>
<Grid>
<Value name="Data">
<Input value={tx.data} input={(data) => (tx.data = data)} /><br
/>
</Value>
<Value name="EOL">
<Input value={tx.eol} input={(data) => (tx.eol = data)} />
</Value>
</Grid>
<div style="margin-top: 10px; text-align: center;">
<Button value="Send" on:click={uart_send} />
</div>
</Popup>
</div>

<style>
Expand Down
5 changes: 5 additions & 0 deletions components/svelte-portal/src/lib/WebSocket.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import { onMount, onDestroy } from "svelte";
export let receive = () => {};
export const send = send_data;
function cleanup_server() {
let url = api.server;
Expand All @@ -17,6 +18,10 @@
let gateway = `ws://${cleanup_server()}/api/v1/uart/websocket`;
let websocket;
function send_data(data) {
websocket.send(data);
}
function on_open(event) {}
function on_close(event) {
Expand Down

0 comments on commit 9a92f81

Please sign in to comment.