ostaquet / Arduino-MQ131-driver

Arduino driver for gas sensor MQ131 (Ozone / O3)
MIT License
64 stars 19 forks source link

Additional processing during the heating/reading process #46

Closed MateuszOsiniak closed 2 years ago

MateuszOsiniak commented 2 years ago

Dear Olivier,

For my project I try to use 2 MQ131 sensors one for low and second for high ozone concentration but unfortunatelly I face a problem with timing. I would like to make additional action during sample() function but it block a program like you described. I saw your advice: "If you want to do additional processing during the heating/reading process, you should extend the class. The methods are protected and the driver can be extended easily". Can you described detailed how change the class?

ostaquet commented 2 years ago

To change the behavior of a method in a class. You have two choices: made the change directly in the code of the library (not recommended if it is an external library because new features and bug fixes could happened) or override the method with your own definition of the method.

There are a lot of webpages taking of the concept of overriding in object-oriented language. This page is related to C++: https://www.fluentcpp.com/2020/02/21/virtual-final-and-override-in-cpp/

You extent the base class from the library with your own class and override the sample() method. In the new method, you do whatever you want and you can also call the original sample()method via calling the parent class explicitly.

This issue is not related to the driver but related to the language. So, I will close it here.