#pragma once
#include <Arduino.h>

void get_temp_hum(float *temperature, float *humidity)
{
    bool sht31ok = false;
    Adafruit_SHT31 sht31 = Adafruit_SHT31();

    #ifdef DEBUG
        Serial.printf("[%s]: start USE_SHT31\n",__func__);
    #endif
    if (! sht31.begin(0x44)) 
    {   
        Serial.printf("[%s]: SHT31 NOT detected ... Check your wiring or I2C ADDR!\n",__func__);
        sht31ok = false;
    } else
    {
        sht31ok = true;
        #ifdef DEBUG
            Serial.printf("[%s]: sht31ok =%d\n",__func__,sht31ok);
        #endif
    }

    if (sht31ok)
    {
        #ifndef CALIBRATE_TEMPERATURE
            #define CALIBRATE_TEMPERATURE       0   
        #endif

        #ifndef CALIBRATE_HUMIDITY
            #define CALIBRATE_HUMIDITY          0   
        #endif

        *temperature = sht31.readTemperature() + (CALIBRATE_TEMPERATURE);
        *humidity = sht31.readHumidity()     + (CALIBRATE_HUMIDITY);
    } else 
    {
        *temperature = -99.9f;
        *humidity = -99.9f;
    }
}