2014-12-19 13:18:11 -08:00
|
|
|
/*
|
|
|
|
* Author: William Penner <william.penner@intel.com>
|
|
|
|
* Copyright (c) 2014 Intel Corporation.
|
|
|
|
*
|
2019-07-30 19:41:32 -07:00
|
|
|
* This program and the accompanying materials are made available under the
|
|
|
|
* terms of the The MIT License which is available at
|
|
|
|
* https://opensource.org/licenses/MIT.
|
2014-12-19 13:18:11 -08:00
|
|
|
*
|
2019-07-30 19:41:32 -07:00
|
|
|
* SPDX-License-Identifier: MIT
|
2014-12-19 13:18:11 -08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <signal.h>
|
2017-08-30 15:00:29 -07:00
|
|
|
#include <stdio.h>
|
2014-12-19 13:18:11 -08:00
|
|
|
|
2016-04-25 14:27:51 -07:00
|
|
|
#include "am2315.hpp"
|
2017-08-30 15:00:29 -07:00
|
|
|
#include "upm_utilities.h"
|
2014-12-19 13:18:11 -08:00
|
|
|
|
|
|
|
volatile int doWork = 0;
|
|
|
|
|
|
|
|
void
|
|
|
|
sig_handler(int signo)
|
|
|
|
{
|
|
|
|
if (signo == SIGINT) {
|
|
|
|
printf("\nCtrl-C received.\n");
|
|
|
|
doWork = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2017-08-30 15:00:29 -07:00
|
|
|
main(int argc, char** argv)
|
2014-12-19 13:18:11 -08:00
|
|
|
{
|
|
|
|
// Register signal handler
|
|
|
|
signal(SIGINT, sig_handler);
|
|
|
|
|
|
|
|
//! [Interesting]
|
2017-08-30 15:00:29 -07:00
|
|
|
float humidity = 0.0;
|
2014-12-19 13:18:11 -08:00
|
|
|
float temperature = 0.0;
|
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
upm::AM2315 sensor(0, AM2315_I2C_ADDRESS);
|
2014-12-19 13:18:11 -08:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
sensor.testSensor();
|
2014-12-19 13:18:11 -08:00
|
|
|
|
|
|
|
while (!doWork) {
|
2017-08-30 15:00:29 -07:00
|
|
|
humidity = sensor.getHumidity();
|
|
|
|
temperature = sensor.getTemperature();
|
2014-12-19 13:18:11 -08:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
std::cout << "humidity value = " << humidity << ", temperature value = " << temperature
|
|
|
|
<< std::endl;
|
|
|
|
upm_delay_us(500000);
|
2014-12-19 13:18:11 -08:00
|
|
|
}
|
|
|
|
//! [Interesting]
|
|
|
|
|
|
|
|
std::cout << "exiting application" << std::endl;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|