ModeButtonsToolbar.py 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. """
  2. This is a helper function to create a Toolbar for operation mode buttons
  3. In the main view. It is split into this file to better seperate concerns,
  4. since these buttons have to talk with the board directly.
  5. """
  6. from PyQt4 import QtGui, QtCore
  7. from .groupedelements import Elements
  8. from .backend import board
  9. from .backend.board import available_boards
  10. #FIXME:
  11. #We wanted to support multiple boards at some point but dropped
  12. #the idea eventually. The board selection is still partially in
  13. #the codebase though ... In the future, this might change agin
  14. #but for now just using board 0 is good enough in 99.99% of the
  15. #cases
  16. BOARD_ID = 0
  17. class ModeSelectToolbar(QtGui.QToolBar):
  18. def __init__(self, parent):
  19. super(ModeSelectToolbar, self).__init__()
  20. self.modeLabel = QtGui.QLabel("Sampling Mode:")
  21. self.modeDropdown = QtGui.QComboBox(self)
  22. self.modeDropdown.addItem("Normal")
  23. self.modeDropdown.addItem("Equivalent Timesampling")
  24. self.modeDropdown.addItem("Test Pattern")
  25. #Important: Connect the changed callback AFTER adding the items
  26. #or otherwise adding the first item will immediately fire the
  27. #callback while launching the gui, potentially causing problems
  28. self.modeDropdown.currentIndexChanged.connect(self._modeChanged)
  29. self.dummyDataCheckbox = QtGui.QCheckBox()
  30. self.dummyDataCheckbox.setChecked(False)
  31. self.dummyDataCheckbox.clicked.connect(self._activateDummyData)
  32. self.addWidget(self.modeLabel)
  33. self.addWidget(self.modeDropdown)
  34. self.addWidget(self.dummyDataCheckbox)
  35. self.addWidget(QtGui.QLabel("Generate Dummy Data"))
  36. def _modeChanged(self):
  37. mode = self.modeDropdown.currentIndex()
  38. #FIXME:
  39. #These should really be functions in the board backend class
  40. #I really dislike slinging magic values around in random
  41. #files that no one can understand again later on ...
  42. #Pre-Calculate the mask to switch "Equivalent Sampling" off
  43. #since the sampling modes are supposed to be mutually
  44. #exlusive. Set bit [23] to 0 (Zero-Indexed)
  45. current = int(board.pci.read(BOARD_ID, reg="0x9040", decimal=True)[0])
  46. mask = 0xFF7FFFFF
  47. new = str(hex(current & mask))
  48. if mode == 0:
  49. #normal mode
  50. board.pci.write(BOARD_ID, "30000", "0x9044")
  51. board.pci.write(BOARD_ID, "402000", "0x9064")
  52. board.pci.write(BOARD_ID, "0000", "0x9044")
  53. board.pci.write(BOARD_ID, new, "0x9040")
  54. #print("Sampling Mode Changed to 'Normal Mode'")
  55. elif mode == 1:
  56. #Equivalent Sampling mode
  57. #print("Sampling Mode Changed to 'Equivalent Timesampling'")
  58. #mask = 0b00000000100000000000000000000000
  59. #Set bits [23] (Zero-Indexed)
  60. mask = 0x800000
  61. new = str(hex(current | mask))
  62. board.pci.write(BOARD_ID, new, "0x9040")
  63. elif mode == 2:
  64. #Test Pattern
  65. board.pci.write(BOARD_ID, "30000", "0x9044")
  66. board.pci.write(BOARD_ID, "403000", "0x9064")
  67. board.pci.write(BOARD_ID, "0000", "0x9044")
  68. board.pci.write(BOARD_ID, new, "0x9040")
  69. #print("Sampling Mode Changed to 'Test Pattern'")
  70. def _activateDummyData(self):
  71. current = int(board.pci.read(BOARD_ID, reg="0x9040", decimal=True)[0])
  72. if self.dummyDataCheckbox.isChecked():
  73. self.modeDropdown.setEnabled(False)
  74. #mask = 0b00000010000000000000000000000000
  75. #Set bits [25] (Zero-Indexed)
  76. mask = 0x2000000
  77. new = str(hex(current | mask))
  78. board.pci.write(BOARD_ID, new, "0x9040")
  79. #print("Activate Dummy Data")
  80. else:
  81. self.modeDropdown.setEnabled(True)
  82. #mask = 0b00000010000000000000000000000000
  83. #Remove bits [25] (Zero-Indexed)
  84. mask = 0xFDFFFFFF
  85. new = str(hex(current & mask))
  86. board.pci.write(BOARD_ID, new, "0x9040")
  87. #print("Deactivate Dummy Data")