examples: Cleaned up C examples.

This commit cleans up multiple items with the UPM C example source.

    * Switch from usleep and sleep to upm_delay* methods
    * Include a mraa_init and check return value prior to using sensor
    * All example mains now return
    * Added include for mraa.h and upm_utilites.h to all examples
    * Reformatted/removed tabs
    * Updated author line for the examples I wrote

Signed-off-by: Noel Eck <noel.eck@intel.com>
This commit is contained in:
Noel Eck
2016-09-19 15:45:22 -07:00
parent 2ccdc3e673
commit 324af8fc92
35 changed files with 775 additions and 482 deletions

View File

@ -26,6 +26,8 @@
#include <signal.h>
#include "nmea_gps.h"
#include "upm_utilities.h"
#include "mraa.h"
bool shouldRun = true;
@ -39,42 +41,48 @@ void sig_handler(int signo)
int main()
{
signal(SIGINT, sig_handler);
//! [Interesting]
// Instantiate a NMEA_GPS sensor on uart 0 at 9600 baud with enable
// pin on D3. If you do not need an enable pin, you can specify -1.
nmea_gps_context sensor = nmea_gps_init(0, 9600, 3);
if (!sensor)
if (mraa_init() != MRAA_SUCCESS)
{
printf("nmea_gps_init() failed.\n");
return 1;
perror("Failed to initialize mraa\n");
return -1;
}
char buffer[bufferLength];
int rv = 0;
signal(SIGINT, sig_handler);
// loop, dumping NMEA data out as fast as it comes in
while (shouldRun && nmea_gps_data_available(sensor, 5000))
//! [Interesting]
// Instantiate a NMEA_GPS sensor on uart 0 at 9600 baud with enable
// pin on D3. If you do not need an enable pin, you can specify -1.
nmea_gps_context sensor = nmea_gps_init(0, 9600, 3);
if (!sensor)
{
if ((rv = nmea_gps_read(sensor, buffer, bufferLength)) >= 0)
printf("nmea_gps_init() failed.\n");
return 1;
}
char buffer[bufferLength];
int rv = 0;
// loop, dumping NMEA data out as fast as it comes in
while (shouldRun && nmea_gps_data_available(sensor, 5000))
{
if ((rv = nmea_gps_read(sensor, buffer, bufferLength)) >= 0)
{
int i;
for (i=0; i<rv; i++)
printf("%c", buffer[i]);
int i;
for (i=0; i<rv; i++)
printf("%c", buffer[i]);
}
}
if (shouldRun)
printf("Timed out\n");
if (shouldRun)
printf("Timed out\n");
//! [Interesting]
//! [Interesting]
printf("Exiting\n");
printf("Exiting\n");
nmea_gps_close(sensor);
nmea_gps_close(sensor);
return 0;
return 0;
}