2014-08-26 20:39:58 +00:00
|
|
|
/*
|
|
|
|
* Author: Yevgeniy Kiveisha <yevgeniy.kiveisha@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-08-26 20:39:58 +00:00
|
|
|
*
|
2019-07-30 19:41:32 -07:00
|
|
|
* SPDX-License-Identifier: MIT
|
2014-08-26 20:39:58 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
#include <signal.h>
|
2017-08-30 15:00:29 -07:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
#include "gas.hpp"
|
|
|
|
#include "mq5.hpp"
|
2014-08-26 20:39:58 +00:00
|
|
|
|
|
|
|
int is_running = 0;
|
2017-08-30 15:00:29 -07:00
|
|
|
uint16_t buffer[128];
|
2014-08-26 20:39:58 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
sig_handler(int signo)
|
|
|
|
{
|
|
|
|
printf("got signal\n");
|
|
|
|
if (signo == SIGINT) {
|
|
|
|
is_running = 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
//! [Interesting]
|
|
|
|
int
|
2017-08-30 15:00:29 -07:00
|
|
|
main(int argc, char** argv)
|
2014-08-26 20:39:58 +00:00
|
|
|
{
|
2017-08-30 15:00:29 -07:00
|
|
|
upm::MQ5 sensor(0);
|
2014-08-26 20:39:58 +00:00
|
|
|
signal(SIGINT, sig_handler);
|
|
|
|
|
|
|
|
thresholdContext ctx;
|
|
|
|
ctx.averageReading = 0;
|
|
|
|
ctx.runningAverage = 0;
|
2017-08-30 15:00:29 -07:00
|
|
|
ctx.averagedOver = 2;
|
2014-08-26 20:39:58 +00:00
|
|
|
|
|
|
|
while (!is_running) {
|
2017-08-30 15:00:29 -07:00
|
|
|
int len = sensor.getSampledWindow(2, 128, buffer);
|
2014-08-26 20:39:58 +00:00
|
|
|
if (len) {
|
2017-08-30 15:00:29 -07:00
|
|
|
int thresh = sensor.findThreshold(&ctx, 30, buffer, len);
|
|
|
|
sensor.printGraph(&ctx, 7);
|
2014-08-26 20:39:58 +00:00
|
|
|
if (thresh) {
|
|
|
|
// do something ....
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
std::cout << "exiting application" << std::endl;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
//! [Interesting]
|