Remove unnecessary code

This commit is contained in:
GHOSCHT 2021-12-31 21:46:45 +01:00
parent b7fb224442
commit 42abc1b572
No known key found for this signature in database
GPG key ID: A35BD466B8871994
4 changed files with 6 additions and 74 deletions

View file

@ -1,10 +1,8 @@
import React, { useState } from "react"; import React, { useState } from "react";
import { createGlobalStyle } from "styled-components"; import { createGlobalStyle } from "styled-components";
import { useDispatch } from "react-redux"; // import { useDispatch } from "react-redux";
import Select from "react-select"; import Select from "react-select";
import SerialPort from "serialport"; import SerialPort from "serialport";
import { connect, disconnect } from "./redux/actions/asyncSerialConnectionActions";
import { setSerialPort } from "./redux/actions/serialConnectionActions";
import KnobSection from "./Components/KnobSection"; import KnobSection from "./Components/KnobSection";
const GlobalStyle = createGlobalStyle` const GlobalStyle = createGlobalStyle`
@ -28,14 +26,14 @@ const fetchPorts = async () => {
}; };
const App = () => { const App = () => {
const dispatch = useDispatch(); // const dispatch = useDispatch();
fetchPorts(); fetchPorts();
const [portSelectionValue, setPortSelectionValue] = useState(options[0]); const [portSelectionValue, setPortSelectionValue] = useState(options[0]);
const handlePortChange = async (selectedOption: any) => { const handlePortChange = async (selectedOption: any) => {
setPortSelectionValue(selectedOption); setPortSelectionValue(selectedOption);
dispatch(setSerialPort(selectedOption.value)); // dispatch(setSerialPort(selectedOption.value));
}; };
return ( return (
@ -45,7 +43,7 @@ const App = () => {
<button <button
type="button" type="button"
onClick={() => { onClick={() => {
dispatch(connect()); // dispatch(connect());
}} }}
> >
connect connect
@ -53,7 +51,7 @@ const App = () => {
<button <button
type="button" type="button"
onClick={() => { onClick={() => {
dispatch(disconnect()); // dispatch(disconnect());
}} }}
> >
disconnect disconnect

View file

@ -1,43 +0,0 @@
import { ThunkResult } from "typesafe-actions";
import {
connectionStart, connectionSuccess, connectionFailure, setPortController, connectionEnd,
} from "./serialConnectionActions";
import PortController from "../../serial/PortController";
const connect = (): ThunkResult<void> => async (dispatch, getState) => {
const state = getState();
dispatch(connectionStart());
if (state.serialConnection.port === null) {
dispatch(connectionFailure(new Error("No Serial Port set")));
return;
}
const controller = new PortController();
controller.create(state.serialConnection.port);
dispatch(setPortController(controller));
controller.open((error) => {
if (error === null || error === undefined) {
dispatch(connectionSuccess());
} else {
dispatch(connectionFailure(error));
}
}, (error) => {
if (error !== null && error !== undefined) {
if (error.message === "Reading from COM port (ReadIOCompletion): Access denied") {
dispatch(connectionFailure(new Error(`Device ${state.serialConnection.port} disconnected`)));
dispatch(connectionEnd());
}
}
});
};
const disconnect = (): ThunkResult<void> => async (dispatch, getState) => {
const state = getState();
state.serialConnection.portController?.close();
dispatch(connectionEnd());
};
export { connect, disconnect };

View file

@ -1,23 +0,0 @@
import { action } from "typesafe-actions";
import PortController from "../../PortController";
export enum SerialConnectionActionTypes {
SET_SERIAL_PORT = "SET_SERIAL_PORT",
CONNECTION_START = "CONNECTION_START",
CONNECTION_SUCCESS = "CONNECTION_SUCCESS",
CONNECTION_FAILURE = "CONNECTION_FAILURE",
CONNECTION_END = "CONNECTION_END",
SET_PORT_CONTROLLER = "SET_PORT_CONTROLLER"
}
export const setSerialPort = (port: string) => action(SerialConnectionActionTypes.SET_SERIAL_PORT, port);
export const connectionStart = () => action(SerialConnectionActionTypes.CONNECTION_START);
export const connectionSuccess = () => action(SerialConnectionActionTypes.CONNECTION_SUCCESS);
export const connectionFailure = (error: Error) => action(SerialConnectionActionTypes.CONNECTION_FAILURE, error);
export const connectionEnd = () => action(SerialConnectionActionTypes.CONNECTION_END);
export const setPortController = (controller: PortController) => action(SerialConnectionActionTypes.SET_PORT_CONTROLLER, controller);

View file

@ -1,5 +1,5 @@
import { combineReducers } from "redux"; import { combineReducers } from "redux";
import SerialConnectionReducer from "../reducers/serialConnectionReducer"; import SerialConnectionReducer from "../slices/serialConnectionSlice";
const rootReducer = combineReducers({ const rootReducer = combineReducers({
serialConnection: SerialConnectionReducer, serialConnection: SerialConnectionReducer,