Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Need help modifying code for NFC coffee detection window. #9

Open
sergey-gra opened this issue Mar 4, 2023 · 10 comments
Open

Need help modifying code for NFC coffee detection window. #9

sergey-gra opened this issue Mar 4, 2023 · 10 comments
Labels
question Further information is requested

Comments

@sergey-gra
Copy link

sergey-gra commented Mar 4, 2023

I intend to modify the source codebase to include the opening of the NFC detection window every time a coffee request is made. I would appreciate it if you could provide me with instructions on the specific part of the codebase where these modifications should be made. Based on my understanding, it seems likely that the changes will need to be made within the CoffeeSelectionWidget.cpp file on_coffee_button_clicked() function, but I am open to any guidance or recommendations you may have. Thanks in advance.

@COM8 COM8 added the question Further information is requested label Mar 5, 2023
@COM8
Copy link
Member

COM8 commented Mar 5, 2023

You need to call MainWindow::show_nfc_card_detection();.
https://github.com/Jutta-Proto/gtk-ui/blob/d53f559c85e3346bf5d3142ff988deb408027772/src/ui/windows/MainWindow.hpp#L55

I would go into CoffeeSelectionWidget.{cpp, hpp}. There look at how edit_custom_coffee_clicked is implemented via signals. I would create a new signal that triggers once a beverage has been made.

Then go into MainWindow.{cpp, hpp} and subscribe to it, like it's done with the edit_custom_coffee_clicked signal. There than trigger MainWindow::show_nfc_card_detection();.

@sergey-gra
Copy link
Author

Expressing gratitude for your valuable suggestion @COM8 , I will endeavor to incorporate it and subsequently provide you with an update on its implementation.

@sergey-gra
Copy link
Author

sergey-gra commented Mar 5, 2023

You need to call MainWindow::show_nfc_card_detection();. https://github.com/Jutta-Proto/gtk-ui/blob/d53f559c85e3346bf5d3142ff988deb408027772/src/ui/windows/MainWindow.hpp#L55

I would go into CoffeeSelectionWidget.{cpp, hpp}. There look at how edit_custom_coffee_clicked is implemented via signals. I would create a new signal that triggers once a beverage has been made.

Then go into MainWindow.{cpp, hpp} and subscribe to it, like it's done with the edit_custom_coffee_clicked signal. There than trigger MainWindow::show_nfc_card_detection();.

Is it possible in this way to retrieve the status of an NFC reader to determine if a user has attached their card, prior to initiating a product request on a coffee machine? Specifically, the desired behavior is to restrict product requests until the user's card has been detected by the NFC reader. Although modifications were made to enable the NFC reader window to appear when a product is selected, the system is still initiating the UUID call for the product request without waiting for the card to be detected. Upon attaching an NFC card, the system is displaying the NFC card window again. This issue may be due to a my lack of familiarity with GTK 😃

@COM8
Copy link
Member

COM8 commented Mar 6, 2023

The NFC card reader flow is as follows:

  1. User places its card on the reader.
  2. The reader reads the card and sends the number as simple keyboard input to the application.
  3. The application catches any keyboard input.
  4. If there are more than 8 chars as input in less than one second, the backend registers it as a NFC-card input. Code: https://github.com/Jutta-Proto/gtk-ui/blob/bt/src/backend/NfcCardReader.cpp#L83

What you probably want is to lock the coffee maker in between, so the user can not make beverages either via the screen, or by pressing a button on the coffee maker it self.

Take a look at CoffeeMaker::lock() and CoffeeMaker::unlock() defined here:

/**
* Locks the coffee maker screen and disables all button input until unlock() is called.
**/
void lock();
/**
* Unlocks the coffee maker screen again after you have locked it with lock().
**/
void unlock();

I hope this helps since I did not totally understand what your issue is.

@sergey-gra
Copy link
Author

sergey-gra commented Mar 6, 2023

I appreciate your time and prompt response. Please accept my apologies if the description of my problem or issue was difficult to understand.
The desired functionality includes the following steps:

  1. User selects a drink.
  2. A NFC card window is displayed.
  3. The user either attaches an NFC card or clicks on a "continue" button.
  4. The product making process is initiated only after the NFC card is attached or the "continue" button is clicked.

I hope that I have provided a clear and comprehensive understanding of the matter at hand.

@COM8
Copy link
Member

COM8 commented Mar 6, 2023

Aha! Now it makes sense. I will try to reply tomorrow once I'm back from work again.

@sergey-gra
Copy link
Author

sergey-gra commented Mar 6, 2023

Great, I look forward to hearing back from you tomorrow. Have a productive day!

@COM8
Copy link
Member

COM8 commented Mar 7, 2023

OK here is how I would do it:

  1. Remove all existing occurrences (calls) of show_nfc_card_detection(); inside MainWindow.cpp
  2. Create a new event inside CoffeeSelectionWidget.{cpp, hpp} that forwards call to on_coffee_button_clicked();
  3. Remove the call coffeeMaker->request_coffee(product); inside on_coffee_button_clicked(); since we first want to authenticate.
  4. Inside MainWindow.cpp subscribe to the newly created event inside for example prep_widget();
  5. Cache the requested product for example as a member inside MainWindow.cpp.
  6. From inside the event handler call show_nfc_card_detection();
  7. Inside on_nfc_card_detected(...); (MainWindow.cpp) call coffeeMaker->request_coffee(product); with the before cached product.
  8. 🎉

Hope this rough sketch helps you.

@sergey-gra
Copy link
Author

sergey-gra commented Mar 7, 2023

I sincerely appreciate your explanation and your time. I now have a clear understanding. Thank you very much for your assistance. I'll try to implement it.

@sergey-gra
Copy link
Author

sergey-gra commented Mar 8, 2023

I have successfully implemented the steps you specified. However, I have encountered a minor issue whereby the NFC detection window is hiden when I attach the card to the NFC reader, and subsequently reappears. It appears that the on_coffee_button_clicked() function is being invoked again as a result.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants