Many changes from 2018
[owSlave2.git] / DS18B20_VOC_DS2438_SHT direct / DS18B20_DS2438.c
index 5b3461c..2522a0e 100644 (file)
@@ -42,9 +42,9 @@
 #include "../common/I2C/USI_TWI_Master.h"\r
 #include "../common/I2C/SHT2xV2.h"\r
 #include "../common/calibr.h"\r
+#include "../common/owSlave_tools.h"\r
 \r
-extern void OWINIT(void);\r
-extern void EXTERN_SLEEP(void);\r
+OWST_EXTERN_VARS\r
 \r
 \r
 \r
@@ -58,24 +58,11 @@ volatile uint8_t config_info2[26]={0x01,0x06, 0x05,0x08, 0x04,0x07, 11,0x08, 0x0
 #error "Variable not correct"\r
 #endif\r
 \r
-extern uint8_t mode;\r
-extern uint8_t gcontrol;\r
-extern uint8_t reset_indicator;\r
-extern uint8_t alarmflag;\r
-volatile uint8_t wdcounter=1;\r
 extern uint8_t cpsp;\r
 \r
+OWST_WDT_ISR\r
 \r
-#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)\r
-ISR(WATCHDOG_vect) {\r
-       #else\r
-       ISR(WDT_vect) {\r
-               #endif\r
-               wdcounter++;\r
-               if (reset_indicator==1) reset_indicator++;\r
-               else if (reset_indicator==2) mode=0;\r
 \r
-}\r
 \r
 \r
        typedef union {\r
@@ -155,12 +142,13 @@ ISR(WATCHDOG_vect) {
 \r
 \r
 \r
-       volatile int16_t am2302_temp;\r
-       volatile uint16_t am2302_hum;\r
+       volatile int16_t DS2438_2_TEMP;\r
+       volatile uint16_t DS2438_2_VAD;\r
+       volatile uint16_t DS2438_2_VDD=0x01F4;\r
+\r
+       OWST_TESTSW\r
 \r
 \r
-       uint8_t userRegister[1];\r
-       int16_t sRH,sT;\r
        double temperatureC,humidityRH,hhum;\r
        volatile double l;\r
 \r
@@ -183,25 +171,6 @@ ISR(WATCHDOG_vect) {
        double la[4];\r
        uint8_t lainit=1;\r
 \r
-       int testSW(void) {\r
-               uint8_t r;\r
-               DDRB&=~(1<<PORTB0);  //Eingang\r
-               __asm__ __volatile__ ("nop");\r
-               PORTB|=(1<<PORTB0); //Pullup\r
-               __asm__ __volatile__ ("nop");\r
-               __asm__ __volatile__ ("nop");\r
-               __asm__ __volatile__ ("nop");\r
-               __asm__ __volatile__ ("nop");\r
-               __asm__ __volatile__ ("nop");\r
-               r=PINB&(1<<PORTB0);\r
-               __asm__ __volatile__ ("nop");\r
-               PORTB&=~(1<<PORTB0);\r
-               __asm__ __volatile__ ("nop");\r
-               DDRB|=(1<<PORTB0);  //Eingang\r
-               return (r==0);  //Offen mal HIH4030\r
-               \r
-               \r
-       }\r
 \r
        \r
        #define EEPROM_R0 0\r
@@ -290,7 +259,7 @@ ISR(WATCHDOG_vect) {
                        weekmaxarr[i]=pack2.r_week_max;\r
                }\r
 \r
-\r
+               for(uint8_t i=0;i<8;i++) pack2.page6[i]=owid1[i];\r
                if (testSW()) {\r
                        config_info2[5]=12;\r
                        }else{\r
@@ -304,27 +273,7 @@ ISR(WATCHDOG_vect) {
                gcontrol=1;\r
                sei();\r
                while(1)   {\r
-                       /*if (pack1.config==0x1F) {  //Reset R0\r
-                               pack1.config=0x7F;\r
-                               R0=1;\r
-                               pack2.R0=0;\r
-                               writeEEPROM(EEPROM_R0,0);\r
-                       }\r
-                       if (pack1.config==0x05) {  //Reset all Data\r
-                               pack1.config=0x7F;\r
-                               pack2.r_day_max=1;\r
-                               pack2.r_week_max=1;\r
-                               pack2.tol_d=0;\r
-                               pack2.tol_s8=0;  //Tag faengt mit Einschalten an\r
-                               R0=1;\r
-                               writeEEPROM(EEPROM_R0,0xFF);\r
-                               writeEEPROM(EEPROM_R0d,0xFF);  //Maximum des Tages\r
-                               writeEEPROM(EEPROM_R0w,0xFF); //Maximum der Letzten 7 Tage\r
-                               writeEEPROM(EEPROM_dol,0xFF); //Anzahl der Betriebstage\r
-                               for(uint8_t i=0;i<7;i++) {\r
-                                       weekmaxarr[i]=1;\r
-                               }\r
-                       }*/\r
+                       \r
                        if ((cpsp&0x80)!=0) {\r
                                if ((cpsp&0x0F)==5) {\r
                                        if (pack2.reset_code==0x01) {\r
@@ -390,14 +339,13 @@ ISR(WATCHDOG_vect) {
 \r
 \r
                                if (testSW()) {\r
-                                       am2302_hum=RH;\r
-                                       am2302_temp=TC*25.6;\r
+                                       DS2438_2_VAD=RH;\r
+                                       DS2438_2_TEMP=TC*25.6;\r
                                        config_info2[5]=12;     //10V = 100%\r
                                }else{\r
                                        hhum=(1.0546-0.000216*TC)*(RH);\r
-                                       //am2302_hum=0.318*hhum +76.0;\r
-                                       am2302_hum=0.31*hhum +80;\r
-                                       am2302_temp=TC*25.6;\r
+                                       DS2438_2_VAD=0.31*hhum +80;\r
+                                       DS2438_2_TEMP=TC*25.6;\r
                                        config_info2[5]=7;\r
                                }\r
                                mr=0;\r
@@ -456,7 +404,7 @@ ISR(WATCHDOG_vect) {
                                \r
                        }\r
                        \r
-                       if (gcontrol==1) {\r
+                       if ((gcontrol&1)==1) {\r
                                uint16_t w=l;\r
                                uint8_t t8=w>>4;\r
                                uint8_t af=0;\r
@@ -469,27 +417,13 @@ ISR(WATCHDOG_vect) {
                                sei();\r
                                EXTERN_SLEEP();\r
                        }\r
-                       if ((gcontrol==2)||(gcontrol==3)) {\r
+                       if (gcontrol) {\r
                                gcontrol=0;\r
                                \r
                        }\r
 \r
                        \r
-                       #if  defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__)  || defined(__AVR_ATtiny85__)\r
-                       if (((TIMSK & (1<<TOIE0))==0)&& (mode==0))\r
-                       #endif\r
-                       #if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) ||defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)\r
-                       if (((TIMSK0 & (1<<TOIE0))==0)&& (mode==0))\r
-                       #endif\r
-                       {\r
-\r
-                               MCUCR|=(1<<SE)|(1<<SM1);\r
-                               MCUCR&=~(1<<ISC01);\r
-                       } else {\r
-                               MCUCR|=(1<<SE);\r
-                               MCUCR&=~(1<<SM1);\r
-                       }\r
-                       asm("SLEEP");\r
+                       OWST_MAIN_END\r
                }\r
 \r
 \r