2016-09-13 11:27:27 -06:00
|
|
|
/*
|
|
|
|
* Author: Jon Trulson <jtrulson@ics.com>
|
|
|
|
* Copyright (c) 2016 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.
|
2016-09-13 11:27:27 -06:00
|
|
|
*
|
2019-07-30 19:41:32 -07:00
|
|
|
* SPDX-License-Identifier: MIT
|
2016-09-13 11:27:27 -06:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <signal.h>
|
|
|
|
|
|
|
|
#include "ds18b20.h"
|
2016-09-19 15:45:22 -07:00
|
|
|
#include "upm_utilities.h"
|
2016-09-13 11:27:27 -06:00
|
|
|
|
|
|
|
bool shouldRun = true;
|
|
|
|
|
|
|
|
void sig_handler(int signo)
|
|
|
|
{
|
|
|
|
if (signo == SIGINT)
|
|
|
|
shouldRun = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2016-09-19 15:45:22 -07:00
|
|
|
signal(SIGINT, sig_handler);
|
2016-09-13 11:27:27 -06:00
|
|
|
|
2016-09-19 15:45:22 -07:00
|
|
|
//! [Interesting]
|
2016-09-13 11:27:27 -06:00
|
|
|
|
2016-09-19 15:45:22 -07:00
|
|
|
printf("Initializing...\n");
|
2016-09-13 11:27:27 -06:00
|
|
|
|
2016-09-19 15:45:22 -07:00
|
|
|
// Instantiate an DS18B20 instance using the uart 0
|
|
|
|
ds18b20_context sensor = ds18b20_init(0);
|
2016-09-13 11:27:27 -06:00
|
|
|
|
2016-09-19 15:45:22 -07:00
|
|
|
if (!sensor)
|
2016-09-13 11:27:27 -06:00
|
|
|
{
|
2016-09-19 15:45:22 -07:00
|
|
|
printf("ds18b20_init() failed.\n");
|
|
|
|
return(1);
|
2016-09-13 11:27:27 -06:00
|
|
|
}
|
|
|
|
|
2016-09-19 15:45:22 -07:00
|
|
|
printf("Found %d device(s)\n\n", ds18b20_devices_found(sensor));
|
2016-09-13 11:27:27 -06:00
|
|
|
|
2017-01-18 13:09:51 -07:00
|
|
|
// update and print available values every 2 seconds
|
2016-09-19 15:45:22 -07:00
|
|
|
while (shouldRun)
|
2016-09-13 11:27:27 -06:00
|
|
|
{
|
2016-09-19 15:45:22 -07:00
|
|
|
// update our values for all sensors
|
|
|
|
ds18b20_update(sensor, -1);
|
2016-09-13 11:27:27 -06:00
|
|
|
|
2018-02-07 12:17:54 -08:00
|
|
|
for (unsigned int i=0; i<ds18b20_devices_found(sensor); i++)
|
2016-09-13 11:27:27 -06:00
|
|
|
{
|
2016-09-19 15:45:22 -07:00
|
|
|
printf("Device %02d: Temperature: %f C\n",
|
|
|
|
i, ds18b20_get_temperature(sensor, i));
|
2016-09-13 11:27:27 -06:00
|
|
|
}
|
2016-09-19 15:45:22 -07:00
|
|
|
printf("\n");
|
2016-09-13 11:27:27 -06:00
|
|
|
|
2016-09-19 15:45:22 -07:00
|
|
|
upm_delay(2);
|
2016-09-13 11:27:27 -06:00
|
|
|
}
|
|
|
|
|
2016-09-19 15:45:22 -07:00
|
|
|
printf("Exiting...\n");
|
2016-09-13 11:27:27 -06:00
|
|
|
|
2016-09-19 15:45:22 -07:00
|
|
|
ds18b20_close(sensor);
|
|
|
|
//! [Interesting]
|
2016-09-13 11:27:27 -06:00
|
|
|
|
2016-09-19 15:45:22 -07:00
|
|
|
return 0;
|
2016-09-13 11:27:27 -06:00
|
|
|
}
|