micsv89: made few aesthetic formatting changes and renamed update function

Signed-off-by: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
This commit is contained in:
Mihai Tudor Panu 2015-10-06 12:13:18 -07:00
parent bf856c5fca
commit 81c5962220
4 changed files with 79 additions and 96 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 906 KiB

After

Width:  |  Height:  |  Size: 44 KiB

View File

@ -22,15 +22,11 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
#include "mraa.hpp"
#include <iostream> #include <iostream>
#include <unistd.h> #include <unistd.h>
#include <signal.h>
#include "micsv89.h" #include "micsv89.h"
/* /*
* An example for using the MICSV89 sensor library. * An example for using the MICSV89 sensor library.
* The MICSV89 comes in 4 variants, PWM and I2c * The MICSV89 comes in 4 variants, PWM and I2c
@ -40,39 +36,43 @@
* Device output is not valid until a warm up of 15 minutes * Device output is not valid until a warm up of 15 minutes
* of operation. * of operation.
* *
* Additional linker flags: none * Additional linker flags: -lupm-micsv89
*/ */
using namespace std; using namespace std;
upm::MICSV89 *sensor = NULL; volatile int running = 1;
void
sig_handler(int signo)
{
if (signo == SIGINT) {
cout << "Exiting program." << endl;
running = 0;
}
}
int main() int main()
{ {
signal(SIGINT, sig_handler);
//! [Interesting]
upm::MICSV89 *sensor = new upm::MICSV89(6);
sensor = new upm::MICSV89(6); while(running)
{
sensor->update();
while(!sensor->valid());
cout << "co2: " << sensor->co2equ() << endl;
cout << "short: " << sensor->vocshort() << endl;
cout << "tvoc: " << sensor->tvoc() << endl;
cout << "resistor: " << sensor->resistor() << endl;
cout << "****************************" << endl;
sleep(5);
}
delete sensor;
//! [Interesting]
return MRAA_SUCCESS;
while(true)
{
sensor->start();
while(!sensor->valid());
cout << "co2: " << sensor->co2equ() << endl;
cout << "short: " << sensor->vocshort() << endl;
cout << "tvoc: " << sensor->tvoc() << endl;
cout << "resistor: " << sensor->resistor() << endl;
cout << "****************************" << endl;
sleep(5);
}
delete sensor;
return MRAA_SUCCESS;
} }

View File

@ -22,59 +22,48 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
#include "micsv89.h" #include "micsv89.h"
using namespace upm; using namespace upm;
MICSV89::MICSV89 (int bus, uint8_t address) { MICSV89::MICSV89 (int bus, uint8_t address) {
m_name = "micsv89"; m_name = "micsv89";
m_valid = false; m_valid = false;
m_address = address; m_address = address;
i2c = new mraa::I2c(bus); i2c = new mraa::I2c(bus);
tx_buf[0] = 0x09; tx_buf[0] = 0x09;
tx_buf[1] = 0x00; tx_buf[1] = 0x00;
tx_buf[2] = 0x00; tx_buf[2] = 0x00;
} }
void MICSV89::update() {
void MICSV89::start() m_valid = false;
{ i2c->address(m_address);
m_valid = false; i2c->frequency(MRAA_I2C_STD);
i2c->address(m_address); i2c->write(tx_buf, 3);
i2c->frequency(MRAA_I2C_STD); sleep(1); //Give the device time to make the measurement.
i2c->write(tx_buf, 3); i2c->address(m_address);
sleep(1); //Give the device time to make the measurement. i2c->frequency(MRAA_I2C_STD);
i2c->address(m_address); i2c->read(rx_buf, 6);
i2c->frequency(MRAA_I2C_STD); m_valid = true;
i2c->read(rx_buf, 6);
m_valid = true;
} }
float MICSV89::co2equ() float MICSV89::co2equ() {
{ return ((rx_buf[0] - 13) * (1600/229) + 400);
return ((rx_buf[0] - 13) * (1600/229) + 400);
} }
int MICSV89::vocshort() int MICSV89::vocshort() {
{ return rx_buf[1];
return rx_buf[1];
} }
float MICSV89::tvoc() float MICSV89::tvoc() {
{ return rx_buf[2] * (1000/229);
return rx_buf[2] * (1000/229);
} }
float MICSV89::resistor() float MICSV89::resistor() {
{ return 10 * (rx_buf[3] + (256 * rx_buf[4]) + (65536 * rx_buf[5]));
return 10 * (rx_buf[3] + (256 * rx_buf[4]) + (65536 * rx_buf[5]));
} }
MICSV89::~MICSV89 () { MICSV89::~MICSV89() {
delete i2c; delete i2c;
} }

