Browse Source

micsv89: made few aesthetic formatting changes and renamed update function

Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
Mihai Tudor Panu 9 years ago
parent
commit
81c5962220
4 changed files with 83 additions and 100 deletions
  1. BIN
      docs/images/micsv89.jpg
  2. 32
    32
      examples/c++/micsv89.cxx
  3. 27
    38
      src/micsv89/micsv89.cxx
  4. 24
    30
      src/micsv89/micsv89.h

BIN
docs/images/micsv89.jpg View File


+ 32
- 32
examples/c++/micsv89.cxx View File

@@ -22,15 +22,11 @@
22 22
  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 23
  */
24 24
 
25
-#include "mraa.hpp"
26
-
27
-
28 25
 #include <iostream>
29 26
 #include <unistd.h>
27
+#include <signal.h>
30 28
 #include "micsv89.h"
31 29
 
32
-
33
-
34 30
 /*
35 31
  * An example for using the MICSV89 sensor library.
36 32
  * The MICSV89 comes in 4 variants, PWM and I2c
@@ -40,39 +36,43 @@
40 36
  * Device output is not valid until a warm up of 15 minutes
41 37
  * of operation.
42 38
  *
43
- * Additional linker flags: none
39
+ * Additional linker flags: -lupm-micsv89
44 40
  */
45 41
 
46 42
 using namespace std;
47 43
 
48
-upm::MICSV89 *sensor = NULL;
44
+volatile int running = 1;
49 45
 
46
+void
47
+sig_handler(int signo)
48
+{
49
+    if (signo == SIGINT) {
50
+        cout << "Exiting program." << endl;
51
+        running = 0;
52
+    }
53
+}
50 54
 
51 55
 int main()
52 56
 {
53
-
54
-
55
-	sensor = new upm::MICSV89(6);
56
-
57
-
58
-
59
-	while(true)
60
-	{
61
-		sensor->start();
62
-		while(!sensor->valid());
63
-		cout << "co2: " << sensor->co2equ() << endl;
64
-		cout << "short: " << sensor->vocshort() << endl;
65
-		cout << "tvoc: " << sensor->tvoc() << endl;
66
-		cout << "resistor: " << sensor->resistor() << endl;
67
-		cout << "****************************" << endl;
68
-		sleep(5);
69
-
70
-	}
71
-
72
-
73
-
74
-	delete sensor;
75
-
76
-
77
-	return MRAA_SUCCESS;
57
+    signal(SIGINT, sig_handler);
58
+
59
+//! [Interesting]
60
+    upm::MICSV89 *sensor = new upm::MICSV89(6);
61
+
62
+    while(running)
63
+    {
64
+        sensor->update();
65
+        while(!sensor->valid());
66
+        cout << "co2: " << sensor->co2equ() << endl;
67
+        cout << "short: " << sensor->vocshort() << endl;
68
+        cout << "tvoc: " << sensor->tvoc() << endl;
69
+        cout << "resistor: " << sensor->resistor() << endl;
70
+        cout << "****************************" << endl;
71
+        sleep(5);
72
+    }
73
+
74
+    delete sensor;
75
+//! [Interesting]
76
+
77
+    return MRAA_SUCCESS;
78 78
 }

+ 27
- 38
src/micsv89/micsv89.cxx View File

@@ -22,59 +22,48 @@
22 22
  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 23
  */
24 24
 
25
-
26
-
27 25
 #include "micsv89.h"
28 26
 
29
-
30 27
 using namespace upm;
31 28
 
32 29
 MICSV89::MICSV89 (int bus, uint8_t address) {
33
-	m_name = "micsv89";
34
-	m_valid = false;
35
-	m_address = address;
36
-	i2c = new mraa::I2c(bus);
37
-	tx_buf[0] = 0x09;
38
-	tx_buf[1] = 0x00;
39
-	tx_buf[2] = 0x00;
30
+    m_name = "micsv89";
31
+    m_valid = false;
32
+    m_address = address;
33
+    i2c = new mraa::I2c(bus);
34
+    tx_buf[0] = 0x09;
35
+    tx_buf[1] = 0x00;
36
+    tx_buf[2] = 0x00;
40 37
 }
41 38
 
