Linux Git
authorTobias <tm@tm3d.de>
Tue, 24 Oct 2017 15:01:11 +0000 (17:01 +0200)
committerTobias <tm@tm3d.de>
Tue, 24 Oct 2017 15:01:11 +0000 (17:01 +0200)
12 files changed:
DS2450_APDS9960/DS2450_APDS9960.c
DS2450_IAQCORE/DS2450_IAQCORE.c
common/I2C/APDS9960.c
common/I2C/APDS9960.h
common/I2C/BME680.c
common/I2C/BME680.h
common/I2C/IAQCORE.c
common/I2C/IAQCORE.h
common/I2C/SGP30.c
common/I2C/SGP30.h
programmer/programmer/programmer.asm
programmer/programmer/programmer.asmproj

index 4ded72e..b8eee45 100644 (file)
-
-// Copyright (c) 2017, Tobias Mueller tm(at)tm3d.de
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-//  * Redistributions of source code must retain the above copyright
-//    notice, this list of conditions and the following disclaimer.
-//  * Redistributions in binary form must reproduce the above copyright
-//    notice, this list of conditions and the following disclaimer in the
-//    documentation and/or other materials provided with the
-//    distribution.
-//  * All advertising materials mentioning features or use of this
-//    software must display the following acknowledgement: This product
-//    includes software developed by tm3d.de and its contributors.
-//  * Neither the name of tm3d.de nor the names of its contributors may
-//    be used to endorse or promote products derived from this software
-//    without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#define F_CPU 8000000UL
-#include <avr/io.h>
-#include <avr/interrupt.h>
-#include <util/delay.h>
-#include <avr/wdt.h>
-#include <avr/sleep.h>
-#include <avr/pgmspace.h>
-#include "../common/I2C/USI_TWI_Master.h"
-#include "../common/I2C/APDS9960.h"
-
-extern void OWINIT();
-extern void EXTERN_SLEEP();
-
-uint8_t owid[8]={0x20, 0xA2, 0xD9, 0x84, 0x00, 0x16, 0x23, 0x20};/**/
-//uint8_t config_info[26]={0x03,13,0x03,13,0x03,13,0x3,15,0x02,20,20,20,20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
-uint8_t config_info[26]={16,15,17,15,18,15,3,15,0x02,23,23,23,23,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
-
-#if (owid>128) 
-#error "Variable not correct"
-#endif
-
-extern uint8_t mode;
-extern uint8_t gcontrol;
-extern uint8_t reset_indicator;
-extern uint8_t alarmflag;
-
-
-typedef union {
-       volatile uint8_t bytes[0x20];
-       struct {
-               //Page0
-               uint16_t A;  //0
-               uint16_t B;  //2
-               uint16_t C;  //4
-               uint16_t D;  //6
-               //Page1
-               uint8_t CSA1;
-               uint8_t CSA2;
-               uint8_t CSB1;
-               uint8_t CSB2;
-               uint8_t CSC1;
-               uint8_t CSC2;
-               uint8_t CSD1;
-               uint8_t CSD2;
-               //Page2
-               uint8_t LA;
-               uint8_t HA;
-               uint8_t LB;
-               uint8_t HB;
-               uint8_t LC;
-               uint8_t HC;
-               uint8_t LD;
-               uint8_t HD;
-               //Page3
-               uint8_t FC1;
-               uint8_t FC2;
-               uint8_t FC3;
-               uint8_t FC4;
-               uint8_t VCCP;
-               uint8_t FC5;
-               uint8_t FC6;
-               uint8_t FC7;
-               uint8_t convc1;
-               uint8_t convc2;
-               
-               
-       };
-} pack_t;
-volatile pack_t pack;
-
-
-uint16_t light[4];
-double rlight[4];
-uint8_t gain=2;
-uint8_t atime=192;
-//uint8_t atime=255;
-double r_gain;
-double r_atime;
-
-void getLight(uint8_t setparameterr) {
-       if (setparameterr) {
-               r_gain=(1<<(2*gain));
-               r_atime=(256.0-atime)*2.78;
-               APDS9960setGain(gain);
-               APDS9960setATime(atime);
-               _delay_ms(700);
-       }
-       APDS9960getRGBC(&light[0],&light[1],&light[2],&light[3]);
-}
-
-
-
-
-int main(void){
-       pack.A=0;
-       pack.B=0;
-       pack.C=0;
-       pack.D=0;
-       pack.CSA1=0x08;
-       pack.CSA2=0x8C;
-       pack.CSB1=0x08;
-       pack.CSB2=0x8C;
-       pack.CSC1=0x08;
-       pack.CSC2=0x8C;
-       pack.CSD1=0x08;
-       pack.CSD2=0x8C;
-       pack.HA=0xFF;
-       pack.LA=0x00;
-       pack.HB=0xFF;
-       pack.LB=0x00;
-       pack.HC=0xFF;
-       pack.LC=0x00;
-       pack.HD=0xFF;
-       pack.LD=0x00;
-       pack.VCCP=0;
-
-       PORTA=0xFF;
-       PORTB=0xFF;
-
-       OWINIT();
-
-       MCUCR &=~(1<<PUD); //All Pins Pullup...
-       MCUCR |=(1<<BODS);
-       //PORTA&=~((1<<PINA0)|(1<<PINA1)|(1<<PINA2)|(1<<PINA3));
-
-       ADCSRA=(1<<ADEN)|(1<ADPS0)|(1<<ADPS2);
-
-       
-       
-       gcontrol=1;
-       ADCSRB|=(1<<ADLAR); 
-       USI_TWI_Master_Initialise();
-       
-       initAPDS9960();
-       //gain=2;
-       //atime=253;
-       getLight(1);
-       sei();
-       
-       //DDRB|=(1<<PINB1);
-
-    while(1)   {
-
-
-               if (gcontrol) {
-                       //PORTB|=(1<<PINB1);
-                       uint8_t bb=1;
-                       uint8_t bb1=1;
-                       for(uint8_t i=0;i<4;i++){
-                               if (pack.convc1&bb1) {
-                                       if (pack.convc2&(bb)) {pack.bytes[i*2]=0;pack.bytes[i*2+1]=0;}
-                                       bb=bb<<1;
-                                       if (pack.convc2&(bb)) {pack.bytes[i*2]=0xFF;pack.bytes[i*2+1]=0xFF;}
-                                       bb=bb<<1;
-                               } else bb=bb<<2;
-                               bb1=bb1<<1;                             
-                       }
-                       //CHanel A
-                       if (pack.convc1&1) {
-                               getLight(0);
-                               while (light[3]>0xF000) {
-                               //while (light[3]>900) {
-                                       if (gain!=0) {
-                                               gain--;
-                                               getLight(1);
-                                       }  else break;
-                               } 
-                               if (light[3]<0x2222) {
-                               //if (light[3]<0x22) {
-                                       if (gain<3) {
-                                               gain++;
-                                               getLight(1);
-                                       }
-
-                               }
-                               for(uint8_t i=0;i<4;i++) {
-                                       rlight[i]=(double)light[i]/r_atime/r_gain*70.0;
-                                       rlight[i]=(log(rlight[i])*1000)+32767.0;
-                               }
-                               cli();pack.A=rlight[0];sei();
-                               //cli();pack.A=r_gain;sei();
-                               alarmflag=0;
-                               if (pack.CSA2&0x08)  //AEH
-                                       if (pack.bytes[1]>pack.HA) {alarmflag=1;pack.CSA2|=0x20;}
-                               if (pack.CSA2&0x04)  //AEL
-                                       if (pack.bytes[1]<pack.LA) {alarmflag=1;pack.CSA2|=0x10;}
-                       }
-
-                       if (pack.convc1&2) {
-                               cli();pack.B=rlight[1];sei();
-                               //cli();pack.B=atime;sei();
-                               if (pack.CSB2&0x08)  //AEH
-                                       if (pack.bytes[1]>pack.HB) {alarmflag=1;pack.CSB2|=0x20;}
-                               if (pack.CSB2&0x04)  //AEL
-                                       if (pack.bytes[1]<pack.LB) {alarmflag=1;pack.CSB2|=0x10;}
-                       }
-
-                       if (pack.convc1&4) {
-                               cli();pack.C=rlight[2];sei();
-                               //cli();pack.C=light[3];sei();
-                               if (pack.CSC2&0x08)  //AEH
-                                       if (pack.bytes[1]>pack.HC) {alarmflag=1;pack.CSC2|=0x20;}
-                               if (pack.CSC2&0x04)  //AEL
-                                       if (pack.bytes[1]<pack.LC) {alarmflag=1;pack.CSC2|=0x10;}
-                       } 
-                       if (pack.convc1&8) {
-                               cli();pack.D=rlight[3];sei();
-                               if (pack.CSD2&0x08)  //AEH
-                                       if (pack.bytes[1]>pack.HD) {alarmflag=1;pack.CSD2|=0x20;}
-                               if (pack.CSD2&0x04)  //AEL
-                                       if (pack.bytes[1]<pack.LD) {alarmflag=1;pack.CSD2|=0x10;}
-                       }
-                       
-                       EXTERN_SLEEP();
-                       //PORTB&=~(1<<PINB1);
-               }
-
-               uint8_t bb=1;
-               for(uint8_t i=0;i<4;i++) {
-                       if (pack.bytes[8+i*2]&0x80) {  //Chanel as output
-                               if (pack.bytes[8+i*2]&0x40) {
-                                       DDRA|=bb;
-                               } else {
-                                       DDRA&=~bb;
-                               }
-                       } else {
-                               DDRA&=~bb;
-                       }
-                       bb=bb*2;
-               }
-               
-#if  defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__)  || defined(__AVR_ATtiny85__)
-                       if (((TIMSK & (1<<TOIE0))==0)&& (mode==0))
-#endif                 
-#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) ||defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)
-                       if (((TIMSK0 & (1<<TOIE0))==0)&& (mode==0))
-#endif
-                         {
-
-                       MCUCR|=(1<<SE)|(1<<SM1);
-                       MCUCR&=~(1<<ISC01);
-               } else {
-                       MCUCR|=(1<<SE);
-                       MCUCR&=~(1<<SM1);
-               }
-       //      asm("SLEEP");
-   }
-
-
+\r
+// Copyright (c) 2017, Tobias Mueller tm(at)tm3d.de\r
+// All rights reserved.\r
+//\r
+// Redistribution and use in source and binary forms, with or without\r
+// modification, are permitted provided that the following conditions are\r
+// met:\r
+//\r
+//  * Redistributions of source code must retain the above copyright\r
+//    notice, this list of conditions and the following disclaimer.\r
+//  * Redistributions in binary form must reproduce the above copyright\r
+//    notice, this list of conditions and the following disclaimer in the\r
+//    documentation and/or other materials provided with the\r
+//    distribution.\r
+//  * All advertising materials mentioning features or use of this\r
+//    software must display the following acknowledgement: This product\r
+//    includes software developed by tm3d.de and its contributors.\r
+//  * Neither the name of tm3d.de nor the names of its contributors may\r
+//    be used to endorse or promote products derived from this software\r
+//    without specific prior written permission.\r
+//\r
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\r
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\r
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+\r
+#define F_CPU 8000000UL\r
+#include <avr/io.h>\r
+#include <avr/interrupt.h>\r
+#include <util/delay.h>\r
+#include <avr/wdt.h>\r
+#include <avr/sleep.h>\r
+#include <avr/pgmspace.h>\r
+#include "../common/I2C/USI_TWI_Master.h"\r
+#include "../common/I2C/APDS9960.h"\r
+\r
+extern void OWINIT();\r
+extern void EXTERN_SLEEP();\r
+\r
+uint8_t owid[8]={0x20, 0xA2, 0xD9, 0x84, 0x00, 0x16, 0x23, 0x20};/**/\r
+//uint8_t config_info[26]={0x03,13,0x03,13,0x03,13,0x3,15,0x02,20,20,20,20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};\r
+uint8_t config_info[26]={16,15,17,15,18,15,3,15,0x02,23,23,23,23,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};\r
+\r
+#if (owid>128) \r
+#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
+\r
+\r
+typedef union {\r
+       volatile uint8_t bytes[0x20];\r
+       struct {\r
+               //Page0\r
+               uint16_t A;  //0\r
+               uint16_t B;  //2\r
+               uint16_t C;  //4\r
+               uint16_t D;  //6\r
+               //Page1\r
+               uint8_t CSA1;\r
+               uint8_t CSA2;\r
+               uint8_t CSB1;\r
+               uint8_t CSB2;\r
+               uint8_t CSC1;\r
+               uint8_t CSC2;\r
+               uint8_t CSD1;\r
+               uint8_t CSD2;\r
+               //Page2\r
+               uint8_t LA;\r
+               uint8_t HA;\r
+               uint8_t LB;\r
+               uint8_t HB;\r
+               uint8_t LC;\r
+               uint8_t HC;\r
+               uint8_t LD;\r
+               uint8_t HD;\r
+               //Page3\r
+               uint8_t FC1;\r
+               uint8_t FC2;\r
+               uint8_t FC3;\r
+               uint8_t FC4;\r
+               uint8_t VCCP;\r
+               uint8_t FC5;\r
+               uint8_t FC6;\r
+               uint8_t FC7;\r
+               uint8_t convc1;\r
+               uint8_t convc2;\r
+               \r
+               \r
+       };\r
+} pack_t;\r
+volatile pack_t pack;\r
+\r
+\r
+uint16_t light[4];\r
+double rlight[4];\r
+uint8_t gain=2;\r
+uint8_t atime=192;\r
+//uint8_t atime=255;\r
+double r_gain;\r
+double r_atime;\r
+\r
+void getLight(uint8_t setparameterr) {\r
+       if (setparameterr) {\r
+               r_gain=(1<<(2*gain));\r
+               r_atime=(256.0-atime)*2.78;\r
+               APDS9960setGain(gain);\r
+               APDS9960setATime(atime);\r
+               _delay_ms(700);\r
+       }\r
+       APDS9960getRGBC(&light[0],&light[1],&light[2],&light[3]);\r
+}\r
+\r
+\r
+\r
+\r
+int main(void){\r
+       pack.A=0;\r
+       pack.B=0;\r
+       pack.C=0;\r
+       pack.D=0;\r
+       pack.CSA1=0x08;\r
+       pack.CSA2=0x8C;\r
+       pack.CSB1=0x08;\r
+       pack.CSB2=0x8C;\r
+       pack.CSC1=0x08;\r
+       pack.CSC2=0x8C;\r
+       pack.CSD1=0x08;\r
+       pack.CSD2=0x8C;\r
+       pack.HA=0xFF;\r
+       pack.LA=0x00;\r
+       pack.HB=0xFF;\r
+       pack.LB=0x00;\r
+       pack.HC=0xFF;\r
+       pack.LC=0x00;\r
+       pack.HD=0xFF;\r
+       pack.LD=0x00;\r
+       pack.VCCP=0;\r
+\r
+       PORTA=0xFF;\r
+       PORTB=0xFF;\r
+\r
+       OWINIT();\r
+\r
+       MCUCR &=~(1<<PUD); //All Pins Pullup...\r
+       MCUCR |=(1<<BODS);\r
+       //PORTA&=~((1<<PINA0)|(1<<PINA1)|(1<<PINA2)|(1<<PINA3));\r
+\r
+       ADCSRA=(1<<ADEN)|(1<ADPS0)|(1<<ADPS2);\r
+\r
+       \r
+       \r
+       gcontrol=1;\r
+       ADCSRB|=(1<<ADLAR); \r
+       USI_TWI_Master_Initialise();\r
+       \r
+       initAPDS9960();\r
+       //gain=2;\r
+       //atime=253;\r
+       getLight(1);\r
+       sei();\r
+       \r
+       //DDRB|=(1<<PINB1);\r
+\r
+    while(1)   {\r
+\r
+\r
+               if (gcontrol) {\r
+                       //PORTB|=(1<<PINB1);\r
+                       uint8_t bb=1;\r
+                       uint8_t bb1=1;\r
+                       for(uint8_t i=0;i<4;i++){\r
+                               if (pack.convc1&bb1) {\r
+                                       if (pack.convc2&(bb)) {pack.bytes[i*2]=0;pack.bytes[i*2+1]=0;}\r
+                                       bb=bb<<1;\r
+                                       if (pack.convc2&(bb)) {pack.bytes[i*2]=0xFF;pack.bytes[i*2+1]=0xFF;}\r
+                                       bb=bb<<1;\r
+                               } else bb=bb<<2;\r
+                               bb1=bb1<<1;                             \r
+                       }\r
+                       //CHanel A\r
+                       if (pack.convc1&1) {\r
+                               getLight(0);\r
+                               while (light[3]>0xF000) {\r
+                               //while (light[3]>900) {\r
+                                       if (gain!=0) {\r
+                                               gain--;\r
+                                               getLight(1);\r
+                                       }  else break;\r
+                               } \r
+                               if (light[3]<0x2222) {\r
+                               //if (light[3]<0x22) {\r
+                                       if (gain<3) {\r
+                                               gain++;\r
+                                               getLight(1);\r
+                                       }\r
+\r
+                               }\r
+                               for(uint8_t i=0;i<4;i++) {\r
+                                       rlight[i]=(double)light[i]/r_atime/r_gain*70.0;\r
+                                       rlight[i]=(log(rlight[i])*1000)+32767.0;\r
+                               }\r
+                               cli();pack.A=rlight[0];sei();\r
+                               //cli();pack.A=r_gain;sei();\r
+                               alarmflag=0;\r
+                               if (pack.CSA2&0x08)  //AEH\r
+                                       if (pack.bytes[1]>pack.HA) {alarmflag=1;pack.CSA2|=0x20;}\r
+                               if (pack.CSA2&0x04)  //AEL\r
+                                       if (pack.bytes[1]<pack.LA) {alarmflag=1;pack.CSA2|=0x10;}\r
+                       }\r
+\r
+                       if (pack.convc1&2) {\r
+                               cli();pack.B=rlight[1];sei();\r
+                               //cli();pack.B=atime;sei();\r
+                               if (pack.CSB2&0x08)  //AEH\r
+                                       if (pack.bytes[1]>pack.HB) {alarmflag=1;pack.CSB2|=0x20;}\r
+                               if (pack.CSB2&0x04)  //AEL\r
+                                       if (pack.bytes[1]<pack.LB) {alarmflag=1;pack.CSB2|=0x10;}\r
+                       }\r
+\r
+                       if (pack.convc1&4) {\r
+                               cli();pack.C=rlight[2];sei();\r
+                               //cli();pack.C=light[3];sei();\r
+                               if (pack.CSC2&0x08)  //AEH\r
+                                       if (pack.bytes[1]>pack.HC) {alarmflag=1;pack.CSC2|=0x20;}\r
+                               if (pack.CSC2&0x04)  //AEL\r
+                                       if (pack.bytes[1]<pack.LC) {alarmflag=1;pack.CSC2|=0x10;}\r
+                       } \r
+                       if (pack.convc1&8) {\r
+                               cli();pack.D=rlight[3];sei();\r
+                               if (pack.CSD2&0x08)  //AEH\r
+                                       if (pack.bytes[1]>pack.HD) {alarmflag=1;pack.CSD2|=0x20;}\r
+                               if (pack.CSD2&0x04)  //AEL\r
+                                       if (pack.bytes[1]<pack.LD) {alarmflag=1;pack.CSD2|=0x10;}\r
+                       }\r
+                       \r
+                       EXTERN_SLEEP();\r
+                       //PORTB&=~(1<<PINB1);\r
+               }\r
+\r
+               uint8_t bb=1;\r
+               for(uint8_t i=0;i<4;i++) {\r
+                       if (pack.bytes[8+i*2]&0x80) {  //Chanel as output\r
+                               if (pack.bytes[8+i*2]&0x40) {\r
+                                       DDRA|=bb;\r
+                               } else {\r
+                                       DDRA&=~bb;\r
+                               }\r
+                       } else {\r
+                               DDRA&=~bb;\r
+                       }\r
+                       bb=bb*2;\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
+   }\r
+\r
+\r
 }
\ No newline at end of file
index cee219c..750cb9b 100644 (file)
-
-// Copyright (c) 2017, Tobias Mueller tm(at)tm3d.de
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-//  * Redistributions of source code must retain the above copyright
-//    notice, this list of conditions and the following disclaimer.
-//  * Redistributions in binary form must reproduce the above copyright
-//    notice, this list of conditions and the following disclaimer in the
-//    documentation and/or other materials provided with the
-//    distribution.
-//  * All advertising materials mentioning features or use of this
-//    software must display the following acknowledgement: This product
-//    includes software developed by tm3d.de and its contributors.
-//  * Neither the name of tm3d.de nor the names of its contributors may
-//    be used to endorse or promote products derived from this software
-//    without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-#define F_CPU 8000000UL
-#include <avr/io.h>
-#include <avr/interrupt.h>
-#include <util/delay.h>
-#include <avr/wdt.h>
-#include <avr/sleep.h>
-#include <avr/pgmspace.h>
-#include "../common/I2C/USI_TWI_Master.h"
-#include "../common/I2C/IAQCORE.h"
-
-extern void OWINIT();
-extern void EXTERN_SLEEP();
-
-uint8_t owid[8]={0x20, 0xA2, 0xD9, 0x84, 0x00, 0x16, 0x02, 0x5D};/**/
-uint8_t config_info[26]={0x06,13,0x06,13,0x06,13,0x06,13,0x02,20,20,20,20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};
-
-#if (owid>128) 
-#error "Variable not correct"
-#endif
-
-extern uint8_t mode;
-extern uint8_t gcontrol;
-extern uint8_t reset_indicator;
-extern uint8_t alarmflag;
-
-
-typedef union {
-       volatile uint8_t bytes[0x20];
-       struct {
-               //Page0
-               uint16_t A;  //0
-               uint16_t B;  //2
-               uint16_t C;  //4
-               uint16_t D;  //6
-               //Page1
-               uint8_t CSA1;
-               uint8_t CSA2;
-               uint8_t CSB1;
-               uint8_t CSB2;
-               uint8_t CSC1;
-               uint8_t CSC2;
-               uint8_t CSD1;
-               uint8_t CSD2;
-               //Page2
-               uint8_t LA;
-               uint8_t HA;
-               uint8_t LB;
-               uint8_t HB;
-               uint8_t LC;
-               uint8_t HC;
-               uint8_t LD;
-               uint8_t HD;
-               //Page3
-               uint8_t FC1;
-               uint8_t FC2;
-               uint8_t FC3;
-               uint8_t FC4;
-               uint8_t VCCP;
-               uint8_t FC5;
-               uint8_t FC6;
-               uint8_t FC7;
-               uint8_t convc1;
-               uint8_t convc2;
-               
-               
-       };
-} pack_t;
-volatile pack_t pack;
-
-
-
-IAQCORE_Data_t IAQCORE_Data;
-
-
-int main(void){
-       pack.A=0;
-       pack.B=0;
-       pack.C=0;
-       pack.D=0;
-       pack.CSA1=0x08;
-       pack.CSA2=0x8C;
-       pack.CSB1=0x08;
-       pack.CSB2=0x8C;
-       pack.CSC1=0x08;
-       pack.CSC2=0x8C;
-       pack.CSD1=0x08;
-       pack.CSD2=0x8C;
-       pack.HA=0xFF;
-       pack.LA=0x00;
-       pack.HB=0xFF;
-       pack.LB=0x00;
-       pack.HC=0xFF;
-       pack.LC=0x00;
-       pack.HD=0xFF;
-       pack.LD=0x00;
-       pack.VCCP=0;
-       OWINIT();
-
-       MCUCR &=~(1<<PUD); //All Pins Pullup...
-       MCUCR |=(1<<BODS);
-       PORTA&=~((1<<PINA0)|(1<<PINA1)|(1<<PINA2)|(1<<PINA3));
-       ADCSRA=(1<<ADEN)|(1<ADPS0)|(1<<ADPS2);
-
-       
-       
-       gcontrol=1;
-       USI_TWI_Master_Initialise();
-       ADCSRB|=(1<<ADLAR); 
-       sei();
-       
-       //DDRB|=(1<<PINB1);
-
-    while(1)   {
-
-
-               if (gcontrol) {
-                       readIAQCORE(&IAQCORE_Data);
-                       //PORTB|=(1<<PINB1);
-                       uint8_t bb=1;
-                       uint8_t bb1=1;
-                       for(uint8_t i=0;i<4;i++){
-                               if (pack.convc1&bb1) {
-                                       if (pack.convc2&(bb)) {pack.bytes[i*2]=0;pack.bytes[i*2+1]=0;}
-                                       bb=bb<<1;
-                                       if (pack.convc2&(bb)) {pack.bytes[i*2]=0xFF;pack.bytes[i*2+1]=0xFF;}
-                                       bb=bb<<1;
-                               } else bb=bb<<2;
-                               bb1=bb1<<1;                             
-                       }
-                       //CHanel A
-                       if (pack.convc1&1) {
-                               cli();pack.A=IAQCORE_Data.CO2;sei();
-                               alarmflag=0;
-                               if (pack.CSA2&0x08)  //AEH
-                                       if (pack.bytes[1]>pack.HA) {alarmflag=1;pack.CSA2|=0x20;}
-                               if (pack.CSA2&0x04)  //AEL
-                                       if (pack.bytes[1]<pack.LA) {alarmflag=1;pack.CSA2|=0x10;}
-                       }
-
-                       if (pack.convc1&2) {
-                               cli();pack.B=IAQCORE_Data.TVOC;sei();
-                               if (pack.CSB2&0x08)  //AEH
-                                       if (pack.bytes[1]>pack.HB) {alarmflag=1;pack.CSB2|=0x20;}
-                               if (pack.CSB2&0x04)  //AEL
-                                       if (pack.bytes[1]<pack.LB) {alarmflag=1;pack.CSB2|=0x10;}
-                       }
-
-                       if (pack.convc1&4) {
-                               cli();pack.C=IAQCORE_Data.resistance/1000;sei();
-                               if (pack.CSC2&0x08)  //AEH
-                                       if (pack.bytes[1]>pack.HC) {alarmflag=1;pack.CSC2|=0x20;}
-                               if (pack.CSC2&0x04)  //AEL
-                                       if (pack.bytes[1]<pack.LC) {alarmflag=1;pack.CSC2|=0x10;}
-                       } 
-                       if (pack.convc1&8) {
-                               cli();pack.D=IAQCORE_Data.state;sei();
-                               if (pack.CSD2&0x08)  //AEH
-                                       if (pack.bytes[1]>pack.HD) {alarmflag=1;pack.CSD2|=0x20;}
-                               if (pack.CSD2&0x04)  //AEL
-                                       if (pack.bytes[1]<pack.LD) {alarmflag=1;pack.CSD2|=0x10;}
-                       }
-                       
-                       EXTERN_SLEEP();
-                       //PORTB&=~(1<<PINB1);
-               }
-
-               uint8_t bb=1;
-               for(uint8_t i=0;i<4;i++) {
-                       if (pack.bytes[8+i*2]&0x80) {  //Chanel as output
-                               if (pack.bytes[8+i*2]&0x40) {
-                                       DDRA|=bb;
-                               } else {
-                                       DDRA&=~bb;
-                               }
-                       } else {
-                               DDRA&=~bb;
-                       }
-                       bb=bb*2;
-               }
-               
-#if  defined(__AVR_ATtiny25__)||defined(__AVR_ATtiny45__)  || defined(__AVR_ATtiny85__)
-                       if (((TIMSK & (1<<TOIE0))==0)&& (mode==0))
-#endif                 
-#if  defined(__AVR_ATtiny24__)||defined(__AVR_ATtiny44__)  || defined(__AVR_ATtiny84__) ||defined(__AVR_ATtiny24A__)||defined(__AVR_ATtiny44A__)  || defined(__AVR_ATtiny84A__)
-                       if (((TIMSK0 & (1<<TOIE0))==0)&& (mode==0))
-#endif
-                         {
-
-                       MCUCR|=(1<<SE)|(1<<SM1);
-                       MCUCR&=~(1<<ISC01);
-               } else {
-                       MCUCR|=(1<<SE);
-                       MCUCR&=~(1<<SM1);
-               }
-       //      asm("SLEEP");
-   }
-
-
+\r
+// Copyright (c) 2017, Tobias Mueller tm(at)tm3d.de\r
+// All rights reserved.\r
+//\r
+// Redistribution and use in source and binary forms, with or without\r
+// modification, are permitted provided that the following conditions are\r
+// met:\r
+//\r
+//  * Redistributions of source code must retain the above copyright\r
+//    notice, this list of conditions and the following disclaimer.\r
+//  * Redistributions in binary form must reproduce the above copyright\r
+//    notice, this list of conditions and the following disclaimer in the\r
+//    documentation and/or other materials provided with the\r
+//    distribution.\r
+//  * All advertising materials mentioning features or use of this\r
+//    software must display the following acknowledgement: This product\r
+//    includes software developed by tm3d.de and its contributors.\r
+//  * Neither the name of tm3d.de nor the names of its contributors may\r
+//    be used to endorse or promote products derived from this software\r
+//    without specific prior written permission.\r
+//\r
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\r
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\r
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+\r
+#define F_CPU 8000000UL\r
+#include <avr/io.h>\r
+#include <avr/interrupt.h>\r
+#include <util/delay.h>\r
+#include <avr/wdt.h>\r
+#include <avr/sleep.h>\r
+#include <avr/pgmspace.h>\r
+#include "../common/I2C/USI_TWI_Master.h"\r
+#include "../common/I2C/IAQCORE.h"\r
+\r
+extern void OWINIT();\r
+extern void EXTERN_SLEEP();\r
+\r
+uint8_t owid[8]={0x20, 0xA2, 0xD9, 0x84, 0x00, 0x16, 0x02, 0x5D};/**/\r
+uint8_t config_info[26]={0x06,13,0x06,13,0x06,13,0x06,13,0x02,20,20,20,20,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00};\r
+\r
+#if (owid>128) \r
+#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
+\r
+\r
+typedef union {\r
+       volatile uint8_t bytes[0x20];\r
+       struct {\r
+               //Page0\r
+               uint16_t A;  //0\r
+               uint16_t B;  //2\r
+               uint16_t C;  //4\r
+               uint16_t D;  //6\r
+               //Page1\r
+               uint8_t CSA1;\r
+               uint8_t CSA2;\r
+               uint8_t CSB1;\r
+               uint8_t CSB2;\r
+               uint8_t CSC1;\r
+               uint8_t CSC2;\r
+               uint8_t CSD1;\r
+               uint8_t CSD2;\r
+               //Page2\r
+               uint8_t LA;\r
+               uint8_t HA;\r
+               uint8_t LB;\r
+               uint8_t HB;\r
+               uint8_t LC;\r
+               uint8_t HC;\r
+               uint8_t LD;\r
+               uint8_t HD;\r
+               //Page3\r
+               uint8_t FC1;\r
+               uint8_t FC2;\r
+               uint8_t FC3;\r
+               uint8_t FC4;\r
+               uint8_t VCCP;\r
+               uint8_t FC5;\r
+               uint8_t FC6;\r
+               uint8_t FC7;\r
+               uint8_t convc1;\r
+               uint8_t convc2;\r
+               \r
+               \r
+       };\r
+} pack_t;\r
+volatile pack_t pack;\r
+\r
+\r
+\r
+IAQCORE_Data_t IAQCORE_Data;\r
+\r
+\r
+int main(void){\r
+       pack.A=0;\r
+       pack.B=0;\r
+       pack.C=0;\r
+       pack.D=0;\r
+       pack.CSA1=0x08;\r
+       pack.CSA2=0x8C;\r
+       pack.CSB1=0x08;\r
+       pack.CSB2=0x8C;\r
+       pack.CSC1=0x08;\r
+       pack.CSC2=0x8C;\r
+       pack.CSD1=0x08;\r
+       pack.CSD2=0x8C;\r
+       pack.HA=0xFF;\r
+       pack.LA=0x00;\r
+       pack.HB=0xFF;\r
+       pack.LB=0x00;\r
+       pack.HC=0xFF;\r
+       pack.LC=0x00;\r
+       pack.HD=0xFF;\r
+       pack.LD=0x00;\r
+       pack.VCCP=0;\r
+       OWINIT();\r
+\r
+       MCUCR &=~(1<<PUD); //All Pins Pullup...\r
+       MCUCR |=(1<<BODS);\r
+       PORTA&=~((1<<PINA0)|(1<<PINA1)|(1<<PINA2)|(1<<PINA3));\r
+       ADCSRA=(1<<ADEN)|(1<ADPS0)|(1<<ADPS2);\r
+\r
+       \r
+       \r
+       gcontrol=1;\r
+       USI_TWI_Master_Initialise();\r
+       ADCSRB|=(1<<ADLAR); \r
+       sei();\r
+       \r
+       //DDRB|=(1<<PINB1);\r
+\r
+    while(1)   {\r
+\r
+\r
+               if (gcontrol) {\r
+                       readIAQCORE(&IAQCORE_Data);\r
+                       //PORTB|=(1<<PINB1);\r
+                       uint8_t bb=1;\r
+                       uint8_t bb1=1;\r
+                       for(uint8_t i=0;i<4;i++){\r
+                               if (pack.convc1&bb1) {\r
+                                       if (pack.convc2&(bb)) {pack.bytes[i*2]=0;pack.bytes[i*2+1]=0;}\r
+                                       bb=bb<<1;\r
+                                       if (pack.convc2&(bb)) {pack.bytes[i*2]=0xFF;pack.bytes[i*2+1]=0xFF;}\r
+                                       bb=bb<<1;\r
+                               } else bb=bb<<2;\r
+                               bb1=bb1<<1;                             \r
+                       }\r
+                       //CHanel A\r
+                       if (pack.convc1&1) {\r
+                               cli();pack.A=IAQCORE_Data.CO2;sei();\r
+                               alarmflag=0;\r
+                               if (pack.CSA2&0x08)  //AEH\r
+                                       if (pack.bytes[1]>pack.HA) {alarmflag=1;pack.CSA2|=0x20;}\r
+                               if (pack.CSA2&0x04)  //AEL\r
+                                       if (pack.bytes[1]<pack.LA) {alarmflag=1;pack.CSA2|=0x10;}\r
+                       }\r
+\r
+                       if (pack.convc1&2) {\r
+                               cli();pack.B=IAQCORE_Data.TVOC;sei();\r
+                               if (pack.CSB2&0x08)  //AEH\r
+                                       if (pack.bytes[1]>pack.HB) {alarmflag=1;pack.CSB2|=0x20;}\r
+                               if (pack.CSB2&0x04)  //AEL\r
+                                       if (pack.bytes[1]<pack.LB) {alarmflag=1;pack.CSB2|=0x10;}\r
+                       }\r
+\r
+                       if (pack.convc1&4) {\r
+                               cli();pack.C=IAQCORE_Data.resistance/1000;sei();\r
+                               if (pack.CSC2&0x08)  //AEH\r
+                                       if (pack.bytes[1]>pack.HC) {alarmflag=1;pack.CSC2|=0x20;}\r
+                               if (pack.CSC2&0x04)  //AEL\r
+                                       if (pack.bytes[1]<pack.LC) {alarmflag=1;pack.CSC2|=0x10;}\r
+                       } \r
+                       if (pack.convc1&8) {\r
+                               cli();pack.D=IAQCORE_Data.state;sei();\r
+                               if (pack.CSD2&0x08)  //AEH\r
+                                       if (pack.bytes[1]>pack.HD) {alarmflag=1;pack.CSD2|=0x20;}\r
+                               if (pack.CSD2&0x04)  //AEL\r
+                                       if (pack.bytes[1]<pack.LD) {alarmflag=1;pack.CSD2|=0x10;}\r
+                       }\r
+                       \r
+                       EXTERN_SLEEP();\r
+                       //PORTB&=~(1<<PINB1);\r
+               }\r
+\r
+               uint8_t bb=1;\r
+               for(uint8_t i=0;i<4;i++) {\r
+                       if (pack.bytes[8+i*2]&0x80) {  //Chanel as output\r
+                               if (pack.bytes[8+i*2]&0x40) {\r
+                                       DDRA|=bb;\r
+                               } else {\r
+                                       DDRA&=~bb;\r
+                               }\r
+                       } else {\r
+                               DDRA&=~bb;\r
+                       }\r
+                       bb=bb*2;\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
+   }\r
+\r
+\r
 }
\ No newline at end of file
index 92df22e..9e6b6f5 100644 (file)
-// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-//  * Redistributions of source code must retain the above copyright
-//    notice, this list of conditions and the following disclaimer.
-//  * Redistributions in binary form must reproduce the above copyright
-//    notice, this list of conditions and the following disclaimer in the
-//    documentation and/or other materials provided with the
-//    distribution.
-//  * All advertising materials mentioning features or use of this
-//    software must display the following acknowledgement: This product
-//    includes software developed by tm3d.de and its contributors.
-//  * Neither the name of tm3d.de nor the names of its contributors may
-//    be used to endorse or promote products derived from this software
-//    without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#define F_CPU 8000000UL
-#include <avr/io.h>
-
-#include <util/delay.h>
-
-
-#include "USI_TWI_Master.h"
-#include "APDS9960.h"
-
-#define WC 0b01110010
-#define RC 0b01110011
-
-int8_t initAPDS9960() {
-       I2c_StartCondition();
-       I2c_WriteByte(WC);
-       I2c_WriteByte(0x80);
-       I2c_StartCondition();
-       I2c_WriteByte (RC);
-       uint8_t b1 =I2c_ReadByte(NO_ACK);
-       I2c_StopCondition();
-       if (b1==0xFF) return 0; else {
-               I2c_StartCondition();
-               I2c_WriteByte(WC);
-               I2c_WriteByte(0x80);
-               I2c_WriteByte(0x0B); //ALS Enable PowerON
-               I2c_StopCondition();
-       }
-       return 1;
-}
-void APDS9960setATime(uint8_t ATime) {
-       I2c_StartCondition();
-       I2c_WriteByte(WC);
-       I2c_WriteByte(0x81);
-       I2c_WriteByte(ATime); 
-       I2c_StopCondition();
-}
-void APDS9960setGain(uint8_t Gain) {
-       I2c_StartCondition();
-       I2c_WriteByte(WC);
-       I2c_WriteByte(0x8F);
-       I2c_WriteByte(Gain&0x03);
-       I2c_StopCondition();
-}
-uint8_t APDS9960getAVALID() {return 0;}
-uint8_t APDS9960getASAT() {return 0;}
-
-void APDS9960getRGBC(uint16_t* R,uint16_t* G,uint16_t* B,uint16_t* C) {
-       I2c_StartCondition();
-       I2c_WriteByte(WC);
-       I2c_WriteByte(0x94);
-       I2c_StartCondition();
-       I2c_WriteByte (RC);
-       *C=I2c_ReadByte(ACK)|I2c_ReadByte(ACK)<<8;
-       *R=I2c_ReadByte(ACK)|I2c_ReadByte(ACK)<<8;
-       *G=I2c_ReadByte(ACK)|I2c_ReadByte(ACK)<<8;
-       *B=I2c_ReadByte(ACK)|I2c_ReadByte(NO_ACK)<<8;
-       I2c_StopCondition();
-}
-
-
-/*
-uint8_t checkMAX44009(uint8_t nr) {
-       volatile uint8_t b1;
-       nr=(nr<<1)&0x02f;
-       
-       I2c_StartCondition();
-       I2c_WriteByte(0b10010100|nr);
-       I2c_WriteByte(0x03);
-       I2c_StartCondition();
-       I2c_WriteByte (0b10010101|nr);
-       b1 =I2c_ReadByte(NO_ACK);
-       I2c_StopCondition();
-       return b1!=0xFF;
-       
-}
-
-
-double MAX44009getlux(uint8_t nr)  {
-       volatile uint8_t b1,b2;
-       nr=(nr<<1)&0x02f;
-       
-       I2c_StartCondition();
-       I2c_WriteByte(0b10010100|nr);
-       I2c_WriteByte(0x03);
-       I2c_StartCondition();
-       I2c_WriteByte (0b10010101|nr);
-       b1 =I2c_ReadByte(NO_ACK);
-       I2c_StopCondition();
-       I2c_StartCondition();
-       I2c_WriteByte(0b10010100|nr);
-       I2c_WriteByte(0x04);
-       I2c_StartCondition();
-       I2c_WriteByte (0b10010101|nr);
-       b2 =I2c_ReadByte(NO_ACK);
-       I2c_StopCondition();
-       uint8_t exponent = (b1 & 0xF0) >> 4;// upper four bits of high byte register
-       uint8_t mantissa = (b1 & 0x0F) << 4;// lower four bits of high byte register =
-       // upper four bits of mantissa
-       mantissa += b2 & 0x0F;    // lower four bits of low byte register =
-       // lower four bits of mantissa
-       
-       return (double)mantissa * (double)(1 << (uint16_t)exponent) * 0.045;
-       
-       
-
-}
+// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de\r
+// All rights reserved.\r
+//\r
+// Redistribution and use in source and binary forms, with or without\r
+// modification, are permitted provided that the following conditions are\r
+// met:\r
+//\r
+//  * Redistributions of source code must retain the above copyright\r
+//    notice, this list of conditions and the following disclaimer.\r
+//  * Redistributions in binary form must reproduce the above copyright\r
+//    notice, this list of conditions and the following disclaimer in the\r
+//    documentation and/or other materials provided with the\r
+//    distribution.\r
+//  * All advertising materials mentioning features or use of this\r
+//    software must display the following acknowledgement: This product\r
+//    includes software developed by tm3d.de and its contributors.\r
+//  * Neither the name of tm3d.de nor the names of its contributors may\r
+//    be used to endorse or promote products derived from this software\r
+//    without specific prior written permission.\r
+//\r
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\r
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\r
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+#define F_CPU 8000000UL\r
+#include <avr/io.h>\r
+\r
+#include <util/delay.h>\r
+\r
+\r
+#include "USI_TWI_Master.h"\r
+#include "APDS9960.h"\r
+\r
+#define WC 0b01110010\r
+#define RC 0b01110011\r
+\r
+int8_t initAPDS9960() {\r
+       I2c_StartCondition();\r
+       I2c_WriteByte(WC);\r
+       I2c_WriteByte(0x80);\r
+       I2c_StartCondition();\r
+       I2c_WriteByte (RC);\r
+       uint8_t b1 =I2c_ReadByte(NO_ACK);\r
+       I2c_StopCondition();\r
+       if (b1==0xFF) return 0; else {\r
+               I2c_StartCondition();\r
+               I2c_WriteByte(WC);\r
+               I2c_WriteByte(0x80);\r
+               I2c_WriteByte(0x0B); //ALS Enable PowerON\r
+               I2c_StopCondition();\r
+       }\r
+       return 1;\r
+}\r
+void APDS9960setATime(uint8_t ATime) {\r
+       I2c_StartCondition();\r
+       I2c_WriteByte(WC);\r
+       I2c_WriteByte(0x81);\r
+       I2c_WriteByte(ATime); \r
+       I2c_StopCondition();\r
+}\r
+void APDS9960setGain(uint8_t Gain) {\r
+       I2c_StartCondition();\r
+       I2c_WriteByte(WC);\r
+       I2c_WriteByte(0x8F);\r
+       I2c_WriteByte(Gain&0x03);\r
+       I2c_StopCondition();\r
+}\r
+uint8_t APDS9960getAVALID() {return 0;}\r
+uint8_t APDS9960getASAT() {return 0;}\r
+\r
+void APDS9960getRGBC(uint16_t* R,uint16_t* G,uint16_t* B,uint16_t* C) {\r
+       I2c_StartCondition();\r
+       I2c_WriteByte(WC);\r
+       I2c_WriteByte(0x94);\r
+       I2c_StartCondition();\r
+       I2c_WriteByte (RC);\r
+       *C=I2c_ReadByte(ACK)|I2c_ReadByte(ACK)<<8;\r
+       *R=I2c_ReadByte(ACK)|I2c_ReadByte(ACK)<<8;\r
+       *G=I2c_ReadByte(ACK)|I2c_ReadByte(ACK)<<8;\r
+       *B=I2c_ReadByte(ACK)|I2c_ReadByte(NO_ACK)<<8;\r
+       I2c_StopCondition();\r
+}\r
+\r
+\r
+/*\r
+uint8_t checkMAX44009(uint8_t nr) {\r
+       volatile uint8_t b1;\r
+       nr=(nr<<1)&0x02f;\r
+       \r
+       I2c_StartCondition();\r
+       I2c_WriteByte(0b10010100|nr);\r
+       I2c_WriteByte(0x03);\r
+       I2c_StartCondition();\r
+       I2c_WriteByte (0b10010101|nr);\r
+       b1 =I2c_ReadByte(NO_ACK);\r
+       I2c_StopCondition();\r
+       return b1!=0xFF;\r
+       \r
+}\r
+\r
+\r
+double MAX44009getlux(uint8_t nr)  {\r
+       volatile uint8_t b1,b2;\r
+       nr=(nr<<1)&0x02f;\r
+       \r
+       I2c_StartCondition();\r
+       I2c_WriteByte(0b10010100|nr);\r
+       I2c_WriteByte(0x03);\r
+       I2c_StartCondition();\r
+       I2c_WriteByte (0b10010101|nr);\r
+       b1 =I2c_ReadByte(NO_ACK);\r
+       I2c_StopCondition();\r
+       I2c_StartCondition();\r
+       I2c_WriteByte(0b10010100|nr);\r
+       I2c_WriteByte(0x04);\r
+       I2c_StartCondition();\r
+       I2c_WriteByte (0b10010101|nr);\r
+       b2 =I2c_ReadByte(NO_ACK);\r
+       I2c_StopCondition();\r
+       uint8_t exponent = (b1 & 0xF0) >> 4;// upper four bits of high byte register\r
+       uint8_t mantissa = (b1 & 0x0F) << 4;// lower four bits of high byte register =\r
+       // upper four bits of mantissa\r
+       mantissa += b2 & 0x0F;    // lower four bits of low byte register =\r
+       // lower four bits of mantissa\r
+       \r
+       return (double)mantissa * (double)(1 << (uint16_t)exponent) * 0.045;\r
+       \r
+       \r
+\r
+}\r
 */
\ No newline at end of file
index a6ab18a..c21b23f 100644 (file)
@@ -1,45 +1,45 @@
-#ifndef APDS9960_H
-#define APDS9960_H
-// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-//  * Redistributions of source code must retain the above copyright
-//    notice, this list of conditions and the following disclaimer.
-//  * Redistributions in binary form must reproduce the above copyright
-//    notice, this list of conditions and the following disclaimer in the
-//    documentation and/or other materials provided with the
-//    distribution.
-//  * All advertising materials mentioning features or use of this
-//    software must display the following acknowledgement: This product
-//    includes software developed by tm3d.de and its contributors.
-//  * Neither the name of tm3d.de nor the names of its contributors may
-//    be used to endorse or promote products derived from this software
-//    without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-int8_t initAPDS9960();
-void APDS9960setATime(uint8_t ATime);
-void APDS9960setGain(uint8_t Gain);
-uint8_t APDS9960getAVALID();
-uint8_t APDS9960getASAT();
-
-void APDS9960getRGBC(uint16_t* R,uint16_t* G,uint16_t* B,uint16_t* C);
-
-
-
+#ifndef APDS9960_H\r
+#define APDS9960_H\r
+// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de\r
+// All rights reserved.\r
+//\r
+// Redistribution and use in source and binary forms, with or without\r
+// modification, are permitted provided that the following conditions are\r
+// met:\r
+//\r
+//  * Redistributions of source code must retain the above copyright\r
+//    notice, this list of conditions and the following disclaimer.\r
+//  * Redistributions in binary form must reproduce the above copyright\r
+//    notice, this list of conditions and the following disclaimer in the\r
+//    documentation and/or other materials provided with the\r
+//    distribution.\r
+//  * All advertising materials mentioning features or use of this\r
+//    software must display the following acknowledgement: This product\r
+//    includes software developed by tm3d.de and its contributors.\r
+//  * Neither the name of tm3d.de nor the names of its contributors may\r
+//    be used to endorse or promote products derived from this software\r
+//    without specific prior written permission.\r
+//\r
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\r
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\r
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+\r
+int8_t initAPDS9960();\r
+void APDS9960setATime(uint8_t ATime);\r
+void APDS9960setGain(uint8_t Gain);\r
+uint8_t APDS9960getAVALID();\r
+uint8_t APDS9960getASAT();\r
+\r
+void APDS9960getRGBC(uint16_t* R,uint16_t* G,uint16_t* B,uint16_t* C);\r
+\r
+\r
+\r
 #endif
\ No newline at end of file
index 3f425ba..9907867 100644 (file)
-// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-//  * Redistributions of source code must retain the above copyright
-//    notice, this list of conditions and the following disclaimer.
-//  * Redistributions in binary form must reproduce the above copyright
-//    notice, this list of conditions and the following disclaimer in the
-//    documentation and/or other materials provided with the
-//    distribution.
-//  * All advertising materials mentioning features or use of this
-//    software must display the following acknowledgement: This product
-//    includes software developed by tm3d.de and its contributors.
-//  * Neither the name of tm3d.de nor the names of its contributors may
-//    be used to endorse or promote products derived from this software
-//    without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#ifdef  __4MHZ__
-#define F_CPU 4000000UL
-#else
-#define F_CPU 8000000UL
-#endif
-#include <avr/io.h>
-
-
-/** Array Index to Field data mapping for Calibration Data*/
-#define BME680_T2_LSB_REG      (1)
-#define BME680_T2_MSB_REG      (2)
-#define BME680_T3_REG          (3)
-#define BME680_P1_LSB_REG      (5)
-#define BME680_P1_MSB_REG      (6)
-#define BME680_P2_LSB_REG      (7)
-#define BME680_P2_MSB_REG      (8)
-#define BME680_P3_REG          (9)
-#define BME680_P4_LSB_REG      (11)
-#define BME680_P4_MSB_REG      (12)
-#define BME680_P5_LSB_REG      (13)
-#define BME680_P5_MSB_REG      (14)
-#define BME680_P7_REG          (15)
-#define BME680_P6_REG          (16)
-#define BME680_P8_LSB_REG      (19)
-#define BME680_P8_MSB_REG      (20)
-#define BME680_P9_LSB_REG      (21)
-#define BME680_P9_MSB_REG      (22)
-#define BME680_P10_REG         (23)
-#define BME680_H2_MSB_REG      (25)
-#define BME680_H2_LSB_REG      (26)
-#define BME680_H1_LSB_REG      (26)
-#define BME680_H1_MSB_REG      (27)
-#define BME680_H3_REG          (28)
-#define BME680_H4_REG          (29)
-#define BME680_H5_REG          (30)
-#define BME680_H6_REG          (31)
-#define BME680_H7_REG          (32)
-#define BME680_T1_LSB_REG      (33)
-#define BME680_T1_MSB_REG      (34)
-#define BME680_GH2_LSB_REG     (35)
-#define BME680_GH2_MSB_REG     (36)
-#define BME680_GH1_REG         (37)
-#define BME680_GH3_REG (38)
-
-
-#include <util/delay.h>
-#include <avr/pgmspace.h>
-
-#include "USI_TWI_Master.h"
-#include "BME680.h"
-
-#define WC 0b11101100
-#define RC 0b11101101
-typedef union {
-       volatile uint8_t d[41];
-       struct {
-               uint8_t fr1;
-               int16_t t2;
-               int8_t t3;
-               uint8_t fr2; //4
-               uint16_t p1;
-               int16_t p2; //7
-               int8_t p3;
-               uint8_t fr3; //10
-               int16_t p4;
-               int16_t p5;
-               int8_t p7;
-               int8_t p6;
-               uint8_t fr4[2]; //17-18
-               int16_t p8;
-               int16_t p9;
-               uint8_t p10;
-               uint8_t fr5; //24
-               uint16_t h2_; //25 +26
-               uint8_t h1_;  //halb und halb 26+27
-               int8_t h3;
-               int8_t h4;
-               int8_t h5;
-               uint8_t h6;
-               int8_t h7;//32
-               uint16_t t1;
-               int16_t gh2;
-               int8_t gh1;
-               int8_t gh3; //38
-               int8_t fr6;// 39;
-               int8_t fr7; //40;
-               uint16_t h2; //Berechnung
-               uint16_t h1; //Berechnung       
-               int32_t t_fine; //Berechnung bei Temperaturmessung      
+// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de\r
+// All rights reserved.\r
+//\r
+// Redistribution and use in source and binary forms, with or without\r
+// modification, are permitted provided that the following conditions are\r
+// met:\r
+//\r
+//  * Redistributions of source code must retain the above copyright\r
+//    notice, this list of conditions and the following disclaimer.\r
+//  * Redistributions in binary form must reproduce the above copyright\r
+//    notice, this list of conditions and the following disclaimer in the\r
+//    documentation and/or other materials provided with the\r
+//    distribution.\r
+//  * All advertising materials mentioning features or use of this\r
+//    software must display the following acknowledgement: This product\r
+//    includes software developed by tm3d.de and its contributors.\r
+//  * Neither the name of tm3d.de nor the names of its contributors may\r
+//    be used to endorse or promote products derived from this software\r
+//    without specific prior written permission.\r
+//\r
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\r
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\r
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+#ifdef  __4MHZ__\r
+#define F_CPU 4000000UL\r
+#else\r
+#define F_CPU 8000000UL\r
+#endif\r
+#include <avr/io.h>\r
+\r
+\r
+/** Array Index to Field data mapping for Calibration Data*/\r
+#define BME680_T2_LSB_REG      (1)\r
+#define BME680_T2_MSB_REG      (2)\r
+#define BME680_T3_REG          (3)\r
+#define BME680_P1_LSB_REG      (5)\r
+#define BME680_P1_MSB_REG      (6)\r
+#define BME680_P2_LSB_REG      (7)\r
+#define BME680_P2_MSB_REG      (8)\r
+#define BME680_P3_REG          (9)\r
+#define BME680_P4_LSB_REG      (11)\r
+#define BME680_P4_MSB_REG      (12)\r
+#define BME680_P5_LSB_REG      (13)\r
+#define BME680_P5_MSB_REG      (14)\r
+#define BME680_P7_REG          (15)\r
+#define BME680_P6_REG          (16)\r
+#define BME680_P8_LSB_REG      (19)\r
+#define BME680_P8_MSB_REG      (20)\r
+#define BME680_P9_LSB_REG      (21)\r
+#define BME680_P9_MSB_REG      (22)\r
+#define BME680_P10_REG         (23)\r
+#define BME680_H2_MSB_REG      (25)\r
+#define BME680_H2_LSB_REG      (26)\r
+#define BME680_H1_LSB_REG      (26)\r
+#define BME680_H1_MSB_REG      (27)\r
+#define BME680_H3_REG          (28)\r
+#define BME680_H4_REG          (29)\r
+#define BME680_H5_REG          (30)\r
+#define BME680_H6_REG          (31)\r
+#define BME680_H7_REG          (32)\r
+#define BME680_T1_LSB_REG      (33)\r
+#define BME680_T1_MSB_REG      (34)\r
+#define BME680_GH2_LSB_REG     (35)\r
+#define BME680_GH2_MSB_REG     (36)\r
+#define BME680_GH1_REG         (37)\r
+#define BME680_GH3_REG (38)\r
+\r
+\r
+#include <util/delay.h>\r
+#include <avr/pgmspace.h>\r
+\r
+#include "USI_TWI_Master.h"\r
+#include "BME680.h"\r
+\r
+#define WC 0b11101100\r
+#define RC 0b11101101\r
+typedef union {\r
+       volatile uint8_t d[41];\r
+       struct {\r
+               uint8_t fr1;\r
+               int16_t t2;\r
+               int8_t t3;\r
+               uint8_t fr2; //4\r
+               uint16_t p1;\r
+               int16_t p2; //7\r
+               int8_t p3;\r
+               uint8_t fr3; //10\r
+               int16_t p4;\r
+               int16_t p5;\r
+               int8_t p7;\r
+               int8_t p6;\r
+               uint8_t fr4[2]; //17-18\r
+               int16_t p8;\r
+               int16_t p9;\r
+               uint8_t p10;\r
+               uint8_t fr5; //24\r
+               uint16_t h2_; //25 +26\r
+               uint8_t h1_;  //halb und halb 26+27\r
+               int8_t h3;\r
+               int8_t h4;\r
+               int8_t h5;\r
+               uint8_t h6;\r
+               int8_t h7;//32\r
+               uint16_t t1;\r
+               int16_t gh2;\r
+               int8_t gh1;\r
+               int8_t gh3; //38\r
+               int8_t fr6;// 39;\r
+               int8_t fr7; //40;\r
+               uint16_t h2; //Berechnung\r
+               uint16_t h1; //Berechnung       \r
+               int32_t t_fine; //Berechnung bei Temperaturmessung      \r
                uint8_t  res_heat_range;/**<resistance calculation*/
                int8_t  res_heat_val; /**<correction factor*/
-               int8_t  range_switching_error;/**<range switching error*/
-               int8_t ltemp; //letzte Temperatur
-       };
-} calib_t;
-
-volatile calib_t calib;
-
-
-#define BME680_CALIB_I2C_ADDR_1                                (0x89)
-#define BME680_CALIB_I2C_ADDR_2                                (0xE1)
-#define BME680_PAGE0_I2C_ID_REG                                (0xD0)
-#define BME680_CALIB_DATA_LENGTH_GAS                   (25)
-#define BME680_CALIB_DATA_LENGTH                       (16)
-
-
-#define BME680_MAX_HUMIDITY_VALUE              (102400)
-#define BME680_MIN_HUMIDITY_VALUE              (0)
-
-
-//ME680_CALIB_I2C_ADDR_1,
-//                                             a_data_u8,
-//                                             BME680_CALIB_DATA_LENGTH_GAS);
-                               /* read the humidity and gas
-                               calibration data*/
-/*                             com_status = (enum bme680_return_type)
-                                            bme680->bme680_bus_read(
-                                            bme680->dev_addr,
-                                            BME680_CALIB_I2C_ADDR_2,
-                                           (a_data_u8 +
-                                           BME680_CALIB_DATA_LENGTH_GAS),
-                                           BME680_CALIB_DATA_LENGTH);
-
-
-
-                                               */
-
-
-void setup_read(uint8_t addr) {
-       I2c_StartCondition();
-       I2c_WriteByte(WC);
-       I2c_WriteByte(addr);  //Ctrl hum
-       I2c_StartCondition();
-       I2c_WriteByte (RC);
-       
-}
-
-void setup_write(uint8_t addr) {
-       I2c_StartCondition();
-       I2c_WriteByte(WC);
-       I2c_WriteByte(addr);  //Ctrl hum
-}
-
-
-uint8_t readone(uint8_t addr) {
-       setup_read(addr);
-       uint8_t b=I2c_ReadByte(NO_ACK);
-       I2c_StopCondition();
-       return b;
-}
-
-void writeone(uint8_t addr,uint8_t b) {
-       setup_write(addr);
-       I2c_WriteByte(b);  //Ctrl hum
-       I2c_StopCondition();
-}
-
-int8_t initBME680() {
-       uint8_t b1=readone(0xD0);
-       setup_read(BME680_CALIB_I2C_ADDR_1);
-       for(uint8_t i=0;i<BME680_CALIB_DATA_LENGTH_GAS-1;i++) {
-               calib.d[i]=I2c_ReadByte(ACK);
-       }
-       calib.d[BME680_CALIB_DATA_LENGTH_GAS-1]=I2c_ReadByte(NO_ACK);
-       I2c_StopCondition();
-
-       setup_read(BME680_CALIB_I2C_ADDR_2);
-       for(uint8_t i=BME680_CALIB_DATA_LENGTH_GAS;i<BME680_CALIB_DATA_LENGTH_GAS+BME680_CALIB_DATA_LENGTH-1;i++) {
-               calib.d[i]=I2c_ReadByte(ACK);
-       }
-       calib.d[BME680_CALIB_DATA_LENGTH_GAS+BME680_CALIB_DATA_LENGTH-1]=I2c_ReadByte(NO_ACK);
-       I2c_StopCondition();
-       calib.res_heat_range=(readone(0x02)&0x30)>>4;
-       calib.res_heat_val=readone(0);
-       calib.range_switching_error=(readone(0x04)& 0xF0)>>4;
-
-
-    calib.h1 = (uint16_t)(((((uint16_t)calib.d[ BME680_H1_MSB_REG]))
-               << 4) | (calib.d[ BME680_H1_LSB_REG] &0x0F));
-       calib.h2 = (uint16_t)(((((uint16_t)calib.d[ BME680_H2_MSB_REG]))
-               << 4) | ((calib.d[ BME680_H2_LSB_REG]) >> 4));
-
-       
-       /*
-       
-       I2c_StartCondition();
-       I2c_WriteByte(WC);
-       I2c_WriteByte(0x72);  //Ctrl hum
-       I2c_WriteByte(0x01); //1x oversembling hum
-       I2c_WriteByte(0x74);  //Ctrl hum
-       I2c_WriteByte(0b01010101); //2x oversembling t - 16x oversemmping p - mode cont
-       I2c_StopCondition();    
-
-       */
-       calib.ltemp=25;
-
-       return b1==0x61;
-
-}
-
-
+               int8_t  range_switching_error;/**<range switching error*/\r
+               int8_t ltemp; //letzte Temperatur\r
+       };\r
+} calib_t;\r
+\r
+volatile calib_t calib;\r
+\r
+\r
+#define BME680_CALIB_I2C_ADDR_1                                (0x89)\r
+#define BME680_CALIB_I2C_ADDR_2                                (0xE1)\r
+#define BME680_PAGE0_I2C_ID_REG                                (0xD0)\r
+#define BME680_CALIB_DATA_LENGTH_GAS                   (25)\r
+#define BME680_CALIB_DATA_LENGTH                       (16)\r
+\r
+\r
+#define BME680_MAX_HUMIDITY_VALUE              (102400)\r
+#define BME680_MIN_HUMIDITY_VALUE              (0)\r
+\r
+\r
+//ME680_CALIB_I2C_ADDR_1,\r
+//                                             a_data_u8,\r
+//                                             BME680_CALIB_DATA_LENGTH_GAS);\r
+                               /* read the humidity and gas\r
+                               calibration data*/\r
+/*                             com_status = (enum bme680_return_type)\r
+                                            bme680->bme680_bus_read(\r
+                                            bme680->dev_addr,\r
+                                            BME680_CALIB_I2C_ADDR_2,\r
+                                           (a_data_u8 +\r
+                                           BME680_CALIB_DATA_LENGTH_GAS),\r
+                                           BME680_CALIB_DATA_LENGTH);\r
+\r
+\r
+\r
+                                               */\r
+\r
+\r
+void setup_read(uint8_t addr) {\r
+       I2c_StartCondition();\r
+       I2c_WriteByte(WC);\r
+       I2c_WriteByte(addr);  //Ctrl hum\r
+       I2c_StartCondition();\r
+       I2c_WriteByte (RC);\r
+       \r
+}\r
+\r
+void setup_write(uint8_t addr) {\r
+       I2c_StartCondition();\r
+       I2c_WriteByte(WC);\r
+       I2c_WriteByte(addr);  //Ctrl hum\r
+}\r
+\r
+\r
+uint8_t readone(uint8_t addr) {\r
+       setup_read(addr);\r
+       uint8_t b=I2c_ReadByte(NO_ACK);\r
+       I2c_StopCondition();\r
+       return b;\r
+}\r
+\r
+void writeone(uint8_t addr,uint8_t b) {\r
+       setup_write(addr);\r
+       I2c_WriteByte(b);  //Ctrl hum\r
+       I2c_StopCondition();\r
+}\r
+\r
+int8_t initBME680() {\r
+       uint8_t b1=readone(0xD0);\r
+       setup_read(BME680_CALIB_I2C_ADDR_1);\r
+       for(uint8_t i=0;i<BME680_CALIB_DATA_LENGTH_GAS-1;i++) {\r
+               calib.d[i]=I2c_ReadByte(ACK);\r
+       }\r
+       calib.d[BME680_CALIB_DATA_LENGTH_GAS-1]=I2c_ReadByte(NO_ACK);\r
+       I2c_StopCondition();\r
+\r
+       setup_read(BME680_CALIB_I2C_ADDR_2);\r
+       for(uint8_t i=BME680_CALIB_DATA_LENGTH_GAS;i<BME680_CALIB_DATA_LENGTH_GAS+BME680_CALIB_DATA_LENGTH-1;i++) {\r
+               calib.d[i]=I2c_ReadByte(ACK);\r
+       }\r
+       calib.d[BME680_CALIB_DATA_LENGTH_GAS+BME680_CALIB_DATA_LENGTH-1]=I2c_ReadByte(NO_ACK);\r
+       I2c_StopCondition();\r
+       calib.res_heat_range=(readone(0x02)&0x30)>>4;\r
+       calib.res_heat_val=readone(0);\r
+       calib.range_switching_error=(readone(0x04)& 0xF0)>>4;\r
+\r
+\r
+    calib.h1 = (uint16_t)(((((uint16_t)calib.d[ BME680_H1_MSB_REG]))\r
+               << 4) | (calib.d[ BME680_H1_LSB_REG] &0x0F));\r
+       calib.h2 = (uint16_t)(((((uint16_t)calib.d[ BME680_H2_MSB_REG]))\r
+               << 4) | ((calib.d[ BME680_H2_LSB_REG]) >> 4));\r
+\r
+       \r
+       /*\r
+       \r
+       I2c_StartCondition();\r
+       I2c_WriteByte(WC);\r
+       I2c_WriteByte(0x72);  //Ctrl hum\r
+       I2c_WriteByte(0x01); //1x oversembling hum\r
+       I2c_WriteByte(0x74);  //Ctrl hum\r
+       I2c_WriteByte(0b01010101); //2x oversembling t - 16x oversemmping p - mode cont\r
+       I2c_StopCondition();    \r
+\r
+       */\r
+       calib.ltemp=25;\r
+\r
+       return b1==0x61;\r
+\r
+}\r
+\r
+\r
 const float lookup_k1_range[16] PROGMEM = {
        1, 1, 1, 1, 1,0.99, 1, 0.992,
 1, 1, 0.998, 0.995, 1, 0.99, 1, 1};
 const float lookup_k2_range[16] PROGMEM = {
        8e6, 4e6, 2e6, 1e6,499500.4995, 248262.1648, 125000, 63004.03226,
-31281.28128, 15625, 7812.5, 3906.25,1953.125,976.5625, 488.28125, 244.140625};
-
+31281.28128, 15625, 7812.5, 3906.25,1953.125,976.5625, 488.28125, 244.140625};\r
+\r
 double bme680_compensate_gas_double(uint16_t gas_adc_u16, uint8_t gas_range_u8)
 {
        double gas_res_d = 0;
@@ -256,12 +256,12 @@ double bme680_compensate_gas_double(uint16_t gas_adc_u16, uint8_t gas_range_u8)
        gas_res_d = var1*a2/(gas_adc_u16-512.0+var1);
        return gas_res_d;
 }
-
-
-void readBMP680(int16_t *T,uint16_t *H,uint32_t *P,uint16_t *G){
-
-
-       
+\r
+\r
+void readBMP680(int16_t *T,uint16_t *H,uint32_t *P,uint16_t *G){\r
+\r
+\r
+       \r
        int32_t var1 ;
        int32_t var2 ;
        int32_t var3 ;
@@ -284,8 +284,8 @@ void readBMP680(int16_t *T,uint16_t *H,uint32_t *P,uint16_t *G){
 
                res_heat_x100 = (int32_t)(((var4 / var5) - 250) * 34);
                res_heat = (uint8_t) ((res_heat_x100 + 50) / 100);
-       }
-       uint16_t duration=100;
+       }\r
+       uint16_t duration=100;\r
        uint8_t factor = 0;
 
        while ((duration) > 0x3F) {
@@ -293,144 +293,144 @@ void readBMP680(int16_t *T,uint16_t *H,uint32_t *P,uint16_t *G){
                factor += 1;
        }
        (duration) = (duration) + (factor * 64);
-
-       //I2c_WriteByte(0x74);  //Ctrl hum
-       //I2c_WriteByte(0b01010101); //2x oversembling t - 16x oversemmping p - mode cont
-       // [71] <- 10;  [72] <- 04;  [73] <- 0C;  [74] <- 91;  [75] <- 00;
-       // [70] <- 00     [71] <- 10;  [72] <- 04;  [73] <- 0C;  [74] <- 91;  [75] <- 00;
-       setup_write(0x70);
-       I2c_WriteByte(0x00);
-       I2c_WriteByte(0x71);
-       I2c_WriteByte(0x10);
-       I2c_WriteByte(0x72);
-       I2c_WriteByte(0x04);
-       I2c_WriteByte(0x73);
-       I2c_WriteByte(0x0C);
-       I2c_WriteByte(0x74);
-       I2c_WriteByte(0x90);
-       I2c_WriteByte(0x75);
-       I2c_WriteByte(0x00);
-
-       I2c_WriteByte(0x5A);
-       I2c_WriteByte(res_heat);
-       I2c_WriteByte(0x64);
-       I2c_WriteByte(duration);
-       I2c_StopCondition();
-
-
-       writeone(0x74,0x91);
-       _delay_ms(1000);
-       
-       uint8_t bx=0x91;
-       while ((bx&0x01)==0x01) {
-               bx=readone(0x74);
-               _delay_ms(5);
-       }
-
-       //volatile uint8_t rs=readone(0x2B);
-       uint32_t Th,Hh,Ph;
-       setup_read(0x1F);
-       Ph=I2c_ReadByte(ACK);Ph=Ph<<8;
-       Ph|=I2c_ReadByte(ACK);Ph=Ph<<4;
-       Ph|=I2c_ReadByte(ACK)>>4;
-       Th=I2c_ReadByte(ACK);Th=Th<<8;
-       Th|=I2c_ReadByte(ACK);Th=Th<<4;
-       Th|=I2c_ReadByte(ACK)>>4;       
-       Hh=I2c_ReadByte(ACK);Hh=Hh<<8;
-       Hh|=I2c_ReadByte(NO_ACK);
-       I2c_StopCondition();
-       setup_read(0x2A);
-       volatile uint8_t g1=I2c_ReadByte(ACK);
-       volatile uint8_t g2=I2c_ReadByte(NO_ACK);
-       I2c_StopCondition();
-       *G=(((uint16_t)g1)<<2)|(g2>>6);
-       *P=*G;
-       *G= bme680_compensate_gas_double(*G,g2&0xF)/10.0;
-
-       int32_t temp_comp = 0;
-
-       var1 = ((int32_t)Th >> 3) -
-       ((int32_t)calib.t1 << 1);
-       var2 = (var1 * (int32_t)calib.t2) >> 11;
-       var3 = ((((var1 >> 1) * (var1 >> 1)) >> 12) *
-       ((int32_t)calib.t3 << 4)) >> 14;
-       calib.t_fine = var2 + var3;
-       temp_comp = ((calib.t_fine * 5) + 128) >> 8;
-
-       int32_t temp_scaled = 0;
-       int32_t var6    = 0;
-       int32_t humidity_comp = 0;
-
-       temp_scaled = (((int32_t)calib.t_fine * 5) + 128) >> 8;
-       var1 = (int32_t)Hh -
-               ((int32_t)((int32_t)calib.h1 << 4)) -
-               (((temp_scaled * (int32_t)calib.h3) /
-               ((int32_t)100)) >> 1);
-
-       var2 = ((int32_t)calib.h2 *
-               (((temp_scaled * (int32_t)calib.h4) /
-               ((int32_t)100)) + (((temp_scaled *
-               ((temp_scaled * (int32_t)calib.h5) /
-               ((int32_t)100))) >> 6) / ((int32_t)100)) + (int32_t)(1 << 14))) >> 10;
-
-       var3 = var1 * var2;
-
-       var4 = ((((int32_t)calib.h6) << 7) +
-               ((temp_scaled * (int32_t)calib.h7) /
-               ((int32_t)100))) >> 4;
-
-       var5 = ((var3 >> 14) * (var3 >> 14)) >> 10;
-       var6 = (var4 * var5) >> 1;
-
-       humidity_comp = (var3 + var6) >> 12;
-       if (humidity_comp > BME680_MAX_HUMIDITY_VALUE)
-               humidity_comp = BME680_MAX_HUMIDITY_VALUE;
-               else if (humidity_comp < BME680_MIN_HUMIDITY_VALUE)
-               humidity_comp = BME680_MIN_HUMIDITY_VALUE;
-
-    int32_t pressure_comp = 0;//int -> 5684
-
-    var1 = (((int32_t)calib.t_fine) >> 1) - (int32_t)64000;
-    var2 = ((((var1 >> 2) * (var1 >> 2)) >> 11) *
-    (int32_t)calib.p6) >> 2;
-    var2 = var2 + ((var1 * (int32_t)calib.p5) << 1);
-    var2 = (var2 >> 2) + ((int32_t)calib.p4 << 16);
-    var1 = (((((var1 >> 2) * (var1 >> 2)) >> 13) *
-    ((int32_t)calib.p3 << 5)) >> 3) +
-    (((int32_t)calib.p2 * var1) >> 1);
-    var1 = var1 >> 18;
-    var1 = (((int32_t)32768 + var1) * (int32_t)calib.p1) >> 15;
-    pressure_comp = (int32_t)1048576 - Ph;
-    pressure_comp = (int32_t)((pressure_comp - (var2 >> 12)) * ((uint32_t)3125));
-    var4 = ((int32_t)1 << 31);
-    if (pressure_comp >= var4)
-    pressure_comp = ((pressure_comp / (uint32_t)var1) << 1);
-    else
-    pressure_comp = ((pressure_comp << 1) / (uint32_t)var1);
-    var1 = ((int32_t)calib.p9 * (int32_t)(((pressure_comp >> 3) *
-    (pressure_comp >> 3)) >> 13)) >> 12;
-    var2 = ((int32_t)(pressure_comp >> 2) *
-    (int32_t)calib.p8) >> 13;
-    var3 = ((int32_t)(pressure_comp >> 8) * (int32_t)(pressure_comp >> 8) *
-    (int32_t)(pressure_comp >> 8) *
-    (int32_t)calib.p10) >> 17;
-
-    pressure_comp = (int32_t)(pressure_comp) + ((var1 + var2 + var3 +
-    ((int32_t)calib.p7 << 7)) >> 4);
-
-
-
-
-       
-       *T=(int16_t)temp_comp;
-       calib.ltemp=temp_comp/100;
-       //*P=pressure_comp;
-       *H=(uint16_t)(humidity_comp/10);
-       //*P=rs;
-       *T=g1;
-       *H=g2;
-       //*P=
-
-
-}
-
+\r
+       //I2c_WriteByte(0x74);  //Ctrl hum\r
+       //I2c_WriteByte(0b01010101); //2x oversembling t - 16x oversemmping p - mode cont\r
+       // [71] <- 10;  [72] <- 04;  [73] <- 0C;  [74] <- 91;  [75] <- 00;\r
+       // [70] <- 00     [71] <- 10;  [72] <- 04;  [73] <- 0C;  [74] <- 91;  [75] <- 00;\r
+       setup_write(0x70);\r
+       I2c_WriteByte(0x00);\r
+       I2c_WriteByte(0x71);\r
+       I2c_WriteByte(0x10);\r
+       I2c_WriteByte(0x72);\r
+       I2c_WriteByte(0x04);\r
+       I2c_WriteByte(0x73);\r
+       I2c_WriteByte(0x0C);\r
+       I2c_WriteByte(0x74);\r
+       I2c_WriteByte(0x90);\r
+       I2c_WriteByte(0x75);\r
+       I2c_WriteByte(0x00);\r
+\r
+       I2c_WriteByte(0x5A);\r
+       I2c_WriteByte(res_heat);\r
+       I2c_WriteByte(0x64);\r
+       I2c_WriteByte(duration);\r
+       I2c_StopCondition();\r
+\r
+\r
+       writeone(0x74,0x91);\r
+       _delay_ms(1000);\r
+       \r
+       uint8_t bx=0x91;\r
+       while ((bx&0x01)==0x01) {\r
+               bx=readone(0x74);\r
+               _delay_ms(5);\r
+       }\r
+\r
+       //volatile uint8_t rs=readone(0x2B);\r
+       uint32_t Th,Hh,Ph;\r
+       setup_read(0x1F);\r
+       Ph=I2c_ReadByte(ACK);Ph=Ph<<8;\r
+       Ph|=I2c_ReadByte(ACK);Ph=Ph<<4;\r
+       Ph|=I2c_ReadByte(ACK)>>4;\r
+       Th=I2c_ReadByte(ACK);Th=Th<<8;\r
+       Th|=I2c_ReadByte(ACK);Th=Th<<4;\r
+       Th|=I2c_ReadByte(ACK)>>4;       \r
+       Hh=I2c_ReadByte(ACK);Hh=Hh<<8;\r
+       Hh|=I2c_ReadByte(NO_ACK);\r
+       I2c_StopCondition();\r
+       setup_read(0x2A);\r
+       volatile uint8_t g1=I2c_ReadByte(ACK);\r
+       volatile uint8_t g2=I2c_ReadByte(NO_ACK);\r
+       I2c_StopCondition();\r
+       *G=(((uint16_t)g1)<<2)|(g2>>6);\r
+       *P=*G;\r
+       *G= bme680_compensate_gas_double(*G,g2&0xF)/10.0;\r
+\r
+       int32_t temp_comp = 0;\r
+\r
+       var1 = ((int32_t)Th >> 3) -\r
+       ((int32_t)calib.t1 << 1);\r
+       var2 = (var1 * (int32_t)calib.t2) >> 11;\r
+       var3 = ((((var1 >> 1) * (var1 >> 1)) >> 12) *\r
+       ((int32_t)calib.t3 << 4)) >> 14;\r
+       calib.t_fine = var2 + var3;\r
+       temp_comp = ((calib.t_fine * 5) + 128) >> 8;\r
+\r
+       int32_t temp_scaled = 0;\r
+       int32_t var6    = 0;\r
+       int32_t humidity_comp = 0;\r
+\r
+       temp_scaled = (((int32_t)calib.t_fine * 5) + 128) >> 8;\r
+       var1 = (int32_t)Hh -\r
+               ((int32_t)((int32_t)calib.h1 << 4)) -\r
+               (((temp_scaled * (int32_t)calib.h3) /\r
+               ((int32_t)100)) >> 1);\r
+\r
+       var2 = ((int32_t)calib.h2 *\r
+               (((temp_scaled * (int32_t)calib.h4) /\r
+               ((int32_t)100)) + (((temp_scaled *\r
+               ((temp_scaled * (int32_t)calib.h5) /\r
+               ((int32_t)100))) >> 6) / ((int32_t)100)) + (int32_t)(1 << 14))) >> 10;\r
+\r
+       var3 = var1 * var2;\r
+\r
+       var4 = ((((int32_t)calib.h6) << 7) +\r
+               ((temp_scaled * (int32_t)calib.h7) /\r
+               ((int32_t)100))) >> 4;\r
+\r
+       var5 = ((var3 >> 14) * (var3 >> 14)) >> 10;\r
+       var6 = (var4 * var5) >> 1;\r
+\r
+       humidity_comp = (var3 + var6) >> 12;\r
+       if (humidity_comp > BME680_MAX_HUMIDITY_VALUE)\r
+               humidity_comp = BME680_MAX_HUMIDITY_VALUE;\r
+               else if (humidity_comp < BME680_MIN_HUMIDITY_VALUE)\r
+               humidity_comp = BME680_MIN_HUMIDITY_VALUE;\r
+\r
+    int32_t pressure_comp = 0;//int -> 5684\r
+\r
+    var1 = (((int32_t)calib.t_fine) >> 1) - (int32_t)64000;\r
+    var2 = ((((var1 >> 2) * (var1 >> 2)) >> 11) *\r
+    (int32_t)calib.p6) >> 2;\r
+    var2 = var2 + ((var1 * (int32_t)calib.p5) << 1);\r
+    var2 = (var2 >> 2) + ((int32_t)calib.p4 << 16);\r
+    var1 = (((((var1 >> 2) * (var1 >> 2)) >> 13) *\r
+    ((int32_t)calib.p3 << 5)) >> 3) +\r
+    (((int32_t)calib.p2 * var1) >> 1);\r
+    var1 = var1 >> 18;\r
+    var1 = (((int32_t)32768 + var1) * (int32_t)calib.p1) >> 15;\r
+    pressure_comp = (int32_t)1048576 - Ph;\r
+    pressure_comp = (int32_t)((pressure_comp - (var2 >> 12)) * ((uint32_t)3125));\r
+    var4 = ((int32_t)1 << 31);\r
+    if (pressure_comp >= var4)\r
+    pressure_comp = ((pressure_comp / (uint32_t)var1) << 1);\r
+    else\r
+    pressure_comp = ((pressure_comp << 1) / (uint32_t)var1);\r
+    var1 = ((int32_t)calib.p9 * (int32_t)(((pressure_comp >> 3) *\r
+    (pressure_comp >> 3)) >> 13)) >> 12;\r
+    var2 = ((int32_t)(pressure_comp >> 2) *\r
+    (int32_t)calib.p8) >> 13;\r
+    var3 = ((int32_t)(pressure_comp >> 8) * (int32_t)(pressure_comp >> 8) *\r
+    (int32_t)(pressure_comp >> 8) *\r
+    (int32_t)calib.p10) >> 17;\r
+\r
+    pressure_comp = (int32_t)(pressure_comp) + ((var1 + var2 + var3 +\r
+    ((int32_t)calib.p7 << 7)) >> 4);\r
+\r
+\r
+\r
+\r
+       \r
+       *T=(int16_t)temp_comp;\r
+       calib.ltemp=temp_comp/100;\r
+       //*P=pressure_comp;\r
+       *H=(uint16_t)(humidity_comp/10);\r
+       //*P=rs;\r
+       *T=g1;\r
+       *H=g2;\r
+       //*P=\r
+\r
+\r
+}\r
+\r
index 159d3f3..7311e1d 100644 (file)
@@ -1,46 +1,46 @@
-#ifndef BME680_H
-#define BME680_H
-// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-//  * Redistributions of source code must retain the above copyright
-//    notice, this list of conditions and the following disclaimer.
-//  * Redistributions in binary form must reproduce the above copyright
-//    notice, this list of conditions and the following disclaimer in the
-//    documentation and/or other materials provided with the
-//    distribution.
-//  * All advertising materials mentioning features or use of this
-//    software must display the following acknowledgement: This product
-//    includes software developed by tm3d.de and its contributors.
-//  * Neither the name of tm3d.de nor the names of its contributors may
-//    be used to endorse or promote products derived from this software
-//    without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-int8_t initBME680();
-void readBMP680(int16_t *T,uint16_t *H,uint32_t *P,uint16_t *G);
-/*void APDS9960setATime(uint8_t ATime);
-void APDS9960setGain(uint8_t Gain);
-uint8_t APDS9960getAVALID();
-uint8_t APDS9960getASAT();
-
-void APDS9960getRGBC(uint16_t* R,uint16_t* G,uint16_t* B,uint16_t* C);
-*/
-
-
+#ifndef BME680_H\r
+#define BME680_H\r
+// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de\r
+// All rights reserved.\r
+//\r
+// Redistribution and use in source and binary forms, with or without\r
+// modification, are permitted provided that the following conditions are\r
+// met:\r
+//\r
+//  * Redistributions of source code must retain the above copyright\r
+//    notice, this list of conditions and the following disclaimer.\r
+//  * Redistributions in binary form must reproduce the above copyright\r
+//    notice, this list of conditions and the following disclaimer in the\r
+//    documentation and/or other materials provided with the\r
+//    distribution.\r
+//  * All advertising materials mentioning features or use of this\r
+//    software must display the following acknowledgement: This product\r
+//    includes software developed by tm3d.de and its contributors.\r
+//  * Neither the name of tm3d.de nor the names of its contributors may\r
+//    be used to endorse or promote products derived from this software\r
+//    without specific prior written permission.\r
+//\r
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\r
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\r
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+\r
+int8_t initBME680();\r
+void readBMP680(int16_t *T,uint16_t *H,uint32_t *P,uint16_t *G);\r
+/*void APDS9960setATime(uint8_t ATime);\r
+void APDS9960setGain(uint8_t Gain);\r
+uint8_t APDS9960getAVALID();\r
+uint8_t APDS9960getASAT();\r
+\r
+void APDS9960getRGBC(uint16_t* R,uint16_t* G,uint16_t* B,uint16_t* C);\r
+*/\r
+\r
+\r
 #endif
\ No newline at end of file
index 357912d..2512f61 100644 (file)
@@ -1,57 +1,57 @@
-// Copyright (c) 2017, Tobias Mueller tm(at)tm3d.de
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-//  * Redistributions of source code must retain the above copyright
-//    notice, this list of conditions and the following disclaimer.
-//  * Redistributions in binary form must reproduce the above copyright
-//    notice, this list of conditions and the following disclaimer in the
-//    documentation and/or other materials provided with the
-//    distribution.
-//  * All advertising materials mentioning features or use of this
-//    software must display the following acknowledgement: This product
-//    includes software developed by tm3d.de and its contributors.
-//  * Neither the name of tm3d.de nor the names of its contributors may
-//    be used to endorse or promote products derived from this software
-//    without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#define F_CPU 8000000UL
-#include <avr/io.h>
-
-#include <util/delay.h>
-
-
-#include "USI_TWI_Master.h"
-#include "IAQCORE.h"
-
-
-uint8_t readIAQCORE(IAQCORE_Data_t *d) {
-       uint8_t *da=(uint8_t*)d;
-       I2c_StartCondition();
-       I2c_WriteByte(0b10110101);
-       da[1]=I2c_ReadByte(ACK);
-       da[0]=I2c_ReadByte(ACK);
-       da[2]=I2c_ReadByte(ACK);
-       da[6]=I2c_ReadByte(ACK);
-       da[5]=I2c_ReadByte(ACK);
-       da[4]=I2c_ReadByte(ACK);
-       da[3]=I2c_ReadByte(ACK);
-       da[8]=I2c_ReadByte(ACK);
-       da[7]=I2c_ReadByte(NO_ACK);
-       I2c_StopCondition();
-       return 0;
-}
+// Copyright (c) 2017, Tobias Mueller tm(at)tm3d.de\r
+// All rights reserved.\r
+//\r
+// Redistribution and use in source and binary forms, with or without\r
+// modification, are permitted provided that the following conditions are\r
+// met:\r
+//\r
+//  * Redistributions of source code must retain the above copyright\r
+//    notice, this list of conditions and the following disclaimer.\r
+//  * Redistributions in binary form must reproduce the above copyright\r
+//    notice, this list of conditions and the following disclaimer in the\r
+//    documentation and/or other materials provided with the\r
+//    distribution.\r
+//  * All advertising materials mentioning features or use of this\r
+//    software must display the following acknowledgement: This product\r
+//    includes software developed by tm3d.de and its contributors.\r
+//  * Neither the name of tm3d.de nor the names of its contributors may\r
+//    be used to endorse or promote products derived from this software\r
+//    without specific prior written permission.\r
+//\r
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\r
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\r
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+#define F_CPU 8000000UL\r
+#include <avr/io.h>\r
+\r
+#include <util/delay.h>\r
+\r
+\r
+#include "USI_TWI_Master.h"\r
+#include "IAQCORE.h"\r
+\r
+\r
+uint8_t readIAQCORE(IAQCORE_Data_t *d) {\r
+       uint8_t *da=(uint8_t*)d;\r
+       I2c_StartCondition();\r
+       I2c_WriteByte(0b10110101);\r
+       da[1]=I2c_ReadByte(ACK);\r
+       da[0]=I2c_ReadByte(ACK);\r
+       da[2]=I2c_ReadByte(ACK);\r
+       da[6]=I2c_ReadByte(ACK);\r
+       da[5]=I2c_ReadByte(ACK);\r
+       da[4]=I2c_ReadByte(ACK);\r
+       da[3]=I2c_ReadByte(ACK);\r
+       da[8]=I2c_ReadByte(ACK);\r
+       da[7]=I2c_ReadByte(NO_ACK);\r
+       I2c_StopCondition();\r
+       return 0;\r
+}\r
index 12c538b..ac9476a 100644 (file)
@@ -1,44 +1,44 @@
-#ifndef IAQCORE_H
-#define IAQCORE_H
-// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-//  * Redistributions of source code must retain the above copyright
-//    notice, this list of conditions and the following disclaimer.
-//  * Redistributions in binary form must reproduce the above copyright
-//    notice, this list of conditions and the following disclaimer in the
-//    documentation and/or other materials provided with the
-//    distribution.
-//  * All advertising materials mentioning features or use of this
-//    software must display the following acknowledgement: This product
-//    includes software developed by tm3d.de and its contributors.
-//  * Neither the name of tm3d.de nor the names of its contributors may
-//    be used to endorse or promote products derived from this software
-//    without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-typedef struct  {
-uint16_t CO2;
-int8_t state;
-int32_t resistance;
-uint16_t TVOC;
-} IAQCORE_Data_t;
-
-uint8_t readIAQCORE(IAQCORE_Data_t *d);
-
+#ifndef IAQCORE_H\r
+#define IAQCORE_H\r
+// Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de\r
+// All rights reserved.\r
+//\r
+// Redistribution and use in source and binary forms, with or without\r
+// modification, are permitted provided that the following conditions are\r
+// met:\r
+//\r
+//  * Redistributions of source code must retain the above copyright\r
+//    notice, this list of conditions and the following disclaimer.\r
+//  * Redistributions in binary form must reproduce the above copyright\r
+//    notice, this list of conditions and the following disclaimer in the\r
+//    documentation and/or other materials provided with the\r
+//    distribution.\r
+//  * All advertising materials mentioning features or use of this\r
+//    software must display the following acknowledgement: This product\r
+//    includes software developed by tm3d.de and its contributors.\r
+//  * Neither the name of tm3d.de nor the names of its contributors may\r
+//    be used to endorse or promote products derived from this software\r
+//    without specific prior written permission.\r
+//\r
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\r
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\r
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+\r
+typedef struct  {\r
+uint16_t CO2;\r
+int8_t state;\r
+int32_t resistance;\r
+uint16_t TVOC;\r
+} IAQCORE_Data_t;\r
+\r
+uint8_t readIAQCORE(IAQCORE_Data_t *d);\r
+\r
 #endif
\ No newline at end of file
index ee19d6a..62841c4 100644 (file)
-// Copyright (c) 2017, Tobias Mueller tm(at)tm3d.de
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-//  * Redistributions of source code must retain the above copyright
-//    notice, this list of conditions and the following disclaimer.
-//  * Redistributions in binary form must reproduce the above copyright
-//    notice, this list of conditions and the following disclaimer in the
-//    documentation and/or other materials provided with the
-//    distribution.
-//  * All advertising materials mentioning features or use of this
-//    software must display the following acknowledgement: This product
-//    includes software developed by tm3d.de and its contributors.
-//  * Neither the name of tm3d.de nor the names of its contributors may
-//    be used to endorse or promote products derived from this software
-//    without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-#ifdef  __4MHZ__
-#define F_CPU 4000000UL
-#else
-#define F_CPU 8000000UL
-#endif
-#include <avr/io.h>
-
-
-#include <util/delay.h>
-#include <avr/pgmspace.h>
-
-#include "USI_TWI_Master.h"
-#include "SGP30.h"
-//0x58
-#define WC 0b10110000
-#define RC 0b10110001
-#define CRC8_POLYNOMIAL             0x31
-#define CRC8_INIT                   0xFF
-#define CRC8_LEN                    1
-
-
-uint8_t sensirion_common_generate_crc(uint8_t *data, uint8_t count)
-{
-       uint16_t current_byte;
-       uint8_t crc = CRC8_INIT;
-       uint8_t crc_bit;
-
-       /* calculates 8-Bit checksum with given polynomial */
-       for (current_byte = 0; current_byte < count; ++current_byte) {
-               crc ^= (data[current_byte]);
-               for (crc_bit = 8; crc_bit > 0; --crc_bit) {
-                       if (crc & 0x80)
-                       crc = (crc << 1) ^ CRC8_POLYNOMIAL;
-                       else
-                       crc = (crc << 1);
-               }
-       }
-       return crc;
-}
-
-int8_t sensirion_common_check_crc(uint8_t *data, uint8_t count, uint8_t checksum)
-{
-       if (sensirion_common_generate_crc(data, count) != checksum)
-       return 0;
-       return 1;
-}
-
-void readSGPXX(uint16_t com, uint8_t* data, uint8_t len) {
-       I2c_StartCondition();
-       I2c_WriteByte(WC);
-       I2c_WriteByte(com>>8);  //Ctrl hum
-       I2c_WriteByte(com&0x00FF);  //Ctrl hum
-       _delay_ms(100);
-       I2c_StartCondition();
-       I2c_WriteByte (RC);
-       for(uint8_t i=0;i<len-1;i++) {
-               data[i]=I2c_ReadByte(ACK);
-       }
-       data[len-1]=I2c_ReadByte(NO_ACK);
-       I2c_StopCondition();
-}
-
-void writeSGPXX(uint16_t com, uint8_t* data, uint8_t len) {
-       I2c_StartCondition();
-       I2c_WriteByte(WC);
-       I2c_WriteByte(com>>8);  //Ctrl hum
-       I2c_WriteByte(com&0x00FF);  //Ctrl hum
-       for(uint8_t i=0;i<len;i++) {
-               I2c_WriteByte(data[i]);
-       }
-       I2c_StopCondition();
-}
-
-
-
-
-
-uint16_t bl1S=0,bl2S=0;
-
+// Copyright (c) 2017, Tobias Mueller tm(at)tm3d.de\r
+// All rights reserved.\r
+//\r
+// Redistribution and use in source and binary forms, with or without\r
+// modification, are permitted provided that the following conditions are\r
+// met:\r
+//\r
+//  * Redistributions of source code must retain the above copyright\r
+//    notice, this list of conditions and the following disclaimer.\r
+//  * Redistributions in binary form must reproduce the above copyright\r
+//    notice, this list of conditions and the following disclaimer in the\r
+//    documentation and/or other materials provided with the\r
+//    distribution.\r
+//  * All advertising materials mentioning features or use of this\r
+//    software must display the following acknowledgement: This product\r
+//    includes software developed by tm3d.de and its contributors.\r
+//  * Neither the name of tm3d.de nor the names of its contributors may\r
+//    be used to endorse or promote products derived from this software\r
+//    without specific prior written permission.\r
+//\r
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\r
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\r
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+#ifdef  __4MHZ__\r
+#define F_CPU 4000000UL\r
+#else\r
+#define F_CPU 8000000UL\r
+#endif\r
+#include <avr/io.h>\r
+\r
+\r
+#include <util/delay.h>\r
+#include <avr/pgmspace.h>\r
+\r
+#include "USI_TWI_Master.h"\r
+#include "SGP30.h"\r
+//0x58\r
+#define WC 0b10110000\r
+#define RC 0b10110001\r
+#define CRC8_POLYNOMIAL             0x31\r
+#define CRC8_INIT                   0xFF\r
+#define CRC8_LEN                    1\r
+\r
+\r
+uint8_t sensirion_common_generate_crc(uint8_t *data, uint8_t count)\r
+{\r
+       uint16_t current_byte;\r
+       uint8_t crc = CRC8_INIT;\r
+       uint8_t crc_bit;\r
+\r
+       /* calculates 8-Bit checksum with given polynomial */\r
+       for (current_byte = 0; current_byte < count; ++current_byte) {\r
+               crc ^= (data[current_byte]);\r
+               for (crc_bit = 8; crc_bit > 0; --crc_bit) {\r
+                       if (crc & 0x80)\r
+                       crc = (crc << 1) ^ CRC8_POLYNOMIAL;\r
+                       else\r
+                       crc = (crc << 1);\r
+               }\r
+       }\r
+       return crc;\r
+}\r
+\r
+int8_t sensirion_common_check_crc(uint8_t *data, uint8_t count, uint8_t checksum)\r
+{\r
+       if (sensirion_common_generate_crc(data, count) != checksum)\r
+       return 0;\r
+       return 1;\r
+}\r
+\r
+void readSGPXX(uint16_t com, uint8_t* data, uint8_t len) {\r
+       I2c_StartCondition();\r
+       I2c_WriteByte(WC);\r
+       I2c_WriteByte(com>>8);  //Ctrl hum\r
+       I2c_WriteByte(com&0x00FF);  //Ctrl hum\r
+       _delay_ms(100);\r
+       I2c_StartCondition();\r
+       I2c_WriteByte (RC);\r
+       for(uint8_t i=0;i<len-1;i++) {\r
+               data[i]=I2c_ReadByte(ACK);\r
+       }\r
+       data[len-1]=I2c_ReadByte(NO_ACK);\r
+       I2c_StopCondition();\r
+}\r
+\r
+void writeSGPXX(uint16_t com, uint8_t* data, uint8_t len) {\r
+       I2c_StartCondition();\r
+       I2c_WriteByte(WC);\r
+       I2c_WriteByte(com>>8);  //Ctrl hum\r
+       I2c_WriteByte(com&0x00FF);  //Ctrl hum\r
+       for(uint8_t i=0;i<len;i++) {\r
+               I2c_WriteByte(data[i]);\r
+       }\r
+       I2c_StopCondition();\r
+}\r
+\r
+\r
+\r
+\r
+\r
+uint16_t bl1S=0,bl2S=0;\r
+\r
 uint16_t getbl=1000;
-
-
-int8_t check_convert_buf(uint8_t *b,uint16_t *v1,uint16_t *v2) {
-       int8_t ret=1;
-       if (sensirion_common_check_crc(b,2,b[2])) {     *v1=((int16_t)b[0])<<8|b[1];} else {*v1=0;ret=0;}
-       if (sensirion_common_check_crc(b+3,2,b[5])) {*v2=((int16_t)b[3])<<8|b[4];} else {*v2=0;ret=0;}
-       return ret;
-}
-
-
-
-uint16_t readEEPROM(uint8_t addr,uint16_t def) {
-       uint16_t hr;
-       EEARH=0;
-       while(EECR & (1<<EEPE));
-       EEARL=addr+1;
-       EECR |= (1<<EERE);
-       hr=EEDR;
-       if (hr!=0xFF) {
-               hr=hr<<8;
-               while(EECR & (1<<EEPE));
-               EEARL=addr;
-               EECR |= (1<<EERE);
-               hr|=EEDR;
-               return hr;
-       }
-       return def;
-}
-
-void writeEEPROM(uint8_t addr,uint16_t val) {
-       EEARH=0;
-       while(EECR & (1<<EEPE));
-       EECR = (0<<EEPM1)|(0<<EEPM0);
-       EEARL = addr;
-       EEDR = val&0xFF;
-       EECR |= (1<<EEMPE);
-       EECR |= (1<<EEPE);
-       while(EECR & (1<<EEPE));
-       EECR = (0<<EEPM1)|(0<<EEPM0);
-       EEARL = addr+1;
-       EEDR = val>>8;
-       EECR |= (1<<EEMPE);
-       EECR |= (1<<EEPE);
-}
-
-void save_baseline(uint16_t b1,uint16_t b2 ) {
-       writeEEPROM(0,b1);
-       writeEEPROM(2,b2);
-}
-
-void read_baseline(uint16_t *b1,uint16_t *b2) {
-       *b1=readEEPROM(0,0xFFFF);
-       *b2=readEEPROM(2,0xFFFF);
-}
-
-void set_baseline(uint16_t b1,uint16_t b2) {
-       uint8_t b[10];
-       b[3]=(uint16_t)b1>>8;  //irgendwie werden die Werte vertauscht zwischen lesen und schreiben
-       b[4]=(uint16_t)b1&0x00FF;
-       b[5]=sensirion_common_generate_crc(b+3,2);
-       b[0]=(uint16_t)b2>>8;
-       b[1]=(uint16_t)b2&0x00FF;
-       b[2]=sensirion_common_generate_crc(b,2);
-       writeSGPXX(0x201e,b,6);
-       bl1S=b1;
-       bl2S=b2;
-}
-
-int8_t initSGP30() {
-       uint8_t b[10];
-       readSGPXX(0x2032,b,3);
-       _delay_ms(300);
-       writeSGPXX(0x2003,0,0);
-       _delay_ms(10);
-       uint16_t b1=0,b2=0;
-       //set_baseline(0x2210,0x3320);
-       //readSGPXX(0x2015,b,6);
-       read_baseline(&b1,&b2);
-       if (b1!=0xFFFF) {
-               set_baseline(b1,b2);
-               //readSGPXX(0x2015,b,6);
-               //uint16_t bl1,bl2;
-               //check_convert_buf(b,&bl1,&bl2);
-               
-       }
-       return 0x1;
-
-}
-
-void runSGP30(uint16_t *CO2,uint16_t *VOC,uint16_t *ETH,uint16_t *H2){
-       uint8_t b[10];
-       readSGPXX(0x2008,b,6);
-       check_convert_buf(b,CO2,VOC);
-       getbl--;
-       if (getbl==0) {
-               uint8_t eq=1;
-               readSGPXX(0x2015,b,6);
-               uint16_t bl1,bl2;
-               check_convert_buf(b,&bl1,&bl2);
-               int8_t bl1d=bl1-bl1S;
-               int8_t bl2d=bl2-bl2S;
-               if (bl1d<0) bl1d=-bl1d;
-               if (bl2d<0) bl2d=-bl2d;
-               if (bl1d>4) {bl1S=bl1;eq=0;}
-               if (bl2d>4) {bl2S=bl2;eq=0;}
-               getbl=200;  //Naechste bruefunf in 100 s
-               if (eq==0) {
-                       *VOC+=1000;
-                       save_baseline(bl1,bl2);
-               } 
-       }
-       readSGPXX(0x2050,b,6);
-       check_convert_buf(b,ETH,H2);
-
-}
-
-
+\r
+\r
+int8_t check_convert_buf(uint8_t *b,uint16_t *v1,uint16_t *v2) {\r
+       int8_t ret=1;\r
+       if (sensirion_common_check_crc(b,2,b[2])) {     *v1=((int16_t)b[0])<<8|b[1];} else {*v1=0;ret=0;}\r
+       if (sensirion_common_check_crc(b+3,2,b[5])) {*v2=((int16_t)b[3])<<8|b[4];} else {*v2=0;ret=0;}\r
+       return ret;\r
+}\r
+\r
+\r
+\r
+uint16_t readEEPROM(uint8_t addr,uint16_t def) {\r
+       uint16_t hr;\r
+       EEARH=0;\r
+       while(EECR & (1<<EEPE));\r
+       EEARL=addr+1;\r
+       EECR |= (1<<EERE);\r
+       hr=EEDR;\r
+       if (hr!=0xFF) {\r
+               hr=hr<<8;\r
+               while(EECR & (1<<EEPE));\r
+               EEARL=addr;\r
+               EECR |= (1<<EERE);\r
+               hr|=EEDR;\r
+               return hr;\r
+       }\r
+       return def;\r
+}\r
+\r
+void writeEEPROM(uint8_t addr,uint16_t val) {\r
+       EEARH=0;\r
+       while(EECR & (1<<EEPE));\r
+       EECR = (0<<EEPM1)|(0<<EEPM0);\r
+       EEARL = addr;\r
+       EEDR = val&0xFF;\r
+       EECR |= (1<<EEMPE);\r
+       EECR |= (1<<EEPE);\r
+       while(EECR & (1<<EEPE));\r
+       EECR = (0<<EEPM1)|(0<<EEPM0);\r
+       EEARL = addr+1;\r
+       EEDR = val>>8;\r
+       EECR |= (1<<EEMPE);\r
+       EECR |= (1<<EEPE);\r
+}\r
+\r
+void save_baseline(uint16_t b1,uint16_t b2 ) {\r
+       writeEEPROM(0,b1);\r
+       writeEEPROM(2,b2);\r
+}\r
+\r
+void read_baseline(uint16_t *b1,uint16_t *b2) {\r
+       *b1=readEEPROM(0,0xFFFF);\r
+       *b2=readEEPROM(2,0xFFFF);\r
+}\r
+\r
+void set_baseline(uint16_t b1,uint16_t b2) {\r
+       uint8_t b[10];\r
+       b[3]=(uint16_t)b1>>8;  //irgendwie werden die Werte vertauscht zwischen lesen und schreiben\r
+       b[4]=(uint16_t)b1&0x00FF;\r
+       b[5]=sensirion_common_generate_crc(b+3,2);\r
+       b[0]=(uint16_t)b2>>8;\r
+       b[1]=(uint16_t)b2&0x00FF;\r
+       b[2]=sensirion_common_generate_crc(b,2);\r
+       writeSGPXX(0x201e,b,6);\r
+       bl1S=b1;\r
+       bl2S=b2;\r
+}\r
+\r
+int8_t initSGP30() {\r
+       uint8_t b[10];\r
+       readSGPXX(0x2032,b,3);\r
+       _delay_ms(300);\r
+       writeSGPXX(0x2003,0,0);\r
+       _delay_ms(10);\r
+       uint16_t b1=0,b2=0;\r
+       //set_baseline(0x2210,0x3320);\r
+       //readSGPXX(0x2015,b,6);\r
+       read_baseline(&b1,&b2);\r
+       if (b1!=0xFFFF) {\r
+               set_baseline(b1,b2);\r
+               //readSGPXX(0x2015,b,6);\r
+               //uint16_t bl1,bl2;\r
+               //check_convert_buf(b,&bl1,&bl2);\r
+               \r
+       }\r
+       return 0x1;\r
+\r
+}\r
+\r
+void runSGP30(uint16_t *CO2,uint16_t *VOC,uint16_t *ETH,uint16_t *H2){\r
+       uint8_t b[10];\r
+       readSGPXX(0x2008,b,6);\r
+       check_convert_buf(b,CO2,VOC);\r
+       getbl--;\r
+       if (getbl==0) {\r
+               uint8_t eq=1;\r
+               readSGPXX(0x2015,b,6);\r
+               uint16_t bl1,bl2;\r
+               check_convert_buf(b,&bl1,&bl2);\r
+               int8_t bl1d=bl1-bl1S;\r
+               int8_t bl2d=bl2-bl2S;\r
+               if (bl1d<0) bl1d=-bl1d;\r
+               if (bl2d<0) bl2d=-bl2d;\r
+               if (bl1d>4) {bl1S=bl1;eq=0;}\r
+               if (bl2d>4) {bl2S=bl2;eq=0;}\r
+               getbl=200;  //Naechste bruefunf in 100 s\r
+               if (eq==0) {\r
+                       *VOC+=1000;\r
+                       save_baseline(bl1,bl2);\r
+               } \r
+       }\r
+       readSGPXX(0x2050,b,6);\r
+       check_convert_buf(b,ETH,H2);\r
+\r
+}\r
+\r
+\r
index c285008..d576b18 100644 (file)
@@ -1,39 +1,39 @@
-#ifndef SGP30_H
-#define SGP30_H
-// Copyright (c) 2017, Tobias Mueller tm(at)tm3d.de
-// All rights reserved.
-//
-// Redistribution and use in source and binary forms, with or without
-// modification, are permitted provided that the following conditions are
-// met:
-//
-//  * Redistributions of source code must retain the above copyright
-//    notice, this list of conditions and the following disclaimer.
-//  * Redistributions in binary form must reproduce the above copyright
-//    notice, this list of conditions and the following disclaimer in the
-//    documentation and/or other materials provided with the
-//    distribution.
-//  * All advertising materials mentioning features or use of this
-//    software must display the following acknowledgement: This product
-//    includes software developed by tm3d.de and its contributors.
-//  * Neither the name of tm3d.de nor the names of its contributors may
-//    be used to endorse or promote products derived from this software
-//    without specific prior written permission.
-//
-// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
-// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
-// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
-// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
-// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
-// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
-// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
-// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
-// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
-// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
-// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
-
-int8_t initSGP30();
-void runSGP30(uint16_t *CO2,uint16_t *VOC,uint16_t *ETH,uint16_t *H2);
-
-
+#ifndef SGP30_H\r
+#define SGP30_H\r
+// Copyright (c) 2017, Tobias Mueller tm(at)tm3d.de\r
+// All rights reserved.\r
+//\r
+// Redistribution and use in source and binary forms, with or without\r
+// modification, are permitted provided that the following conditions are\r
+// met:\r
+//\r
+//  * Redistributions of source code must retain the above copyright\r
+//    notice, this list of conditions and the following disclaimer.\r
+//  * Redistributions in binary form must reproduce the above copyright\r
+//    notice, this list of conditions and the following disclaimer in the\r
+//    documentation and/or other materials provided with the\r
+//    distribution.\r
+//  * All advertising materials mentioning features or use of this\r
+//    software must display the following acknowledgement: This product\r
+//    includes software developed by tm3d.de and its contributors.\r
+//  * Neither the name of tm3d.de nor the names of its contributors may\r
+//    be used to endorse or promote products derived from this software\r
+//    without specific prior written permission.\r
+//\r
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\r
+// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\r
+// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\r
+// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\r
+// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\r
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\r
+// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\r
+// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\r
+// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\r
+// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\r
+// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\r
+\r
+int8_t initSGP30();\r
+void runSGP30(uint16_t *CO2,uint16_t *VOC,uint16_t *ETH,uint16_t *H2);\r
+\r
+\r
 #endif
\ No newline at end of file
index 5a51e4e..b08cc96 100644 (file)
@@ -83,14 +83,14 @@ jreset:
 \r
 \r
 .ORG 0x0EC0\r
-//7552 Byte \r
+\r
 start: \r
                cli\r
                ldi temp,0\r
                mov zero,temp\r
-               set_clock 0x00 ;8mhz\r
+               set_clock 0x01 ;4mhz\r
                ldi mode,OWM_SLEEP\r
-               ldi temp,(1<<CS01) //1us\r
+               ldi temp,(1<<CS01) //2us\r
                out TCCR0B,temp\r
                ldi temp, HIGH(RAMEND) ; HIGH-Byte der obersten RAM-Adresse \r
                out SPH, temp \r
@@ -115,10 +115,11 @@ pro_copy_loop: ;copy ID on SRAM for better handling
 pro_loop:\r
                ;sbi PORTB,0\r
                owwl                            ;wait for line goes low (polling)\r
-               sbrs writelow,0         ;test of zero send\r
+               sbrc writelow,0         ;test of zero send\r
+               sbi OW_DDR,OW_PIN       ;yes pull line to low 2us faster\r
+               sbrs writelow,0     ;test egain 2us faster.....\r
                rjmp pro_loop1          ;no ? goes next\r
-               sbi OW_DDR,OW_PIN       ;yes pull line to low\r
-               ldi param,45            ;wait for 50 us\r
+               ldi param,20            ;wait for 50 us\r
                rcall wait_time\r
                clr writelow            ;reset write low indecator\r
                cbi OW_DDR,OW_PIN   ;release line\r
@@ -140,7 +141,7 @@ pro_loop_send1:  ;prebare next bit
                rjmp pro_loop_end\r
 \r
 pro_loop_resv:\r
-               ldi param,15  ;wait 15us\r
+               ldi param,7  ;wait 15us\r
                rcall wait_time\r
                lsr rwbyte\r
                ;cbi PORTB,0\r
@@ -158,7 +159,7 @@ pro_loop_end_test_reset:
                sbic OW_PINN,OW_PIN  //leitung wieder high\r
                rjmp pro_loop\r
                in temp,TCNT0\r
-               cpi temp,130\r
+               cpi temp,63\r
                brlo pro_loop_end_test_reset\r
                rcall pro_sleep_s2\r
                rjmp pro_loop\r
@@ -172,16 +173,16 @@ pro_sleep_s1:
                sbic OW_PINN,OW_PIN  //leitung wieder high\r
                ret\r
                in temp,TCNT0\r
-               cpi temp,200\r
+               cpi temp,100\r
                brlo pro_sleep_s1\r
                //leitung wieder high\r
 pro_sleep_s2:\r
                owwh \r
-               ldi param,40\r
+               ldi param,20\r
                rcall wait_time\r
                //Presents Impuls\r
                sbi OW_DDR,OW_PIN\r
-               ldi param,130\r
+               ldi param,75\r
                rcall wait_time\r
                cbi OW_DDR,OW_PIN\r
                //init read byte\r
@@ -190,7 +191,7 @@ pro_sleep_s2:
                clr smode\r
                ldi mode,OWM_READ_ROM_COMMAND\r
                //Wait for all other devices presents impuls finished\r
-               ldi param,40\r
+               ldi param,20\r
                rcall wait_time\r
                ret\r
 \r
index cffffb4..2f55cc1 100644 (file)
@@ -25,7 +25,7 @@
     <preserveEEPROM>true</preserveEEPROM>\r
     <OverrideVtorValue>exception_table</OverrideVtorValue>\r
     <BootSegment>2</BootSegment>\r
-    <eraseonlaunchrule>1</eraseonlaunchrule>\r
+    <eraseonlaunchrule>0</eraseonlaunchrule>\r
     <AsfFrameworkConfig>\r
       <framework-data>\r
         <options />\r
@@ -38,7 +38,7 @@
         </dependencies>\r
       </framework-data>\r
     </AsfFrameworkConfig>\r
-    <avrtool>com.atmel.avrdbg.tool.atmelice</avrtool>\r
+    <avrtool>com.atmel.avrdbg.tool.avrdragon</avrtool>\r
     <com_atmel_avrdbg_tool_atmelice>\r
       <ToolOptions>\r
         <InterfaceProperties>\r
       <ToolNumber>J41800000789</ToolNumber>\r
       <ToolName>Atmel-ICE</ToolName>\r
     </com_atmel_avrdbg_tool_atmelice>\r
-    <avrtoolinterface>debugWIRE</avrtoolinterface>\r
+    <avrtoolinterface>ISP</avrtoolinterface>\r
     <ExternalProgrammingToolCommand />\r
-    <avrtoolserialnumber>J41800000789</avrtoolserialnumber>\r
+    <avrtoolserialnumber>00A200054127</avrtoolserialnumber>\r
     <avrdeviceexpectedsignature>0x1E930C</avrdeviceexpectedsignature>\r
+    <com_atmel_avrdbg_tool_avrdragon>\r
+      <ToolOptions>\r
+        <InterfaceProperties>\r
+          <IspClock>125000</IspClock>\r
+        </InterfaceProperties>\r
+        <InterfaceName>ISP</InterfaceName>\r
+      </ToolOptions>\r
+      <ToolType>com.atmel.avrdbg.tool.avrdragon</ToolType>\r
+      <ToolNumber>00A200054127</ToolNumber>\r
+      <ToolName>AVR Dragon</ToolName>\r
+    </com_atmel_avrdbg_tool_avrdragon>\r
+    <avrtoolinterfaceclock>125000</avrtoolinterfaceclock>\r
   </PropertyGroup>\r
   <PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">\r
     <ToolchainSettings>\r