2015-02-05 11:38:05 -07:00
|
|
|
/*
|
|
|
|
* Author: Jon Trulson <jtrulson@ics.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.
|
2015-02-05 11:38:05 -07:00
|
|
|
*
|
2019-07-30 19:41:32 -07:00
|
|
|
* SPDX-License-Identifier: MIT
|
2015-02-05 11:38:05 -07:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <iomanip>
|
2017-08-30 15:00:29 -07:00
|
|
|
#include <iostream>
|
2015-02-05 11:38:05 -07:00
|
|
|
#include <signal.h>
|
2017-08-30 15:00:29 -07:00
|
|
|
#include <stdexcept>
|
|
|
|
#include <string>
|
|
|
|
|
2016-04-25 14:27:51 -07:00
|
|
|
#include "otp538u.hpp"
|
2017-08-30 15:00:29 -07:00
|
|
|
#include "upm_utilities.h"
|
2015-02-05 11:38:05 -07:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
bool shouldRun = true;
|
|
|
|
|
|
|
|
// analog voltage, usually 3.3 or 5.0
|
2017-08-30 15:00:29 -07:00
|
|
|
#define OTP538U_AREF 5.0
|
2015-02-05 11:38:05 -07:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
void
|
|
|
|
sig_handler(int signo)
|
2015-02-05 11:38:05 -07:00
|
|
|
{
|
2017-08-30 15:00:29 -07:00
|
|
|
if (signo == SIGINT)
|
|
|
|
shouldRun = false;
|
2015-02-05 11:38:05 -07:00
|
|
|
}
|
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
int
|
|
|
|
main()
|
2015-02-05 11:38:05 -07:00
|
|
|
{
|
2017-08-30 15:00:29 -07:00
|
|
|
signal(SIGINT, sig_handler);
|
|
|
|
|
|
|
|
//! [Interesting]
|
2015-02-05 11:38:05 -07:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
// Instantiate a OTP538U on analog pins A0 and A1
|
|
|
|
// A0 is used for the Ambient Temperature and A1 is used for the
|
|
|
|
// Object temperature.
|
|
|
|
upm::OTP538U temps(0, 1, OTP538U_AREF);
|
2015-02-05 11:38:05 -07:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
// enable debugging if you would like
|
|
|
|
// temps.setDebug(true);
|
2016-08-16 11:07:56 -06:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
// Output ambient and object temperatures
|
|
|
|
while (shouldRun) {
|
|
|
|
try {
|
|
|
|
cout << "Ambient temp: " << std::fixed << setprecision(2) << temps.ambientTemperature()
|
|
|
|
<< " C, Object temp: " << temps.objectTemperature() << " C" << endl;
|
|
|
|
} catch (std::out_of_range& e) {
|
|
|
|
cerr << "Temperature(s) are out of range: " << e.what() << endl;
|
|
|
|
}
|
2016-08-16 11:07:56 -06:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
cout << endl;
|
|
|
|
upm_delay(1);
|
2015-02-05 11:38:05 -07:00
|
|
|
}
|
2017-08-30 15:00:29 -07:00
|
|
|
//! [Interesting]
|
2015-02-05 11:38:05 -07:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
cout << "Exiting" << endl;
|
2015-02-05 11:38:05 -07:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
return 0;
|
2015-02-05 11:38:05 -07:00
|
|
|
}
|