diff --git a/NERODevelopment/content/Configuration.qml b/NERODevelopment/content/Configuration.qml index adc7658..b55f7f6 100644 --- a/NERODevelopment/content/Configuration.qml +++ b/NERODevelopment/content/Configuration.qml @@ -26,6 +26,8 @@ Item { case Qt.Key_Return: configurationController.enterButtonPressed() break + default: + break } } @@ -37,8 +39,8 @@ Item { } onIsFocusedChanged: { + focus = !isFocused focus = isFocused - console.log("setting focus to", isFocused, focus) } ValueText { @@ -58,11 +60,15 @@ Item { KeyboardInput { id: driverKeyboard label: "Enter Driver" - onAccepted: { - configuration.driverText = text + onAccepted: text => { + configuration.driverText = text + configuration.isFocused = false + configuration.isFocused = true + configurationController.setDriverName(text) + configurationController.setIsKeyboardSelected(false) + } + onRejected: { configuration.isFocused = false - configuration.isFocused = true - configurationController.setDriverName(text) configurationController.setIsKeyboardSelected(false) } selected: configuration.isKeyboardSelected @@ -82,11 +88,15 @@ Item { KeyboardInput { label: "Enter Location" - onAccepted: { - configuration.locationText = text + onAccepted: text => { + configuration.locationText = text + configuration.isFocused = false + configuration.isFocused = true + configurationController.setLocationName(text) + configurationController.setIsKeyboardSelected(false) + } + onRejected: { configuration.isFocused = false - configuration.isFocused = true - configurationController.setLocationName(text) configurationController.setIsKeyboardSelected(false) } selected: configuration.isKeyboardSelected @@ -105,11 +115,15 @@ Item { anchors.horizontalCenter: parent.horizontalCenter KeyboardInput { label: "Enter System" - onAccepted: { - configuration.systemText = text + onAccepted: text => { + configuration.systemText = text + configuration.isFocused = false + configuration.isFocused = true + configurationController.setSystemName(text) + configurationController.setIsKeyboardSelected(false) + } + onRejected: { configuration.isFocused = false - configuration.isFocused = true - configurationController.setSystemName(text) configurationController.setIsKeyboardSelected(false) } selected: configuration.isKeyboardSelected diff --git a/NERODevelopment/content/Keyboard.qml b/NERODevelopment/content/Keyboard.qml index f035f06..f040b31 100644 --- a/NERODevelopment/content/Keyboard.qml +++ b/NERODevelopment/content/Keyboard.qml @@ -25,6 +25,7 @@ Item { property double rows: 5 property int selectedIndex: keyboardViewController.selectedIndex property bool isKeySelected: keyboardViewController.selectedKey + property bool exit: keyboardViewController.exit property int numKeys: 44 Keys.onPressed: event => { @@ -44,9 +45,19 @@ Item { case Qt.Key_Return: keyboardViewController.enterButtonPressed() break + case Qt.Key_Escape: + keyboardViewController.homeButtonPressed() + break } } + onExitChanged: { + if (exit) { + rejected() + keyboardViewController.setExit(false) + } + } + MouseArea { anchors.fill: parent } // don't allow touches to pass to MouseAreas underneath @@ -419,7 +430,6 @@ Item { onIsKeySelectedChanged: { if (root.isKeySelected && highlighted) { clicked() - event.accepted = true } } } diff --git a/NERODevelopment/content/KeyboardController.qml b/NERODevelopment/content/KeyboardController.qml index e38a4d9..3821daf 100644 --- a/NERODevelopment/content/KeyboardController.qml +++ b/NERODevelopment/content/KeyboardController.qml @@ -8,6 +8,8 @@ Item { signal accepted(string text) + signal rejected + // onAccepted: print('onAccepted', text) function show() { keyboard = keyboardComponent.createObject(null, { @@ -37,11 +39,14 @@ Item { Connections { target: keyboard - onAccepted: { - root.accepted(text) // emit - keyboard.destroy() // hide - } + onAccepted: text => { + root.accepted(text) // emit + keyboard.destroy() // hide + } - onRejected: keyboard.destroy() // hide + onRejected: { + root.rejected() + keyboard.destroy() + } } } diff --git a/NERODevelopment/content/KeyboardInput.qml b/NERODevelopment/content/KeyboardInput.qml index 15e8fc2..cb394b5 100644 --- a/NERODevelopment/content/KeyboardInput.qml +++ b/NERODevelopment/content/KeyboardInput.qml @@ -11,7 +11,9 @@ Rectangle { property alias text: textInput.text // in/out signal accepted(string text) + // onAccepted: print('onAccepted', text) + signal rejected // private width: 500 @@ -57,9 +59,11 @@ Rectangle { password: root.password - onAccepted: { - textInput.text = text - root.accepted(text) // emit - } + onAccepted: text => { + textInput.text = text + root.accepted(text) // emit + } + + onRejected: root.rejected() } } diff --git a/NERODevelopment/content/NavigationController.qml b/NERODevelopment/content/NavigationController.qml index 089e6b9..58d71da 100644 --- a/NERODevelopment/content/NavigationController.qml +++ b/NERODevelopment/content/NavigationController.qml @@ -4,7 +4,7 @@ import NERO Item { id: navigation anchors.fill: parent - focus: !isSelected + focus: !navigation.isSelected property int selectedPageIndex: navigationController.selectedPageIndex property bool isSelected: navigationController.isSelected diff --git a/NERODevelopment/src/controllers/buttoncontroller.cpp b/NERODevelopment/src/controllers/buttoncontroller.cpp index 0b61c94..68f94b2 100644 --- a/NERODevelopment/src/controllers/buttoncontroller.cpp +++ b/NERODevelopment/src/controllers/buttoncontroller.cpp @@ -18,27 +18,84 @@ void ButtonController::leftButtonPressed() {} void ButtonController::rightButtonPressed() {} -void ButtonController::homeButtonPressed() {} +void ButtonController::homeButtonPressed() { + qDebug() << "Home button pressed button controller"; + this->m_model->currentPageIndex = -1; +} void ButtonController::buttonUpdate() { if (this->m_pageIndex == this->m_model->currentPageIndex) { - if (this->m_model->getBackwardButtonPressed() == 1) { + QDateTime currentDate = QDateTime::currentDateTime(); + // qDebug() << "Button Pressed" + // << this->m_model->getBackwardButtonPressed().value_or(-1) + // << this->m_model->getDownButtonPressed().value_or(-1) + // << this->m_model->getEnterButtonPressed().value_or(-1) + // << this->m_model->getRightButtonPressed().value_or(-1) + // << this->m_model->getUpButtonPressed().value_or(-1) + // << this->m_model->getHomeButtonPressed().value_or(-1) + // << this->m_model->getForwardButtonPressed().value_or(-1) + // << this->m_model->currentPageIndex; + if (this->m_model->getBackwardButtonPressed() == 1 && + currentDate.toMSecsSinceEpoch() - this->m_leftButtonDebounce > + this->m_debounceOffset) { + qDebug() << "Back Button Pressed"; + this->leftButtonPressed(); + this->m_leftButtonDebounce = currentDate.toMSecsSinceEpoch(); } - if (this->m_model->getDownButtonPressed() == 1) { + if (this->m_model->getDownButtonPressed() == 1 && + currentDate.toMSecsSinceEpoch() - this->m_downButtonDebounce > + this->m_debounceOffset) { + qDebug() << "Down Button Pressed"; + this->downButtonPressed(); + this->m_downButtonDebounce = currentDate.toMSecsSinceEpoch(); } - if (this->m_model->getEnterButtonPressed() == 1) { + if (this->m_model->getEnterButtonPressed() == 1 && + currentDate.toMSecsSinceEpoch() - this->m_enterButtonDebounce > + this->m_debounceOffset) { + qDebug() << "Enter Button Pressed"; + this->enterButtonPressed(); + this->m_enterButtonDebounce = currentDate.toMSecsSinceEpoch(); } - if (this->m_model->getRightButtonPressed() == 1) { + if (this->m_model->getRightButtonPressed() == 1 && + currentDate.toMSecsSinceEpoch() - this->m_rightButtonDebounce > + this->m_debounceOffset) { + qDebug() << "Right Button Pressed"; + this->rightButtonPressed(); + this->m_rightButtonDebounce = currentDate.toMSecsSinceEpoch(); } - if (this->m_model->getDownButtonPressed() == 1) { + if (this->m_model->getDownButtonPressed() == 1 && + currentDate.toMSecsSinceEpoch() - this->m_downButtonDebounce > + this->m_debounceOffset) { + qDebug() << "Down Button Pressed"; this->downButtonPressed(); + this->m_downButtonDebounce = currentDate.toMSecsSinceEpoch(); + } + + if (this->m_model->getUpButtonPressed() == 1 && + currentDate.toMSecsSinceEpoch() - this->m_upButtonDebounce > + this->m_debounceOffset) { + qDebug() << "Up button pressed"; + this->upButtonPressed(); + this->m_upButtonDebounce = currentDate.toMSecsSinceEpoch(); + } + if (this->m_model->getForwardButtonPressed() == 1 && + currentDate.toMSecsSinceEpoch() - this->m_rightButtonDebounce > + this->m_debounceOffset) { + + qDebug() << "Forward button pressed"; + this->rightButtonPressed(); + this->m_rightButtonDebounce = currentDate.toMSecsSinceEpoch(); } - if (this->m_model->getHomeButtonPressed() == 1) { + if (this->m_model->getHomeButtonPressed() == 1 && + currentDate.toMSecsSinceEpoch() - this->m_homeButtonDebounce > + this->m_debounceOffset) { + qDebug() << "Home button pressed"; this->homeButtonPressed(); + this->m_homeButtonDebounce = currentDate.toMSecsSinceEpoch(); } } } diff --git a/NERODevelopment/src/controllers/buttoncontroller.h b/NERODevelopment/src/controllers/buttoncontroller.h index 840b866..7286afc 100644 --- a/NERODevelopment/src/controllers/buttoncontroller.h +++ b/NERODevelopment/src/controllers/buttoncontroller.h @@ -11,7 +11,7 @@ class ButtonController : public QObject { QObject *parent = nullptr); public slots: - void buttonUpdate(); + virtual void buttonUpdate(); virtual void enterButtonPressed(); virtual void upButtonPressed(); @@ -23,6 +23,13 @@ public slots: protected: Model *m_model; int m_pageIndex; + qint64 m_enterButtonDebounce = 0; + qint64 m_upButtonDebounce = 0; + qint64 m_downButtonDebounce = 0; + qint64 m_rightButtonDebounce = 0; + qint64 m_leftButtonDebounce = 0; + qint64 m_homeButtonDebounce = 0; + int m_debounceOffset = 500; }; #endif // BUTTONCONTROLLER_H diff --git a/NERODevelopment/src/controllers/configurationcontroller.cpp b/NERODevelopment/src/controllers/configurationcontroller.cpp index 6a786c2..808c9e8 100644 --- a/NERODevelopment/src/controllers/configurationcontroller.cpp +++ b/NERODevelopment/src/controllers/configurationcontroller.cpp @@ -17,10 +17,8 @@ bool ConfigurationController::isKeyboardSelected() const { return this->m_isKeyboardSelected; } void ConfigurationController::setIsKeyboardSelected(bool selected) { - if (this->m_isKeyboardSelected != selected) { - this->m_isKeyboardSelected = selected; - emit this->isKeyboardSelectedChanged(); - } + this->m_isKeyboardSelected = selected; + emit this->isKeyboardSelectedChanged(); } void ConfigurationController::setDriverName(QString driverName) { @@ -56,11 +54,19 @@ void ConfigurationController::upButtonPressed() { } void ConfigurationController::enterButtonPressed() { - if (this->m_selectedConfigurationIndex == 3) { - this->m_model->sendMessage("driver", this->m_driverName); - this->m_model->sendMessage("system", this->m_systemName); - this->m_model->sendMessage("location", this->m_locationName); - } else { - this->setIsKeyboardSelected(!this->m_isKeyboardSelected); + if (!this->m_isKeyboardSelected) { + if (this->m_selectedConfigurationIndex == 3) { + this->m_model->sendMessage("driver", this->m_driverName); + this->m_model->sendMessage("system", this->m_systemName); + this->m_model->sendMessage("location", this->m_locationName); + } else { + this->setIsKeyboardSelected(true); + } + } +} + +void ConfigurationController::homeButtonPressed() { + if (!this->m_isKeyboardSelected) { + this->m_model->currentPageIndex = -1; } } diff --git a/NERODevelopment/src/controllers/configurationcontroller.h b/NERODevelopment/src/controllers/configurationcontroller.h index 61f8103..dac70a8 100644 --- a/NERODevelopment/src/controllers/configurationcontroller.h +++ b/NERODevelopment/src/controllers/configurationcontroller.h @@ -30,6 +30,7 @@ public slots: void downButtonPressed() override; void upButtonPressed() override; void enterButtonPressed() override; + void homeButtonPressed() override; private: int m_selectedConfigurationIndex = 0; diff --git a/NERODevelopment/src/controllers/flappybirdcontroller.cpp b/NERODevelopment/src/controllers/flappybirdcontroller.cpp index 1ca43be..7a718ad 100644 --- a/NERODevelopment/src/controllers/flappybirdcontroller.cpp +++ b/NERODevelopment/src/controllers/flappybirdcontroller.cpp @@ -1,7 +1,9 @@ #include "flappybirdcontroller.h" FlappyBirdController::FlappyBirdController(Model *model, QObject *parent) - : ButtonController{model, 4, parent} {} + : ButtonController{model, 4, parent} { + this->m_debounceOffset = 150; +} bool FlappyBirdController::didJump() const { return m_didJump; } void FlappyBirdController::setDidJump(bool didJump) { diff --git a/NERODevelopment/src/controllers/keyboardcontroller.cpp b/NERODevelopment/src/controllers/keyboardcontroller.cpp index 4420b5e..0b7fd9c 100644 --- a/NERODevelopment/src/controllers/keyboardcontroller.cpp +++ b/NERODevelopment/src/controllers/keyboardcontroller.cpp @@ -22,11 +22,15 @@ void KeyboardController::setSelectedKey(bool selected) { } void KeyboardController::downButtonPressed() { + qDebug() << "down Button Pressed Keyboard"; + this->setSelectedIndex( std::min(this->m_numKeys - 1, this->m_selectedIndex + this->m_columns)); } void KeyboardController::upButtonPressed() { + qDebug() << "up Button Pressed Keyboard"; + this->setSelectedIndex(std::max(0, this->m_selectedIndex - this->m_columns)); } @@ -39,6 +43,18 @@ void KeyboardController::rightButtonPressed() { std::min(this->m_numKeys - 1, this->m_selectedIndex + 1)); } +void KeyboardController::setExit(bool exit) { + this->m_exit = exit; + emit exitChanged(); +} +bool KeyboardController::exit() const { return this->m_exit; } + +void KeyboardController::homeButtonPressed() { + qDebug() << "Home Button Pressed Keyboard"; + this->setExit(true); + this->m_model->currentPageIndex = -1; +} + void KeyboardController::enterButtonPressed() { this->setSelectedKey(true); this->setSelectedKey(false); diff --git a/NERODevelopment/src/controllers/keyboardcontroller.h b/NERODevelopment/src/controllers/keyboardcontroller.h index a10fe5b..d5965c9 100644 --- a/NERODevelopment/src/controllers/keyboardcontroller.h +++ b/NERODevelopment/src/controllers/keyboardcontroller.h @@ -9,31 +9,37 @@ class KeyboardController : public ButtonController { selectedIndexChanged FINAL) Q_PROPERTY(bool selectedKey READ selectedKey WRITE setSelectedKey NOTIFY selectedKeyChanged FINAL) + Q_PROPERTY(bool exit READ exit WRITE setExit NOTIFY exitChanged FINAL) public: explicit KeyboardController(Model *model, QObject *parent = nullptr); int selectedIndex() const; bool selectedKey() const; + bool exit() const; signals: void selectedIndexChanged(); void selectedKeyChanged(); + void exitChanged(); public slots: void setSelectedIndex(int); void setSelectedKey(bool); + void setExit(bool); void downButtonPressed() override; void upButtonPressed() override; void leftButtonPressed() override; void rightButtonPressed() override; void enterButtonPressed() override; + void homeButtonPressed() override; private: int m_selectedIndex = 0; bool m_selectedKey = false; int m_numKeys = 45; int m_columns = 10; + bool m_exit = false; }; #endif // KEYBOARDCONTROLLER_H diff --git a/NERODevelopment/src/controllers/navigationcontroller.cpp b/NERODevelopment/src/controllers/navigationcontroller.cpp index 1b2a90e..d36596b 100644 --- a/NERODevelopment/src/controllers/navigationcontroller.cpp +++ b/NERODevelopment/src/controllers/navigationcontroller.cpp @@ -16,9 +16,9 @@ void NavigationController::setSelectedPageIndex(int index) { bool NavigationController::isSelected() const { return this->m_isSelected; } void NavigationController::setIsSelected(bool isSelected) { if (isSelected != this->m_isSelected) { - qDebug() << "Setting isSelected to " << isSelected << " from " - << this->m_isSelected - << " in NavigationController::setIsSelected(bool isSelected)"; + // qDebug() << "Setting isSelected to " << isSelected << " from " + // << this->m_isSelected + // << " in NavigationController::setIsSelected(bool isSelected)"; this->m_isSelected = isSelected; emit this->isSelectedChanged(); } @@ -48,3 +48,25 @@ void NavigationController::homeButtonPressed() { this->m_model->currentPageIndex = -1; this->setIsSelected(false); } + +void NavigationController::buttonUpdate() { + if (this->m_model->currentPageIndex == this->m_pageIndex) { + std::optional modeIndex = this->m_model->getModeIndex(); + if (modeIndex) { + this->setSelectedPageIndex(*modeIndex); + } + + std::optional homeButtonPressed = + this->m_model->getHomeButtonPressed(); + + if (homeButtonPressed) { + if (homeButtonPressed == 0) { + this->enterButtonPressed(); + } else { + this->homeButtonPressed(); + } + } else { + this->homeButtonPressed(); + } + } +} diff --git a/NERODevelopment/src/controllers/navigationcontroller.h b/NERODevelopment/src/controllers/navigationcontroller.h index 5ea28ab..a8f9ce1 100644 --- a/NERODevelopment/src/controllers/navigationcontroller.h +++ b/NERODevelopment/src/controllers/navigationcontroller.h @@ -28,6 +28,7 @@ public slots: void downButtonPressed() override; void upButtonPressed() override; void homeButtonPressed() override; + void buttonUpdate() override; private: bool m_isSelected = false; diff --git a/NERODevelopment/src/models/mock_model.cpp b/NERODevelopment/src/models/mock_model.cpp index 0c86347..5d78d38 100644 --- a/NERODevelopment/src/models/mock_model.cpp +++ b/NERODevelopment/src/models/mock_model.cpp @@ -227,7 +227,7 @@ std::optional MockModel::getBmsFault() { return bmsFaults; } std::optional MockModel::getMpuFault() { return mpuFaults; } -std::optional MockModel::getModeIndex() { return modeIndex; } +std::optional MockModel::getModeIndex() { return std::nullopt; } std::optional MockModel::getMaxCellVoltage() { return round(maxCellVoltage * 10) / 10; @@ -347,7 +347,7 @@ std::optional MockModel::getBackwardButtonPressed() { return 0; } std::optional MockModel::getRightButtonPressed() { return 0; } -std::optional MockModel::getHomeButtonPressed() { return 0; } +std::optional MockModel::getHomeButtonPressed() { return std::nullopt; } std::optional MockModel::getIsTalking() { return true; } diff --git a/NERODevelopment/src/models/raspberry_model.cpp b/NERODevelopment/src/models/raspberry_model.cpp index d05cb56..47b355f 100644 --- a/NERODevelopment/src/models/raspberry_model.cpp +++ b/NERODevelopment/src/models/raspberry_model.cpp @@ -32,6 +32,7 @@ void RaspberryModel::sendMessage(const QString topic, const QString message) { void RaspberryModel::receiveServerData(const serverdata::ServerData data, const QString topic) { + // qDebug() << "Topic: " << topic << "Data" << data.values(); this->currentData[topic] = DataInfo(topic, data.unit(), data.values()); emit this->onCurrentDataChange(); } @@ -243,9 +244,10 @@ std::optional RaspberryModel::getBmsFault() { std::optional RaspberryModel::getForwardButtonPressed() { std::optional value = this->getById(FORWARDBUTTON); + if (value) { std::string binary = std::bitset<8>(static_cast(*value)).to_string(); - return binary.length() >= 7 ? binary[6] : false; + return binary.length() >= 3 ? binary[2] == '1' : false; } return std::nullopt; } @@ -254,7 +256,7 @@ std::optional RaspberryModel::getBackwardButtonPressed() { std::optional value = this->getById(BACKWARDBUTTON); if (value) { std::string binary = std::bitset<8>(static_cast(*value)).to_string(); - return binary.length() >= 8 ? binary[7] == 1 : false; + return binary.length() >= 8 ? binary[7] == '1' : false; } return std::nullopt; } @@ -263,7 +265,7 @@ std::optional RaspberryModel::getRightButtonPressed() { std::optional value = this->getById(RIGHTBUTTON); if (value) { std::string binary = std::bitset<8>(static_cast(*value)).to_string(); - return binary.length() >= 2 ? binary[1] == 1 : false; + return binary.length() >= 1 ? binary[0] == '1' : false; } return std::nullopt; } @@ -272,7 +274,7 @@ std::optional RaspberryModel::getEnterButtonPressed() { std::optional value = this->getById(ENTERBUTTON); if (value) { std::string binary = std::bitset<8>(static_cast(*value)).to_string(); - return binary[0] == 1; + return binary.length() >= 4 ? binary[3] == '1' : false; } return std::nullopt; } @@ -281,7 +283,7 @@ std::optional RaspberryModel::getUpButtonPressed() { std::optional value = this->getById(UPBUTTON); if (value) { std::string binary = std::bitset<8>(static_cast(*value)).to_string(); - return binary.length() >= 6 ? binary[5] == 1 : false; + return binary.length() >= 7 ? binary[6] == '1' : false; } return std::nullopt; } @@ -290,16 +292,21 @@ std::optional RaspberryModel::getDownButtonPressed() { std::optional value = this->getById(DOWNBUTTON); if (value) { std::string binary = std::bitset<8>(static_cast(*value)).to_string(); - return binary.length() >= 5 ? binary[4] == 1 : false; + return binary.length() >= 6 ? binary[5] == '1' : false; } return std::nullopt; } std::optional RaspberryModel::getHomeButtonPressed() { std::optional value = this->getById(HOMEBUTTON); + // if (value) { + // std::string binary = + // std::bitset<8>(static_cast(*value)).to_string(); return + // binary.length() >= 5 ? binary[4] == '1' : false; + // } + // return std::nullopt; if (value) { - std::string binary = std::bitset<8>(static_cast(*value)).to_string(); - return binary.length() >= 1 ? binary[1] == 1 : false; + return *value == 1; } return std::nullopt; } diff --git a/NERODevelopment/src/utils/data_type_names.h b/NERODevelopment/src/utils/data_type_names.h index 903b7fc..74b88aa 100644 --- a/NERODevelopment/src/utils/data_type_names.h +++ b/NERODevelopment/src/utils/data_type_names.h @@ -37,14 +37,14 @@ #define MPUFAULT "mpufault" #define DCL "dcl" #define CCL "ccl" -#define FORWARDBUTTON "forwardbutton" -#define BACKWARDBUTTON "backwardbutton" -#define RIGHTBUTTON "rightbutton" -#define ENTERBUTTON "rightbutton" -#define UPBUTTON "upbutton" -#define DOWNBUTTON "downbutton" -#define HOMEBUTTON "homebutton" -#define MODEINDEX "modeindex" +#define FORWARDBUTTON "WHEEL/Buttons/1" +#define BACKWARDBUTTON "WHEEL/Buttons/1" +#define RIGHTBUTTON "WHEEL/Buttons/1" +#define ENTERBUTTON "WHEEL/Buttons/1" +#define UPBUTTON "WHEEL/Buttons/1" +#define DOWNBUTTON "WHEEL/Buttons/1" +#define HOMEBUTTON "MPU/State/Mode" +#define MODEINDEX "MPU/State/ModeIndex" #define GFORCEX "gforcex" #define GFORCEY "gforcey" #define GFORCEZ "gforcez"