mirror of
https://github.com/eclipse/upm.git
synced 2025-03-14 20:47:30 +03:00
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:
parent
bf856c5fca
commit
81c5962220
Binary file not shown.
Before Width: | Height: | Size: 906 KiB After Width: | Height: | Size: 44 KiB |
@ -22,15 +22,11 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "mraa.hpp"
|
||||
|
||||
|
||||
#include <iostream>
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
#include "micsv89.h"
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* An example for using the MICSV89 sensor library.
|
||||
* 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
|
||||
* of operation.
|
||||
*
|
||||
* Additional linker flags: none
|
||||
* Additional linker flags: -lupm-micsv89
|
||||
*/
|
||||
|
||||
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()
|
||||
{
|
||||
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]
|
||||
|
||||
|
||||
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;
|
||||
return MRAA_SUCCESS;
|
||||
}
|
||||
|
@ -22,59 +22,48 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#include "micsv89.h"
|
||||
|
||||
|
||||
using namespace upm;
|
||||
|
||||
MICSV89::MICSV89 (int bus, uint8_t address) {
|
||||
m_name = "micsv89";
|
||||
m_valid = false;
|
||||
m_address = address;
|
||||
i2c = new mraa::I2c(bus);
|
||||
tx_buf[0] = 0x09;
|
||||
tx_buf[1] = 0x00;
|
||||
tx_buf[2] = 0x00;
|
||||
m_name = "micsv89";
|
||||
m_valid = false;
|
||||
m_address = address;
|
||||
i2c = new mraa::I2c(bus);
|
||||
tx_buf[0] = 0x09;
|
||||
tx_buf[1] = 0x00;
|
||||
tx_buf[2] = 0x00;
|
||||
}
|
||||
|
||||
|
||||
void MICSV89::start()
|
||||
{
|
||||
m_valid = false;
|
||||
i2c->address(m_address);
|
||||
i2c->frequency(MRAA_I2C_STD);
|
||||
i2c->write(tx_buf, 3);
|
||||
sleep(1); //Give the device time to make the measurement.
|
||||
i2c->address(m_address);
|
||||
i2c->frequency(MRAA_I2C_STD);
|
||||
i2c->read(rx_buf, 6);
|
||||
m_valid = true;
|
||||
void MICSV89::update() {
|
||||
m_valid = false;
|
||||
i2c->address(m_address);
|
||||
i2c->frequency(MRAA_I2C_STD);
|
||||
i2c->write(tx_buf, 3);
|
||||
sleep(1); //Give the device time to make the measurement.
|
||||
i2c->address(m_address);
|
||||
i2c->frequency(MRAA_I2C_STD);
|
||||
i2c->read(rx_buf, 6);
|
||||
m_valid = true;
|
||||
}
|
||||
|
||||
float MICSV89::co2equ()
|
||||
{
|
||||
return ((rx_buf[0] - 13) * (1600/229) + 400);
|
||||
float MICSV89::co2equ() {
|
||||
return ((rx_buf[0] - 13) * (1600/229) + 400);
|
||||
}
|
||||
|
||||
int MICSV89::vocshort()
|
||||
{
|
||||
return rx_buf[1];
|
||||
int MICSV89::vocshort() {
|
||||
return rx_buf[1];
|
||||
}
|
||||
|
||||
float MICSV89::tvoc()
|
||||
{
|
||||
return rx_buf[2] * (1000/229);
|
||||
float MICSV89::tvoc() {
|
||||
return rx_buf[2] * (1000/229);
|
||||
}
|
||||
|
||||
float MICSV89::resistor()
|
||||
{
|
||||
return 10 * (rx_buf[3] + (256 * rx_buf[4]) + (65536 * rx_buf[5]));
|
||||
float MICSV89::resistor() {
|
||||
return 10 * (rx_buf[3] + (256 * rx_buf[4]) + (65536 * rx_buf[5]));
|
||||
}
|
||||
|
||||
MICSV89::~MICSV89 () {
|
||||
delete i2c;
|
||||
MICSV89::~MICSV89() {
|
||||
delete i2c;
|
||||
}
|
||||
|
||||
|
||||
|
@ -22,8 +22,6 @@
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
@ -31,33 +29,34 @@
|
||||
#include "mraa.hpp"
|
||||
#include "mraa/i2c.hpp"
|
||||
|
||||
|
||||
|
||||
namespace upm {
|
||||
/**
|
||||
* @library gas
|
||||
* @sensor MICS-V89
|
||||
* @comname MICS-V89
|
||||
* @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
|
||||
* @brief MICS-VZ89 environmental sensor library
|
||||
* @defgroup micsv89 libupm-micsv89
|
||||
* @ingroup generic i2c gaseous
|
||||
*/
|
||||
/**
|
||||
* @library micsv89
|
||||
* @sensor micsv89
|
||||
* @comname MICS-VZ89 Gas Sensor
|
||||
* @type gaseous
|
||||
* @man generic
|
||||
* @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
|
||||
* 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
|
||||
* in 3.3 volts and 5 volts. This library only implements
|
||||
* the I2c version of the device.
|
||||
* 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.
|
||||
*
|
||||
* Device output is not valid until a warm up of 15 minutes
|
||||
* of operation.
|
||||
* The MICSV89 comes in 4 variants, PWM and I2C in 3.3 volts and 5 volts.
|
||||
* 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
|
||||
*/
|
||||
class MICSV89 {
|
||||
@ -84,7 +83,7 @@ namespace upm {
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the CO2 equivalent value.
|
||||
* Returns the CO2 equivalent value.
|
||||
*/
|
||||
float co2equ();
|
||||
|
||||
@ -106,7 +105,7 @@ namespace upm {
|
||||
/**
|
||||
* Performs a write/read cycle.
|
||||
*/
|
||||
void start();
|
||||
void update();
|
||||
|
||||
/**
|
||||
* Returns true if a valid write/read cycle has been completed.
|
||||
@ -114,20 +113,15 @@ namespace upm {
|
||||
*/
|
||||
bool valid()
|
||||
{
|
||||
return m_valid;
|
||||
return m_valid;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private:
|
||||
std::string m_name;
|
||||
bool m_valid;
|
||||
uint8_t m_address;
|
||||
uint8_t rx_buf[6];
|
||||
uint8_t tx_buf[3];
|
||||
mraa::I2c* i2c;
|
||||
|
||||
|
||||
uint8_t tx_buf[3];
|
||||
mraa::I2c* i2c;
|
||||
};
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user