2014-11-21 07:46:12 -08:00
|
|
|
/*
|
|
|
|
* Author: William Penner <william.penner@intel.com>
|
|
|
|
* 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>
|
|
|
|
#include <signal.h>
|
2017-08-30 15:00:29 -07:00
|
|
|
#include <stdio.h>
|
2014-11-21 07:46:12 -08:00
|
|
|
|
2016-04-25 14:27:51 -07:00
|
|
|
#include "htu21d.hpp"
|
2017-08-30 15:00:29 -07:00
|
|
|
#include "upm_utilities.h"
|
2014-11-25 20:34:35 +00:00
|
|
|
|
|
|
|
volatile int doWork = 0;
|
|
|
|
|
2014-11-21 07:46:12 -08:00
|
|
|
void
|
|
|
|
sig_handler(int signo)
|
|
|
|
{
|
|
|
|
if (signo == SIGINT) {
|
2014-11-25 20:34:35 +00:00
|
|
|
printf("\nCtrl-C received.\n");
|
2014-11-21 07:46:12 -08:00
|
|
|
doWork = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2017-08-30 15:00:29 -07:00
|
|
|
main(int argc, char** argv)
|
2014-11-21 07:46:12 -08:00
|
|
|
{
|
2014-11-25 20:34:35 +00:00
|
|
|
// Register signal handler
|
|
|
|
signal(SIGINT, sig_handler);
|
|
|
|
|
2014-11-21 07:46:12 -08:00
|
|
|
//! [Interesting]
|
2017-08-30 15:00:29 -07:00
|
|
|
float humidity = 0.0;
|
2014-11-25 20:34:35 +00:00
|
|
|
float temperature = 0.0;
|
2017-08-30 15:00:29 -07:00
|
|
|
float compRH = 0.0;
|
2014-11-21 07:46:12 -08:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
upm::HTU21D sensor(0, HTU21D_I2C_ADDRESS);
|
2014-11-21 07:46:12 -08:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
sensor.testSensor();
|
2014-11-25 20:34:35 +00:00
|
|
|
|
2014-11-21 07:46:12 -08:00
|
|
|
while (!doWork) {
|
2017-08-30 15:00:29 -07:00
|
|
|
compRH = sensor.getCompRH(true);
|
|
|
|
humidity = sensor.getHumidity(false);
|
|
|
|
temperature = sensor.getTemperature(false);
|
2014-11-21 07:46:12 -08:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
std::cout << "humidity value = " << humidity << ", temperature value = " << temperature
|
|
|
|
<< ", compensated RH value = " << compRH << std::endl;
|
|
|
|
upm_delay_us(500000);
|
2014-11-21 07:46:12 -08:00
|
|
|
}
|
|
|
|
//! [Interesting]
|
|
|
|
|
|
|
|
std::cout << "exiting application" << std::endl;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|