View File

@ -22,8 +22,6 @@
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/ */
#pragma once #pragma once
#include <iostream> #include <iostream>
@ -31,33 +29,34 @@
#include "mraa.hpp" #include "mraa.hpp"
#include "mraa/i2c.hpp" #include "mraa/i2c.hpp"
namespace upm { namespace upm {
/** /**
* @library gas * @brief MICS-VZ89 environmental sensor library
* @sensor MICS-V89 * @defgroup micsv89 libupm-micsv89
* @comname MICS-V89 * @ingroup generic i2c gaseous
* @type Environmental. VOC and CO2 */
* @man http://sgx.cdistore.com/datasheets/e2v/MiCS-VZ-86%20and%20VZ-89%20rev%204.pdf /**
* @man http://www.sgxsensortech.com/content/uploads/2015/01/MICS-VZ-89-I2C-specs-rev-A.pdf * @library micsv89
* @sensor micsv89
* @comname MICS-VZ89 Gas Sensor
* @type gaseous
* @man generic
* @con i2c * @con i2c
* @web http://sgx.cdistore.com/datasheets/e2v/MiCS-VZ-86%20and%20VZ-89%20rev%204.pdf
* @web http://www.sgxsensortech.com/content/uploads/2015/01/MICS-VZ-89-I2C-specs-rev-A.pdf
* *
* @brief API for the MICS-VZ89 Gas Sensor * @brief API for the MICS-VZ89 Gas Sensor
* The MiCS-VZ-86/89 combines state-of-the-art MOS
* sensor technology with intelligent detection algorithms
* to monitor VOCs and CO2 equivalent variations in
* confined spaces.
* *
* The MICSV89 comes in 4 variants, PWM and I2c * The MiCS-VZ-86/89 combines state-of-the-art MOS sensor technology with
* in 3.3 volts and 5 volts. This library only implements * intelligent detection algorithms to monitor VOCs and CO2 equivalent
* the I2c version of the device. * variations in confined spaces.
* *
* Device output is not valid until a warm up of 15 minutes * The MICSV89 comes in 4 variants, PWM and I2C in 3.3 volts and 5 volts.
* of operation. * This library only implements the I2c version of the device.
* *
* Device output is not valid until a warm up of 15 minutes of operation.
* *
* @image html micsv89.jpg * @image html micsv89.jpg
* @snippet micsv89.cxx Interesting * @snippet micsv89.cxx Interesting
*/ */
class MICSV89 { class MICSV89 {
@ -84,7 +83,7 @@ namespace upm {
} }
/** /**
* Returns the CO2 equivalent value. * Returns the CO2 equivalent value.
*/ */
float co2equ(); float co2equ();
@ -106,7 +105,7 @@ namespace upm {
/** /**
* Performs a write/read cycle. * Performs a write/read cycle.
*/ */
void start(); void update();
/** /**
* Returns true if a valid write/read cycle has been completed. * Returns true if a valid write/read cycle has been completed.
@ -114,20 +113,15 @@ namespace upm {
*/ */
bool valid() bool valid()
{ {
return m_valid; return m_valid;
} }
private: private:
std::string m_name; std::string m_name;
bool m_valid; bool m_valid;
uint8_t m_address; uint8_t m_address;
uint8_t rx_buf[6]; uint8_t rx_buf[6];
uint8_t tx_buf[3]; uint8_t tx_buf[3];
mraa::I2c* i2c; mraa::I2c* i2c;
}; };
} }