diff --git a/examples/c++/veml6070.cxx b/examples/c++/veml6070.cxx new file mode 100644 index 00000000..65fd16a9 --- /dev/null +++ b/examples/c++/veml6070.cxx @@ -0,0 +1,58 @@ +/* + * Author: Abhishek Malik + * Copyright (c) 2017 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 +#include +#include +#include "veml6070.hpp" + +using namespace std; + +int shouldRun = true; + +void sig_handler(int signo) +{ + if (signo == SIGINT) + shouldRun = false; +} + + +int main () +{ + signal(SIGINT, sig_handler); + +//! [Interesting] + // Instantiate an VEML6070 sensor on i2c bus 0 + upm::VEML6070* veml = new upm::VEML6070(0, VEML6070_CTRL_REG); + while (shouldRun) { + cout << "Retrieved UV value: " << veml->getUVIntensity() << endl; + sleep(1); + } +//! [Interesting] + + cout << "Exiting..." << endl; + + delete veml; + return 0; +} diff --git a/examples/c/veml6070.c b/examples/c/veml6070.c new file mode 100644 index 00000000..094074e2 --- /dev/null +++ b/examples/c/veml6070.c @@ -0,0 +1,49 @@ +/* + * Author: Abhishek Malik + * Copyright (c) 2017 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 +#include +#include +#include +#include +#include "veml6070.h" + +#include "upm_utilities.h" + +int main() +{ + veml6070_context dev = veml6070_init(0, VEML6070_CTRL_REG); + if(dev == NULL) { + printf("Unable to initialize sensor\n"); + return 0; + } + upm_delay(1); + + while(1){ + printf("Retrieved UV Value: %d\n", veml6070_get_uv_intensity(dev)); + upm_delay(1); + } + + return 0; +} diff --git a/examples/java/CMakeLists.txt b/examples/java/CMakeLists.txt index 777cceb2..e915162d 100644 --- a/examples/java/CMakeLists.txt +++ b/examples/java/CMakeLists.txt @@ -188,6 +188,7 @@ add_example(BMA250E_Example bma250e) add_example(BMM150_Example bmm150) add_example(LSM303AGR_Example lsm303agr) add_example(LSM303D_Example lsm303d) +add_example(VEML6070Sample veml6070) add_example_with_path(Jhd1313m1_lcdSample jhd1313m1 jhd1313m1) add_example_with_path(Jhd1313m1Sample jhd1313m1 jhd1313m1) diff --git a/examples/java/VEML6070Sample.java b/examples/java/VEML6070Sample.java new file mode 100644 index 00000000..d6ab7be4 --- /dev/null +++ b/examples/java/VEML6070Sample.java @@ -0,0 +1,48 @@ +/* + * Author: Abhishek Malik + * Copyright (c) 2017 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_veml6070.VEML6070; + +public class VEML6070Sample { + + public static void main(String[] args) { + // TODO Auto-generated method stub + + //! [Interesting] + // Instantiate a VEML6070 UV sensor + VEML6070 veml = new VEML6070(0, 0x38); + + while(true){ + System.out.println("UV Value: "+veml.getUVIntensity()); + try { + Thread.sleep(500); + } catch (InterruptedException e) { + // TODO Auto-generated catch block + System.out.println("The following exception occurred: "+e.getMessage()); + } + } + //! [Interesting] + } + +} diff --git a/examples/javascript/veml6070.js b/examples/javascript/veml6070.js new file mode 100644 index 00000000..3fde4fce --- /dev/null +++ b/examples/javascript/veml6070.js @@ -0,0 +1,41 @@ +/* +* Author: Abhishek Malik +* Copyright (c) 2017 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 veml6070 = require("jsupm_veml6070"); + +// Instantiate a Vishay UV sensor at bus 0 +var veml6070_sensor = new veml6070.VEML6070(0, 0x38); + +var myInterval = setInterval(function() +{ + console.log("UV value: " + veml6070_sensor.getUVIntensity()); +}, 100); + +// When exiting: clear interval and print message +process.on('SIGINT', function() +{ + clearInterval(myInterval); + console.log("Exiting..."); + process.exit(0); +}); diff --git a/examples/python/veml6070.py b/examples/python/veml6070.py new file mode 100644 index 00000000..cfdced18 --- /dev/null +++ b/examples/python/veml6070.py @@ -0,0 +1,52 @@ +#!/usr/bin/python +# Author: Abhishek Malik +# Copyright (c) 2017 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. + +from __future__ import print_function +import time, sys, signal, atexit +from upm import pyupm_veml6070 as veml6070 + +def main(): + # Instantiate a Vishay UV Sensor on the I2C bus 0 + veml6070_sensor = veml6070.VEML6070(0, 0x38); + + ## 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, including functions from abpdrrt005pg2a5 + def exitHandler(): + print("Exiting") + sys.exit(0) + + # Register exit handlers + atexit.register(exitHandler) + signal.signal(signal.SIGINT, SIGINTHandler) + + # Read the value every second and detect the pressure + while(1): + print("UV Value: {0}".format(veml6070_sensor.getUVIntensity())) + time.sleep(1) + +if __name__ == '__main__': + main() diff --git a/src/veml6070/CMakeLists.txt b/src/veml6070/CMakeLists.txt new file mode 100644 index 00000000..9ed32a9f --- /dev/null +++ b/src/veml6070/CMakeLists.txt @@ -0,0 +1,8 @@ +upm_mixed_module_init (NAME veml6070 + DESCRIPTION "Vishay UV Sensor" + C_HDR veml6070.h + C_SRC veml6070.c + CPP_HDR veml6070.hpp + CPP_SRC veml6070.cxx + CPP_WRAPS_C + REQUIRES mraa) diff --git a/src/veml6070/javaupm_veml6070.i b/src/veml6070/javaupm_veml6070.i new file mode 100644 index 00000000..35467981 --- /dev/null +++ b/src/veml6070/javaupm_veml6070.i @@ -0,0 +1,20 @@ +%module javaupm_veml6070 +%include "../upm.i" +%include "stdint.i" +%include "typemaps.i" + +%{ + #include "veml6070.hpp" +%} +%include "veml6070.hpp" + +%pragma(java) jniclasscode=%{ + static { + try { + System.loadLibrary("javaupm_veml6070"); + } catch (UnsatisfiedLinkError e) { + System.err.println("Native code library failed to load. \n" + e); + System.exit(1); + } + } +%} diff --git a/src/veml6070/jsupm_veml6070.i b/src/veml6070/jsupm_veml6070.i new file mode 100644 index 00000000..f40f9e4e --- /dev/null +++ b/src/veml6070/jsupm_veml6070.i @@ -0,0 +1,8 @@ +%module jsupm_veml6070 +%include "../upm.i" + +%{ + #include "veml6070.hpp" +%} + +%include "veml6070.hpp" diff --git a/src/veml6070/pyupm_veml6070.i b/src/veml6070/pyupm_veml6070.i new file mode 100644 index 00000000..518fb99e --- /dev/null +++ b/src/veml6070/pyupm_veml6070.i @@ -0,0 +1,11 @@ +// Include doxygen-generated documentation +%include "pyupm_doxy2swig.i" +%module pyupm_veml6070 +%include "../upm.i" + +%feature("autodoc", "3"); + +%include "veml6070.hpp" +%{ + #include "veml6070.hpp" +%} diff --git a/src/veml6070/veml6070.c b/src/veml6070/veml6070.c new file mode 100644 index 00000000..47fe3799 --- /dev/null +++ b/src/veml6070/veml6070.c @@ -0,0 +1,119 @@ +/* + * Author: Abhishek Malik + * Copyright (c) 2017 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 "veml6070.h" + +veml6070_context veml6070_init(uint8_t bus, uint8_t address) { + // make sure MRAA is initialized + int mraa_rv; + if ((mraa_rv = mraa_init()) != MRAA_SUCCESS) + { + printf("%s: mraa_init() failed (%d).\n", __FUNCTION__, mraa_rv); + return NULL; + } + + veml6070_context dev = + (veml6070_context) malloc(sizeof(struct _veml6070_context)); + + if (!dev) + { + return NULL; + } + + dev->i2c_bus_number = bus; + // setting up the control register address here + dev->address = address; + + dev->i2c = mraa_i2c_init(dev->i2c_bus_number); + if (dev->i2c == NULL){ + free(dev); + return NULL; + } + + if (mraa_i2c_address(dev->i2c, dev->address) != MRAA_SUCCESS) + { + mraa_i2c_stop(dev->i2c); + free(dev); + return NULL; + } + + // reset the sensor here + + return dev; +} + +void veml6070_close(veml6070_context dev) { + free(dev); +} + +int16_t veml6070_get_uv_intensity(veml6070_context dev) { + int8_t seq_1, seq_2; + int16_t intensity; + + // reading seq1 + dev->address = VEML6070_SEQ1_DATA_BUF_REG; + + if (mraa_i2c_address(dev->i2c, dev->address) != MRAA_SUCCESS) + { + printf("Unable to add seq 1 address\n"); + return -1; + } + + seq_1 = mraa_i2c_read_byte(dev->i2c); + if(seq_1 == -1) + return -1; + + // reading seq2 + dev->address = VEML6070_SEQ2_DATA_BUF_REG; + + if (mraa_i2c_address(dev->i2c, dev->address) != MRAA_SUCCESS) + { + printf("Unable to add seq 2 address\n"); + return -1; + } + + seq_2 = mraa_i2c_read_byte(dev->i2c); + if (seq_2 == -1) + return -1; + + intensity = (seq_1<<8)|seq_2; + + return intensity; +} + +upm_result_t veml6070_set_integration_time(veml6070_context dev, veml6070_integration_time_t time) { + // setting integration time address + dev->address = VEML6070_CTRL_REG; + + if (mraa_i2c_address(dev->i2c, dev->address) != MRAA_SUCCESS) + { + return UPM_ERROR_UNSPECIFIED; + } + + uint8_t integrationTime = ((time<<2)|0x02); + if(mraa_i2c_write(dev->i2c, &integrationTime, 1) != MRAA_SUCCESS) { + return UPM_ERROR_UNSPECIFIED; + } + + return UPM_SUCCESS; +} \ No newline at end of file diff --git a/src/veml6070/veml6070.cxx b/src/veml6070/veml6070.cxx new file mode 100644 index 00000000..f5cf1d24 --- /dev/null +++ b/src/veml6070/veml6070.cxx @@ -0,0 +1,55 @@ +/* + * Author: Abhishek Malik + * Copyright (c) 2017 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 +#include +#include + +#include "veml6070.hpp" + +using namespace upm; + +VEML6070::VEML6070(int bus, int devAddress) : + m_veml6070(veml6070_init(bus, devAddress)) +{ + if(!m_veml6070) + throw std::runtime_error(std::string(__FUNCTION__) + + ": veml6070_init failed"); +} + +VEML6070::~VEML6070() +{ + veml6070_close(m_veml6070); +} + +int VEML6070::getUVIntensity() +{ + return veml6070_get_uv_intensity(m_veml6070); +} + +void VEML6070::setIntegrationTime(veml6070_integration_time_t time) +{ + if(veml6070_set_integration_time(m_veml6070, time) != UPM_SUCCESS) + std::cout << "VEML6070 sensor unable to update integration time" << std::endl; +} diff --git a/src/veml6070/veml6070.h b/src/veml6070/veml6070.h new file mode 100644 index 00000000..7d0a6c0e --- /dev/null +++ b/src/veml6070/veml6070.h @@ -0,0 +1,99 @@ +/* + * Author: Abhishek Malik + * Copyright (c) 2017 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. + */ +#pragma once + +#include +#include +#include +#include + +#include "upm.h" +#include "mraa/i2c.h" + +#ifdef __cplusplus +extern "C" { +#endif + +#define VEML6070_CTRL_REG 0x38 // write only +#define VEML6070_SEQ1_DATA_BUF_REG 0x39 // read only +#define VEML6070_SEQ2_DATA_BUF_REG 0x38 // read only + +typedef enum { + HALF_T = 0, + ONE_T, + TWO_T, + FOUR_T } veml6070_integration_time_t; + +/** + * @file veml6070.h + * @library veml6070 + * @brief C API for the VEML6070 Vishay UV Sensor + * + * @include veml6070.c + */ + +typedef struct _veml6070_context { + mraa_i2c_context i2c; + uint8_t address; + uint8_t i2c_bus_number; +} *veml6070_context; + +/** + * VEML6070 Initialization function + * + * @param bus I2C bus to use + * @param address I2C address to use + * + * @return device context pointer + */ +veml6070_context veml6070_init(uint8_t bus, uint8_t address); + +/** + * VEML6070 Close function + * + * @param dev veml6070_context pointer + */ +void veml6070_close(veml6070_context dev); + +/** + * Function to get the UV values + * + * @param dev veml6070_context pointer + * @return int16_t UV value + */ +int16_t veml6070_get_uv_intensity(veml6070_context dev); + +/** + * Function to set the integration time of the sensor + * + * @param dev veml6070_context pointer + * @param time veml6070_integration_time_t + * + * @return upm_result_t + */ +upm_result_t veml6070_set_integration_time(veml6070_context dev, veml6070_integration_time_t time); + +#ifdef __cplusplus +} +#endif diff --git a/src/veml6070/veml6070.hpp b/src/veml6070/veml6070.hpp new file mode 100644 index 00000000..f3dabdbd --- /dev/null +++ b/src/veml6070/veml6070.hpp @@ -0,0 +1,111 @@ +/* + * Author: Abhishek Malik + * Copyright (c) 2017 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. + */ + +#pragma once + +#include "veml6070.h" + +namespace upm { +/** + * @defgroup veml6070 libupm-veml6070 + * @ingroup vishay i2c light + */ + +/** + * @library veml6070 + * @sensor veml6070 + * @comname Vishay VEML6070 UV Sensor + * @type other + * @man Vishay + * @web http://www.vishay.com/docs/84277/veml6070.pdf + * @con i2c + * @kit other + * + * @brief API for the Vishay VEML6070 UV Sensor + * + * VEML6070 is an advanced ultraviolet (UV) light sensor with + * I2C protocol interface and designed by the CMOS process. + * It is easily operated via a simple I2C command. The active + * acknowledge (ACK) feature with threshold windows setting + * allows the UV sensor to send out a UVI alert message. + * Under a strong solar UVI condition, the smart ACK signal + * can be easily implemented by the software programming. + * VEML6070 incorporates a photodiode, amplifiers, and + * analog / digital circuits into a single chip. VEML6070's + * adoption of FiltronTM UV technology provides the best + * spectral sensitivity to cover UV spectrum sensing. It has an + * excellent temperature compensation and a robust refresh + * rate setting that does not use an external RC low pass filter. + * VEML6070 has linear sensitivity to solar UV light and is + * easily adjusted by an external resistor. Software shutdown + * mode is provided, which reduces power consumption to be + * less than 1 uA. VEML6070's operating voltage ranges from + * 2.7 V to 5.5 V. + * + * @image html veml6070.jpg + * @snippet veml6070.cxx Interesting + */ + class VEML6070 { + + public: + /** + * VEML6070 constructor + * + * @param bus i2c bus to be used + * @param devAddress i2c address of the sensor + */ + VEML6070(int bus, int devAddress); + /** + * VEML6070 destructor + */ + ~VEML6070(); + + /** + * Function to get the UV value. + * + * @return int16_t UV value + */ + int getUVIntensity(); + + /** + * Function to allow the user to set the intergration time + * for the sensor. + * Integration time: + * Bit Setting | Description | RSet + * IT1 IT0 | | 300 k-ohms | 600 k-ohms + * 0 0 | 1/2T | 62.5 ms | 125 ms + * 0 1 | 1T | 125 ms | 250 ms + * 1 0 | 2T | 250 ms | 500 ms + * 1 1 | 4T | 500 ms | 1000 ms + * + * @param time veml6070_integration_time_t + */ + void setIntegrationTime(veml6070_integration_time_t time); + + private: + veml6070_context m_veml6070; + VEML6070(const VEML6070& src) { /* do not create copied constructor */} + VEML6070& operator=(const VEML6070&) {return *this;} + }; +} \ No newline at end of file