-// 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