2014-12-19 09:20:48 -05:00
|
|
|
/*
|
|
|
|
* Author: Zion Orent <zorent@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.
|
2014-12-19 09:20:48 -05:00
|
|
|
*
|
2019-07-30 19:41:32 -07:00
|
|
|
* SPDX-License-Identifier: MIT
|
2014-12-19 09:20:48 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <signal.h>
|
2017-08-30 15:00:29 -07:00
|
|
|
#include <string>
|
|
|
|
|
2016-04-25 14:27:51 -07:00
|
|
|
#include "ppd42ns.hpp"
|
2014-12-19 09:20:48 -05:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
int shouldRun = true;
|
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
void
|
|
|
|
sig_handler(int signo)
|
2014-12-19 09:20:48 -05:00
|
|
|
{
|
2016-11-02 17:38:44 -06:00
|
|
|
if (signo == SIGINT)
|
|
|
|
shouldRun = false;
|
2014-12-19 09:20:48 -05:00
|
|
|
}
|
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
int
|
|
|
|
main()
|
2014-12-19 09:20:48 -05:00
|
|
|
{
|
2016-11-02 17:38:44 -06:00
|
|
|
signal(SIGINT, sig_handler);
|
2014-12-19 09:20:48 -05:00
|
|
|
|
2017-08-30 15:00:29 -07:00
|
|
|
//! [Interesting]
|
2016-11-02 17:38:44 -06:00
|
|
|
// Instantiate a dust sensor on GPIO pin D8
|
2017-08-30 15:00:29 -07:00
|
|
|
upm::PPD42NS dust(8);
|
2016-11-02 17:38:44 -06:00
|
|
|
ppd42ns_dust_data data;
|
|
|
|
cout << "This program will give readings every 30 seconds until "
|
2017-08-30 15:00:29 -07:00
|
|
|
<< "you stop it" << endl;
|
|
|
|
while (shouldRun) {
|
|
|
|
data = dust.getData();
|
2016-11-02 17:38:44 -06:00
|
|
|
cout << "Low pulse occupancy: " << data.lowPulseOccupancy << endl;
|
|
|
|
cout << "Ratio: " << data.ratio << endl;
|
|
|
|
cout << "Concentration: " << data.concentration << endl;
|
|
|
|
cout << endl;
|
|
|
|
}
|
2017-08-30 15:00:29 -07:00
|
|
|
//! [Interesting]
|
2014-12-19 09:20:48 -05:00
|
|
|
|
2016-11-02 17:38:44 -06:00
|
|
|
cout << "Exiting" << endl;
|
2014-12-19 09:20:48 -05:00
|
|
|
|
2016-11-02 17:38:44 -06:00
|
|
|
return 0;
|
2014-12-19 09:20:48 -05:00
|
|
|
}
|