Skip to content

Commit

Permalink
Button controller debugging (#93)
Browse files Browse the repository at this point in the history
* Debug Button Pressing

* Add Home Button Pressing

* Set Topic Names

* Debug Wheel Output

* Debug Incoming Messages

* Move Debugs

* Check Binary String

* Another Debug Statement

* Another debug

* Actually Call Function

* Add Back Debug Statement

* Check for Characters

* WORK

* Add Debounce

* Remove Debug Statements

* Switch Around Numbers

* debug binary string

* Debug Statements

* Reverse Buttons

* remove debug

* Use Longs

* use actual epoch time

* Long long

* Lower debounce for flappy bird

* Slightly increase flappy bird debounce

* Make Slave to MPU for Menu Screen

* Virtualize buttonUpdate

* Change Data type names

* Render Home Button Press

* Validated MPU Control

* Fix Mock Model and Configuration Keyboard not exiting

* Check For Home Button Presses in Subviews

* Debugging Home Button When On Keyboard

* More Debug Statements

* Add Debug to button controller home

* Ignore Home Button From Configuration when Keyboard is Selected
  • Loading branch information
Peyton-McKee authored Apr 3, 2024
1 parent fe356a8 commit badba62
Show file tree
Hide file tree
Showing 17 changed files with 222 additions and 64 deletions.
40 changes: 27 additions & 13 deletions NERODevelopment/content/Configuration.qml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ Item {
case Qt.Key_Return:
configurationController.enterButtonPressed()
break
default:
break
}
}

Expand All @@ -37,8 +39,8 @@ Item {
}

onIsFocusedChanged: {
focus = !isFocused
focus = isFocused
console.log("setting focus to", isFocused, focus)
}

ValueText {
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
12 changes: 11 additions & 1 deletion NERODevelopment/content/Keyboard.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand All @@ -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
Expand Down Expand Up @@ -419,7 +430,6 @@ Item {
onIsKeySelectedChanged: {
if (root.isKeySelected && highlighted) {
clicked()
event.accepted = true
}
}
}
Expand Down
15 changes: 10 additions & 5 deletions NERODevelopment/content/KeyboardController.qml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ Item {

signal accepted(string text)

signal rejected

// onAccepted: print('onAccepted', text)
function show() {
keyboard = keyboardComponent.createObject(null, {
Expand Down Expand Up @@ -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()
}
}
}
12 changes: 8 additions & 4 deletions NERODevelopment/content/KeyboardInput.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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()
}
}
2 changes: 1 addition & 1 deletion NERODevelopment/content/NavigationController.qml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
71 changes: 64 additions & 7 deletions NERODevelopment/src/controllers/buttoncontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
}
}
9 changes: 8 additions & 1 deletion NERODevelopment/src/controllers/buttoncontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class ButtonController : public QObject {
QObject *parent = nullptr);

public slots:
void buttonUpdate();
virtual void buttonUpdate();

virtual void enterButtonPressed();
virtual void upButtonPressed();
Expand All @@ -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
26 changes: 16 additions & 10 deletions NERODevelopment/src/controllers/configurationcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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;
}
}
1 change: 1 addition & 0 deletions NERODevelopment/src/controllers/configurationcontroller.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ public slots:
void downButtonPressed() override;
void upButtonPressed() override;
void enterButtonPressed() override;
void homeButtonPressed() override;

private:
int m_selectedConfigurationIndex = 0;
Expand Down
4 changes: 3 additions & 1 deletion NERODevelopment/src/controllers/flappybirdcontroller.cpp
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down
16 changes: 16 additions & 0 deletions NERODevelopment/src/controllers/keyboardcontroller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}

Expand All @@ -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);
Expand Down
Loading

0 comments on commit badba62

Please sign in to comment.