forked from Ultrawipf/OpenFFBoard-configurator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
system_ui.py
82 lines (69 loc) · 2.78 KB
/
system_ui.py
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
from PyQt5.QtWidgets import QMainWindow
from PyQt5.QtWidgets import QDialog
from PyQt5.QtWidgets import QWidget
from PyQt5.QtWidgets import QMessageBox
from PyQt5 import uic
from helper import res_path,classlistToIds
from PyQt5.QtCore import QTimer
from base_ui import WidgetUI
class SystemUI(WidgetUI):
classes = []
classIds = {}
mainID = None
def __init__(self, main=None):
WidgetUI.__init__(self, main,'baseclass.ui')
self.setEnabled(False)
self.pushButton_ok.clicked.connect(self.mainBtn)
self.pushButton_reboot.clicked.connect(self.reboot)
self.pushButton_dfu.clicked.connect(self.dfu)
self.pushButton_reset.clicked.connect(self.factoryResetBtn)
def serialConnected(self,connected):
if(connected):
self.getMainClasses()
else:
self.setEnabled(False)
def mainBtn(self):
id = self.classes[self.comboBox_main.currentIndex()][0]
self.main.comms.serialWrite("main="+str(id)+"\n")
self.main.resetPort()
msg = QMessageBox(QMessageBox.Information,"Main class changed","Please reconnect.\n Depending on the main class the serial port may have changed.")
msg.exec_()
def reboot(self):
self.main.comms.serialWrite("reboot\n")
self.main.reconnect()
def dfu(self):
self.main.comms.serialWrite("dfu\n")
self.main.resetPort()
msg = QMessageBox(QMessageBox.Information,"DFU","Switched to DFU mode.\nConnect with DFU programmer")
msg.exec_()
def factoryReset(self, btn):
cmd = btn.text()
if(cmd=="OK"):
self.main.comms.serialWrite("format=1\n")
self.main.comms.serialWrite("reboot\n")
self.main.resetPort()
def factoryResetBtn(self):
msg = QMessageBox()
msg.setIcon(QMessageBox.Warning)
msg.setText("Format flash and reset?")
msg.setStandardButtons(QMessageBox.Ok | QMessageBox.Cancel)
msg.buttonClicked.connect(self.factoryReset)
msg.exec_()
def getMainClasses(self):
def updateMains(dat):
self.comboBox_main.clear()
self.classIds,self.classes = classlistToIds(dat)
if(self.mainID == None):
#self.main.resetPort()
self.setEnabled(False)
return
self.setEnabled(True)
for c in self.classes:
self.comboBox_main.addItem(c[1])
self.comboBox_main.setCurrentIndex(self.classIds[self.mainID][0])
self.main.log("Detected mode: "+self.comboBox_main.currentText())
self.main.updateTabs()
def f(i):
self.mainID = i
self.main.comms.serialGetAsync("id?",f,int)
self.main.comms.serialGetAsync("lsmain",updateMains)