mirror of
https://github.com/eclipse/upm.git
synced 2025-03-24 09:20:39 +03:00
VEML6070: Adding separate i2c contexts for separate addresses
Signed-off-by: Abhishek Malik <abhishek.malik@intel.com>
This commit is contained in:
parent
c70f378f72
commit
b4bc15201b
@ -44,7 +44,7 @@ int main ()
|
|||||||
|
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
// Instantiate an VEML6070 sensor on i2c bus 0
|
// Instantiate an VEML6070 sensor on i2c bus 0
|
||||||
upm::VEML6070* veml = new upm::VEML6070(0, VEML6070_CTRL_REG);
|
upm::VEML6070* veml = new upm::VEML6070(0);
|
||||||
while (shouldRun) {
|
while (shouldRun) {
|
||||||
cout << "Retrieved UV value: " << veml->getUVIntensity() << endl;
|
cout << "Retrieved UV value: " << veml->getUVIntensity() << endl;
|
||||||
sleep(1);
|
sleep(1);
|
||||||
|
@ -33,7 +33,7 @@
|
|||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
veml6070_context dev = veml6070_init(0, VEML6070_CTRL_REG);
|
veml6070_context dev = veml6070_init(0);
|
||||||
if(dev == NULL) {
|
if(dev == NULL) {
|
||||||
printf("Unable to initialize sensor\n");
|
printf("Unable to initialize sensor\n");
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -31,7 +31,7 @@ public class VEML6070Sample {
|
|||||||
|
|
||||||
//! [Interesting]
|
//! [Interesting]
|
||||||
// Instantiate a VEML6070 UV sensor
|
// Instantiate a VEML6070 UV sensor
|
||||||
VEML6070 veml = new VEML6070(0, 0x38);
|
VEML6070 veml = new VEML6070(0);
|
||||||
|
|
||||||
while(true){
|
while(true){
|
||||||
System.out.println("UV Value: "+veml.getUVIntensity());
|
System.out.println("UV Value: "+veml.getUVIntensity());
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
var veml6070 = require("jsupm_veml6070");
|
var veml6070 = require("jsupm_veml6070");
|
||||||
|
|
||||||
// Instantiate a Vishay UV sensor at bus 0
|
// Instantiate a Vishay UV sensor at bus 0
|
||||||
var veml6070_sensor = new veml6070.VEML6070(0, 0x38);
|
var veml6070_sensor = new veml6070.VEML6070(0);
|
||||||
|
|
||||||
var myInterval = setInterval(function()
|
var myInterval = setInterval(function()
|
||||||
{
|
{
|
||||||
|
@ -27,7 +27,7 @@ from upm import pyupm_veml6070 as veml6070
|
|||||||
|
|
||||||
def main():
|
def main():
|
||||||
# Instantiate a Vishay UV Sensor on the I2C bus 0
|
# Instantiate a Vishay UV Sensor on the I2C bus 0
|
||||||
veml6070_sensor = veml6070.VEML6070(0, 0x38);
|
veml6070_sensor = veml6070.VEML6070(0);
|
||||||
|
|
||||||
## Exit handlers ##
|
## Exit handlers ##
|
||||||
# This function stops python from printing a stacktrace when you hit control-C
|
# This function stops python from printing a stacktrace when you hit control-C
|
||||||
|
@ -23,7 +23,7 @@
|
|||||||
*/
|
*/
|
||||||
#include "veml6070.h"
|
#include "veml6070.h"
|
||||||
|
|
||||||
veml6070_context veml6070_init(uint8_t bus, uint8_t address) {
|
veml6070_context veml6070_init(uint8_t bus) {
|
||||||
// make sure MRAA is initialized
|
// make sure MRAA is initialized
|
||||||
int mraa_rv;
|
int mraa_rv;
|
||||||
if ((mraa_rv = mraa_init()) != MRAA_SUCCESS)
|
if ((mraa_rv = mraa_init()) != MRAA_SUCCESS)
|
||||||
@ -41,22 +41,35 @@ veml6070_context veml6070_init(uint8_t bus, uint8_t address) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dev->i2c_bus_number = bus;
|
dev->i2c_bus_number = bus;
|
||||||
// setting up the control register address here
|
// Setting up 2 contexts for the 2 addresses
|
||||||
dev->address = address;
|
dev->address_seq1 = VEML6070_SEQ1_DATA_BUF_REG;
|
||||||
|
dev->address_seq2 = VEML6070_SEQ2_DATA_BUF_REG;
|
||||||
|
|
||||||
dev->i2c = mraa_i2c_init(dev->i2c_bus_number);
|
dev->i2c_seq1 = mraa_i2c_init(dev->i2c_bus_number);
|
||||||
if (dev->i2c == NULL){
|
if (dev->i2c_seq1 == NULL){
|
||||||
free(dev);
|
free(dev);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mraa_i2c_address(dev->i2c, dev->address) != MRAA_SUCCESS)
|
dev->i2c_seq2 = mraa_i2c_init(dev->i2c_bus_number);
|
||||||
|
if (dev->i2c_seq2 == NULL){
|
||||||
|
free(dev);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (mraa_i2c_address(dev->i2c_seq1, dev->address_seq1) != MRAA_SUCCESS)
|
||||||
{
|
{
|
||||||
mraa_i2c_stop(dev->i2c);
|
mraa_i2c_stop(dev->i2c_seq1);
|
||||||
free(dev);
|
free(dev);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (mraa_i2c_address(dev->i2c_seq2, dev->address_seq2) != MRAA_SUCCESS)
|
||||||
|
{
|
||||||
|
mraa_i2c_stop(dev->i2c_seq2);
|
||||||
|
free(dev);
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
// reset the sensor here
|
// reset the sensor here
|
||||||
|
|
||||||
return dev;
|
return dev;
|
||||||
@ -71,28 +84,12 @@ int16_t veml6070_get_uv_intensity(veml6070_context dev) {
|
|||||||
int16_t intensity;
|
int16_t intensity;
|
||||||
|
|
||||||
// reading seq1
|
// reading seq1
|
||||||
dev->address = VEML6070_SEQ1_DATA_BUF_REG;
|
seq_1 = mraa_i2c_read_byte(dev->i2c_seq1);
|
||||||
|
|
||||||
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)
|
if(seq_1 == -1)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
// reading seq2
|
// reading seq2
|
||||||
dev->address = VEML6070_SEQ2_DATA_BUF_REG;
|
seq_2 = mraa_i2c_read_byte(dev->i2c_seq2);
|
||||||
|
|
||||||
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)
|
if (seq_2 == -1)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
@ -102,16 +99,8 @@ int16_t veml6070_get_uv_intensity(veml6070_context dev) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
upm_result_t veml6070_set_integration_time(veml6070_context dev, veml6070_integration_time_t time) {
|
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);
|
uint8_t integrationTime = ((time<<2)|0x02);
|
||||||
if(mraa_i2c_write(dev->i2c, &integrationTime, 1) != MRAA_SUCCESS) {
|
if(mraa_i2c_write(dev->i2c_seq2, &integrationTime, 1) != MRAA_SUCCESS) {
|
||||||
return UPM_ERROR_UNSPECIFIED;
|
return UPM_ERROR_UNSPECIFIED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,8 +30,8 @@
|
|||||||
|
|
||||||
using namespace upm;
|
using namespace upm;
|
||||||
|
|
||||||
VEML6070::VEML6070(int bus, int devAddress) :
|
VEML6070::VEML6070(int bus) :
|
||||||
m_veml6070(veml6070_init(bus, devAddress))
|
m_veml6070(veml6070_init(bus))
|
||||||
{
|
{
|
||||||
if(!m_veml6070)
|
if(!m_veml6070)
|
||||||
throw std::runtime_error(std::string(__FUNCTION__) +
|
throw std::runtime_error(std::string(__FUNCTION__) +
|
||||||
|
@ -54,44 +54,19 @@ typedef enum {
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
typedef struct _veml6070_context {
|
typedef struct _veml6070_context {
|
||||||
mraa_i2c_context i2c;
|
mraa_i2c_context i2c_seq1;
|
||||||
uint8_t address;
|
mraa_i2c_context i2c_seq2;
|
||||||
|
uint8_t address_seq1;
|
||||||
|
uint8_t address_seq2;
|
||||||
uint8_t i2c_bus_number;
|
uint8_t i2c_bus_number;
|
||||||
} *veml6070_context;
|
} *veml6070_context;
|
||||||
|
|
||||||
/**
|
veml6070_context veml6070_init(uint8_t bus);
|
||||||
* 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);
|
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);
|
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);
|
upm_result_t veml6070_set_integration_time(veml6070_context dev, veml6070_integration_time_t time);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -27,45 +27,7 @@
|
|||||||
#include "veml6070.h"
|
#include "veml6070.h"
|
||||||
|
|
||||||
namespace upm {
|
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 {
|
class VEML6070 {
|
||||||
|
|
||||||
public:
|
public:
|
||||||
@ -75,32 +37,14 @@ namespace upm {
|
|||||||
* @param bus i2c bus to be used
|
* @param bus i2c bus to be used
|
||||||
* @param devAddress i2c address of the sensor
|
* @param devAddress i2c address of the sensor
|
||||||
*/
|
*/
|
||||||
VEML6070(int bus, int devAddress);
|
VEML6070(int bus);
|
||||||
/**
|
/**
|
||||||
* VEML6070 destructor
|
* VEML6070 destructor
|
||||||
*/
|
*/
|
||||||
~VEML6070();
|
~VEML6070();
|
||||||
|
|
||||||
/**
|
|
||||||
* Function to get the UV value.
|
|
||||||
*
|
|
||||||
* @return int16_t UV value
|
|
||||||
*/
|
|
||||||
int getUVIntensity();
|
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);
|
void setIntegrationTime(veml6070_integration_time_t time);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user