protocol-bt-cpp
protocol-bt-cpp copied to clipboard
Need help modifying code for NFC coffee detection window.
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.
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();.
Expressing gratitude for your valuable suggestion @COM8 , I will endeavor to incorporate it and subsequently provide you with an update on its implementation.
You need to call
MainWindow::show_nfc_card_detection();. https://github.com/Jutta-Proto/gtk-ui/blob/d53f559c85e3346bf5d3142ff988deb408027772/src/ui/windows/MainWindow.hpp#L55I would go into
CoffeeSelectionWidget.{cpp, hpp}. There look at howedit_custom_coffee_clickedis 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 theedit_custom_coffee_clickedsignal. There than triggerMainWindow::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 :smiley:
The NFC card reader flow is as follows:
- User places its card on the reader.
- The reader reads the card and sends the number as simple keyboard input to the application.
- The application catches any keyboard input.
- 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: https://github.com/Jutta-Proto/protocol-bt-cpp/blob/e7876b814fb140cc5312165ceedc00f5df3b9777/src/include/jutta_bt_proto/CoffeeMaker.hpp#L175-L182
I hope this helps since I did not totally understand what your issue is.
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:
- User selects a drink.
- A NFC card window is displayed.
- The user either attaches an NFC card or clicks on a "continue" button.
- 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.
Aha! Now it makes sense. I will try to reply tomorrow once I'm back from work again.
Great, I look forward to hearing back from you tomorrow. Have a productive day!
OK here is how I would do it:
- Remove all existing occurrences (calls) of
show_nfc_card_detection();insideMainWindow.cpp - Create a new event inside
CoffeeSelectionWidget.{cpp, hpp}that forwards call toon_coffee_button_clicked(); - Remove the call
coffeeMaker->request_coffee(product);insideon_coffee_button_clicked();since we first want to authenticate. - Inside
MainWindow.cppsubscribe to the newly created event inside for exampleprep_widget(); - Cache the requested product for example as a member inside
MainWindow.cpp. - From inside the event handler call
show_nfc_card_detection(); - Inside
on_nfc_card_detected(...);(MainWindow.cpp) callcoffeeMaker->request_coffee(product);with the before cached product. - 🎉
Hope this rough sketch helps you.
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.
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.