Home | History | Annotate | Download | only in micsv89
      1 /*
      2  * Author: Marc Graham <marc (at) m2ag.net>
      3  * Copyright (c) 2015 Intel Corporation.
      4  *
      5  * Permission is hereby granted, free of charge, to any person obtaining
      6  * a copy of this software and associated documentation files (the
      7  * "Software"), to deal in the Software without restriction, including
      8  * without limitation the rights to use, copy, modify, merge, publish,
      9  * distribute, sublicense, and/or sell copies of the Software, and to
     10  * permit persons to whom the Software is furnished to do so, subject to
     11  * the following conditions:
     12  *
     13  * The above copyright notice and this permission notice shall be
     14  * included in all copies or substantial portions of the Software.
     15  *
     16  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
     17  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
     18  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
     19  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
     20  * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
     21  * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
     22  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
     23  */
     24 
     25 #pragma once
     26 
     27 #include <iostream>
     28 #include <string>
     29 #include "mraa.hpp"
     30 #include "mraa/i2c.hpp"
     31 
     32 namespace upm {
     33   /**
     34    * @brief MICS-VZ89 environmental sensor library
     35    * @defgroup micsv89 libupm-micsv89
     36    * @ingroup generic i2c gaseous
     37    */
     38   /**
     39    * @library micsv89
     40    * @sensor micsv89
     41    * @comname MICS-VZ89 Gas Sensor
     42    * @type gaseous
     43    * @man generic
     44    * @con i2c
     45    * @web http://sgx.cdistore.com/datasheets/e2v/MiCS-VZ-86%20and%20VZ-89%20rev%204.pdf
     46    * @web http://www.sgxsensortech.com/content/uploads/2015/01/MICS-VZ-89-I2C-specs-rev-A.pdf
     47    *
     48    * @brief API for the MICS-VZ89 Gas Sensor
     49    *
     50    * The MiCS-VZ-86/89 combines state-of-the-art MOS sensor technology with
     51    * intelligent detection algorithms to monitor VOCs and CO2 equivalent
     52    * variations in confined spaces.
     53    *
     54    * The MICSV89 comes in 4 variants, PWM and I2C in 3.3 volts and 5 volts.
     55    * This library only implements the I2c version of the device.
     56    *
     57    * Device output is not valid until a warm up of 15 minutes of operation.
     58    *
     59    * @image html micsv89.jpg
     60    * @snippet micsv89.cxx Interesting
     61    */
     62     class MICSV89 {
     63         public:
     64             /**
     65              * MICSV89 constructor
     66              *
     67              * @param bus i2c bus the sensor is attached to.
     68              * @param address. Device address. Default is 0x70.
     69              */
     70             MICSV89 (int bus, uint8_t address = 0x70);
     71 
     72             /**
     73              * MICSV89 destructor
     74              */
     75             ~MICSV89 ();
     76 
     77             /**
     78              * Returns the name of the sensor
     79              */
     80             std::string name()
     81             {
     82                 return m_name;
     83             }
     84 
     85             /**
     86              * Returns the  CO2 equivalent value.
     87              */
     88             float co2equ();
     89 
     90             /**
     91              * Returns VOC Short value.
     92              */
     93             int vocshort();
     94 
     95             /**
     96              * Returns Total VOC.
     97              */
     98             float tvoc();
     99 
    100             /**
    101              * Returns resistor value.
    102              */
    103             float resistor();
    104 
    105             /**
    106              * Performs a write/read cycle.
    107              */
    108             void update();
    109 
    110             /**
    111              * Returns true if a valid write/read cycle has been completed.
    112              * At startup and during write/read cycle will be false.
    113              */
    114             bool valid()
    115             {
    116                 return m_valid;
    117             }
    118 
    119         private:
    120             std::string m_name;
    121             bool m_valid;
    122             uint8_t m_address;
    123             uint8_t rx_buf[6];
    124             uint8_t tx_buf[3];
    125             mraa::I2c* i2c;
    126     };
    127 }
    128