Skip to content

Commit

Permalink
Effect stats per axis
Browse files Browse the repository at this point in the history
  • Loading branch information
Ultrawipf committed May 4, 2023
1 parent f831871 commit f07ecf5
Show file tree
Hide file tree
Showing 9 changed files with 265 additions and 148 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
### Changes this version:
- Added percentage to power slider
- Added axis selection for effect monitor (new firmware required)

### Changes in 1.13.x:
- Fixed issue in encoder tuning UI
Expand Down
8 changes: 8 additions & 0 deletions base_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,14 @@ def log(self, message):
class CommunicationHandler:
"""Store the serial communication to share it to subclass and offer register operation."""

CMDFLAG_GET = 0x01
CMDFLAG_SET = 0x02
CMDFLAG_INFOSTRING = 0x08
CMDFLAG_GETADR = 0x10
CMDFLAG_SETADR = 0x20
CMDFLAG_HIDDEN = 0x40
CMDFLAG_DEBUG = 0x80

comms: serial_comms.SerialComms = None

def __init__(self):
Expand Down
31 changes: 26 additions & 5 deletions effects_graph_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ def __init__(self, dlg=None):
self.start_time = 0
self.chart_last_x = 0

self.axis = None
self.spinBox_axis.valueChanged.connect(self.setAxis)

# Chart setup
self.chart = PyQt6.QtCharts.QChart()
self.chart.setBackgroundRoundness(5)
Expand Down Expand Up @@ -112,6 +115,18 @@ def __init__(self, dlg=None):
# Setup the timer to get data
self.timer = PyQt6.QtCore.QTimer(self)
self.timer.timeout.connect(self.update_timer) # pylint: disable=no-value-for-parameter

def reset(self):
# Clear
self.start_time = PyQt6.QtCore.QTime.currentTime()
self.chart_last_x = 0
for i in range(12):
self.lines[i].clear()

def setAxis(self,axis):
# Reset
self.reset()
self.axis = axis

def setEnabled(self, a0: bool) -> None:
if not a0 and self.isVisible() and self.timer.isActive :
Expand All @@ -133,7 +148,7 @@ def hideEvent(self, event): # pylint: disable=invalid-name, unused-argument

def update_timer(self):
"""Call the board to get instant data."""
self.get_value_async("fx", "effectsForces", self.display_data)
self.get_value_async("fx", "effectsForces", self.display_data,adr=self.axis)

def display_data(self, data):
"""Decode the data received."""
Expand All @@ -145,13 +160,16 @@ def display_data(self, data):
self.update_current(forces)
self.update_effect_stats(effects)

def cmdflags(self,flags):
if flags & base_ui.CommunicationHandler.CMDFLAG_GETADR:
# enable axis selection
self.spinBox_axis.setEnabled(True)

def init_ui(self):
"""Init the ui by clear all data in series."""
# clear graph
self.start_time = PyQt6.QtCore.QTime.currentTime()
self.chart_last_x = 0
for i in range(12):
self.lines[i].clear()
self.reset()
self.get_value_async("fx", "cmdinfo", self.cmdflags,adr=17,conversion=int)

def update_effect_stats(self,dat):
self.spinBox_1.setValue(dat[0])
Expand Down Expand Up @@ -204,6 +222,9 @@ def __init__(self, main=None):
self.layout.addWidget(self.graph_ui)
self.setLayout(self.layout)
self.setWindowTitle("Effects graphics")

def set_max_axes(self,axes):
self.graph_ui.spinBox_axis.setMaximum(axes)

def setEnabled(self, a0: bool) -> None: # pylint: disable=invalid-name
"""Enable the UI, or disable it depends on message."""
Expand Down
18 changes: 17 additions & 1 deletion effects_monitor.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ def __init__(self, main=None, parent = None):
self.parent = parent

self.pushButton_ResetData.clicked.connect(self.resetData)
self.spinBox_axis.valueChanged.connect(self.setAxis)

self.timer = QTimer(self)
self.timer.timeout.connect(self.refreshUi)
Expand All @@ -24,6 +25,13 @@ def __init__(self, main=None, parent = None):
self.icon_ok = icon_ok.pixmap(18, 18)
self.icon_ko = icon_ko.pixmap(18, 18)
self.setActiveState_cb(0)
self.axis = None


def cmdflags(self,flags):
if flags & CommunicationHandler.CMDFLAG_GETADR:
# enable axis selection
self.spinBox_axis.setEnabled(True)

def setEnabled(self, a0: bool) -> None:
self.pushButton_ResetData.setEnabled(a0)
Expand All @@ -33,6 +41,8 @@ def setEnabled(self, a0: bool) -> None:

def showEvent(self, a0: QtGui.QShowEvent) -> None:
self.timer.start(1000)
if self.axis == None:
self.get_value_async("fx", "cmdinfo", self.cmdflags,adr=16,conversion=int) # TODO remove in later version
return super().showEvent(a0)

