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 #include <iostream> 26 #include <unistd.h> 27 #include <signal.h> 28 #include "micsv89.h" 29 30 /* 31 * An example for using the MICSV89 sensor library. 32 * The MICSV89 comes in 4 variants, PWM and I2c 33 * in 3.3 volts and 5 volts. This library only implements 34 * the I2c version of the device. 35 * 36 * Device output is not valid until a warm up of 15 minutes 37 * of operation. 38 * 39 * Additional linker flags: -lupm-micsv89 40 */ 41 42 using namespace std; 43 44 volatile int running = 1; 45 46 void 47 sig_handler(int signo) 48 { 49 if (signo == SIGINT) { 50 cout << "Exiting program." << endl; 51 running = 0; 52 } 53 } 54 55 int main() 56 { 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 } 79