mirror of
https://github.com/eclipse/upm.git
synced 2025-07-01 09:21:12 +03:00
hka5: Initial implementation
This module implements support for the DFRobot Laser PM2.5 Sensor. It connects to a UART at 9600 baud. This is the only baud rate supported. It optionally supports Reset and Set/Sleep gpios as well. Signed-off-by: Jon Trulson <jtrulson@ics.com>
This commit is contained in:
@ -276,6 +276,7 @@ add_example (ms5611)
|
||||
add_example (nmea_gps)
|
||||
add_example (mma7361)
|
||||
add_example (bh1750)
|
||||
add_example (hka5)
|
||||
|
||||
# These are special cases where you specify example binary, source file and module(s)
|
||||
include_directories (${PROJECT_SOURCE_DIR}/src)
|
||||
|
86
examples/c++/hka5.cxx
Normal file
86
examples/c++/hka5.cxx
Normal file
@ -0,0 +1,86 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2016 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <iostream>
|
||||
#include <signal.h>
|
||||
|
||||
#include "hka5.hpp"
|
||||
|
||||
using namespace std;
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate a HKA5 sensor on uart 0. We don't use the set or
|
||||
// reset pins, so we pass -1 for them.
|
||||
upm::HKA5 *sensor = new upm::HKA5(0, -1, -1);
|
||||
|
||||
// update once every 2 seconds and output data
|
||||
while (shouldRun)
|
||||
{
|
||||
sensor->update();
|
||||
|
||||
cout << "PM 1 : "
|
||||
<< sensor->getPM1()
|
||||
<< " ug/m3"
|
||||
<< endl;
|
||||
|
||||
cout << "PM 2.5: "
|
||||
<< sensor->getPM2_5()
|
||||
<< " ug/m3"
|
||||
<< endl;
|
||||
|
||||
cout << "PM 10 : "
|
||||
<< sensor->getPM10()
|
||||
<< " ug/m3"
|
||||
<< endl;
|
||||
|
||||
cout << endl;
|
||||
|
||||
sleep(2);
|
||||
}
|
||||
|
||||
if (shouldRun)
|
||||
cerr << "Timed out" << endl;
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
cout << "Exiting" << endl;
|
||||
|
||||
delete sensor;
|
||||
|
||||
return 0;
|
||||
}
|
@ -92,6 +92,7 @@ add_example (mma7361)
|
||||
add_example (bh1750)
|
||||
add_example (urm37)
|
||||
add_example (urm37-uart)
|
||||
add_example (hka5)
|
||||
|
||||
# Custom examples
|
||||
add_custom_example (nmea_gps_i2c-example-c nmea_gps_i2c.c nmea_gps)
|
||||
|
78
examples/c/hka5.c
Normal file
78
examples/c/hka5.c
Normal file
@ -0,0 +1,78 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2016 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <unistd.h>
|
||||
#include <signal.h>
|
||||
|
||||
#include "hka5.h"
|
||||
|
||||
bool shouldRun = true;
|
||||
|
||||
void sig_handler(int signo)
|
||||
{
|
||||
if (signo == SIGINT)
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
signal(SIGINT, sig_handler);
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
// Instantiate a HKA5 sensor on uart 0. We don't use the set or
|
||||
// reset pins, so we pass -1 for them.
|
||||
hka5_context sensor = hka5_init(0, -1, -1);
|
||||
|
||||
if (!sensor)
|
||||
{
|
||||
printf("hka5_init() failed.\n");
|
||||
return 1;
|
||||
}
|
||||
|
||||
// update once every 2 seconds and output data
|
||||
while (shouldRun)
|
||||
{
|
||||
if (hka5_update(sensor) != UPM_SUCCESS)
|
||||
{
|
||||
printf("hka5_update() failed, exiting.\n");
|
||||
shouldRun = false;
|
||||
}
|
||||
|
||||
printf("PM 1 : %d ug/m3\n", hka5_get_pm1(sensor));
|
||||
printf("PM 2.5: %d ug/m3\n", hka5_get_pm2_5(sensor));
|
||||
printf("PM 10 : %d ug/m3\n", hka5_get_pm10(sensor));
|
||||
printf("\n");
|
||||
|
||||
sleep(2);
|
||||
}
|
||||
|
||||
//! [Interesting]
|
||||
|
||||
printf("Exiting\n");
|
||||
|
||||
hka5_close(sensor);
|
||||
|
||||
return 0;
|
||||
}
|
@ -133,6 +133,7 @@ add_example(BMX055_Example bmx055)
|
||||
add_example(NMEAGPS_Example nmea_gps)
|
||||
add_example(MMA7361_Example mma7361)
|
||||
add_example(BH1750_Example bh1750)
|
||||
add_example(HKA5_Example hka5)
|
||||
|
||||
add_example_with_path(Jhd1313m1_lcdSample lcd i2clcd)
|
||||
add_example_with_path(Jhd1313m1Sample lcd i2clcd)
|
||||
|
59
examples/java/HKA5_Example.java
Normal file
59
examples/java/HKA5_Example.java
Normal file
@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2016 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
import upm_hka5.HKA5;
|
||||
|
||||
public class HKA5_Example
|
||||
{
|
||||
public static void main(String[] args) throws InterruptedException
|
||||
{
|
||||
// ! [Interesting]
|
||||
System.out.println("Initializing...");
|
||||
|
||||
// Instantiate a HKA5 sensor on uart 0. We don't use the set or
|
||||
// reset pins, so we pass -1 for them.
|
||||
HKA5 sensor = new HKA5(0, -1, -1);
|
||||
|
||||
// update once every 2 seconds and output data
|
||||
while (true)
|
||||
{
|
||||
sensor.update();
|
||||
|
||||
System.out.println("PM 1 : "
|
||||
+ sensor.getPM1()
|
||||
+ " ug/m3");
|
||||
System.out.println("PM 2.5: "
|
||||
+ sensor.getPM2_5()
|
||||
+ " ug/m3");
|
||||
System.out.println("PM 10 : "
|
||||
+ sensor.getPM10()
|
||||
+ " ug/m3");
|
||||
|
||||
System.out.println();
|
||||
Thread.sleep(2000);
|
||||
}
|
||||
|
||||
// ! [Interesting]
|
||||
}
|
||||
}
|
63
examples/javascript/hka5.js
Normal file
63
examples/javascript/hka5.js
Normal file
@ -0,0 +1,63 @@
|
||||
/*jslint node:true, vars:true, bitwise:true, unparam:true */
|
||||
/*jshint unused:true */
|
||||
|
||||
/*
|
||||
* Author: Jon Trulson <jtrulson@ics.com>
|
||||
* Copyright (c) 2016 Intel Corporation.
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining
|
||||
* a copy of this software and associated documentation files (the
|
||||
* "Software"), to deal in the Software without restriction, including
|
||||
* without limitation the rights to use, copy, modify, merge, publish,
|
||||
* distribute, sublicense, and/or sell copies of the Software, and to
|
||||
* permit persons to whom the Software is furnished to do so, subject to
|
||||
* the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be
|
||||
* included in all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
*/
|
||||
|
||||
var sensorObj = require('jsupm_hka5');
|
||||
|
||||
// Instantiate a HKA5 sensor on uart 0. We don't use the set or
|
||||
// reset pins, so we pass -1 for them.
|
||||
var sensor = new sensorObj.HKA5(0, -1, -1);
|
||||
|
||||
// update once every 2 seconds and output data
|
||||
setInterval(function()
|
||||
{
|
||||
sensor.update()
|
||||
|
||||
console.log("PM 1 : "
|
||||
+ sensor.getPM1()
|
||||
+ " ug/m3");
|
||||
|
||||
console.log("PM 2.5: "
|
||||
+ sensor.getPM2_5()
|
||||
+ " ug/m3");
|
||||
|
||||
console.log("PM 10 : "
|
||||
+ sensor.getPM10()
|
||||
+ " ug/m3");
|
||||
|
||||
console.log();
|
||||
|
||||
}, 2000);
|
||||
|
||||
// exit on ^C
|
||||
process.on('SIGINT', function()
|
||||
{
|
||||
sensor = null;
|
||||
sensorObj.cleanUp();
|
||||
sensorObj = null;
|
||||
console.log("Exiting.");
|
||||
process.exit(0);
|
||||
});
|
62
examples/python/hka5.py
Normal file
62
examples/python/hka5.py
Normal file
@ -0,0 +1,62 @@
|
||||
#!/usr/bin/python
|
||||
# Author: Jon Trulson <jtrulson@ics.com>
|
||||
# Copyright (c) 2016 Intel Corporation.
|
||||
#
|
||||
# Permission is hereby granted, free of charge, to any person obtaining
|
||||
# a copy of this software and associated documentation files (the
|
||||
# "Software"), to deal in the Software without restriction, including
|
||||
# without limitation the rights to use, copy, modify, merge, publish,
|
||||
# distribute, sublicense, and/or sell copies of the Software, and to
|
||||
# permit persons to whom the Software is furnished to do so, subject to
|
||||
# the following conditions:
|
||||
#
|
||||
# The above copyright notice and this permission notice shall be
|
||||
# included in all copies or substantial portions of the Software.
|
||||
#
|
||||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
||||
# EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||
# MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
||||
# NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
||||
# LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
||||
# OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
||||
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
|
||||
import time, sys, signal, atexit
|
||||
import pyupm_hka5 as sensorObj
|
||||
|
||||
# Instantiate a HKA5 sensor on uart 0. We don't use the set or
|
||||
# reset pins, so we pass -1 for them.
|
||||
sensor = sensorObj.HKA5(0, -1, -1)
|
||||
|
||||
## Exit handlers ##
|
||||
# This function stops python from printing a stacktrace when you hit control-C
|
||||
def SIGINTHandler(signum, frame):
|
||||
raise SystemExit
|
||||
|
||||
# This function lets you run code on exit
|
||||
def exitHandler():
|
||||
print "Exiting"
|
||||
sys.exit(0)
|
||||
|
||||
# Register exit handlers
|
||||
atexit.register(exitHandler)
|
||||
signal.signal(signal.SIGINT, SIGINTHandler)
|
||||
|
||||
# update once every 2 seconds and output data
|
||||
while (True):
|
||||
sensor.update()
|
||||
|
||||
print "PM 1 :",
|
||||
print sensor.getPM1(),
|
||||
print " ug/m3"
|
||||
|
||||
print "PM 2.5:",
|
||||
print sensor.getPM2_5(),
|
||||
print " ug/m3"
|
||||
|
||||
print "PM 10 :",
|
||||
print sensor.getPM10(),
|
||||
print " ug/m3"
|
||||
|
||||
print
|
||||
time.sleep(2)
|
Reference in New Issue
Block a user