Skip to content

Commit d0a2a9d

Browse files
committed
add serial port name and connection status
1 parent fd56d57 commit d0a2a9d

File tree

7 files changed

+27
-4
lines changed

7 files changed

+27
-4
lines changed

README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,18 @@ The application is designed to be as agnostic as possible regarding how and wher
2020

2121
### Config Parameters
2222

23-
The Serial Plotter Web App is initialized by passing a number of parameters in the URL, in the form of a QueryString (eg: http://localhost:3000?currentBaudrate=100&baudrates=300,1200,2400,4800,9600,19200,38400,57600,74880,115200,230400,250000,500000,1000000,2000000&darkTheme=true&wsPort=5000&interpolate=true&generate=true).
23+
The Serial Plotter Web App is initialized by passing a number of parameters in the URL, in the form of a QueryString (eg: http://localhost:3000?currentBaudrate=2400&baudrates=300,1200,2400,4800,9600,19200,38400,57600,74880,115200,230400,250000,500000,1000000,2000000&darkTheme=true&wsPort=5000&connected=true&interpolate=true&generate=true).
2424

2525
| Name | Description | Type (default) |
2626
|-|-|-|
2727
| `currentBaudrate` | currently selected baudrate | Number(9600)|
28+
| `currentLineEnding` | currently selected line ending | String("\r\n")|
2829
| `baudrates` | populate the baudrates menu | String[]/Comma separated strings ([])|
2930
| `darkTheme` | whether to use the dark version of the plotter | Boolean(false) |
3031
| `wsPort` | websocket port used for communication | Number(3030) |
32+
| `interpolate` | whether to smooth the graph or not | Boolean(false) |
33+
| `serialPort` | name of the serial port the data is coming from | String("") |
34+
| `connected` | whether if the serial port is connected or not| Boolean(false) |
3135
| `generate` | generate fake datapoints to print random charts (dev purposes only)| Boolean(false) |
3236

3337
It is possible to update the state of the serial plotter by sending the above parameters via WebSocket in the form of a JSON-stringified object, using the `MIDDLEWARE_CONFIG_CHANGED` [Command](#websocket-communication-protocol).

public/index.html

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
work correctly both with client-side routing and a non-root public URL.
2424
Learn how to configure a non-root public URL by running `npm run build`.
2525
-->
26-
<title>Arduino Serial Plotter Web App</title>
26+
<title>Connecting...</title>
2727
</head>
2828
<body>
2929
<noscript>You need to enable JavaScript to run this app.</noscript>

src/App.tsx

+7-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ export default function App() {
2727
SerialPlotter.Protocol.Command.MIDDLEWARE_CONFIG_CHANGED
2828
) {
2929
// set document dark theme
30-
const { darkTheme } = message.data as SerialPlotter.Config;
30+
const { darkTheme, serialPort, connected } =
31+
message.data as SerialPlotter.Config;
32+
33+
document.title = serialPort + ((!connected && " (disconnected)") || "");
34+
3135
if (typeof darkTheme !== "undefined") {
3236
darkTheme
3337
? document.body.classList.add("dark")
@@ -70,6 +74,8 @@ export default function App() {
7074
darkTheme: urlParams.get("darkTheme") === "true",
7175
wsPort: parseInt(urlParams.get("wsPort") || "3030"),
7276
interpolate: urlParams.get("interpolate") === "true",
77+
serialPort: urlParams.get("serialPort") || "/serial/port/address",
78+
connected: urlParams.get("connected") === "true",
7379
generate: urlParams.get("generate") === "true",
7480
};
7581

src/ChartPlotter.tsx

+1
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,7 @@ function _Chart(
171171
chartRef={chartRef.current}
172172
setPause={togglePause}
173173
pause={pause}
174+
config={config}
174175
/>
175176
)}
176177
<div className="canvas-container">

src/Legend.tsx

+7-1
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,18 @@
11
import React from "react";
22
import { ChartJSOrUndefined } from "react-chartjs-2/dist/types";
33
import { LegendItem } from "./LegendItem";
4+
import { SerialPlotter } from "./utils";
45

56
export function Legend({
67
chartRef,
78
pause,
89
setPause,
10+
config,
911
}: {
1012
chartRef: ChartJSOrUndefined<"line">;
1113
pause: boolean;
1214
setPause: (pause: boolean) => void;
15+
config: SerialPlotter.Config;
1316
}): React.ReactElement {
1417
return (
1518
<div className="legend">
@@ -20,12 +23,15 @@ export function Legend({
2023
</div>
2124
<div className="actions">
2225
<button
26+
disabled={!config.connected}
2327
className="pause-button"
28+
title={config.connected ? undefined : "Serial disconnected"}
2429
onClick={() => {
30+
if (!config.connected) return;
2531
setPause(!pause);
2632
}}
2733
>
28-
{(pause && "RUN") || "STOP"}
34+
{((pause || !config.connected) && "RUN") || "STOP"}
2935
</button>
3036
<button
3137
className="clear-button"

src/index.scss

+4
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,10 @@ button {
248248
color: $white;
249249
padding: 6px 5px;
250250

251+
&[disabled] {
252+
opacity: 0.5;
253+
}
254+
251255
&.disabled {
252256
opacity: 0.3;
253257
}

src/utils.ts

+2
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ export namespace SerialPlotter {
99
darkTheme: boolean;
1010
wsPort: number;
1111
interpolate: boolean;
12+
serialPort: string;
13+
connected: boolean;
1214
generate?: boolean;
1315
};
1416
export namespace Protocol {

0 commit comments

Comments
 (0)