123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109 |
- """
- 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 = int(board.pci.read(BOARD_ID, reg="0x9040", decimal=True)[0])
- mask = 0xFF7FFFFF
- new = str(hex(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 = 0x800000
- new = str(hex(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 = int(board.pci.read(BOARD_ID, reg="0x9040", decimal=True)[0])
- if self.dummyDataCheckbox.isChecked():
- self.modeDropdown.setEnabled(False)
- #mask = 0b00000010000000000000000000000000
- #Set bits [25] (Zero-Indexed)
- mask = 0x2000000
- new = str(hex(current | mask))
- board.pci.write(BOARD_ID, new, "0x9040")
- #print("Activate Dummy Data")
- else:
- self.modeDropdown.setEnabled(True)
- #mask = 0b00000010000000000000000000000000
- #Remove bits [25] (Zero-Indexed)
- mask = 0xFDFFFFFF
- new = str(hex(current & mask))
- board.pci.write(BOARD_ID, new, "0x9040")
- #print("Deactivate Dummy Data")
-
|