diff --git a/.vscode/settings.json b/.vscode/settings.json index a386092..87c409a 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -4,5 +4,5 @@ "java.project.referencedLibraries": [ "lib/**/*.jar" ], - "java.jdt.ls.vmargs": "-XX:+UseParallelGC -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -Dsun.zip.disableMemoryMapping=true -Xmx4G -Xms100m" + "java.jdt.ls.vmargs": "-XX:+UseParallelGC -XX:GCTimeRatio=4 -XX:AdaptiveSizePolicyWeight=90 -Dsun.zip.disableMemoryMapping=true -Xmx8G -Xms100m" } diff --git a/bin/Control/MyControlModel.class b/bin/Control/MyControlModel.class new file mode 100644 index 0000000..c540a8a Binary files /dev/null and b/bin/Control/MyControlModel.class differ diff --git a/bin/Control/MyControlModelPIC.class b/bin/Control/MyControlModelPIC.class deleted file mode 100644 index 69c01fa..0000000 Binary files a/bin/Control/MyControlModelPIC.class and /dev/null differ diff --git a/bin/Control/MyControlModelRuntime.class b/bin/Control/MyControlModelRuntime.class deleted file mode 100644 index 7a686dc..0000000 Binary files a/bin/Control/MyControlModelRuntime.class and /dev/null differ diff --git a/bin/Control/MyControlView.class b/bin/Control/MyControlView.class index 79e4aaf..a2178ab 100644 Binary files a/bin/Control/MyControlView.class and b/bin/Control/MyControlView.class differ diff --git a/bin/Model/Microcontroller/Bitmask.class b/bin/Model/Microcontroller/Bitmask.class index 2912924..0096de6 100644 Binary files a/bin/Model/Microcontroller/Bitmask.class and b/bin/Model/Microcontroller/Bitmask.class differ diff --git a/bin/Model/Microcontroller/EEPROM.class b/bin/Model/Microcontroller/EEPROM.class index 9135188..f50d03e 100644 Binary files a/bin/Model/Microcontroller/EEPROM.class and b/bin/Model/Microcontroller/EEPROM.class differ diff --git a/bin/Model/Microcontroller/PIC.class b/bin/Model/Microcontroller/PIC.class index 5d22d50..eaf5508 100644 Binary files a/bin/Model/Microcontroller/PIC.class and b/bin/Model/Microcontroller/PIC.class differ diff --git a/bin/Model/Microcontroller/RAM.class b/bin/Model/Microcontroller/RAM.class index a7da890..b484a8d 100644 Binary files a/bin/Model/Microcontroller/RAM.class and b/bin/Model/Microcontroller/RAM.class differ diff --git a/bin/Model/Microcontroller/RUNTIMER.class b/bin/Model/Microcontroller/RUNTIMER.class new file mode 100644 index 0000000..5b2748a Binary files /dev/null and b/bin/Model/Microcontroller/RUNTIMER.class differ diff --git a/bin/Model/MyModel.class b/bin/Model/MyModel.class index 29e6739..eb89de8 100644 Binary files a/bin/Model/MyModel.class and b/bin/Model/MyModel.class differ diff --git a/bin/Model/MyModelData.class b/bin/Model/MyModelData.class new file mode 100644 index 0000000..d8df1cf Binary files /dev/null and b/bin/Model/MyModelData.class differ diff --git a/bin/Model/ProgramStepInformation.class b/bin/Model/ProgramStepInformation.class new file mode 100644 index 0000000..fe123a3 Binary files /dev/null and b/bin/Model/ProgramStepInformation.class differ diff --git a/bin/Model/Runtime/Main.class b/bin/Model/Runtime/Main.class deleted file mode 100644 index df06311..0000000 Binary files a/bin/Model/Runtime/Main.class and /dev/null differ diff --git a/bin/Model/Runtime/ProgramStepInformation.class b/bin/Model/Runtime/ProgramStepInformation.class deleted file mode 100644 index a521958..0000000 Binary files a/bin/Model/Runtime/ProgramStepInformation.class and /dev/null differ diff --git a/bin/Model/Runtime/TODO.class b/bin/Model/Runtime/TODO.class deleted file mode 100644 index f045336..0000000 Binary files a/bin/Model/Runtime/TODO.class and /dev/null differ diff --git a/bin/Model/Runtime/Testfile.class b/bin/Model/Runtime/Testfile.class deleted file mode 100644 index bc22f0a..0000000 Binary files a/bin/Model/Runtime/Testfile.class and /dev/null differ diff --git a/bin/Runtime/Main.class b/bin/Runtime/Main.class new file mode 100644 index 0000000..1715eef Binary files /dev/null and b/bin/Runtime/Main.class differ diff --git a/bin/Runtime/TODO.class b/bin/Runtime/TODO.class new file mode 100644 index 0000000..ee39889 Binary files /dev/null and b/bin/Runtime/TODO.class differ diff --git a/bin/View/GUIMainFrame.class b/bin/View/GUIMainFrame.class index 7d34899..8f9bce6 100644 Binary files a/bin/View/GUIMainFrame.class and b/bin/View/GUIMainFrame.class differ diff --git a/bin/View/GUIMenuBar.class b/bin/View/GUIMenuBar.class index 2dc7dd5..085dbe6 100644 Binary files a/bin/View/GUIMenuBar.class and b/bin/View/GUIMenuBar.class differ diff --git a/bin/View/GUIProgramMemory.class b/bin/View/GUIProgramMemory.class new file mode 100644 index 0000000..828af85 Binary files /dev/null and b/bin/View/GUIProgramMemory.class differ diff --git a/bin/View/GUITestFileTable.class b/bin/View/GUITestFileTable.class index bb51c58..034a802 100644 Binary files a/bin/View/GUITestFileTable.class and b/bin/View/GUITestFileTable.class differ diff --git a/bin/View/GUITime.class b/bin/View/GUITime.class index 62d381c..046f622 100644 Binary files a/bin/View/GUITime.class and b/bin/View/GUITime.class differ diff --git a/bin/View/MyView.class b/bin/View/MyView.class index 948961c..94b5bd5 100644 Binary files a/bin/View/MyView.class and b/bin/View/MyView.class differ diff --git a/bin/View/MyViewData.class b/bin/View/MyViewData.class new file mode 100644 index 0000000..21eb421 Binary files /dev/null and b/bin/View/MyViewData.class differ diff --git a/documentation/WORD/.~lock.Rechnerarchitektur Selbststudium Skript Verbesserungsvorschläge.docx# b/documentation/WORD/.~lock.Rechnerarchitektur Selbststudium Skript Verbesserungsvorschläge.docx# new file mode 100644 index 0000000..e846f15 --- /dev/null +++ b/documentation/WORD/.~lock.Rechnerarchitektur Selbststudium Skript Verbesserungsvorschläge.docx# @@ -0,0 +1 @@ +,aaron_moser,aaron-moser-ThinkPad-T430,08.04.2022 11:11,file:///home/aaron_moser/.config/libreoffice/4; \ No newline at end of file diff --git a/documentation/WORD/Rechnerarchitektur Selbststudium Skript Verbesserungsvorschläge.docx b/documentation/WORD/Rechnerarchitektur Selbststudium Skript Verbesserungsvorschläge.docx index c6cb2b7..0d109f0 100755 Binary files a/documentation/WORD/Rechnerarchitektur Selbststudium Skript Verbesserungsvorschläge.docx and b/documentation/WORD/Rechnerarchitektur Selbststudium Skript Verbesserungsvorschläge.docx differ diff --git a/src/Control/MyControlModel.java b/src/Control/MyControlModel.java new file mode 100644 index 0000000..534e4c0 --- /dev/null +++ b/src/Control/MyControlModel.java @@ -0,0 +1,296 @@ +package Control; + +import Model.MyModelData; +import Model.EepromLoader.ReadEepromFile; +import Model.Microcontroller.PIC; +import View.MyView; + +import java.awt.event.ActionEvent; +import java.awt.event.ActionListener; +import java.io.File; +import java.util.ArrayList; +import java.util.concurrent.ConcurrentLinkedQueue; + +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JComboBox; +import javax.swing.JFileChooser; +import javax.swing.JMenuItem; + +public class MyControlModel implements ActionListener { + + MyView oMyView; + + ArrayList oBreakpoints; + ArrayList oControlButtons; + JCheckBox oWDTEnabled; + JComboBox oQuarzIntervals; + ArrayList oMenuItems; + + ConcurrentLinkedQueue qCommandsForModel; + ConcurrentLinkedQueue qDataForModel; + + ReadEepromFile oRef; + int iTestFileLoaded = 0; + boolean[] abBreakpoints; + PIC oPIC; + + MyModelData oMyModelData = new MyModelData(); + + public MyControlModel(MyView view, ConcurrentLinkedQueue qCommandsForModel, ConcurrentLinkedQueue qDataForModel) { + oMyView = view; + this.oPIC = new PIC(); + this.qCommandsForModel = qCommandsForModel; + this.qDataForModel = qDataForModel; + oControlButtons = oMyView.getGUIMCMenu().getControlButtons(); + oBreakpoints = oMyView.getGUITestFileTable().getCheckboxes(); + oWDTEnabled = oMyView.getGUITime().getWDTEnableCheckbox(); + oQuarzIntervals = oMyView.getGUITime().getQuarzComboBox(); + oMenuItems = oMyView.getGUIMenuBar().getMenuItems(); + addActionListeners(); + } + + private void startProgramModel() { + qCommandsForModel.add(1); // 1 == start + } + + private void pauseProgramModel() { + qCommandsForModel.add(2); // 2 == pause + } + + private void resetProgramModel() { + qCommandsForModel.add(3); // 3 == reset + } + + private void stepProgramModel() { + qCommandsForModel.add(4); // 4 == step + } + + public void controlWDTModel(boolean bEnabled) { + + } + + private void loadTestFile() { + File oFile; + //select file to open + JFileChooser oFileChooser = new JFileChooser(); + int iResponse = oFileChooser.showOpenDialog(null); + if (iResponse == JFileChooser.APPROVE_OPTION) { + oFile = new File(oFileChooser.getSelectedFile().getAbsolutePath()); + //System.out.println(oFile); + oRef = new ReadEepromFile(); + oRef.setData(oFile); + oRef.setOPCode(oRef.getData()); + oMyView.getGUITestFileTable().setData(oRef.getData()); + setBreakpointsActionListeners(); + oRef.readFileAndWriteToEEPROM(oPIC); + oMyView.updateWindow(); + iTestFileLoaded = 1; + oMyModelData.setPIC(oPIC); + oMyModelData.setBreakpoints(abBreakpoints); + qDataForModel.add(oMyModelData); + } + } + + private void loadProgStateItem() { + //TODO + } + + private void saveProgStateItem() { + //TODO + } + + /** + * Sets interval of visual running. (instant, 1 sec, 2 sec) + * @param i + */ + private void setIntervalProgramModel(int i) { + oMyModelData.setVisualInterval(i); + qDataForModel.add(oMyModelData); + } + + /** + * Sets ActionListeners for breakpoints. + */ + private void setBreakpointsActionListeners() { + ArrayList data = oRef.getData(); + int iDataSize = data.size(); + ArrayList opcode = oRef.getOPCode(); + + int iOPCodeSize = opcode.size(); + //If testfile was loaded before, reset all checkboxes + if (iTestFileLoaded > 0) { + oBreakpoints = oMyView.getGUITestFileTable().getCheckboxes(); + for (int i = 0; i < iDataSize; i++) { + oBreakpoints.get(i).setEnabled(false); + } + } + //Enable only checkboxes which belong to real code + int[] aiProgramLines = new int[iOPCodeSize]; + int k = 0; + for (int i = 0; i < iDataSize; i++) { + for (int j = 0; j < iOPCodeSize; j++) { + if (data.get(i).equals(opcode.get(j))) { + aiProgramLines[k] = i; + k++; + oBreakpoints = oMyView.getGUITestFileTable().getCheckboxes(); + oBreakpoints.get(i).setEnabled(true); + oBreakpoints.get(i).addActionListener(this); + } + } + } + oPIC.getEeprom().setProgramLines(aiProgramLines); + abBreakpoints = new boolean[iOPCodeSize]; + } + + private void controlBreakpoints(ActionEvent e) { + if (oRef != null) { + int iOPCode = oRef.getOPCode().size(); + if (iOPCode > 0) { + for (int i = 0; i < oBreakpoints.size(); i++) { + if (e.getSource() == oBreakpoints.get(i)) { + for (int j = 0; j < iOPCode; j++) { + if (oRef.getOPCode().get(j).equals(oRef.getData().get(i))) { + abBreakpoints[j] = !abBreakpoints[j]; + oMyModelData.setBreakpoints(abBreakpoints); + qDataForModel.add(oMyModelData); + } + } + } + } + } + } + } + + @Override + public void actionPerformed(ActionEvent e) { + //Breakpoints set/reset + controlBreakpoints(e); + + //Runtime control Buttons + if (e.getSource() == oControlButtons.get(0)) { + startProgramModel(); + } + if (e.getSource() == oControlButtons.get(1)) { + stepProgramModel(); + } + if (e.getSource() == oControlButtons.get(2)) { + pauseProgramModel(); + } + if (e.getSource() == oControlButtons.get(3)) { + resetProgramModel(); + } + + //WDT-Enabled Checkbox + if (e.getSource() == oWDTEnabled) { + //Enable/disable watchdog + System.out.println("Watchdog got set to " + oWDTEnabled.isSelected());//TODO + } + + //Quarzfrequency + if (e.getSource() == oQuarzIntervals) { + oMyModelData.setQuartzInterval(oQuarzIntervals.getSelectedIndex()); + qDataForModel.add(oMyModelData); + } + + int i = 0; + for (JMenuItem oMenuItem : oMenuItems) { + if (e.getSource() == oMenuItem) { + switch (i) { + case 0: { + //Load testfile + loadTestFile(); + }break; + case 1: { + //Load Program State + loadProgStateItem(); + }break; + case 2: { + //Save Program State + saveProgStateItem(); + }break; + case 3: { + //Exit Program + qCommandsForModel.add(0); + System.exit(0); + }break; + case 4: { + //Dark theme + oMyView.setTheme(1); + }break; + case 5: { + //Light theme + oMyView.setTheme(0); + }break; + case 6: { + //Start pic + startProgramModel(); + }break; + case 7: { + //Pause pic + pauseProgramModel(); + }break; + case 8: { + //Reset pic + resetProgramModel(); + }break; + case 9: { + //Step pic + stepProgramModel(); + }break; + case 10: { + //Set interval to as soon as possible + setIntervalProgramModel(0); + }break; + case 11: { + //Set interval to 1 sec + setIntervalProgramModel(1); + }break; + case 12: { + //Set interval to 2 sec + setIntervalProgramModel(2); + }break; + case 13: { + //Change language to german + oMyView.setLanguage(0); + }break; + case 14: { + //Change language to english + oMyView.setLanguage(1); + }break; + case 15: { + //Show manual + }break; + case 16: { + //Show about + }break; + } + } + i++; + } + } + + private void addActionListeners() { + if (oBreakpoints != null) { + for (JCheckBox oBreakpoint : oBreakpoints) { + oBreakpoint.addActionListener(this); + } + } + if (oControlButtons != null) { + for (JButton oButton : oControlButtons) { + oButton.addActionListener(this); + } + } + if (oWDTEnabled != null) { + oWDTEnabled.addActionListener(this); + } + if (oQuarzIntervals != null) { + oQuarzIntervals.addActionListener(this); + } + if (oMenuItems != null) { + for (JMenuItem oMenuItem : oMenuItems) { + oMenuItem.addActionListener(this); + } + } + } +} \ No newline at end of file diff --git a/src/Control/MyControlModelPIC.java b/src/Control/MyControlModelPIC.java deleted file mode 100644 index 56a9805..0000000 --- a/src/Control/MyControlModelPIC.java +++ /dev/null @@ -1,98 +0,0 @@ -package Control; - -import java.util.ArrayList; - -import Model.MyModel; -import View.MyView; - -public class MyControlModelPIC { - - MyModel oModel; - MyView oView; - //put Objects to manipulate here - - public MyControlModelPIC(MyModel model, MyView view) { - oModel = model; - oView = view; - } - - public void setWRegisterModel(int iValue) { - - } - - public void setPCinternModel(int iValue) { - - } - - public void setPCLATHModel(int iValue) { - - } - - public void setPCLModel(int iValue) { - - } - - public void setFSRModel(int iValue) { - - } - - public void setStatusModel(int iValue) { - - } - - public void setOptionModel(int iValue) { - - } - - public void setPrescalerModel(int iValue) { - - } - - public void setTMR0Model(int iValue) { - - } - - - - public void setPortAPinXToYModel(int iPort, boolean bEnabled) { - - } - - public void setPortBPinXToYModel(int iPort, boolean bEnabled) { - - } - - public void setPortATrisXToYModel(int iPort, boolean bEnabled) { - - } - - public void setPortBTrisXToYModel(int iPort, boolean bEnabled) { - - } - - public void setRamModel(int[][] aiiRam) { - - } - - - public void setQuarzModel(int iElement) { - - } - - - public void loadFileToEEPROMModel(ArrayList oData) { - - } - - public void saveSimulatorStateModel() { - - } - - public void loadSimulatorStateModel() { - - } - - public void exitSimulatorModel() { - - } -} diff --git a/src/Control/MyControlModelRuntime.java b/src/Control/MyControlModelRuntime.java deleted file mode 100644 index 0f737d2..0000000 --- a/src/Control/MyControlModelRuntime.java +++ /dev/null @@ -1,85 +0,0 @@ -package Control; - -import Model.MyModel; -import View.MyView; - -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; -import java.awt.event.KeyEvent; - -import java.util.ArrayList; - -import javax.swing.JButton; -import javax.swing.JCheckBox; - -public class MyControlModelRuntime implements ActionListener { - - MyModel oMyModel; - - ArrayList oBreakpoints; - ArrayList oControlButtons; - - public MyControlModelRuntime(MyModel model, MyView view) { - oMyModel = model; - oControlButtons = view.getGUIMCMenu().getControlButtons(); - oBreakpoints = view.getGUITestFileTable().getCheckboxes(); - addActionListeners(); - } - - private void startProgramEnvironment() { - oMyModel.start(); - } - - private void stepProgramEnvironment() { - oMyModel.step(); - } - - private void pauseProgramEnvironment() { - oMyModel.pause(); - } - - private void resetProgramEnvironment() { - - } - - public void controlWDTEnvironment(boolean bEnabled) { - - } - - @Override - public void actionPerformed(ActionEvent e) { - int i = 0; - for (JCheckBox oBreakpoint : oBreakpoints) { - if (e.getSource() == oBreakpoint) { - oMyModel.controlBreakpoint(i); - } - i++; - } - if (e.getSource() == oControlButtons.get(0)) { - //startProgramEnvironment(); - System.out.println("Test"); - } - if (e.getSource() == oControlButtons.get(1)) { - - } - if (e.getSource() == oControlButtons.get(2)) { - - } - - // TODO Auto-generated method stub - - } - - private void addActionListeners() { - if (oBreakpoints != null) { - for (JCheckBox oBreakpoint : oBreakpoints) { - oBreakpoint.addActionListener(this); - } - } - if (oControlButtons != null) { - for (JButton oButton : oControlButtons) { - oButton.addActionListener(this); - } - } - } -} \ No newline at end of file diff --git a/src/Control/MyControlView.java b/src/Control/MyControlView.java index e916029..475f962 100644 --- a/src/Control/MyControlView.java +++ b/src/Control/MyControlView.java @@ -2,17 +2,21 @@ package Control; import java.util.ArrayList; -import Model.MyModel; +import Model.Microcontroller.PIC; import View.MyView; +/** + * Class to set fields of parts of view. + */ public class MyControlView { MyView oMyView; - MyModel oMyModel; + PIC oPIC; - public MyControlView(MyModel model, MyView view) { + public MyControlView(PIC oPIC, MyView view) { oMyView = view; - oMyModel = model; + this.oPIC = oPIC; + updateView(); } public void updateView() { @@ -22,6 +26,7 @@ public class MyControlView { setRamView(); setRegistersDetailed(); setStack(); + setTestFileTable(); } /** @@ -31,19 +36,19 @@ public class MyControlView { //Get values from pic int[] aiValues = new int[9]; - aiValues[0] = oMyModel.getPIC().getRam().get_TMR0(); - aiValues[1] = oMyModel.getPIC().getRam().get_Programcounter(); - aiValues[2] = oMyModel.getPIC().getRam().get_STATUS(); - aiValues[3] = oMyModel.getPIC().getRam().get_PCLATH(); - aiValues[4] = oMyModel.getPIC().getRam().get_FSR(); - aiValues[5] = oMyModel.getPIC().getRam().get_PCL(); - aiValues[6] = oMyModel.getPIC().getRam().get_OPTION(); - if (oMyModel.getPIC().getRam().get_PSA()) { - aiValues[7] = oMyModel.getPIC().getRam().get_WDT_PrescalerRate(); + aiValues[0] = oPIC.getRam().get_TMR0(); + aiValues[1] = oPIC.getRam().get_Programcounter(); + aiValues[2] = oPIC.getRam().get_STATUS(); + aiValues[3] = oPIC.getRam().get_PCLATH(); + aiValues[4] = oPIC.getRam().get_FSR(); + aiValues[5] = oPIC.getRam().get_PCL(); + aiValues[6] = oPIC.getRam().get_OPTION(); + if (oPIC.getRam().get_PSA()) { + aiValues[7] = oPIC.getRam().get_WDT_PrescalerRate(); } else { - aiValues[7] = oMyModel.getPIC().getRam().get_TMR0_PrescalerRate(); + aiValues[7] = oPIC.getRam().get_TMR0_PrescalerRate(); } - aiValues[8] = oMyModel.getPIC().get_WRegister(); + aiValues[8] = oPIC.get_WRegister(); //Fill gui element with gathered values oMyView.getGUIRegister().setRegisters(aiValues); @@ -53,9 +58,9 @@ public class MyControlView { * Sets detailed register-table values to values from PIC. */ public void setRegistersDetailed() { - int iStatus = oMyModel.getPIC().getRam().get_STATUS(); - int iOption = oMyModel.getPIC().getRam().get_OPTION(); - int iIntcon = oMyModel.getPIC().getRam().get_INTCON(); + int iStatus = oPIC.getRam().get_STATUS(); + int iOption = oPIC.getRam().get_OPTION(); + int iIntcon = oPIC.getRam().get_INTCON(); int iS0 = ((iStatus & 1) == 1) ? 1:0; int iS1 = ((iStatus & 2) == 2) ? 1:0; @@ -101,11 +106,11 @@ public class MyControlView { boolean[] abEnabled = new boolean[10]; - abEnabled[0] = oMyModel.getPIC().getRam().get_TRISA0(); - abEnabled[1] = oMyModel.getPIC().getRam().get_TRISA1(); - abEnabled[2] = oMyModel.getPIC().getRam().get_TRISA2(); - abEnabled[3] = oMyModel.getPIC().getRam().get_TRISA3(); - abEnabled[4] = oMyModel.getPIC().getRam().get_TRISA4(); + abEnabled[0] = oPIC.getRam().get_TRISA0(); + abEnabled[1] = oPIC.getRam().get_TRISA1(); + abEnabled[2] = oPIC.getRam().get_TRISA2(); + abEnabled[3] = oPIC.getRam().get_TRISA3(); + abEnabled[4] = oPIC.getRam().get_TRISA4(); abEnabled[5] = true; abEnabled[6] = true; @@ -123,14 +128,14 @@ public class MyControlView { boolean[] abEnabled = new boolean[16]; - abEnabled[0] = oMyModel.getPIC().getRam().get_TRISB0(); - abEnabled[1] = oMyModel.getPIC().getRam().get_TRISB1(); - abEnabled[2] = oMyModel.getPIC().getRam().get_TRISB2(); - abEnabled[3] = oMyModel.getPIC().getRam().get_TRISB3(); - abEnabled[4] = oMyModel.getPIC().getRam().get_TRISB4(); - abEnabled[5] = oMyModel.getPIC().getRam().get_TRISB5(); - abEnabled[6] = oMyModel.getPIC().getRam().get_TRISB6(); - abEnabled[7] = oMyModel.getPIC().getRam().get_TRISB7(); + abEnabled[0] = oPIC.getRam().get_TRISB0(); + abEnabled[1] = oPIC.getRam().get_TRISB1(); + abEnabled[2] = oPIC.getRam().get_TRISB2(); + abEnabled[3] = oPIC.getRam().get_TRISB3(); + abEnabled[4] = oPIC.getRam().get_TRISB4(); + abEnabled[5] = oPIC.getRam().get_TRISB5(); + abEnabled[6] = oPIC.getRam().get_TRISB6(); + abEnabled[7] = oPIC.getRam().get_TRISB7(); abEnabled[8] = true; abEnabled[9] = true; @@ -146,8 +151,8 @@ public class MyControlView { public void setRamView() { int[] aiData; - int[] aiBank0 = oMyModel.getPIC().getRam().get_Bank0(); - int[] aiBank1 = oMyModel.getPIC().getRam().get_Bank1(); + int[] aiBank0 = oPIC.getRam().get_Bank0(); + int[] aiBank1 = oPIC.getRam().get_Bank1(); aiData = new int[256]; for (int i = 0; i < 128; i++) { @@ -162,7 +167,22 @@ public class MyControlView { } public void setStack() { - oMyView.getGUIStack().setStack(oMyModel.getPIC().getStack().getSTACK()); + oMyView.getGUIStack().setStack(oPIC.getStack().getSTACK()); + } + + public void setTestFileTable() { + if (oPIC.getEeprom().getProgramLines() != null) { + if (oPIC.getRam().get_LastProgramcounter() > -1) { + oMyView.getGUITestFileTable().unmarkLine(oPIC.getEeprom().getProgramLine(oPIC.getRam().get_LastProgramcounter())); + oMyView.getGUITestFileTable().markLine(oPIC.getEeprom().getProgramLine(oPIC.getRam().get_Programcounter())); + } else { + int[] aiProgList = oPIC.getEeprom().getProgramLines(); + for (int i = 0; i < aiProgList.length; i++) { + oMyView.getGUITestFileTable().unmarkLine(aiProgList[i]); + } + oMyView.getGUITestFileTable().markLine(oPIC.getEeprom().getProgramLine(0)); + } + } } public void startProgramView() { @@ -205,4 +225,8 @@ public class MyControlView { public void exitSimulatorView() { } + + public void setPIC(PIC oPic) { + oPIC = oPic; + } } \ No newline at end of file diff --git a/src/Model/Microcontroller/Bitmask.java b/src/Model/Microcontroller/Bitmask.java index 797e40d..52dd5ab 100755 --- a/src/Model/Microcontroller/Bitmask.java +++ b/src/Model/Microcontroller/Bitmask.java @@ -7,7 +7,7 @@ public class Bitmask { * @param oPIC */ public int bitMaskDecoderAndExecuteCommand(int iCommandAsIntToMask, PIC oPIC) { - + System.out.println("Command " + Integer.toHexString(iCommandAsIntToMask)); //Return-value will be -1 if command can't be read. int iDecodedCommand = -1; diff --git a/src/Model/Microcontroller/EEPROM.java b/src/Model/Microcontroller/EEPROM.java index 827c0ef..3f82989 100755 --- a/src/Model/Microcontroller/EEPROM.java +++ b/src/Model/Microcontroller/EEPROM.java @@ -12,11 +12,38 @@ public class EEPROM private int[] eeprom; private int eepromLength = 0; + private int[] aiProgramLines; + public EEPROM() { eeprom = new int[1024]; } + /** + * Returns array of program lines in data + * @return + */ + public int[] getProgramLines() { + return aiProgramLines; + } + + /** + * Return element i of program lines in data + * @param i + * @return + */ + public int getProgramLine(int i) { + return aiProgramLines[i]; + } + + /** + * Sets program lines of data + * @param aiProgLines + */ + public void setProgramLines(int[] aiProgLines) { + aiProgramLines = aiProgLines; + } + /** * Returns element of index element in eeprom-array. * @param element index of array. diff --git a/src/Model/Microcontroller/PIC.java b/src/Model/Microcontroller/PIC.java index a889fda..c24b57a 100755 --- a/src/Model/Microcontroller/PIC.java +++ b/src/Model/Microcontroller/PIC.java @@ -1207,9 +1207,6 @@ public class PIC { public void SUBLW(int eightK) { int wRegValue = get_WRegister(); - //Build Two's complement - //eightK = (eightK ^ 0b11111111) + 1; - //Build Two's complement wRegValue = (wRegValue ^ 0b11111111) + 1; diff --git a/src/Model/Microcontroller/RAM.java b/src/Model/Microcontroller/RAM.java index beeeeb2..b5dff93 100755 --- a/src/Model/Microcontroller/RAM.java +++ b/src/Model/Microcontroller/RAM.java @@ -21,7 +21,7 @@ public class RAM { private int[] bank1; //Last programmcounter for function getLastLine in main. - private int lastProgramcounter; + private int lastProgramcounter = -1; // private int iPrescaledTMR0; diff --git a/src/Model/Microcontroller/RUNTIMER.java b/src/Model/Microcontroller/RUNTIMER.java new file mode 100644 index 0000000..f6d149f --- /dev/null +++ b/src/Model/Microcontroller/RUNTIMER.java @@ -0,0 +1,5 @@ +package Model.Microcontroller; + +public class RUNTIMER { + +} diff --git a/src/Model/MyModel.java b/src/Model/MyModel.java index a189ff9..0897af2 100644 --- a/src/Model/MyModel.java +++ b/src/Model/MyModel.java @@ -1,160 +1,178 @@ package Model; -import java.util.ArrayList; +import java.util.concurrent.ConcurrentLinkedQueue; import Model.Microcontroller.Bitmask; import Model.Microcontroller.PIC; -import Model.Microcontroller.WATCHDOG; -import View.GUIMainFrame; -public class MyModel { - private PIC oPIC; +public class MyModel extends Thread { + PIC oPIC = new PIC(); + + MyModelData oMyModelData; - private int iModelState = 3; - private int iActualLine; - private int iLastLine; + boolean bStopProgram = false; - private ArrayList listBreakpoints = new ArrayList(); + int iProgState = 0; + int iVisualInterval = 0; - private long liRuntimeRun; - private long liRuntimeStep; + double dRTIncrVal = 0; - private boolean[] bBreakpoints; + private boolean[] abBreakpoints; - private WATCHDOG watchdog; - GUIMainFrame oMainFrame; + ConcurrentLinkedQueue qReceivedCommands; + ConcurrentLinkedQueue qDataToModel; + ConcurrentLinkedQueue qDataToView; - public MyModel() { - oPIC = new PIC(); + public MyModel(ConcurrentLinkedQueue qCommands, ConcurrentLinkedQueue qDataS, ConcurrentLinkedQueue qDataR) { + qReceivedCommands = qCommands; + qDataToView = qDataS; + qDataToModel = qDataR; } - public PIC getPIC() { - return this.oPIC; + @Override + public void run() { + //Check if end or error + while (!bStopProgram) { + //Check if element to set model + while (!qDataToModel.isEmpty()) { + setModel(qDataToModel.poll()); + } + //Check if element at command-queue + if (!qReceivedCommands.isEmpty()) { + /* -1 == ERROR, 0 == END, 1 == START, 2 == PAUSE, 3 == RESET*/ + iProgState = qReceivedCommands.poll(); + switch (iProgState) { + case (-1): { + System.out.println("Fehler"); + bStopProgram = true; + }break; + case (0): { + System.out.println("Programm wurde beendet."); + bStopProgram = true; + }break; + case (1): { + //start program + while (iProgState == 1) { + //Check if pause/stop was pressed + if (!qReceivedCommands.isEmpty()) { + iProgState = qReceivedCommands.poll(); + } + //Check if breakpoint is set + if (abBreakpoints != null) { + if (!abBreakpoints[oPIC.getRam().get_Programcounter()]) { + if(iVisualInterval > 0) { + try { + Thread.sleep(iVisualInterval * 1000); + } catch (InterruptedException e) { + e.printStackTrace(); + } + } + step(); + qDataToView.add(oPIC); + } else { + //Pause program + iProgState = 2; + } + } + } + }break; + case (2): { + + }break; + case (3): { + oPIC.resetPIC(); + qDataToView.add(oPIC); //TODO + }break; + case (4): { + if (abBreakpoints != null) { + //Check if breakpoint is set + if (!abBreakpoints[oPIC.getRam().get_Programcounter()]) { + step(); + qDataToView.add(oPIC); //TODO + } + } else { + System.out.println("Please load file!"); + } + }break; + } + } + + + } } - private int getModelState() { - return iModelState; - } - - /** - * -1 == ERROR, 0 == END, 1 == START, 2 == PAUSE, 3 == RESET - * @param i - */ - public void setModelState(int i) { - iModelState = i; - } - - public ArrayList getBreakpointsList() { - return listBreakpoints; - } - - public void setBreakpointsList(ArrayList liBreakpoints) { - listBreakpoints = liBreakpoints; - bBreakpoints = new boolean[listBreakpoints.size()]; - } - - /** - * - * @return - */ - public int getActualLine() { - return iActualLine; - } - - /** - * - * @return - */ - public int getLastLine() { - return iLastLine; - } - - /** - * - * @return - */ - public long getRuntimeRun() { - return liRuntimeRun; - } - - /** - * - * @return - */ - public long getRuntimeStep() { - return liRuntimeStep; - } - - /** - * - * @return - */ - public WATCHDOG getWatchdog() { - return watchdog; - } - - public void step() { + private void step() { //Check if step valid - if (oPIC.getRam().get_Programcounter() < (oPIC.getEeprom().getLengthEEPROM() - 1)) { - final long timeStart = System.nanoTime(); - + if (oPIC.getRam().get_Programcounter() < (oPIC.getEeprom().getLengthEEPROM())) { //Makes one step through the eeprom. Bitmask oBitmask = new Bitmask(); oBitmask.bitMaskDecoderAndExecuteCommand(oPIC.getEeprom().getElement(oPIC.getRam().get_Programcounter()), oPIC); - - final long timeEnd = System.nanoTime(); - - liRuntimeStep += (timeEnd - timeStart); - + qDataToView.add(oPIC); } else { System.out.println("Step invalid, end of file reached!"); } } - public void start() { - if (getModelState() != 2) { //Do not start again if paused, instead call start to unpause only. - final long timeStart = System.nanoTime(); + private void setQuarzSpeed(int iInterval) { //TODO Quartz + switch (iInterval) { + //10 {"32 kHz", "100 kHz", "500 kHz", "1 MHz", "2 MHz", "4 MHz", "8 MHz", "12 MHz", "16 MHz", "20 MHz"} + case 0: { + //32 kHz => + dRTIncrVal = (4 / 0.032); + }break; - //workWithWatchdog(1, 1); - //Check if set breakpoint reached or program was stopped or interrupt - - while (getModelState() != 0) { - switch (iModelState) { + case 1: { + //100kHz => 0.000010s + dRTIncrVal = (4 / 0.1); + }break; - case 1: { //START - step(); - // - //workWithWatchdog(1, 2); - final long timeEnd = System.nanoTime(); - liRuntimeRun += timeEnd - timeStart; - oMainFrame.updateWindow(); - }break; + case 2: { + //500kHz => 0.0000020s + dRTIncrVal = (4 / 0.5); + }break; - case 2: { //PAUSE resume() has to be called to continue - while (iModelState == 2) {} - }break; - } - } - } else { //Unpause - iModelState = 1; + case 3: { + //1MHz => 0.0000010s + dRTIncrVal = (4 / 1); + }break; + + case 4: { + //2MHz => 0.0000005s + dRTIncrVal = (4 / 2); + }break; + + case 5: { + //4MHz => 0.00000025s 1 mükrosekunde + dRTIncrVal = (4 / 4); + }break; + + case 6: { + //8MHz => 0.000000125s + dRTIncrVal = (4 / 8); + }break; + + case 7: { + //12MHz => 0.00000008333333 + dRTIncrVal = (4 / 12); + }break; + + case 8: { + //16MHz => 0.0000000625 + dRTIncrVal = (4 / 16); + }break; + + case 9: { + //20MHz => 0.00000005 + dRTIncrVal = (4 / 20); + }break; } } - public void reset() { - if (getModelState() != 1) { - oPIC.resetPIC(); - iModelState = 3; //RESET - } - } - - public void pause() { - iModelState = 2; - } - - public void controlBreakpoint(int iBreakpoint) { - if (bBreakpoints != null) { - bBreakpoints[iBreakpoint] = !bBreakpoints[iBreakpoint]; - System.out.println("Breakpoint " + iBreakpoint + " was set to " + bBreakpoints[iBreakpoint]); - } + private void setModel(MyModelData data) { + oMyModelData = data; + oPIC = oMyModelData.getPIC(); + abBreakpoints = oMyModelData.getBreakpoints(); + setQuarzSpeed(oMyModelData.getQuartzInterval()); + iVisualInterval = oMyModelData.getVisualInterval(); } } diff --git a/src/Model/MyModelData.java b/src/Model/MyModelData.java new file mode 100644 index 0000000..6c788ef --- /dev/null +++ b/src/Model/MyModelData.java @@ -0,0 +1,52 @@ +package Model; + +import Model.Microcontroller.PIC; + +public class MyModelData { + private PIC oPIC; + private int iQuartzInterval; + private int iVisualInterval; + private boolean bWDTEnabled = false; + + private boolean[] abBreakpoints; + + public PIC getPIC() { + return oPIC; + } + + public int getQuartzInterval() { + return iQuartzInterval; + } + + public int getVisualInterval() { + return iVisualInterval; + } + + public boolean[] getBreakpoints() { + return abBreakpoints; + } + + public boolean getWDTEnabled() { + return bWDTEnabled; + } + + public void setPIC(PIC pic) { + this.oPIC = pic; + } + + public void setQuartzInterval(int iIndex) { + this.iQuartzInterval = iIndex; + } + + public void setVisualInterval(int iIndex) { + this.iVisualInterval = iIndex; + } + + public void setBreakpoints(boolean[] abBreakpoints) { + this.abBreakpoints = abBreakpoints; + } + + public void setWDTEnabled(boolean bWDTEnabled) { + this.bWDTEnabled = bWDTEnabled; + } +} diff --git a/src/Model/Runtime/ProgramStepInformation.java b/src/Model/ProgramStepInformation.java similarity index 57% rename from src/Model/Runtime/ProgramStepInformation.java rename to src/Model/ProgramStepInformation.java index ec847f1..d5d36b9 100755 --- a/src/Model/Runtime/ProgramStepInformation.java +++ b/src/Model/ProgramStepInformation.java @@ -1,7 +1,10 @@ -package Model.Runtime; +package Model; import Model.Microcontroller.PIC; +/** + * Class to store program-state. TODO + */ public class ProgramStepInformation { private PIC oPIC; } diff --git a/src/Model/Runtime/Main.java b/src/Model/Runtime/Main.java deleted file mode 100755 index 73fce95..0000000 --- a/src/Model/Runtime/Main.java +++ /dev/null @@ -1,17 +0,0 @@ -package Model.Runtime; - -import Control.MyControlModelPIC; -import Control.MyControlModelRuntime; -import Control.MyControlView; -import Model.MyModel; -import View.MyView; - -public class Main { - public static void main(String[] args) { - MyModel oModel = new MyModel(); - MyView oView = new MyView(oModel); - MyControlView oControlView = new MyControlView(oModel, oView); - MyControlModelRuntime oControlModelRuntime = new MyControlModelRuntime(oModel, oView); - MyControlModelPIC oControlModelPIC = new MyControlModelPIC(oModel, oView); - } -} \ No newline at end of file diff --git a/src/Model/Runtime/Testfile.java b/src/Model/Runtime/Testfile.java deleted file mode 100644 index cca6d2f..0000000 --- a/src/Model/Runtime/Testfile.java +++ /dev/null @@ -1,8 +0,0 @@ -package Model.Runtime; - -import java.util.ArrayList; - -public class Testfile { - ArrayList lsTestfile; - -} \ No newline at end of file diff --git a/src/Runtime/Main.java b/src/Runtime/Main.java new file mode 100755 index 0000000..11f8077 --- /dev/null +++ b/src/Runtime/Main.java @@ -0,0 +1,39 @@ +package Runtime; + +import java.util.concurrent.ConcurrentLinkedQueue; + +import Control.MyControlModel; +import Control.MyControlView; +import Model.MyModel; +import Model.MyModelData; +import Model.Microcontroller.PIC; +import View.MyView; + +public class Main { + + public static void main(String[] args) { + PIC oPIC = new PIC(); + + ConcurrentLinkedQueue qCommandsToModel = new ConcurrentLinkedQueue(); + ConcurrentLinkedQueue qDataToView = new ConcurrentLinkedQueue(); + ConcurrentLinkedQueue qDataToModel = new ConcurrentLinkedQueue(); + + MyModel oModel = new MyModel(qCommandsToModel, qDataToView, qDataToModel); + oModel.start(); + + MyView oView = new MyView(); + + MyControlView oControlView = new MyControlView(oPIC, oView); + + new MyControlModel(oView, qCommandsToModel, qDataToModel); + + //Check if model sent a new pic-element through queue and update view. + while (qCommandsToModel.peek() > 0) { + while (!qDataToView.isEmpty()) { + PIC pic = qDataToView.poll(); + oControlView.setPIC(pic); + oControlView.updateView(); + } + } + } +} \ No newline at end of file diff --git a/src/Model/Runtime/TODO.java b/src/Runtime/TODO.java similarity index 96% rename from src/Model/Runtime/TODO.java rename to src/Runtime/TODO.java index edd1a0d..cb3639a 100755 --- a/src/Model/Runtime/TODO.java +++ b/src/Runtime/TODO.java @@ -1,4 +1,4 @@ -package Model.Runtime; +package Runtime; public class TODO { diff --git a/src/View/GUIMainFrame.java b/src/View/GUIMainFrame.java index f6dfd9c..c269c37 100755 --- a/src/View/GUIMainFrame.java +++ b/src/View/GUIMainFrame.java @@ -141,6 +141,7 @@ public class GUIMainFrame extends JFrame { } public void updateWindow() { + //update tables this.revalidate(); this.repaint(); } diff --git a/src/View/GUIMenuBar.java b/src/View/GUIMenuBar.java index f05a6e6..152c1e2 100644 --- a/src/View/GUIMenuBar.java +++ b/src/View/GUIMenuBar.java @@ -2,32 +2,24 @@ package View; import java.awt.Color; import java.awt.Dimension; -import java.awt.event.ActionEvent; -import java.awt.event.ActionListener; import java.awt.event.KeyEvent; -import java.io.File; import java.util.ArrayList; import javax.swing.BorderFactory; import javax.swing.JCheckBox; -import javax.swing.JFileChooser; import javax.swing.JMenu; import javax.swing.JMenuBar; import javax.swing.JMenuItem; -import Model.MyModel; import Model.EepromLoader.ReadEepromFile; -public class GUIMenuBar extends JMenuBar implements ActionListener { +public class GUIMenuBar extends JMenuBar { MyView oMyView; - MyModel oMyModel; - ArrayList oBreakpoints; ReadEepromFile oRef; boolean[] bBreakpointSet; - int iTestFileLoaded = 0; ArrayList oMenuItems = new ArrayList(); //Custom separators because addSeparator(default) looks not nice. @@ -69,16 +61,16 @@ public class GUIMenuBar extends JMenuBar implements ActionListener { JMenuItem oAbout; //German language array - String[] sGermanLang = {"Datei", "Testdatei laden", "Programmzustand laden", "Programmzustand speichern", "Simulation beenden", + String[][] sLanguages = { + {"Datei", "Testdatei laden", "Programmzustand laden", "Programmzustand speichern", "Simulation beenden", "Ansicht", "Thema", "Dunkler Modus", "Heller Modus", "Microcontroller", "Programm starten", "Programm pausieren", "Programm zuruecksetzen", "Schritt fuer Schritt", "Bearbeitungsintervall", "Sofort", "1 Sekunde", "2 Sekunden", - "Hilfe", "Sprache", "Deutsch", "Englisch", "Anleitung", "Ueber"}; - - //English language array - String[] sEnglishLang = {"File", "Load Testfile", "Load Programstate", "Save Programstate", "Exit simulation", - "View", "Theme", "Dark Theme", "Light Theme", - "Microcontroller", "Start program", "Pause program", "Reset program", "Step by Step", "Workinterval", "Instant", "1 second", "2 seconds", - "Help", "Language", "German", "English", "Manual", "About"}; + "Hilfe", "Sprache", "Deutsch", "Englisch", "Anleitung", "Ueber"}, + + {"File", "Load Testfile", "Load Programstate", "Save Programstate", "Exit simulation", + "View", "Theme", "Dark Theme", "Light Theme", + "Microcontroller", "Start program", "Pause program", "Reset program", "Step by Step", "Workinterval", "Instant", "1 second", "2 seconds", + "Help", "Language", "German", "English", "Manual", "About"}}; //Color for separators is always the same. Color oColorSeparators = new Color(47, 47, 47); @@ -87,7 +79,7 @@ public class GUIMenuBar extends JMenuBar implements ActionListener { * Constructor initializes menubar. * @param frame */ - public GUIMenuBar(MyModel model, MyView view) { //TODO maybe single components, with methods, of frame to set theme + public GUIMenuBar(MyView view) { //Custom Separators since default is not able to change background. oSeparator0 = new JMenuItem(); @@ -106,77 +98,44 @@ public class GUIMenuBar extends JMenuBar implements ActionListener { //Referrence to change different parts of gui for theme. oMyView = view; - oMyModel = model; - //File - oFileMenu = new JMenu(sGermanLang[0]); - oLoadTestFile = new JMenuItem(sGermanLang[1]); - oLoadProgStateItem = new JMenuItem(sGermanLang[2]); - oSaveProgStateItem = new JMenuItem(sGermanLang[3]); - oExitItem = new JMenuItem(sGermanLang[4]); + oFileMenu = new JMenu(sLanguages[0][0]); + oLoadTestFile = new JMenuItem(sLanguages[0][1]); + oLoadProgStateItem = new JMenuItem(sLanguages[0][2]); + oSaveProgStateItem = new JMenuItem(sLanguages[0][3]); + oExitItem = new JMenuItem(sLanguages[0][4]); //View - oViewMenu = new JMenu(sGermanLang[5]); - oChangeColors = new JMenu(sGermanLang[6]); - oDarkTheme = new JMenuItem(sGermanLang[7]); - oLightTheme = new JMenuItem(sGermanLang[8]); + oViewMenu = new JMenu(sLanguages[0][5]); + oChangeColors = new JMenu(sLanguages[0][6]); + oDarkTheme = new JMenuItem(sLanguages[0][7]); + oLightTheme = new JMenuItem(sLanguages[0][8]); //Microcontroller - oMicrocontroller = new JMenu(sGermanLang[9]); - oStartProg = new JMenuItem(sGermanLang[10]); - oPauseProg = new JMenuItem(sGermanLang[11]); - oResetProg = new JMenuItem(sGermanLang[12]); - oStepProg = new JMenuItem(sGermanLang[13]); - oChangeWorkInterval = new JMenu(sGermanLang[14]); - oIntervalASAP = new JMenuItem(sGermanLang[15]); - oInterval1Sec = new JMenuItem(sGermanLang[16]); - oInterval2Sec = new JMenuItem(sGermanLang[17]); + oMicrocontroller = new JMenu(sLanguages[0][9]); + oStartProg = new JMenuItem(sLanguages[0][10]); + oPauseProg = new JMenuItem(sLanguages[0][11]); + oResetProg = new JMenuItem(sLanguages[0][12]); + oStepProg = new JMenuItem(sLanguages[0][13]); + oChangeWorkInterval = new JMenu(sLanguages[0][14]); + oIntervalASAP = new JMenuItem(sLanguages[0][15]); + oInterval1Sec = new JMenuItem(sLanguages[0][16]); + oInterval2Sec = new JMenuItem(sLanguages[0][17]); //Help - oHelpMenu = new JMenu(sGermanLang[18]); - oChangeLanguageMenu = new JMenu(sGermanLang[19]); - oGerLangItem = new JMenuItem(sGermanLang[20]); - oEngLangItem = new JMenuItem(sGermanLang[21]); - oManual = new JMenuItem(sGermanLang[22]); - oAbout = new JMenuItem(sGermanLang[23]); + oHelpMenu = new JMenu(sLanguages[0][18]); + oChangeLanguageMenu = new JMenu(sLanguages[0][19]); + oGerLangItem = new JMenuItem(sLanguages[0][20]); + oEngLangItem = new JMenuItem(sLanguages[0][21]); + oManual = new JMenuItem(sLanguages[0][22]); + oAbout = new JMenuItem(sLanguages[0][23]); fillList(); - setActionListeners(); setGerMnemonics(); buildMenubar(); setTheme(0); } - /** - * Sets ActionListeners to all items. - */ - private void setActionListeners() { - //File - oLoadTestFile.addActionListener(this); - oLoadProgStateItem.addActionListener(this); - oSaveProgStateItem.addActionListener(this); - oExitItem.addActionListener(this); - - //View - oDarkTheme.addActionListener(this); - oLightTheme.addActionListener(this); - - //Microcontroller - oStartProg.addActionListener(this); - oPauseProg.addActionListener(this); - oResetProg.addActionListener(this); - oStepProg.addActionListener(this); - oIntervalASAP.addActionListener(this); - oInterval1Sec.addActionListener(this); - oInterval2Sec.addActionListener(this); - - //Help - oGerLangItem.addActionListener(this); - oEngLangItem.addActionListener(this); - oManual.addActionListener(this); - oAbout.addActionListener(this); - } - /** * Sets english mnemonics. */ @@ -298,122 +257,47 @@ public class GUIMenuBar extends JMenuBar implements ActionListener { * Change language to overhanded language array. * @param lang = language to change to. */ - private void changeLangMenuBar(String[] lang) { + public void changeLangMenuBar(int iLang) { + switch (iLang) { + case 0: { + setGerMnemonics(); + }break; + case 1: { + setEngMnemonics(); + }break; + } + //File - oFileMenu.setText(lang[0]); - oLoadTestFile.setText(lang[1]); - oLoadProgStateItem.setText(lang[2]); - oSaveProgStateItem.setText(lang[3]); - oExitItem.setText(lang[4]); + oFileMenu.setText(sLanguages[iLang][0]); + oLoadTestFile.setText(sLanguages[iLang][1]); + oLoadProgStateItem.setText(sLanguages[iLang][2]); + oSaveProgStateItem.setText(sLanguages[iLang][3]); + oExitItem.setText(sLanguages[iLang][4]); //View - oViewMenu.setText(lang[5]); - oChangeColors.setText(lang[6]); - oDarkTheme.setText(lang[7]); - oLightTheme.setText(lang[8]); + oViewMenu.setText(sLanguages[iLang][5]); + oChangeColors.setText(sLanguages[iLang][6]); + oDarkTheme.setText(sLanguages[iLang][7]); + oLightTheme.setText(sLanguages[iLang][8]); //Microcontroller - oMicrocontroller.setText(lang[9]); - oStartProg.setText(lang[10]); - oPauseProg.setText(lang[11]); - oResetProg.setText(lang[12]); - oStepProg.setText(lang[13]); - oChangeWorkInterval.setText(lang[14]); - oIntervalASAP.setText(lang[15]); - oInterval1Sec.setText(lang[16]); - oInterval2Sec.setText(lang[17]); + oMicrocontroller.setText(sLanguages[iLang][9]); + oStartProg.setText(sLanguages[iLang][10]); + oPauseProg.setText(sLanguages[iLang][11]); + oResetProg.setText(sLanguages[iLang][12]); + oStepProg.setText(sLanguages[iLang][13]); + oChangeWorkInterval.setText(sLanguages[iLang][14]); + oIntervalASAP.setText(sLanguages[iLang][15]); + oInterval1Sec.setText(sLanguages[iLang][16]); + oInterval2Sec.setText(sLanguages[iLang][17]); //Help - oHelpMenu.setText(lang[18]); - oChangeLanguageMenu.setText(lang[19]); - oGerLangItem.setText(lang[20]); - oEngLangItem.setText(lang[21]); - oManual.setText(lang[22]); - oAbout.setText(lang[23]); - } - - @Override - public void actionPerformed(ActionEvent e) { - //File - if (e.getSource() == oLoadTestFile) { - loadTestFile(); - } - if (e.getSource() == oLoadProgStateItem) { - System.out.println("Bro do you even code? load"); - //TODO - } - if (e.getSource() == oSaveProgStateItem) { - System.out.println("Bro do you even code? save"); - //TODO - System.exit(0); - } - if (e.getSource() == oExitItem) { - System.out.println("Bro do you even code? exit"); - //TODO - System.exit(0); - } - - //View - //Change to dark theme - if (e.getSource() == oDarkTheme) { - System.out.println("It's gettin dark brooo"); //TODO - setTheme(1); - oMyView.setTheme(1); - } - //Change to light theme - if (e.getSource() == oLightTheme) { - System.out.println("Death to all vampires!"); //TODO - setTheme(0); - oMyView.setTheme(0); - } - - //Microcontroller - if (e.getSource() == oStartProg) { - System.out.println("Start prog"); //TODO - } - if (e.getSource() == oPauseProg) { - System.out.println("oPauseProg"); //TODO - } - if (e.getSource() == oResetProg) { - System.out.println("oResetProg"); //TODO - } - if (e.getSource() == oStepProg) { - System.out.println("oStepProg"); //TODO - } - if (e.getSource() == oIntervalASAP) { - System.out.println("oIntervalASAP"); //TODO - } - if (e.getSource() == oInterval1Sec) { - System.out.println("oInterval1Sec"); //TODO - } - if (e.getSource() == oInterval2Sec) { - System.out.println("oInterval2Sec"); //TODO - } - - //Help - //Change language at gui. - if (e.getSource() == oGerLangItem) { - changeLangMenuBar(sGermanLang); - setGerMnemonics(); - oMyView.setLanguage(0); - //TODO rest of gui - } - if (e.getSource() == oEngLangItem) { - changeLangMenuBar(sEnglishLang); - setEngMnemonics(); - oMyView.setLanguage(1); - //TODO rest of gui - } - //Show manual - if (e.getSource() == oManual) { - //TODO - } - //Show about - if (e.getSource() == oAbout) { - //TODO - } - - controlBreakpoints(e); + oHelpMenu.setText(sLanguages[iLang][18]); + oChangeLanguageMenu.setText(sLanguages[iLang][19]); + oGerLangItem.setText(sLanguages[iLang][20]); + oEngLangItem.setText(sLanguages[iLang][21]); + oManual.setText(sLanguages[iLang][22]); + oAbout.setText(sLanguages[iLang][23]); } private void fillList() { @@ -640,75 +524,11 @@ public class GUIMenuBar extends JMenuBar implements ActionListener { } } - private void loadTestFile() { - File oFile; - //select file to open - JFileChooser oFileChooser = new JFileChooser(); - int iResponse = oFileChooser.showOpenDialog(null); - if (iResponse == JFileChooser.APPROVE_OPTION) { - oFile = new File(oFileChooser.getSelectedFile().getAbsolutePath()); - //System.out.println(oFile); - oRef = new ReadEepromFile(); - oRef.setData(oFile); - oRef.setOPCode(oRef.getData()); - oMyView.getGUITestFileTable().setData(oRef.getData()); - - setBreakpointsActionListeners(); - - oRef.readFileAndWriteToEEPROM(oMyModel.getPIC()); - oMyView.getGUIMainFrame().updateWindow(); - iTestFileLoaded = 1; - } - } - - private void setBreakpointsActionListeners() { - ArrayList data = oRef.getData(); - int iDataSize = data.size(); - ArrayList opcode = oRef.getOPCode(); - - int iOPCodeSize = opcode.size(); - //If testfile was loaded before, reset all checkboxes - if (iTestFileLoaded > 0) { - oBreakpoints = oMyView.getGUITestFileTable().getCheckboxes(); - for (int i = 0; i < iDataSize; i++) { - oBreakpoints.get(i).setEnabled(false); - } - } - //Enable only checkboxes which belong to real code - for (int i = 0; i < iDataSize; i++) { - for (int j = 0; j < iOPCodeSize; j++) { - if (data.get(i).equals(opcode.get(j))) { - oBreakpoints = oMyView.getGUITestFileTable().getCheckboxes(); - oBreakpoints.get(i).setEnabled(true); - oBreakpoints.get(i).addActionListener(this); - } - } - } - bBreakpointSet = new boolean[iOPCodeSize]; - } - - private void controlBreakpoints(ActionEvent e) { - if (oRef != null) { - int iOPCode = oRef.getOPCode().size(); - if (iOPCode > 0) { - for (int i = 0; i < oBreakpoints.size(); i++) { - if (e.getSource() == oBreakpoints.get(i)) { - for (int j = 0; j < iOPCode; j++) { - if (oRef.getOPCode().get(j).equals(oRef.getData().get(i))) { - bBreakpointSet[j] = !bBreakpointSet[j]; - if (bBreakpointSet[j]) - System.out.println("Breakpoint " + j + " got set."); - else - System.out.println("Breakpoint " + j + " got reset."); - } - } - } - } - } - } - } - public boolean[] getBreakpoints() { return bBreakpointSet; } + + public ArrayList getMenuItems() { + return oMenuItems; + } } \ No newline at end of file diff --git a/src/View/GUIProgramMemory.java b/src/View/GUIProgramMemory.java new file mode 100644 index 0000000..e04ffa7 --- /dev/null +++ b/src/View/GUIProgramMemory.java @@ -0,0 +1,5 @@ +package View; + +public class GUIProgramMemory { + +} \ No newline at end of file diff --git a/src/View/GUITestFileTable.java b/src/View/GUITestFileTable.java index 1b52df6..95e6f5c 100644 --- a/src/View/GUITestFileTable.java +++ b/src/View/GUITestFileTable.java @@ -194,11 +194,12 @@ public class GUITestFileTable extends JScrollPane { * Mark line at testfiletable. * @param iLineToMark */ - public void markLine(int iLineToMark) { //TODO + public void markLine(int iLineToMark) { if (iLineToMark > -1) { - oLineInformation.get(iLineToMark).setForeground(getThemeColor()[3]); - oLineInformation.get(iLineToMark).setBackground(getThemeColor()[4]); - oLineInformation.get(iLineToMark).setBorder(BorderFactory.createLineBorder(getThemeColor()[5])); + oLineInformation.get(iLineToMark * 2).setForeground(getThemeColor()[3]); + oLineInformation.get(iLineToMark * 2).setBorder(BorderFactory.createLineBorder(getThemeColor()[3])); + oLineInformation.get(iLineToMark * 2 + 1).setForeground(getThemeColor()[3]); + oLineInformation.get(iLineToMark * 2 + 1).setBorder(BorderFactory.createLineBorder(getThemeColor()[3])); } } @@ -206,11 +207,12 @@ public class GUITestFileTable extends JScrollPane { * Unmark line at testfiletable. * @param iLineToUnmark */ - public void unmarkLine(int iLineToUnmark) { //TODO + public void unmarkLine(int iLineToUnmark) { if (iLineToUnmark > -1) { - oLineInformation.get(iLineToUnmark).setForeground(getThemeColor()[0]); - oLineInformation.get(iLineToUnmark).setBackground(getThemeColor()[1]); - oLineInformation.get(iLineToUnmark).setBorder(BorderFactory.createLineBorder(getThemeColor()[2])); + oLineInformation.get(iLineToUnmark * 2).setForeground(getThemeColor()[0]); + oLineInformation.get(iLineToUnmark * 2).setBorder(BorderFactory.createLineBorder(getThemeColor()[2])); + oLineInformation.get(iLineToUnmark * 2 + 1).setForeground(getThemeColor()[0]); + oLineInformation.get(iLineToUnmark * 2 + 1).setBorder(BorderFactory.createLineBorder(getThemeColor()[2])); } } diff --git a/src/View/GUITime.java b/src/View/GUITime.java index e25ad82..50e2269 100644 --- a/src/View/GUITime.java +++ b/src/View/GUITime.java @@ -82,6 +82,14 @@ public class GUITime extends JPanel { } } + public JComboBox getQuarzComboBox() { + return oIntervals; + } + + public JCheckBox getWDTEnableCheckbox() { + return oEnableWDT; + } + public void setRuntime(int iRuntime) { this.iRuntime = iRuntime; } diff --git a/src/View/MyView.java b/src/View/MyView.java index 6a2c6fb..7cec26c 100644 --- a/src/View/MyView.java +++ b/src/View/MyView.java @@ -1,8 +1,10 @@ package View; -import javax.swing.JPanel; +import java.util.ArrayList; -import Model.MyModel; +import javax.swing.JButton; +import javax.swing.JCheckBox; +import javax.swing.JPanel; public class MyView implements IMyView { @@ -19,8 +21,8 @@ public class MyView implements IMyView { private JPanel oGUIMainPanel; - public MyView(MyModel model) { - oGUIMenuBar = new GUIMenuBar(model, this); + public MyView() { + oGUIMenuBar = new GUIMenuBar(this); oGUIMCMenu = new GUIMCMenu(); oGUIPorts = new GUIPorts(); oGUIRamTable = new GUIRamTable(); @@ -48,13 +50,37 @@ public class MyView implements IMyView { } public void setLanguage(int iLangNr) { + oGUIMenuBar.changeLangMenuBar(iLangNr); oGUIMCMenu.setLanguage(iLangNr); oGUIRegister.setLanguage(iLangNr); oGUITestFileTable.setLanguage(iLangNr); oGUITime.setLanguage(iLangNr); } - public GUIMainFrame getGUIMainFrame() { + + + public void test() { + this.getGUITime().getQuarzComboBox(); + this.getGUIMenuBar().getMenuItems(); + } + + public ArrayList getControlButtons() { + return this.getGUIMCMenu().getControlButtons(); + } + + public ArrayList getCheckboxes() { + return this.getGUITestFileTable().getCheckboxes(); + } + + public JCheckBox getWDTEnableCheckbox() { + return this.getGUITime().getWDTEnableCheckbox(); + } + + public void updateWindow() { + this.getGUIMainFrame().updateWindow(); + } + + private GUIMainFrame getGUIMainFrame() { return this.oGUIMainFrame; } @@ -93,4 +119,8 @@ public class MyView implements IMyView { public JPanel getGUIMainPanel() { return this.oGUIMainPanel; } + + public GUIMenuBar getGUIMenuBar() { + return oGUIMenuBar; + } } \ No newline at end of file diff --git a/src/View/MyViewData.java b/src/View/MyViewData.java new file mode 100644 index 0000000..bbb0baa --- /dev/null +++ b/src/View/MyViewData.java @@ -0,0 +1,16 @@ +package View; + +import Model.Microcontroller.PIC; + +public class MyViewData { + private PIC oPIC; + + public PIC getPIC() { + return oPIC; + } + + public void setPIC(PIC oPIC) { + this.oPIC = oPIC; + } + +}