Code reusing while using interrupts
Posted: Fri Feb 24, 2023 7:12 am
I have several water flow sensors for which I want to use hardware interrupts. And I don't know how to do it.
In order not to write the same code several times, I have to write a class for working with the sensor, and then create several instances in the application environment to work with each sensor separately. Either I need to create an instance of the class in the interrupt handler, initializing it with certain data from somewhere in memory, since I need to store the value (liters counter, current water flow value for example).
I haven't tried Espressif SDK yet, only Arduino, however even there I ran into this problem: a static method must be used as handleer of hardware interrupts, but in this case, i can't access variables and instance methods.
Tell me, please, how is this problem solved, perhaps what should I read? I don't know C++ very well. It may be simple, but not for me.
In order not to write the same code several times, I have to write a class for working with the sensor, and then create several instances in the application environment to work with each sensor separately. Either I need to create an instance of the class in the interrupt handler, initializing it with certain data from somewhere in memory, since I need to store the value (liters counter, current water flow value for example).
I haven't tried Espressif SDK yet, only Arduino, however even there I ran into this problem: a static method must be used as handleer of hardware interrupts, but in this case, i can't access variables and instance methods.
Tell me, please, how is this problem solved, perhaps what should I read? I don't know C++ very well. It may be simple, but not for me.