42
-
43
-void MICSV89::start()
44
-{
45
-	m_valid = false;
46
-	i2c->address(m_address);
47
-	i2c->frequency(MRAA_I2C_STD);
48
-	i2c->write(tx_buf, 3);
49
-	sleep(1); //Give the device time to make the measurement.
50
-	i2c->address(m_address);
51
-	i2c->frequency(MRAA_I2C_STD);
52
-	i2c->read(rx_buf, 6);
53
-	m_valid = true;
39
+void MICSV89::update() {
40
+    m_valid = false;
41
+    i2c->address(m_address);
42
+    i2c->frequency(MRAA_I2C_STD);
43
+    i2c->write(tx_buf, 3);
44
+    sleep(1); //Give the device time to make the measurement.
45
+    i2c->address(m_address);
46
+    i2c->frequency(MRAA_I2C_STD);
47
+    i2c->read(rx_buf, 6);
48
+    m_valid = true;
54 49
 }
55 50
 
56
-float MICSV89::co2equ()
57
-{
58
-	return ((rx_buf[0] - 13) * (1600/229) + 400);
51
+float MICSV89::co2equ() {
52
+    return ((rx_buf[0] - 13) * (1600/229) + 400);
59 53
 }
60 54
 
61
-int MICSV89::vocshort()
62
-{
63
-	return rx_buf[1];
55
+int MICSV89::vocshort() {
56
+    return rx_buf[1];
64 57
 }
65 58
 
66
-float MICSV89::tvoc()
67
-{
68
-	return rx_buf[2] * (1000/229);
59
+float MICSV89::tvoc() {
60
+    return rx_buf[2] * (1000/229);
69 61
 }
70 62
 
71
-float MICSV89::resistor()
72
-{
73
-	return 10 * (rx_buf[3] + (256 * rx_buf[4]) + (65536 * rx_buf[5]));
63
+float MICSV89::resistor() {
64
+    return 10 * (rx_buf[3] + (256 * rx_buf[4]) + (65536 * rx_buf[5]));
74 65
 }
75 66
 
76
-MICSV89::~MICSV89 () {
77
-	delete i2c;
67
+MICSV89::~MICSV89() {
68
+    delete i2c;
78 69
 }
79
-
80
-

+ 24
- 30
src/micsv89/micsv89.h View File

@@ -22,8 +22,6 @@
22 22
  * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 23
  */
24 24
 
25
-
26
-
27 25
 #pragma once
28 26
 
29 27
 #include <iostream>
@@ -31,33 +29,34 @@
31 29
 #include "mraa.hpp"
32 30
 #include "mraa/i2c.hpp"
33 31
 
34
-
35
-
36 32
 namespace upm {
37 33
   /**
38
-   * @library gas
39
-   * @sensor  MICS-V89
40
-   * @comname MICS-V89
41
-   * @type Environmental. VOC and CO2
42
-   * @man http://sgx.cdistore.com/datasheets/e2v/MiCS-VZ-86%20and%20VZ-89%20rev%204.pdf
43
-   * @man http://www.sgxsensortech.com/content/uploads/2015/01/MICS-VZ-89-I2C-specs-rev-A.pdf
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 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
45 47
    *
46 48
    * @brief API for the MICS-VZ89 Gas Sensor
47
-   * The MiCS-VZ-86/89 combines state-of-the-art MOS
48
-   * sensor technology with intelligent detection algorithms
49
-   * to monitor VOCs and CO2 equivalent variations in
50
-   * confined spaces.
51 49
    *
52
-   * The MICSV89 comes in 4 variants, PWM and I2c
53
-   * in 3.3 volts and 5 volts. This library only implements
54
-   * the I2c version of the device.
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.
55 53
    *
56
-   * Device output is not valid until a warm up of 15 minutes
57
-   * of operation.
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.
58 56
    *
57
+   * Device output is not valid until a warm up of 15 minutes of operation.
59 58
    *
60
-   * @image html micsv89.jpg 
59
+   * @image html micsv89.jpg
61 60
    * @snippet micsv89.cxx Interesting
62 61
    */
63 62
     class MICSV89 {
@@ -84,7 +83,7 @@ namespace upm {
84 83
             }
85 84
 
86 85
             /**
87
-             *	Returns the  CO2 equivalent value.
86
+             * Returns the  CO2 equivalent value.
88 87
              */
89 88
             float co2equ();
90 89
 
@@ -106,7 +105,7 @@ namespace upm {
106 105
             /**
107 106
              * Performs a write/read cycle.
108 107
              */
109
-            void start();
108
+            void update();
110 109
 
111 110
             /**
112 111
              * Returns true if a valid write/read cycle has been completed.
@@ -114,20 +113,15 @@ namespace upm {
114 113
              */
115 114
             bool valid()
116 115
             {
117
-            	return m_valid;
116
+                return m_valid;
118 117
             }
119 118
 
120
-
121
-
122
-
123 119
         private:
124 120
             std::string m_name;
125 121
             bool m_valid;
126 122
             uint8_t m_address;
127 123
             uint8_t rx_buf[6];
128
-           	uint8_t tx_buf[3];
129
-           	mraa::I2c* i2c;
130
-
131
-
124
+            uint8_t tx_buf[3];
125
+            mraa::I2c* i2c;
132 126
     };
133 127
 }