Replies: 6 comments 3 replies
-
OK @vortigont, here we go. I have created an experimental branch, that will probably become v2.0.0 once in a good state. The changes are based on your suggestions and example code you shared under your #10 for RTOS message queues.. See it here: https://github.com/rwmingis/InterruptButton/tree/RTOS-message-Queue I've just made a working copy, but still quite messy. Looking at your dot-points above:
|
Beta Was this translation helpful? Give feedback.
-
Hi @rwmingis, for 2) I have my doubts for synch stuff. There are plenty of button libs around having such alike loop() hooks being called every cycle. Yours could be better designed for RTOS, so does it worth the efforts dragging around the complexity of this legacy for just in case? InterruptButton/InterruptButton.cpp Line 386 in 9681dc0 This code is wrong. You can't evaluate pxHigherPriorityTaskWoken before passing to xQueueSend... and it shouldn't be casted to nullptr either, it's a typedef'ed int. You might wanna take a second look to the action() method. If you call it from an ISR, it needs to be placed in IRAM, or reduced to some simpler inlines. |
Beta Was this translation helpful? Give feedback.
-
Hi @rwmingis
You might want to reconsider using static class members in general. Static class members are not class members at all as it may seem. Consider it as globals, those are not associated with any class instance and can't access non-static members, static methods are not polymorphic and it make inheritance and abstraction a real pain. In general static member functions breaks OOP concepts. It might be useful to bind with C system API or libs (like ISR handlers), but implementing your public classes methods as statics usually complicates things more in perspective.
Sorry, I did not get the idea anyway. Suppose you call it from here InterruptButton/InterruptButton.cpp Lines 135 to 136 in 375dd62 pxHigherPriorityTaskWoken will resolve to false and xQueueSendToBack() will be called, which is obviously wrong. |
Beta Was this translation helpful? Give feedback.
-
looks like with a current code you do not need xQueueSendToBackFromISR() and pxHigherPriorityTaskWoken at all, because you never queue on ISR trigger, but only from a timer. Might worth refactoring readButton() into a short ISR function and another for timered calls. |
Beta Was this translation helpful? Give feedback.
-
Swapped out the RTOS queue as you suggested as an option, in lieu of a simplefied array of pointers to the external user functions. Seems to work well. Also managed to reproduce your issue with deleting dynamic buttons. In my case, it doesn't crash (may be different with the new queue in the form of an array of pointers), but now it goes into an infinite loop of calling the 'action()' function. Very strange. So that is still to solve, like you said probably dangling pointers. 👍 |
Beta Was this translation helpful? Give feedback.
-
Hello @rwmingis!
|
Beta Was this translation helpful? Give feedback.
-
Hi @rwmingis,
so, I've rushed a couple of elephants to your china shop :)
Here is an implementation with rtos queue - check this branch. Not making a PR for now, still lot's of dirty code and comments but already works pretty fine.
pros:
cons:
it's just a draft for now. Thinking about some other improvements, i.e. lot's of static methods within the class does not look nice.
Feel free to try this out.
Cheers!
Beta Was this translation helpful? Give feedback.
All reactions