2014-11-26 17:37:06 +00:00
|
|
|
/*
|
2015-02-10 11:34:28 -08:00
|
|
|
* Author: Mihai Tudor Panu <mihai.tudor.panu@intel.com>
|
2014-11-26 17:37:06 +00:00
|
|
|
* Copyright (c) 2014 Intel Corporation.
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be
|
|
|
|
* included in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
|
|
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
|
|
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
|
|
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
|
|
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <iostream>
|
2017-08-30 15:00:29 -07:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string>
|
|
|
|
|
2016-04-25 14:27:51 -07:00
|
|
|
#include "tp401.hpp"
|
2017-08-30 15:00:29 -07:00
|
|
|
#include "upm_utilities.h"
|
2014-11-26 17:37:06 +00:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
//! [Interesting]
|
|
|
|
// Give a qualitative meaning to the value from the sensor
|
|
|
|
std::string
|
|
|
|
airQuality(uint16_t value)
|
|
|
|
{
|
2017-08-30 15:00:29 -07:00
|
|
|
if (value < 50)
|
|
|
|
return "Fresh Air";
|
|
|
|
if (value < 200)
|
|
|
|
return "Normal Indoor Air";
|
|
|
|
if (value < 400)
|
|
|
|
return "Low Pollution";
|
|
|
|
if (value < 600)
|
|
|
|
return "High Pollution - Action Recommended";
|
2014-11-26 17:37:06 +00:00
|
|
|
return "Very High Pollution - Take Action Immediately";
|
|
|
|
}
|
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
int
|
|
|
|
main()
|
2014-11-26 17:37:06 +00:00
|
|
|
{
|
2017-08-30 15:00:29 -07:00
|
|
|
upm::TP401 airSensor(0);
|
2014-11-26 17:37:06 +00:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
cout << airSensor.name() << endl;
|
2014-11-26 17:37:06 +00:00
|
|
|
|
|
|
|
fprintf(stdout, "Heating sensor for 3 minutes...\n");
|
|
|
|
// wait 3 minutes for sensor to warm up
|
2017-08-30 15:00:29 -07:00
|
|
|
for (int i = 0; i < 3; i++) {
|
|
|
|
if (i) {
|
2014-11-26 17:37:06 +00:00
|
|
|
fprintf(stdout, "Please wait, %d minute(s) passed..\n", i);
|
|
|
|
}
|
2017-08-30 15:00:29 -07:00
|
|
|
upm_delay(60);
|
2014-11-26 17:37:06 +00:00
|
|
|
}
|
|
|
|
fprintf(stdout, "Sensor ready!\n");
|
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
while (true) {
|
|
|
|
uint16_t value = airSensor.getSample(); // Read raw value
|
|
|
|
float ppm = airSensor.getPPM(); // Read CO ppm (can vary slightly from previous read)
|
2014-11-26 17:37:06 +00:00
|
|
|
fprintf(stdout, "raw: %4d ppm: %5.2f %s\n", value, ppm, airQuality(value).c_str());
|
2017-08-30 15:00:29 -07:00
|
|
|
upm_delay_us(2500000); // Sleep for 2.5s
|
2014-11-26 17:37:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
//! [Interesting]
|