Skip to content

Commit

Permalink
feat: added configMode toggle to ControlPadManager class
Browse files Browse the repository at this point in the history
  • Loading branch information
neilmunday committed Sep 30, 2023
1 parent 42dd1f8 commit 279395a
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 25 deletions.
16 changes: 16 additions & 0 deletions src/pes/controlpad.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ class ControlPadManager(QObject):
totalChangedEvent = pyqtSignal(int, arguments=['total'])
__listener = ControlPadListener() # shared instance
__controlPads = {} # shared dictionary of connected control pads
__configMode = False

def __init__(self, parent=None):
super().__init__(parent)
Expand Down Expand Up @@ -296,6 +297,21 @@ def __fireTotalChangedEvent(self, total: int):
logging.debug("ControlPadManager.__fireTotalChangedEvent: %d", total)
self.totalChangedEvent.emit(total)

@pyqtProperty(bool)
def configMode(self) -> bool:
"""
Return's True if config mode has been enabled, False otherwise.
"""
return ControlPadManager.__configMode

@configMode.setter
def configMode(self, mode: bool):
"""
Set the config mode to True or False.
"""
ControlPadManager.__configMode = mode
logging.debug("ControlPadManager.configMode = %s", mode)

@pyqtSlot(result=list)
def getControlPads(self) -> list:
"""
Expand Down
54 changes: 29 additions & 25 deletions src/pes/qml/main.qml
Original file line number Diff line number Diff line change
Expand Up @@ -57,35 +57,39 @@ ApplicationWindow {

onAxisEvent: {
const positive = value > 0
switch(axis) {
case ControlPad.LeftX: {
if (positive) {
keyboardEmitter.keyPress(Qt.Key_Right)
}
else {
keyboardEmitter.keyPress(Qt.Key_Left)
}
}; break
case ControlPad.LeftY: {
if (positive) {
keyboardEmitter.keyPress(Qt.Key_Down)
}
else {
keyboardEmitter.keyPress(Qt.Key_Up)
}
}; break
if (!controlPadManager.configMode) {
switch(axis) {
case ControlPad.LeftX: {
if (positive) {
keyboardEmitter.keyPress(Qt.Key_Right)
}
else {
keyboardEmitter.keyPress(Qt.Key_Left)
}
}; break
case ControlPad.LeftY: {
if (positive) {
keyboardEmitter.keyPress(Qt.Key_Down)
}
else {
keyboardEmitter.keyPress(Qt.Key_Up)
}
}; break
}
}
}

onButtonEvent: {
switch(button) {
case ControlPad.AButton: keyboardEmitter.keyPress(Qt.Key_Backspace); break;
case ControlPad.BButton: keyboardEmitter.keyPress(Qt.Key_Return); break;
case ControlPad.DownButton: keyboardEmitter.keyPress(Qt.Key_Down); break;
case ControlPad.GuideButton: PES.goHome(); break;
case ControlPad.LeftButton: keyboardEmitter.keyPress(Qt.Key_Left); break;
case ControlPad.RightButton: keyboardEmitter.keyPress(Qt.Key_Right); break;
case ControlPad.UpButton: keyboardEmitter.keyPress(Qt.Key_Up); break;
if (!controlPadManager.configMode) {
switch(button) {
case ControlPad.AButton: keyboardEmitter.keyPress(Qt.Key_Backspace); break;
case ControlPad.BButton: keyboardEmitter.keyPress(Qt.Key_Return); break;
case ControlPad.DownButton: keyboardEmitter.keyPress(Qt.Key_Down); break;
case ControlPad.GuideButton: PES.goHome(); break;
case ControlPad.LeftButton: keyboardEmitter.keyPress(Qt.Key_Left); break;
case ControlPad.RightButton: keyboardEmitter.keyPress(Qt.Key_Right); break;
case ControlPad.UpButton: keyboardEmitter.keyPress(Qt.Key_Up); break;
}
}
}
}
Expand Down

0 comments on commit 279395a

Please sign in to comment.