Skip to content

Commit

Permalink
Proper lcd view now
Browse files Browse the repository at this point in the history
  • Loading branch information
tganzhorn committed Jun 11, 2021
1 parent fe81f88 commit fdee88e
Show file tree
Hide file tree
Showing 3 changed files with 266 additions and 93 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "lcd-simulator-electron",
"version": "0.1.0",
"version": "0.2.0",
"private": true,
"author": "Tobias Ganzhorn",
"description": "Simple LCD-Simulator for the Mikrocontroller-Labor-Board.",
Expand Down Expand Up @@ -76,7 +76,7 @@
"type": "development"
},
"win": {
"target": "portable",
"target": "nsis",
"icon": "./public/ms-icon-310x310.png"
},
"linux": {
Expand Down
21 changes: 11 additions & 10 deletions src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,21 +12,21 @@ import {
isDisplayClearCommand
} from './classes/CommandParser';
import { DebugCommandView } from './components/DebugCommandView';
import { LCDView, LCDBuffer } from './components/LCDView';
import { Navbar, Container, Jumbotron, Tabs, Tab, Button } from 'react-bootstrap';
import { DisplayCommandView } from './components/DisplayCommandView';
import "./App.css";
import "./Fonts.css";
import "./bootstrap.min.css";
import { useToasts } from 'react-toast-notifications';
import { LCDView, LCDManager } from './components/LCDView';

function App() {
const [serial, setSerial] = useState<Serial>();
const [serialPort, setSerialPort] = useState<SerialPort>();
const [debugCommands, setDebugCommands] = useState<(DebugNumberCommand | DebugTextCommand)[]>([]);
const [commands, setCommands] = useState<LCDCommand[]>([]);
const [connected, setConnected] = useState(false);
const lcdRef = useRef<[LCDBuffer, React.Dispatch<React.SetStateAction<LCDBuffer>>]>();
const lcdRef = useRef<LCDManager>();

const { addToast } = useToasts();

Expand Down Expand Up @@ -72,23 +72,23 @@ function App() {

commandParser.onNewCommand = (command: LCDCommand) => {
if (!lcdRef.current) return;
const [buffer, setBuffer] = lcdRef.current;
const lcdManager = lcdRef.current;
if (isDebugNumberCommand(command) || isDebugTextCommand(command)) {
setDebugCommands(state => state.concat([command]));
} else {
setCommands(state => state.concat([command]));
}
if (isDisplayCharCommand(command)) {
setBuffer(buffer.insertText(command.text));
lcdManager.insertText(command.text);
}
if (isDisplayTextCommand(command)) {
setBuffer(buffer.insertTextAt(command.text, command.row, command.column));
lcdManager.insertTextAt(command.text, command.row, command.column);
}
if (isDisplaySetCursorCommand(command)) {
setBuffer(buffer.setCursor(command.row, command.column));
lcdManager.setCursor(command.row, command.column);
}
if (isDisplayClearCommand(command)) {
setBuffer(buffer.clearLines());
lcdManager.clearLines();
}

};
Expand Down Expand Up @@ -127,10 +127,11 @@ function App() {

const clearAll = () => {
if (!lcdRef.current) return;
const [buffer, setBuffer] = lcdRef.current;
const lcdManager = lcdRef.current;
setCommands([]);
setDebugCommands([]);
setBuffer(new LCDBuffer(buffer.rows, buffer.columns));
lcdManager.commandsReceived = 0;
lcdManager.clearLines();
}

return (
Expand Down Expand Up @@ -169,7 +170,7 @@ function App() {
<>
<h1>No device connected!</h1>
<p>
Please connect to a the microcontroller by pressing the "Open COM Port" button.
Please connect to a microcontroller by pressing the "Open COM Port" button.
</p>
<Button variant="primary" onClick={handleCOMPortSelection}>Open COM Port</Button>
</>
Expand Down
Loading

0 comments on commit fdee88e

Please sign in to comment.