Browse Source

Sampling Mode Buttons in Toolbar

Timo Dritschler 2 years ago
parent
commit
03a6e29039
2 changed files with 124 additions and 1 deletions
  1. 107 0
      KCG/base/ModeButtonsToolbar.py
  2. 17 1
      KCG/base/MultiWidget.py

+ 107 - 0
KCG/base/ModeButtonsToolbar.py

@@ -0,0 +1,107 @@
+"""
+This is a helper function to create a Toolbar for operation mode buttons
+In the main view. It is split into this file to better seperate concerns,
+since these buttons have to talk with the board directly.
+"""
+from PyQt4 import QtGui, QtCore
+from .groupedelements import Elements
+from .backend import board
+from .backend.board import available_boards
+
+
+#FIXME:
+#We wanted to support multiple boards at some point but dropped
+#the idea eventually. The board selection is still partially in 
+#the codebase though ... In the future, this might change agin
+#but for now just using board 0 is good enough in 99.99% of the
+#cases
+BOARD_ID = 0
+
+
+class ModeSelectToolbar(QtGui.QToolBar):
+
+    def __init__(self, parent):
+        super(ModeSelectToolbar, self).__init__()
+
+        self.modeLabel = QtGui.QLabel("Sampling Mode:")
+        self.modeDropdown = QtGui.QComboBox(self)
+        self.modeDropdown.addItem("Normal")
+        self.modeDropdown.addItem("Equivalent Timesampling")
+        self.modeDropdown.addItem("Test Pattern")
+
+        #Important: Connect the changed callback AFTER adding the items
+        #or otherwise adding the first item will immediately fire the 
+        #callback while launching the gui, potentially causing problems
+        self.modeDropdown.currentIndexChanged.connect(self._modeChanged)
+
+
+        self.dummyDataCheckbox = QtGui.QCheckBox()
+        self.dummyDataCheckbox.setChecked(False)
+        self.dummyDataCheckbox.clicked.connect(self._activateDummyData)
+
+
+        self.addWidget(self.modeLabel)
+        self.addWidget(self.modeDropdown)
+        self.addWidget(self.dummyDataCheckbox)
+        self.addWidget(QtGui.QLabel("Generate Dummy Data"))
+
+
+    def _modeChanged(self):
+        mode = self.modeDropdown.currentIndex()
+        #FIXME:
+        #These should really be functions in the board backend class
+        #I really dislike slinging magic values around in random 
+        #files that no one can understand again later on ...
+
+        #Pre-Calculate the mask to switch "Equivalent Sampling" off
+        #since the sampling modes are supposed to be mutually 
+        #exlusive. Set bit [23] to 0 (Zero-Indexed)
+        current = board.pci.read(BOARD_ID, 0x9040)[0]
+        mask = 0xF7FFFFFF
+        new = current & mask
+
+        if mode == 0:
+            #normal mode
+            board.pci.write(BOARD_ID, 30000, 0x9044) 
+            board.pci.write(BOARD_ID, 402000, 0x9064) 
+            board.pci.write(BOARD_ID, 0000, 0x9044) 
+            board.pci.write(BOARD_ID, new, 0x9040) 
+            #print("Sampling Mode Changed to 'Normal Mode'")
+        elif mode == 1:
+            #Equivalent Sampling mode
+            #print("Sampling Mode Changed to 'Equivalent Timesampling'")
+            #mask = 0b00000000100000000000000000000000
+            #Set bits [23] (Zero-Indexed)
+            mask = 0x8000000
+            new = current | mask
+            board.pci.write(BOARD_ID, new, 0x9040) 
+        elif mode == 2:
+            #Test Pattern
+            board.pci.write(BOARD_ID, 30000, 0x9044) 
+            board.pci.write(BOARD_ID, 403000, 0x9064) 
+            board.pci.write(BOARD_ID, 0000, 0x9044) 
+            board.pci.write(BOARD_ID, new, 0x9040) 
+            #print("Sampling Mode Changed to 'Test Pattern'")
+
+
+
+    def _activateDummyData(self):
+        current = board.pci.read(BOARD_ID, 0x9040)[0]
+        if self.dummyDataCheckbox.isChecked():
+            #mask = 0b00001010000000000000000000000000
+            #Set bits [25] and [27] (Zero-Indexed)
+            mask = 0xa000000
+            new = current | mask
+            board.pci.write(BOARD_ID, new, 0x9040) 
+            #print("Activate Dummy Data")
+        else:
+            #mask = 0b00001010000000000000000000000000
+            #Remove bits [25] and [27] (Zero-Indexed)
+            mask = 0xF5FFFFFF
+            new = current & mask
+            board.pci.write(BOARD_ID, new, 0x9040) 
+            #print("Deactivate Dummy Data")
+        
+
+
+

+ 17 - 1
KCG/base/MultiWidget.py

@@ -7,6 +7,7 @@ from . import kcgwidget as kcgw
 from . import LeftBar
 from .globals import glob as global_objects
 from .. import config
+from . import ModeButtonsToolbar
 
 tr = kcgw.tr
 
@@ -108,7 +109,22 @@ class MultiWidget(QtGui.QWidget):
         self.new_data_action.triggered.connect(lambda: self.leftBar.add_plot(LeftBar.FILE))
         self.new_data_action.setToolTip(tr("Button", "New Data Plot") + "\n(Ctrl+D/O)")
 
-        self.layout.addWidget(self.toolbar)
+        #By Timo on 26.11.2021
+        #Michele wants buttons for operation modes in the toolbar
+        #so here we go.
+        #Since most of these buttons will directly communicate with the board,
+        #the creation and functionality setup of these buttons does not belong
+        #here, where we're only doing layout. I will move the creation of the
+        #Mode Toolbar to it's own function in a separate file, to better
+        #seperate these concerns
+        self.modeToolbar = ModeButtonsToolbar.ModeSelectToolbar(self)
+
+        self.toolbarHBox = QtGui.QHBoxLayout()
+        self.toolbarHBox.addWidget(self.toolbar)
+        self.toolbarHBox.addWidget(self.modeToolbar)
+        self.layout.addLayout(self.toolbarHBox)
+
+
         # ------[ End Tool Bar ]-----
 
         self.splitter.addWidget(self.leftBar)