add SHT3X support / new smaller SHT2X (V2)
[owSlave2.git] / DS2438_SHT2X / DS2438_SHT2X.c
index eb182ef..632a112 100644 (file)
@@ -39,8 +39,7 @@
 #include <avr/sleep.h>\r
 #include <avr/pgmspace.h>\r
 #include "../common/I2C/USI_TWI_Master.h"\r
-#include "../common/I2C/MAX44009.h"\r
-#include "../common/I2C/SHT2x.h"\r
+#include "../common/I2C/SHT2xV2.h"\r
 #include "../common/calibr.h"\r
 \r
 extern void OWINIT();\r
@@ -86,8 +85,7 @@ volatile int16_t am2302_temp;
 volatile uint16_t am2302_hum;\r
 \r
 uint8_t userRegister[1];\r
-int16_t sRH,sT;\r
-volatile double temperatureC,humidityRH;\r
+double temperatureC,humidityRH;\r
 volatile double l;\r
 \r
 #if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)\r
@@ -150,47 +148,31 @@ int main(void){
     for(i=0;i<64;i++) pack.bytes[i]=0;\r
        MCUSR=0;\r
        USI_TWI_Master_Initialise();\r
-       SHT2x_SoftReset();\r
-       SHT2x_ReadUserRegister(userRegister);\r
-       //(userRegister & ~SHT2x_RES_MASK) | SHT2x_RES_10_13BIT;\r
-       SHT2x_WriteUserRegister(userRegister); //write changed user reg\r
-       // --- measure humidity with "Hold Master Mode (HM)" ---\r
-       SHT2x_MeasurePoll(HUMIDITY, &sRH);\r
-       // --- measure temperature with "Polling Mode" (no hold master) ---\r
-       SHT2x_MeasurePoll(TEMP, &sT);\r
-       //-- calculate humidity and temperature --\r
-       temperatureC = SHT2x_CalcTemperatureC(sT);\r
-       humidityRH = SHT2x_CalcRH(sRH);\r
-       \r
+       initSHT2x();\r
+       _delay_ms(100);\r
        sei();\r
        \r
-        while(1)   {\r
+        while(1)   { \r
                 if (gcontrol) {\r
                         wdcounter=3;\r
                         gcontrol=0;\r
                 }\r
                 if (wdcounter>2) {\r
-                        //PORTB|=(1<<PINB1); //Dauer 440ms\r
-                        SHT2x_MeasurePoll(HUMIDITY, &sRH);\r
-                        // --- measure temperature with "Polling Mode" (no hold master) ---\r
-                        SHT2x_MeasurePoll(TEMP, &sT);\r
-                        //-- calculate humidity and temperature --\r
-                        temperatureC = SHT2x_CalcTemperatureC(sT);\r
-                        humidityRH = calibr_hum(temperatureC,-0.2,SHT2x_CalcRH(sRH))*10.0;\r
-                        temperatureC-=0.2;\r
-                        temperatureC*=10.0;\r
+                        getSHT2xHumTemp(&temperatureC,&humidityRH);\r
+                        double RH = humidityRH*10.0;//calibr_hum(temperatureC,-0.2,humidityRH)*10.0;\r
+                        double T=temperatureC;//-0.2;\r
+                        T*=10.0;\r
                         if (testSW()) {\r
-                                am2302_hum= humidityRH;\r
-                                am2302_temp=temperatureC*25.6;\r
-                                //am2302_temp=am2302_temp-45;\r
+                                am2302_hum= RH;\r
+                                am2302_temp=T*25.6;\r
                                 config_info[5]=12;     \r
                                 \r
                         }else{\r
                                 \r
-                               double hhum=(1.0546-0.000216*temperatureC)*(humidityRH);\r
+                               double hhum=(1.0546-0.000216*T)*(RH);\r
                                //am2302_hum=0.318*hhum +76.0;\r
                                am2302_hum=0.31*hhum +80;\r
-                               am2302_temp=temperatureC*25.6;\r
+                               am2302_temp=T*25.6;\r
                                //am2302_temp=am2302_temp-45;\r
                                config_info[5]=7;\r
                         }\r