IP Configuration
This commit is contained in:
197
lib/Adafruit_VEML7700_Library/Adafruit_VEML7700.cpp
Normal file
197
lib/Adafruit_VEML7700_Library/Adafruit_VEML7700.cpp
Normal file
@@ -0,0 +1,197 @@
|
||||
/*!
|
||||
* @file Adafruit_VEML7700.cpp
|
||||
*
|
||||
* @mainpage Adafruit VEML7700 I2C Lux Sensor
|
||||
*
|
||||
* @section intro_sec Introduction
|
||||
*
|
||||
* I2C Driver for the VEML7700 I2C Lux sensor
|
||||
*
|
||||
* This is a library for the Adafruit VEML7700 breakout:
|
||||
* http://www.adafruit.com/
|
||||
*
|
||||
* Adafruit invests time and resources providing this open source code,
|
||||
* please support Adafruit and open-source hardware by purchasing products from
|
||||
* Adafruit!
|
||||
*
|
||||
* @section author Author
|
||||
*
|
||||
* Limor Fried (Adafruit Industries)
|
||||
*
|
||||
* @section license License
|
||||
*
|
||||
* BSD (see license.txt)
|
||||
*
|
||||
* @section HISTORY
|
||||
*
|
||||
* v1.0 - First release
|
||||
*/
|
||||
|
||||
#include "Arduino.h"
|
||||
#include <Wire.h>
|
||||
|
||||
#include "Adafruit_VEML7700.h"
|
||||
|
||||
/*!
|
||||
* @brief Instantiates a new VEML7700 class
|
||||
*/
|
||||
Adafruit_VEML7700::Adafruit_VEML7700(void) {}
|
||||
|
||||
/*!
|
||||
* @brief Setups the HW
|
||||
* @param addr
|
||||
* @return True if initialization was successful, otherwise false.
|
||||
*/
|
||||
boolean Adafruit_VEML7700::begin(TwoWire *theWire) {
|
||||
i2c_dev = new Adafruit_I2CDevice(VEML7700_I2CADDR_DEFAULT);
|
||||
|
||||
if (!i2c_dev->begin()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ALS_Config = new Adafruit_I2CRegister(i2c_dev, VEML7700_ALS_CONFIG, 2, LSBFIRST);
|
||||
ALS_HighThreshold = new Adafruit_I2CRegister(i2c_dev, VEML7700_ALS_THREHOLD_HIGH, 2, LSBFIRST);
|
||||
ALS_LowThreshold = new Adafruit_I2CRegister(i2c_dev, VEML7700_ALS_THREHOLD_LOW, 2, LSBFIRST);
|
||||
Power_Saving = new Adafruit_I2CRegister(i2c_dev, VEML7700_ALS_POWER_SAVE, 2, LSBFIRST);
|
||||
ALS_Data = new Adafruit_I2CRegister(i2c_dev, VEML7700_ALS_DATA, 2, LSBFIRST);
|
||||
White_Data = new Adafruit_I2CRegister(i2c_dev, VEML7700_WHITE_DATA, 2, LSBFIRST);
|
||||
Interrupt_Status = new Adafruit_I2CRegister(i2c_dev, VEML7700_INTERRUPTSTATUS, 2, LSBFIRST);
|
||||
|
||||
ALS_Shutdown = new Adafruit_I2CRegisterBits(ALS_Config, 1, 0); // # bits, bit_shift
|
||||
ALS_Interrupt_Enable = new Adafruit_I2CRegisterBits(ALS_Config, 1, 1);
|
||||
ALS_Persistence = new Adafruit_I2CRegisterBits(ALS_Config, 2, 4);
|
||||
ALS_Integration_Time = new Adafruit_I2CRegisterBits(ALS_Config, 4, 6);
|
||||
ALS_Gain = new Adafruit_I2CRegisterBits(ALS_Config, 2, 11);
|
||||
PowerSave_Enable = new Adafruit_I2CRegisterBits(Power_Saving, 1, 0);
|
||||
PowerSave_Mode = new Adafruit_I2CRegisterBits(Power_Saving, 2, 1);
|
||||
|
||||
enable(false);
|
||||
interruptEnable(false);
|
||||
setPersistence(VEML7700_PERS_1);
|
||||
setGain(VEML7700_GAIN_1);
|
||||
setIntegrationTime(VEML7700_IT_100MS);
|
||||
powerSaveEnable(false);
|
||||
enable(true);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
float Adafruit_VEML7700::normalize(float value) {
|
||||
// adjust for gain (1x is normalized)
|
||||
switch (getGain()) {
|
||||
case VEML7700_GAIN_2:
|
||||
value /= 2.0; break;
|
||||
case VEML7700_GAIN_1_4:
|
||||
value *= 4; break;
|
||||
case VEML7700_GAIN_1_8:
|
||||
value *= 8; break;
|
||||
}
|
||||
|
||||
// adjust for integrationtime (100ms is normalized)
|
||||
switch (getIntegrationTime()) {
|
||||
case VEML7700_IT_25MS:
|
||||
value *= 4; break;
|
||||
case VEML7700_IT_50MS:
|
||||
value *= 2; break;
|
||||
case VEML7700_IT_200MS:
|
||||
value /= 2.0; break;
|
||||
case VEML7700_IT_400MS:
|
||||
value /= 4.0; break;
|
||||
case VEML7700_IT_800MS:
|
||||
value /= 8.0; break;
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
|
||||
float Adafruit_VEML7700::readLux() {
|
||||
return normalize(ALS_Data->read()) * 0.0576; // see app note lux table on page 5
|
||||
}
|
||||
|
||||
uint16_t Adafruit_VEML7700::readALS() {
|
||||
return ALS_Data->read();
|
||||
}
|
||||
|
||||
|
||||
float Adafruit_VEML7700::readWhite() {
|
||||
return normalize(White_Data->read()) * 0.0576; // Unclear if this is the right multiplier
|
||||
}
|
||||
|
||||
|
||||
void Adafruit_VEML7700::enable(bool enable) {
|
||||
ALS_Shutdown->write(!enable);
|
||||
}
|
||||
|
||||
bool Adafruit_VEML7700::enabled(void) {
|
||||
return !ALS_Shutdown->read();
|
||||
}
|
||||
|
||||
void Adafruit_VEML7700::interruptEnable(bool enable) {
|
||||
ALS_Interrupt_Enable->write(enable);
|
||||
}
|
||||
|
||||
bool Adafruit_VEML7700::interruptEnabled(void) {
|
||||
return ALS_Interrupt_Enable->read();
|
||||
}
|
||||
|
||||
void Adafruit_VEML7700::setPersistence(uint8_t pers) {
|
||||
ALS_Persistence->write(pers);
|
||||
}
|
||||
|
||||
uint8_t Adafruit_VEML7700::getPersistence(void) {
|
||||
return ALS_Persistence->read();
|
||||
}
|
||||
|
||||
void Adafruit_VEML7700::setIntegrationTime(uint8_t it) {
|
||||
ALS_Integration_Time->write(it);
|
||||
}
|
||||
|
||||
uint8_t Adafruit_VEML7700::getIntegrationTime(void) {
|
||||
return ALS_Integration_Time->read();
|
||||
}
|
||||
|
||||
void Adafruit_VEML7700::setGain(uint8_t gain) {
|
||||
ALS_Gain->write(gain);
|
||||
}
|
||||
|
||||
uint8_t Adafruit_VEML7700::getGain(void) {
|
||||
return ALS_Gain->read();
|
||||
}
|
||||
|
||||
void Adafruit_VEML7700::powerSaveEnable(bool enable) {
|
||||
PowerSave_Enable->write(enable);
|
||||
}
|
||||
|
||||
bool Adafruit_VEML7700::powerSaveEnabled(void) {
|
||||
return PowerSave_Enable->read();
|
||||
}
|
||||
|
||||
void Adafruit_VEML7700::setPowerSaveMode(uint8_t mode) {
|
||||
PowerSave_Mode->write(mode);
|
||||
}
|
||||
|
||||
uint8_t Adafruit_VEML7700::getPowerSaveMode(void) {
|
||||
return PowerSave_Mode->read();
|
||||
}
|
||||
|
||||
void Adafruit_VEML7700::setLowThreshold(uint16_t value) {
|
||||
ALS_LowThreshold->write(value);
|
||||
}
|
||||
|
||||
uint16_t Adafruit_VEML7700::getLowThreshold(void) {
|
||||
return ALS_LowThreshold->read();
|
||||
}
|
||||
|
||||
|
||||
void Adafruit_VEML7700::setHighThreshold(uint16_t value) {
|
||||
ALS_HighThreshold->write(value);
|
||||
}
|
||||
|
||||
uint16_t Adafruit_VEML7700::getHighThreshold(void) {
|
||||
return ALS_HighThreshold->read();
|
||||
}
|
||||
|
||||
uint16_t Adafruit_VEML7700::interruptStatus(void) {
|
||||
return Interrupt_Status->read();
|
||||
}
|
||||
111
lib/Adafruit_VEML7700_Library/Adafruit_VEML7700.h
Normal file
111
lib/Adafruit_VEML7700_Library/Adafruit_VEML7700.h
Normal file
@@ -0,0 +1,111 @@
|
||||
/*!
|
||||
* @file Adafruit_VEML7700.h
|
||||
*
|
||||
* I2C Driver for VEML7700 Lux sensor
|
||||
*
|
||||
* This is a library for the Adafruit VEML7700 breakout:
|
||||
* http://www.adafruit.com/
|
||||
*
|
||||
* Adafruit invests time and resources providing this open source code,
|
||||
*please support Adafruit and open-source hardware by purchasing products from
|
||||
* Adafruit!
|
||||
*
|
||||
*
|
||||
* BSD license (see license.txt)
|
||||
*/
|
||||
|
||||
#ifndef _ADAFRUIT_VEML7700_H
|
||||
#define _ADAFRUIT_VEML7700_H
|
||||
|
||||
#include "Arduino.h"
|
||||
#include <Wire.h>
|
||||
#include <Adafruit_I2CDevice.h>
|
||||
#include <Adafruit_I2CRegister.h>
|
||||
|
||||
#define VEML7700_I2CADDR_DEFAULT 0x10 ///< I2C address
|
||||
|
||||
#define VEML7700_ALS_CONFIG 0x00
|
||||
#define VEML7700_ALS_THREHOLD_HIGH 0x01
|
||||
#define VEML7700_ALS_THREHOLD_LOW 0x02
|
||||
#define VEML7700_ALS_POWER_SAVE 0x03
|
||||
#define VEML7700_ALS_DATA 0x04
|
||||
#define VEML7700_WHITE_DATA 0x05
|
||||
#define VEML7700_INTERRUPTSTATUS 0x06
|
||||
|
||||
#define VEML7700_INTERRUPT_HIGH 0x4000
|
||||
#define VEML7700_INTERRUPT_LOW 0x8000
|
||||
|
||||
#define VEML7700_GAIN_1 0x00
|
||||
#define VEML7700_GAIN_2 0x01
|
||||
#define VEML7700_GAIN_1_8 0x02
|
||||
#define VEML7700_GAIN_1_4 0x03
|
||||
|
||||
#define VEML7700_IT_100MS 0x00
|
||||
#define VEML7700_IT_200MS 0x01
|
||||
#define VEML7700_IT_400MS 0x02
|
||||
#define VEML7700_IT_800MS 0x03
|
||||
#define VEML7700_IT_50MS 0x08
|
||||
#define VEML7700_IT_25MS 0x0C
|
||||
|
||||
#define VEML7700_PERS_1 0x00
|
||||
#define VEML7700_PERS_2 0x01
|
||||
#define VEML7700_PERS_4 0x02
|
||||
#define VEML7700_PERS_8 0x03
|
||||
|
||||
#define VEML7700_POWERSAVE_MODE1 0x00
|
||||
#define VEML7700_POWERSAVE_MODE2 0x01
|
||||
#define VEML7700_POWERSAVE_MODE3 0x02
|
||||
#define VEML7700_POWERSAVE_MODE4 0x03
|
||||
|
||||
|
||||
/*!
|
||||
* @brief Class that stores state and functions for interacting with
|
||||
* VEML7700 Temp Sensor
|
||||
*/
|
||||
class Adafruit_VEML7700 {
|
||||
public:
|
||||
Adafruit_VEML7700();
|
||||
boolean begin(TwoWire *theWire = &Wire);
|
||||
|
||||
void enable(bool enable);
|
||||
bool enabled(void);
|
||||
|
||||
void interruptEnable(bool enable);
|
||||
bool interruptEnabled(void);
|
||||
void setPersistence(uint8_t pers);
|
||||
uint8_t getPersistence(void);
|
||||
void setIntegrationTime(uint8_t it);
|
||||
uint8_t getIntegrationTime(void);
|
||||
void setGain(uint8_t gain);
|
||||
uint8_t getGain(void);
|
||||
void powerSaveEnable(bool enable);
|
||||
bool powerSaveEnabled(void);
|
||||
void setPowerSaveMode(uint8_t mode);
|
||||
uint8_t getPowerSaveMode(void);
|
||||
|
||||
void setLowThreshold(uint16_t value);
|
||||
uint16_t getLowThreshold(void);
|
||||
void setHighThreshold(uint16_t value);
|
||||
uint16_t getHighThreshold(void);
|
||||
uint16_t interruptStatus(void);
|
||||
|
||||
|
||||
float readLux();
|
||||
uint16_t readALS();
|
||||
float readWhite();
|
||||
|
||||
Adafruit_I2CRegister *ALS_Config, *ALS_Data, *White_Data,
|
||||
*ALS_HighThreshold, *ALS_LowThreshold, *Power_Saving, *Interrupt_Status;
|
||||
Adafruit_I2CRegisterBits *ALS_Shutdown, *ALS_Interrupt_Enable,
|
||||
*ALS_Persistence, *ALS_Integration_Time, *ALS_Gain,
|
||||
*PowerSave_Enable, *PowerSave_Mode;
|
||||
|
||||
|
||||
private:
|
||||
float normalize(float value);
|
||||
|
||||
Adafruit_I2CDevice *i2c_dev;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
16
lib/Adafruit_VEML7700_Library/README.md
Normal file
16
lib/Adafruit_VEML7700_Library/README.md
Normal file
@@ -0,0 +1,16 @@
|
||||
Adafruit_VEML7700 [](https://travis-ci.com/adafruit/Adafruit_VEML7700)
|
||||
================
|
||||
|
||||
This is the Adafruit VEML7700 Lux sensor library
|
||||
|
||||
Tested and works great with the [Adafruit VEML7700 Breakout Board](http://www.adafruit.com/)
|
||||
|
||||
This chip uses I2C to communicate, 2 pins are required to interface
|
||||
|
||||
Adafruit invests time and resources providing this open source code,
|
||||
please support Adafruit and open-source hardware by purchasing
|
||||
products from Adafruit!
|
||||
|
||||
Written by Kevin Townsend/Limor Fried for Adafruit Industries.
|
||||
BSD license, check license.txt for more information
|
||||
All text above must be included in any redistribution
|
||||
@@ -0,0 +1,58 @@
|
||||
#include "Adafruit_VEML7700.h"
|
||||
|
||||
Adafruit_VEML7700 veml = Adafruit_VEML7700();
|
||||
|
||||
void setup() {
|
||||
while (!Serial) { delay(10); }
|
||||
Serial.begin(115200);
|
||||
Serial.println("Adafruit VEML7700 Test");
|
||||
|
||||
if (!veml.begin()) {
|
||||
Serial.println("Sensor not found");
|
||||
while (1);
|
||||
}
|
||||
Serial.println("Sensor found");
|
||||
|
||||
veml.setGain(VEML7700_GAIN_1);
|
||||
veml.setIntegrationTime(VEML7700_IT_800MS);
|
||||
|
||||
Serial.print(F("Gain: "));
|
||||
switch (veml.getGain()) {
|
||||
case VEML7700_GAIN_1: Serial.println("1"); break;
|
||||
case VEML7700_GAIN_2: Serial.println("2"); break;
|
||||
case VEML7700_GAIN_1_4: Serial.println("1/4"); break;
|
||||
case VEML7700_GAIN_1_8: Serial.println("1/8"); break;
|
||||
}
|
||||
|
||||
Serial.print(F("Integration Time (ms): "));
|
||||
switch (veml.getIntegrationTime()) {
|
||||
case VEML7700_IT_25MS: Serial.println("25"); break;
|
||||
case VEML7700_IT_50MS: Serial.println("50"); break;
|
||||
case VEML7700_IT_100MS: Serial.println("100"); break;
|
||||
case VEML7700_IT_200MS: Serial.println("200"); break;
|
||||
case VEML7700_IT_400MS: Serial.println("400"); break;
|
||||
case VEML7700_IT_800MS: Serial.println("800"); break;
|
||||
}
|
||||
|
||||
//veml.powerSaveEnable(true);
|
||||
//veml.setPowerSaveMode(VEML7700_POWERSAVE_MODE4);
|
||||
|
||||
veml.setLowThreshold(10000);
|
||||
veml.setHighThreshold(20000);
|
||||
veml.interruptEnable(true);
|
||||
}
|
||||
|
||||
void loop() {
|
||||
Serial.print("Lux: "); Serial.println(veml.readLux());
|
||||
Serial.print("White: "); Serial.println(veml.readWhite());
|
||||
Serial.print("Raw ALS: "); Serial.println(veml.readALS());
|
||||
|
||||
uint16_t irq = veml.interruptStatus();
|
||||
if (irq & VEML7700_INTERRUPT_LOW) {
|
||||
Serial.println("** Low threshold");
|
||||
}
|
||||
if (irq & VEML7700_INTERRUPT_HIGH) {
|
||||
Serial.println("** High threshold");
|
||||
}
|
||||
delay(500);
|
||||
}
|
||||
9
lib/Adafruit_VEML7700_Library/library.properties
Normal file
9
lib/Adafruit_VEML7700_Library/library.properties
Normal file
@@ -0,0 +1,9 @@
|
||||
name=Adafruit VEML7700 Library
|
||||
version=1.0.0
|
||||
author=Adafruit
|
||||
maintainer=Adafruit <info@adafruit.com>
|
||||
sentence=Arduino library for the VEML7700 sensors in the Adafruit shop
|
||||
paragraph=Arduino library for the VEML7700 sensors in the Adafruit shop
|
||||
category=Sensors
|
||||
url=https://github.com/adafruit/Adafruit_VEML7700
|
||||
architectures=*
|
||||
26
lib/Adafruit_VEML7700_Library/license.txt
Normal file
26
lib/Adafruit_VEML7700_Library/license.txt
Normal file
@@ -0,0 +1,26 @@
|
||||
Software License Agreement (BSD License)
|
||||
|
||||
Copyright (c) 2012, Adafruit Industries
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
1. Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
2. Redistributions in binary form must reproduce the above copyright
|
||||
notice, this list of conditions and the following disclaimer in the
|
||||
documentation and/or other materials provided with the distribution.
|
||||
3. Neither the name of the copyright holders nor the
|
||||
names of its contributors may be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
|
||||
EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
|
||||
DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
||||
ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
Reference in New Issue
Block a user