def hideEvent(self, a0) -> None:
Expand All @@ -43,8 +53,11 @@ def hideEvent(self, a0) -> None:
def resetData(self):
self.send_value("fx","effectsDetails",0)

def setAxis(self,axis):
self.axis = axis

def refreshUi(self):
self.get_value_async("fx","effectsDetails",self.decodeData_cb)
self.get_value_async("fx","effectsDetails",self.decodeData_cb,adr=self.axis)
self.get_value_async("fx","effects",self.setActiveState_cb,conversion=int)

def setLabelPixmapState(self,label,state):
Expand Down Expand Up @@ -102,6 +115,9 @@ def __init__(self,main=None):
self.setLayout(self.layout)
self.setWindowTitle("Effects statistics")

def set_max_axes(self,axes):
self.ui.spinBox_axis.setMaximum(axes)

def setEnabled(self, a0: bool) -> None:
self.ui.setEnabled(a0)
if not a0:
Expand Down
17 changes: 9 additions & 8 deletions effects_tuning_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -180,15 +180,12 @@ def load_settings(self):
"spring","damper","friction","inertia",
"filterProfile_id","damper_f","damper_q","friction_f","friction_q","inertia_f","inertia_q"],0)

self.get_value_async("main","id",self.get_main_id,0,int)

def get_main_id(self, id):
"""Setup axis number from main class and start polling metrics on the axis."""
if id == 1:
self.spinBox_axis.setMaximum(0)
elif id == 2:
self.spinBox_axis.setMaximum(1)
# self.get_value_async("main","id",self.get_main_id,0,int)
self.timer.start(100)

def set_max_axes(self, axes):
"""Setup axis number for selection"""
self.spinBox_axis.setMaximum(axes)

def restore_default(self):
self.horizontalSlider_spring_gain.setValue(64)
Expand Down Expand Up @@ -522,3 +519,7 @@ def display(self):
self.show()
self.raise_()
self.activateWindow()

def set_max_axes(self, axes):
"""Setup axis number for selection"""
self.advanced_tweak_ui.set_max_axes(axes)
1 change: 1 addition & 0 deletions ffb_ui.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def __init__(self, main : 'main.MainUi'=None, title = "FFB main"):
self.axisbtns.setExclusive(False)

self.effect_tuning_dlg = effects_tuning_ui.AdvancedFFBTuneDialog(self)
self.main.maxaxischanged.connect(self.effect_tuning_dlg.set_max_axes)

self.horizontalSlider_cffilter.valueChanged.connect(self.cffilter_changed)

Expand Down
8 changes: 8 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
class MainUi(PyQt6.QtWidgets.QMainWindow, base_ui.WidgetUI, base_ui.CommunicationHandler):
"""Display and manage the main UI."""
tabsinitialized = PyQt6.QtCore.pyqtSignal(bool)
maxaxischanged = PyQt6.QtCore.pyqtSignal(int)
def __init__(self):
"""Init the mainUI : init the UI, all the dlg element, and the main timer."""
PyQt6.QtWidgets.QMainWindow.__init__(self)
Expand All @@ -83,7 +84,9 @@ def __init__(self):
self.tabWidget_main.currentChanged.connect(self.tab_changed)
self.errors_dlg = errors.ErrorsDialog(self)
self.effects_monitor_dlg = effects_monitor.EffectsMonitorDialog(self)
self.maxaxischanged.connect(self.effects_monitor_dlg.set_max_axes)
self.effects_graph_dlg = effects_graph_ui.EffectsGraphDialog(self)
self.maxaxischanged.connect(self.effects_graph_dlg.set_max_axes)
self.active_class_dlg = activelist.ActiveClassDialog(self)
self.active_classes = {}
self.fw_version_str = None
Expand All @@ -92,6 +95,7 @@ def __init__(self):

self.process_events_timer = PyQt6.QtCore.QTimer()
self.process_events_timer.timeout.connect(process_events) # Kick eventloop when timeouting
self.axes = 0

def setup(self):
"""Init the systray, the serial, the toolbar, the status bar and the connection status."""
Expand Down Expand Up @@ -334,6 +338,8 @@ def reset_tabs(self):
self.effects_graph_dlg.setEnabled(False)
self.actionEffectsMonitor.setEnabled(False)
self.actionEffects_forces.setEnabled(False)
self.axes = 0
self.maxaxischanged.emit(self.axes)

# Delete signals
for connection in self.tab_connections:
Expand Down Expand Up @@ -390,6 +396,8 @@ def update_tabs_cb(active):
self.active_classes[name] = classe
self.add_tab(classe, name_axis)
self.profile_ui.set_save_btn(True)
self.axes = max(self.axes,classe.axis)
self.maxaxischanged.emit(self.axes)
elif classe_active["id"] == 0x81 or classe_active["id"] == 0x82 or \
classe_active["id"] == 0x83:
classe = tmc4671_ui.TMC4671Ui(main=self, unique=classe_active["unique"])
Expand Down
Loading

0 comments on commit f07ecf5

Please sign in to comment.