forked from Ultrawipf/OpenFFBoard-configurator
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathencoderconf_ui.py
More file actions
157 lines (123 loc) · 4.85 KB
/
encoderconf_ui.py
File metadata and controls
157 lines (123 loc) · 4.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
from PyQt6.QtWidgets import QMainWindow
from PyQt6.QtWidgets import QDialog
from PyQt6.QtWidgets import QWidget,QGroupBox
from PyQt6.QtWidgets import QMessageBox,QVBoxLayout,QHBoxLayout,QCheckBox,QButtonGroup,QPushButton,QLabel,QSpinBox,QComboBox,QFormLayout
from PyQt6 import uic
import main
from PyQt6.QtCore import QObjectCleanupHandler
from helper import res_path,classlistToIds
from base_ui import CommunicationHandler
class EncoderOptions(QGroupBox):
def __init__(self,main,id):
super().__init__()
self.widget = None
self.main = main
self.setType(id)
def setType(self,id):
layout = QVBoxLayout()
found = True
self.setTitle("Encoder settings")
if(id == 2): # local encoder
self.widget = (LocalEncoderConf(self,self.main))
self.setTitle("Local Encoder")
elif(id == 1): # tmc
layout.addWidget(QLabel("Configure in TMC tab"))
found = False
elif(id == 4): # MT SPI
self.widget = (MtEncoderConf(self,self.main))
self.setTitle("SPI Settings")
elif(id == 5): # BISS-C
self.widget = (BissEncoderConf(self,self.main))
self.setTitle("BISS Settings")
else:
layout.addWidget(QLabel("No settings"))
layout.setContentsMargins(0,0,0,0)
if self.widget:
layout.addWidget(self.widget)
self.applyBtn = QPushButton("Apply")
self.applyBtn.clicked.connect(self.widget.apply)
footer = QHBoxLayout()
footer.setContentsMargins(0,0,0,0)
footer.addStretch(5)
footer.addWidget(self.applyBtn)
footer.addStretch(5)
layout.addLayout(footer)
self.setLayout(layout)
class EncoderOption(QWidget):
def __init__(self,parent):
super().__init__(parent)
def apply(self):
pass
def hideEvent(self, a0) -> None:
self.onclose()
return super().hideEvent(a0)
def showEvent(self, a0) -> None:
self.onshown()
return super().showEvent(a0)
def onshown(self):
pass
def onclose(self):
pass
class LocalEncoderConf(EncoderOption,CommunicationHandler):
def __init__(self,parent,main):
self.main = main
EncoderOption.__init__(self,parent)
CommunicationHandler.__init__(self)
self.initUI()
def initUI(self):
layout = QFormLayout()
layout.setContentsMargins(0,0,0,0)
self.spinBox_cpr = QSpinBox()
self.spinBox_cpr.setRange(0,0xffff)
layout.addWidget(QLabel("CPR = 4x PPR"))
layout.addRow(QLabel("CPR:"),self.spinBox_cpr)
self.checkBox_index = QCheckBox("Use index homing")
layout.addRow(QLabel("Index:"),self.checkBox_index)
self.setLayout(layout)
def onshown(self):
self.get_value_async("localenc","cpr",self.spinBox_cpr.setValue,0,int)
self.get_value_async("localenc","index",self.checkBox_index.setChecked,0,int)
def apply(self):
val = self.spinBox_cpr.value()
self.send_value("localenc","cpr",val=val)
self.send_value("localenc","index",val = 1 if self.checkBox_index.checkState() else 0)
class MtEncoderConf(EncoderOption,CommunicationHandler):
def __init__(self,parent,main):
self.main = main
EncoderOption.__init__(self,parent)
CommunicationHandler.__init__(self)
self.initUI()
def initUI(self):
layout = QFormLayout()
layout.setContentsMargins(0,0,0,0)
self.spinBox_cs = QSpinBox()
self.spinBox_cs.setRange(1,3)
layout.addWidget(QLabel("SPI3 extension port"))
layout.addRow(QLabel("CS pin"),self.spinBox_cs)
self.setLayout(layout)
def onshown(self):
self.get_value_async("mtenc","cs",self.spinBox_cs.setValue,0,int)
def apply(self):
val = self.spinBox_cs.value()
self.send_value("mtenc","cs",val=val)
class BissEncoderConf(EncoderOption,CommunicationHandler):
def __init__(self,parent,main):
self.main = main
EncoderOption.__init__(self,parent)
CommunicationHandler.__init__(self)
self.initUI()
def initUI(self):
layout = QFormLayout()
layout.setContentsMargins(0,0,0,0)
self.spinBox_cs = QSpinBox()
self.spinBox_cs.setRange(1,3)
self.spinBox_bits = QSpinBox()
self.spinBox_bits.setRange(1,32)
layout.addWidget(QLabel("SPI3 extension port"))
layout.addRow(QLabel("Bits"),self.spinBox_bits)
layout.addWidget(QLabel("Port is used exclusively! CS pins are not usable !"))
self.setLayout(layout)
def onshown(self):
self.get_value_async("bissenc","bits",self.spinBox_bits.setValue,0,int)
def apply(self):
self.send_value("bissenc","bits",val=self.spinBox_bits.value())