Javert
Member level 2
I have such a philosophical programming question.
I have a project in which the STM32 controls a pair of air valves according to a prepared program or according to how the operator presses the controls on the panel (rather for condition and functionality testing, not normal operation).
The first version was simple when the user pressed a button so the edge triggered an extit and a flag was set in the interrupt handler (button pressed).
In the main program (infinite loop) the flag was checked at each pass and if it was set some command was executed (for example the valve was opened for 100ms)
Now two things have happened
1. I had to add the emWIN library to the project and with it the RTOS, (I chose FreeRTOS)
Yes, so far I have only added our infinite loop to a single system task
2. For one button I need to
- if pressed briefly to function as before
- if pressed for a long time to turn the selected valve on permanently
Now I'm thinking about how to do it and I can't decide which solution to choose.
Which is the best in the future
My ideas
- Add a loop to the interrupt handler, which will be executed as long as the button is pressed, and then return the short or long press flag, depending on the number of passes.
- In the interrupt handler, at the rising edge, note the time (How best to mark the time?) or start the timer. In the interrupt handler, at the falling edge, read the times or stop the counter and set the short or long press flag depending on the time
- somehow use FreeRTOS, whether you use software OStimer or front operation of control buttons to move to a separate task. I don't know I have no experience with that
What is the solution that will be the most suitable for the future? For example, when the complexity of control or the complexity of the program increases again-
I really don't even know how long to choose the time to distinguish between short and long presses? Just 1 second or 1.5, 2, 3 ..? when will it still be interchangeable and when will it bother the operator?
I would welcome both my own obedience and a link to a sample example with the solution of operating the buttons, for example in FreeRTOS
I have a project in which the STM32 controls a pair of air valves according to a prepared program or according to how the operator presses the controls on the panel (rather for condition and functionality testing, not normal operation).
The first version was simple when the user pressed a button so the edge triggered an extit and a flag was set in the interrupt handler (button pressed).
In the main program (infinite loop) the flag was checked at each pass and if it was set some command was executed (for example the valve was opened for 100ms)
Now two things have happened
1. I had to add the emWIN library to the project and with it the RTOS, (I chose FreeRTOS)
Yes, so far I have only added our infinite loop to a single system task
2. For one button I need to
- if pressed briefly to function as before
- if pressed for a long time to turn the selected valve on permanently
Now I'm thinking about how to do it and I can't decide which solution to choose.
Which is the best in the future
My ideas
- Add a loop to the interrupt handler, which will be executed as long as the button is pressed, and then return the short or long press flag, depending on the number of passes.
- In the interrupt handler, at the rising edge, note the time (How best to mark the time?) or start the timer. In the interrupt handler, at the falling edge, read the times or stop the counter and set the short or long press flag depending on the time
- somehow use FreeRTOS, whether you use software OStimer or front operation of control buttons to move to a separate task. I don't know I have no experience with that
What is the solution that will be the most suitable for the future? For example, when the complexity of control or the complexity of the program increases again-
I really don't even know how long to choose the time to distinguish between short and long presses? Just 1 second or 1.5, 2, 3 ..? when will it still be interchangeable and when will it bother the operator?
I would welcome both my own obedience and a link to a sample example with the solution of operating the buttons, for example in FreeRTOS