From 9cd11ed62f427d6c874b688c93204e5b0c7fa65b Mon Sep 17 00:00:00 2001
From: GHOSCHT <31184695+GHOSCHT@users.noreply.github.com>
Date: Thu, 26 Aug 2021 01:29:59 +0200
Subject: [PATCH] Probably fix knob skipping steps if devtools closed
---
Dashboard/src/App.tsx | 24 ++++++++++++++++++------
Dashboard/src/Components/Knob.tsx | 30 +++++++++++++++++-------------
Dashboard/src/SerialConnection.ts | 11 +++++++++++
3 files changed, 46 insertions(+), 19 deletions(-)
create mode 100644 Dashboard/src/SerialConnection.ts
diff --git a/Dashboard/src/App.tsx b/Dashboard/src/App.tsx
index 416772f..8c879b9 100644
--- a/Dashboard/src/App.tsx
+++ b/Dashboard/src/App.tsx
@@ -1,7 +1,8 @@
-import React from "react";
-import SerialPort from "serialport";
+import React, { useState } from "react";
import { createGlobalStyle } from "styled-components";
+import SerialPort from "serialport";
import Knob from "./Components/Knob";
+import SerialConnection from "./SerialConnection";
const GlobalStyle = createGlobalStyle`
html {
@@ -15,15 +16,17 @@ const GlobalStyle = createGlobalStyle`
}
`;
+const port = SerialConnection();
+
const App = () => {
- const port = new SerialPort("COM5", {
- baudRate: 9600,
- autoOpen: false,
- });
+ const [counter, setCounter] = useState(0);
+
const sendIncreaseHandler = () => {
+ setCounter(counter + 1);
port.write("2i");
};
const sendDecreaseHandler = () => {
+ setCounter(counter - 1);
port.write("2d");
};
const sendToggleHandler = () => {
@@ -37,6 +40,7 @@ const App = () => {
increase={sendIncreaseHandler}
decrease={sendDecreaseHandler}
toggle={sendToggleHandler}
+ status={counter}
/>
+