CCS811 dumb library

Dependents:   Mt05_MtSense02 embernet-sensor-test

Files at this revision

API Documentation at this revision

Comitter:
johnathanlyu
Date:
Fri Apr 27 09:51:20 2018 +0000
Parent:
0:b5dbfc21185d
Commit message:
update initial flow

Changed in this revision

CCS811.cpp Show annotated file Show diff for this revision Revisions of this file
CCS811.h Show annotated file Show diff for this revision Revisions of this file
diff -r b5dbfc21185d -r 57eb62ded32d CCS811.cpp
--- a/CCS811.cpp	Tue Jun 27 05:17:02 2017 +0000
+++ b/CCS811.cpp	Fri Apr 27 09:51:20 2018 +0000
@@ -1,6 +1,6 @@
 #include "CCS811.h"
 
-CCS811::CCS811(I2C& i2c) : m_i2c(i2c), pc(p5, p4) {
+CCS811::CCS811(I2C& i2c, Serial& pc) : m_i2c(i2c), m_pc(pc) {
     
 }
 
@@ -13,19 +13,19 @@
     if (!checkHW()) {
         return;
     }else {
-        pc.printf("CCS811 is confirm!\r\n");    
+        m_pc.printf("CCS811 is confirm!\r\n");    
     }
     
+    send[0] = CCS811_REG_APP_START;
+    send[1] = 0x00;
+    
+    m_i2c.write(CCS811_I2C_ADDR, send, 2);
+    
     send[0] = CCS811_REG_MEAS_MODE;
     send[1] = CCS811_MEASUREMENT_MODE1;
     
     m_i2c.write(CCS811_I2C_ADDR, send, 2);
     
-    send[0] = CCS811_REG_APP_START;
-    send[1] = 0x00;
-    
-    m_i2c.write(CCS811_I2C_ADDR, send, 2);
-    
 }
 
 int CCS811::setMeasureMode(char mode) {
@@ -58,10 +58,10 @@
     m_i2c.write(CCS811_I2C_ADDR, recv, 1);
     m_i2c.read( CCS811_I2C_ADDR, recv, 8);
 
-//    pc.printf("%X %X\r\n", recv[0], recv[1]);
-//    pc.printf("%X %X\r\n", recv[2], recv[3]);
-//    pc.printf("%X %X\r\n", recv[4], recv[5]);
-//    pc.printf("%X %X\r\n", recv[6], recv[7]);
+//    m_pc.printf("%X %X\r\n", recv[0], recv[1]);
+//    m_pc.printf("%X %X\r\n", recv[2], recv[3]);
+//    m_pc.printf("%X %X\r\n", recv[4], recv[5]);
+//    m_pc.printf("%X %X\r\n", recv[6], recv[7]);
     
     *ECO2 = (uint16_t) (recv[0] <<8) + recv[1];
     *TVOC = (uint16_t) (recv[2] <<8) + recv[3];
@@ -83,7 +83,7 @@
     m_i2c.write(CCS811_I2C_ADDR, read, 1, false);
     m_i2c.read(CCS811_I2C_ADDR, hid, 1, false);
     
-//    pc.printf("%X\r\n", hid[0]);
+//    m_pc.printf("%X\r\n", hid[0]);
     
     if (hid[0] == 0x81) {
         return true;
diff -r b5dbfc21185d -r 57eb62ded32d CCS811.h
--- a/CCS811.h	Tue Jun 27 05:17:02 2017 +0000
+++ b/CCS811.h	Fri Apr 27 09:51:20 2018 +0000
@@ -34,7 +34,7 @@
 
 class CCS811 {
     public:
-        CCS811(I2C& i2c);
+        CCS811(I2C& i2c, Serial &pc);
         void init();
         int setMeasureMode(char mode);
         int readData(uint16_t *ECO2, uint16_t *TVOC);
@@ -42,7 +42,7 @@
         bool softRest();
     protected:
         I2C m_i2c;
-        Serial pc;
+        Serial m_pc;
     private:
 };