Open edWin-m opened 1 year ago
Can you provide more information on why this is necessary? What's an example use case that requires this empty constructor?
@caternuson An empty constructor will allow users to define an instance of DHT as a member of their classes. Furthermore, it grants users more options on how and at what stage of their program logic they can set the library config.
DHT dht;
void setup()
{
dht.begin(D7, DHT11);
}
void loop()
{
...
float humidity = dht.readHumidity();
...
}
class MySensor {
public:
MySensor();
MySensor(uint8_t pin);
void begin();
void begin(uint8_t pin);
...
private:
...
DHT dht;
...
};
void my_sensor_loop();
void my_sensor_setup(uint8_t data_pin, sensor_callback_t cb_func);
...
static DHT sg_dht;
...
void my_sensor_setup(uint8_t data_pin, sensor_callback_t cb_func)
{
...
sg_callback = cb_func;
sg_dht.begin(data_pin, DHT11);
...
}
void my_sensor_loop()
{
...
float humidity = sg_dht.readHumidity();
float temperature = sg_dht.readTemperature();
...
}
The use of an empty constructor allows for some more complex and flexible initialization logic without the need to write out every step explicitly.