Merge branch 'mega' into P039_MERGE_RTD

This commit is contained in:
chri-kai-in
2021-05-15 12:58:00 +02:00
committed by GitHub
20 changed files with 578 additions and 36 deletions
+63 -11
View File
@@ -21,6 +21,56 @@ Maintainer: |P012_maintainer|
Used libraries: |P012_usedlibraries|
Description
-----------
This plugin can be used to control an I2C connected LCD display. These displays often offer 2 lines of 16 characters or 4 lines of 20 characters for displaying all kinds of information.
Configuration
-------------
After adding the plugin to a Task in the Devices list, it should be configured for proper operation.
.. image:: P012_DeviceConfiguration.png
**Name** A unique name should be entered here.
**Enabled** The device can be disabled or enabled. When not enabled the device should not use any resources.
I2C Options
^^^^^^^^^^^^
The available settings here depend on the build used. At least the **Force Slow I2C speed** option is available, but selections for the I2C Multiplexer can also be shown. For details see the :ref:`Hardware_page`
**I2C Address**: The address the device is using. Most devices allow a configurable address, usually the information on how to set/change that address is available on the printed circuit board, or on the manufacturers website.
Device Settings
^^^^^^^^^^^^^^^^
**Display Size** Select the size of the display, either 2x16 characters or 4x20 characters can be selected.
.. image:: P012_DisplaySize.png
**Line 1..4** Up to 4 lines can be pre-configured with text to display. For the 2x16 device size, only Line 1 and 2 will be used. Variables can be used, f.e. to display values provided by a sensor.
**Display button** A button can be configured to enable the display on demand. This function is enabled by selecting a GPIO pin to monitor. Combined with Inversed login and Display Timeout the display will be automatically turned off after the timeout has expired.
**Inversed logic** Normally the Display button GPIO pin must be connected to GND to activate the display. With this option checked the signal should be normally connected to ground, and get a high level (3.3V) to turn the display on. This way, f.e. a PIR sensor or touch button that provides an active-high signal can be used.
**Display Timeout** This defines how long the display will be turned on when the Display button turns it on (or after the start of the display). The timeout unit is seconds.
**LCD Command mode**
.. image:: P012_LCDCommandMode.png
*Continue to next line (as in v1.4)* Compatible with older versions mode, where text sent via rules, http or mqtt, will wrap over to the next line when longer then the display is wide.
*Truncate exceeding message* When text to display is too long to fit, the excess won't be displayed (discarded).
*Clear then truncate exceeding message* This will first clear the line where the text is to be displayed from the column where it is to start, and then the actual text will be displayed, discarding any text beyond the width of the display.
The Interval setting defines the delay in seconds between updates of the display. When the Line 1..4 fields are used, these lines will be updated with the updated data of any variables used there.
Build Info
----------
@@ -32,19 +82,26 @@ Supported hardware
|P012_usedby|
.. Commands available
.. ^^^^^^^^^^^^^^^^^^
Example photo of a 4x20 (LCD2004) display:
.. .. include:: P012_commands.repl
.. image:: P012_LCD_4x20.jpg
.. Events
.. ~~~~~~
.. warning:: When using a 5V powered display with on-board pull-up resistors on the I2C bus, a level-convert should be used to connect to an ESP to avoid damage to the 3.3V I2C bus on the ESP and any other I2C devices connected!
.. .. include:: P012_events.repl
Commands available
^^^^^^^^^^^^^^^^^^
.. include:: P012_commands.repl
Change log
----------
.. versionchanged:: 2021-05-03
...
|added|
Inversed logic setting to allow high-active Display button.
.. versionchanged:: 2020-09-14
...
@@ -56,8 +113,3 @@ Change log
|added|
Initial release version.
Binary file not shown.

After

Width:  |  Height:  |  Size: 26 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

+30
View File
@@ -0,0 +1,30 @@
.. csv-table::
:header: "Command", "Extra information"
:widths: 20, 30
"
``lcdcmd,<value>``
Value:
* ``on`` will turn the display ON.
* ``off`` will turn the display OFF.
* ``clear`` will clear any information from the display.
","
Using these commands, either from rules, via http or mqtt, the state of the display can be controlled.
"
"
``lcd,<row>,<col>,<text>``
","
The <row> parameter corresponds with the same lines as the plugin configuration has.
The <col> parameter sets the column the text will be displayed.
The <text> parameter must be a single command parameter.
Meaning, it must be wrapped in quotes when using a space or comma as text.
If double quote characters are needed, wrap the parameter in single quotes or back quotes.
All template notations can be used, like system variables, or reference to a task value.
"
+99
View File
@@ -0,0 +1,99 @@
.. include:: ../Plugin/_plugin_substitutions_p11x.repl
.. _P114_page:
|P114_typename|
==================================================
|P114_shortinfo|
Plugin details
--------------
Type: |P114_type|
Name: |P114_name|
Status: |P114_status|
GitHub: |P114_github|_
Maintainer: |P114_maintainer|
Used libraries: |P114_usedlibraries|
Description
-----------
This I2C sensor with 2 resolutions (normal/high dynamic) offers UVA (365 +/-10 nm) and UVB (330 +/-10 nm) measurement and a calculated UVIndex value. Output result for UV is in irradiance, watt per square metre. The maximum value that can me measured is 65535, as the chip provides 16 bit values.
NB: If the unit is over-exposed, possibly the measurement could exceed the maximum returned value of 65535, and the calculated UVIndex value will *not* be correct.
NB2: When measuring outside UV exposure, the sensor should also be outside, as f.e. window glass filters out most UV radiance, and measurements will be (very) inaccurate.
Configuration
--------------
.. image:: P114_DeviceConfiguration.png
**Name** A unique name should be entered here.
**Enabled** The device can be disabled or enabled. When not enabled the device should not use any resources.
I2C Options
^^^^^^^^^^^^
The available settings here depend on the build used. At least the **Force Slow I2C speed** option is available, but selections for the I2C Multiplexer can also be shown. For details see the :ref:`Hardware_page`
**I2C Address**: The address the device is using. Depending on the board used, when available a SDO pin, or soldering a 0 ohm resistor on a different location, can be used to select the used address. If that address selection is not available, then an I2C multiplexer (in a matching ESPEasy build) can be used to use multiple sensors on a single ESPEasy unit.
Device Settings
^^^^^^^^^^^^^^^^
**Integration Time**: The integration time setting of the sensor determines the accuracy of the measurement. There are 5 options available:
.. image:: P114_IntegrationTime.png
*50 ms* The default value, using an integration time of 50 msec.
*100ms*
*200ms*
*400ms*
*800ms*
Usually a higher integration time results in a more accurate measurement.
**Dynamic Setting**: This determines the dynamic setting:
.. image:: P114_DynamicSetting.png
*Normal Dynamic*
*High Dynamic* For better response to changing conditions during measurement.
The Data Acquisition, Send to Controller and Interval settings are standard available configuration items. Send to Controller only when one or more Controllers are configured.
**Interval** By default, Interval will be set to 60 sec. The minimum value allowed is 1 sec. but for measuring UV values, that don't change very quickly, reasonable values should be between 10 and 300 sec.
Values
^^^^^^
The measured values are available in ``UVA``, ``UVB`` and ``UCIndex``. A formula can be set to recalculate. The number of decimals is by default set to 2, and can be set to 0 for ``UVA`` and ``UVB``, as no decimals are provided from the measurement. ``UVIndex`` value is often used without decimals, but can be set as desired.
.. Events
.. ~~~~~~
.. .. include:: P114_events.repl
Change log
----------
.. versionchanged:: 2.0
|added| 2021-04-24 Moved to main repository as Plugin 114 UV - VEML6075 UVA/UVB Sensor from the ESPEasyPluginPlayground (P130).
Binary file not shown.

After

Width:  |  Height:  |  Size: 40 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.1 KiB

+1
View File
@@ -137,6 +137,7 @@ There are different released versions of ESP Easy:
":ref:`P110_page`","|P110_status|","P110"
":ref:`P111_page`","|P111_status|","P111"
":ref:`P113_page`","|P113_status|","P113"
":ref:`P114_page`","|P114_status|","P114"
":ref:`P115_page`","|P115_status|","P115"
+1 -1
View File
@@ -15,7 +15,7 @@
.. |Plugin_Hardware| replace:: :ref:`P046_page`
.. |Plugin_Keypad| replace:: :ref:`P058_page`, :ref:`P061_page`, :ref:`P062_page`, :ref:`P063_page`
.. |Plugin_Light_Color| replace:: :ref:`P050_page`, :ref:`P066_page`
.. |Plugin_Light_UV| replace:: :ref:`P084_page`, :ref:`P107_page`
.. |Plugin_Light_UV| replace:: :ref:`P084_page`, :ref:`P107_page`, :ref:`P114_page`
.. |Plugin_Light_Lux| replace:: :ref:`P010_page`, :ref:`P015_page`, :ref:`P074_page`
.. |Plugin_Motor| replace:: :ref:`P048_page`, :ref:`P079_page`
.. |Plugin_Notify| replace:: :ref:`P055_page`, :ref:`P065_page`
@@ -37,6 +37,19 @@
.. |P113_compileinfo| replace:: `.`
.. |P113_usedlibraries| replace:: `https://github.com/sparkfun/SparkFun_VL53L1X_Arduino_Library (local copy)`
.. |P114_name| replace:: :cyan:`VEML6075`
.. |P114_type| replace:: :cyan:`UV`
.. |P114_typename| replace:: :cyan:`UV - VEML6075`
.. |P114_porttype| replace:: `.`
.. |P114_status| replace:: :yellow:`TESTING D`
.. |P114_github| replace:: P114_VEML6075.ino
.. _P114_github: https://github.com/letscontrolit/ESPEasy/blob/mega/src/_P114_VEML6075.ino
.. |P114_usedby| replace:: `.`
.. |P114_shortinfo| replace:: `UVA/UVB Sensor`
.. |P114_maintainer| replace:: `TD-er, clumsy-stefan, tonhuisman`
.. |P114_compileinfo| replace:: `.`
.. |P114_usedlibraries| replace:: `.`
.. |P115_name| replace:: :cyan:`MAX1704x`
.. |P115_type| replace:: :cyan:`Energy`
.. |P115_typename| replace:: :cyan:`Energy - MAX1704x`
+3 -3
View File
@@ -188,10 +188,10 @@ P003 :ref:`P003_page`
.. .. include:: ../Plugin/P011_commands.repl
.. P012 :ref:`P012_page`
.. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
P012 :ref:`P012_page`
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.. .. include:: ../Plugin/P012_commands.repl
.. include:: ../Plugin/P012_commands.repl
.. P013 :ref:`P013_page`
+27 -20
View File
@@ -30,6 +30,7 @@
# define P012_SIZE PCONFIG(1)
# define P012_TIMER PCONFIG(2)
# define P012_MODE PCONFIG(3)
# define P012_INVERSE_BTN PCONFIG(4)
boolean Plugin_012(byte function, struct EventStruct *event, String& string)
{
@@ -109,6 +110,8 @@ boolean Plugin_012(byte function, struct EventStruct *event, String& string)
addRowLabel(F("Display button"));
addPinSelect(false, F("taskdevicepin3"), CONFIG_PIN3);
addFormCheckBox(F("Inversed logic"), F("p012_inversed_btn"), P012_INVERSE_BTN == 1, false);
addFormNumericBox(F("Display Timeout"), F("p012_timer"), P012_TIMER);
String options3[3];
@@ -124,10 +127,11 @@ boolean Plugin_012(byte function, struct EventStruct *event, String& string)
case PLUGIN_WEBFORM_SAVE:
{
P012_I2C_ADDR = getFormItemInt(F("i2c_addr"));
P012_SIZE = getFormItemInt(F("p012_size"));
P012_TIMER = getFormItemInt(F("p012_timer"));
P012_MODE = getFormItemInt(F("p012_mode"));
P012_I2C_ADDR = getFormItemInt(F("i2c_addr"));
P012_SIZE = getFormItemInt(F("p012_size"));
P012_TIMER = getFormItemInt(F("p012_timer"));
P012_MODE = getFormItemInt(F("p012_mode"));
P012_INVERSE_BTN = isFormItemChecked(F("p012_inversed_btn")) ? 1 : 0;
// FIXME TD-er: This is a huge stack allocated object.
char deviceTemplate[P12_Nlines][P12_Nchars];
@@ -169,7 +173,7 @@ boolean Plugin_012(byte function, struct EventStruct *event, String& string)
{
if (CONFIG_PIN3 != -1)
{
if (!digitalRead(CONFIG_PIN3))
if (digitalRead(CONFIG_PIN3) == P012_INVERSE_BTN)
{
P012_data_struct *P012_data =
static_cast<P012_data_struct *>(getPluginTaskData(event->TaskIndex));
@@ -264,12 +268,14 @@ String P012_parseTemplate(String& tmpString, byte lineSize) {
String result = parseTemplate_padded(tmpString, lineSize);
const char degree[3] = { 0xc2, 0xb0, 0 }; // Unicode degree symbol
const char degree_lcd[2] = { 0xdf, 0 }; // P012_LCD degree symbol
result.replace(degree, degree_lcd);
char unicodePrefix = 0xc4;
#ifdef USES_P012_POLISH_CHARS
if (result.indexOf(unicodePrefix) != -1) {
# ifdef USES_P012_POLISH_CHARS
if (result.indexOf(unicodePrefix) != -1) {
const char znak_a_uni[3] = { 0xc4, 0x85, 0 }; // Unicode znak a
const char znak_a_lcd[2] = { 0x05, 0 }; // P012_LCD znak a
result.replace(znak_a_uni, znak_a_lcd);
@@ -293,27 +299,27 @@ String P012_parseTemplate(String& tmpString, byte lineSize) {
}
unicodePrefix = 0xc5;
if (result.indexOf(unicodePrefix) != -1) {
const char znak_l_uni[3] = { 0xc5, 0x82, 0 }; // Unicode znak l
const char znak_l_lcd[2] = { 0x01, 0 }; // P012_LCD znak l
if (result.indexOf(unicodePrefix) != -1) {
const char znak_l_uni[3] = { 0xc5, 0x82, 0 }; // Unicode znak l
const char znak_l_lcd[2] = { 0x01, 0 }; // P012_LCD znak l
result.replace(znak_l_uni, znak_l_lcd);
const char znak_L_uni[3] = { 0xc5, 0x81, 0 }; // Unicode znak L
const char znak_L_uni[3] = { 0xc5, 0x81, 0 }; // Unicode znak L
result.replace(znak_L_uni, znak_l_lcd);
const char znak_n_uni[3] = { 0xc5, 0x84, 0 }; // Unicode znak n
const char znak_n_lcd[2] = { 0x04, 0 }; // P012_LCD znak n
const char znak_n_uni[3] = { 0xc5, 0x84, 0 }; // Unicode znak n
const char znak_n_lcd[2] = { 0x04, 0 }; // P012_LCD znak n
result.replace(znak_n_uni, znak_n_lcd);
const char znak_N_uni[3] = { 0xc5, 0x83, 0 }; // Unicode znak N
const char znak_N_uni[3] = { 0xc5, 0x83, 0 }; // Unicode znak N
result.replace(znak_N_uni, znak_n_lcd);
const char znak_s_uni[3] = { 0xc5, 0x9b, 0 }; // Unicode znak s
const char znak_s_lcd[2] = { 0x06, 0 }; // P012_LCD znak s
const char znak_s_uni[3] = { 0xc5, 0x9b, 0 }; // Unicode znak s
const char znak_s_lcd[2] = { 0x06, 0 }; // P012_LCD znak s
result.replace(znak_s_uni, znak_s_lcd);
const char znak_S_uni[3] = { 0xc5, 0x9a, 0 }; // Unicode znak S
const char znak_S_uni[3] = { 0xc5, 0x9a, 0 }; // Unicode znak S
result.replace(znak_S_uni, znak_s_lcd);
const char znak_z1_uni[3] = { 0xc5, 0xba, 0 }; // Unicode znak z z kreska
@@ -332,8 +338,8 @@ String P012_parseTemplate(String& tmpString, byte lineSize) {
}
unicodePrefix = 0xc3;
if (result.indexOf(unicodePrefix) != -1) {
if (result.indexOf(unicodePrefix) != -1) {
const char znak_o_uni[3] = { 0xc3, 0xB3, 0 }; // Unicode znak o
const char znak_o_lcd[2] = { 0x08, 0 }; // P012_LCD znak o
result.replace(znak_o_uni, znak_o_lcd);
@@ -341,9 +347,10 @@ String P012_parseTemplate(String& tmpString, byte lineSize) {
const char znak_O_uni[3] = { 0xc3, 0x93, 0 }; // Unicode znak O
result.replace(znak_O_uni, znak_o_lcd);
}
#endif // USES_P012_POLISH_CHARS
# endif // USES_P012_POLISH_CHARS
unicodePrefix = 0xc3;
if (result.indexOf(unicodePrefix) != -1) {
// See: https://github.com/letscontrolit/ESPEasy/issues/2081
+170
View File
@@ -0,0 +1,170 @@
#include "_Plugin_Helper.h"
#ifdef USES_P114
// #######################################################################################################
// ########################### Plugin 114 VEML6075 I2C UVA/UVB Sensor ###############################
// #######################################################################################################
// ###################################### stefan@clumsy.ch ##########################################
// #######################################################################################################
# define PLUGIN_114
# define PLUGIN_ID_114 114
# define PLUGIN_NAME_114 "UV - VEML6075 UVA/UVB Sensor [TESTING]"
# define PLUGIN_VALUENAME1_114 "UVA"
# define PLUGIN_VALUENAME2_114 "UVB"
# define PLUGIN_VALUENAME3_114 "UVIndex"
# include "./src/PluginStructs/P114_data_struct.h"
boolean Plugin_114(byte function, struct EventStruct *event, String& string)
{
boolean success = false;
switch (function)
{
case PLUGIN_DEVICE_ADD:
{
Device[++deviceCount].Number = PLUGIN_ID_114;
Device[deviceCount].Type = DEVICE_TYPE_I2C;
Device[deviceCount].VType = Sensor_VType::SENSOR_TYPE_TRIPLE;
Device[deviceCount].Ports = 0;
Device[deviceCount].PullUpOption = false;
Device[deviceCount].InverseLogicOption = false;
Device[deviceCount].FormulaOption = true;
Device[deviceCount].ValueCount = 3;
Device[deviceCount].SendDataOption = true;
Device[deviceCount].TimerOption = true;
Device[deviceCount].GlobalSyncOption = true;
break;
}
case PLUGIN_GET_DEVICENAME:
{
string = F(PLUGIN_NAME_114);
break;
}
case PLUGIN_GET_DEVICEVALUENAMES:
{
strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[0], PSTR(PLUGIN_VALUENAME1_114));
strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[1], PSTR(PLUGIN_VALUENAME2_114));
strcpy_P(ExtraTaskSettings.TaskDeviceValueNames[2], PSTR(PLUGIN_VALUENAME3_114));
break;
}
case PLUGIN_WEBFORM_SHOW_I2C_PARAMS:
{
int optionValues[2] = { 0x10, 0x11 };
addFormSelectorI2C(F("plugin_114_veml6075_i2c"), 2, optionValues, PCONFIG(0));
addFormNote(F("SDO Low=0x10, High=0x11"));
break;
}
case PLUGIN_WEBFORM_LOAD:
{
{
String optionsMode2[5];
optionsMode2[0] = F("50 ms");
optionsMode2[1] = F("100 ms");
optionsMode2[2] = F("200 ms");
optionsMode2[3] = F("400 ms");
optionsMode2[4] = F("800 ms");
int optionValuesMode2[5];
optionValuesMode2[0] = IT_50;
optionValuesMode2[1] = IT_100;
optionValuesMode2[2] = IT_200;
optionValuesMode2[3] = IT_400;
optionValuesMode2[4] = IT_800;
addFormSelector(F("Integration Time"), F("plugin_114_veml6075_it"), 5, optionsMode2, optionValuesMode2, PCONFIG(1));
}
{
String optionsMode3[2];
optionsMode3[0] = F("Normal Dynamic");
optionsMode3[1] = F("High Dynamic");
int optionValuesMode3[2];
optionValuesMode3[0] = 0;
optionValuesMode3[1] = 1;
addFormSelector(F("Dynamic Setting"), F("plugin_114_veml6075_hd"), 2, optionsMode3, optionValuesMode3, PCONFIG(2));
}
success = true;
break;
}
case PLUGIN_WEBFORM_SAVE:
{
PCONFIG(0) = getFormItemInt(F("plugin_114_veml6075_i2c"));
PCONFIG(1) = getFormItemInt(F("plugin_114_veml6075_it"));
PCONFIG(2) = getFormItemInt(F("plugin_114_veml6075_hd"));
success = true;
break;
}
case PLUGIN_INIT:
{
initPluginTaskData(event->TaskIndex, new (std::nothrow) P114_data_struct(PCONFIG(0), PCONFIG(1), PCONFIG(2) == 1));
P114_data_struct *P114_data =
static_cast<P114_data_struct *>(getPluginTaskData(event->TaskIndex));
if (nullptr == P114_data) {
return success;
}
success = true;
break;
}
case PLUGIN_READ:
{
P114_data_struct *P114_data =
static_cast<P114_data_struct *>(getPluginTaskData(event->TaskIndex));
if (nullptr == P114_data) {
return success;
}
String log;
float UVA = 0.0f;
float UVB = 0.0f;
float UVIndex = 0.0f;
if (P114_data->read_sensor(UVA, UVB, UVIndex)) {
UserVar[event->BaseVarIndex] = UVA;
UserVar[event->BaseVarIndex + 1] = UVB;
UserVar[event->BaseVarIndex + 2] = UVIndex;
if (loglevelActiveFor(LOG_LEVEL_INFO)) {
log.reserve(130);
log = F("VEML6075: Address: 0x");
log += String(PCONFIG(0), HEX);
log += F(" / Integration Time: ");
log += PCONFIG(1);
log += F(" / Dynamic Mode: ");
log += PCONFIG(2);
log += F(" / divisor: ");
log += String(pow(2, PCONFIG(1) - 1));
log += F(" / UVA: ");
log += UserVar[event->BaseVarIndex];
log += F(" / UVB: ");
log += UserVar[event->BaseVarIndex + 1];
log += F(" / UVIndex: ");
log += UserVar[event->BaseVarIndex + 2];
addLog(LOG_LEVEL_INFO, log);
}
success = true;
}
break;
}
}
return success;
}
#endif // ifdef USES_P114
+1 -1
View File
@@ -1369,7 +1369,7 @@ To create/register a plugin, you have to :
#define USES_P113 // VL53L1X
#endif
#ifndef USES_P114
#define USES_P114 //
#define USES_P114 // VEML6075 UVA/UVB sensor
#endif
#ifndef USES_P115
#define USES_P115 //
+1
View File
@@ -18,6 +18,7 @@
#include "../Helpers/Network.h"
#include "../Helpers/Numerical.h"
#include "../Helpers/StringConverter.h"
#include "../Helpers/StringProvider.h"
#include <IPAddress.h>
+106
View File
@@ -0,0 +1,106 @@
#include "../PluginStructs/P114_data_struct.h"
#ifdef USES_P114
// **************************************************************************/
// Constructor
// **************************************************************************/
P114_data_struct::P114_data_struct(uint8_t i2c_addr, uint8_t integration_time, bool highDensity)
: i2cAddress(i2c_addr), IT(integration_time), HD(highDensity) {}
// **************************************************************************/
// Initialize sensor and read data from VEML6075
// **************************************************************************/
bool P114_data_struct::read_sensor(float& _UVA, float& _UVB, float& _UVIndex) {
if (!initialised) {
initialised = init_sensor(); // Check id device is present
}
String log;
if (loglevelActiveFor(LOG_LEVEL_DEBUG)) {
log.reserve(40);
log = F("VEML6075: i2caddress: 0x");
log += String(i2cAddress, HEX);
addLog(LOG_LEVEL_DEBUG, log);
log = F("VEML6075: initialized: ");
log += String(initialised ? F("true") : F("false"));
addLog(LOG_LEVEL_DEBUG, log);
}
if (initialised) {
for (int j = 0; j < 5; j++) {
UVData[j] = I2C_read16_LE_reg(i2cAddress, VEML6075_UVA_DATA + j);
}
// Calculate the UV Index, valid in open air not behind glass!
UVAComp = (UVData[0] - UVData[1]) - ACoef * (UVData[3] - UVData[1]) - BCoef * (UVData[4] - UVData[1]);
UVBComp = (UVData[2] - UVData[1]) - CCoef * (UVData[3] - UVData[1]) - DCoef * (UVData[4] - UVData[1]);
_UVIndex = ((UVBComp * UVBresponsivity) + (UVAComp * UVAresponsivity)) / 2.;
_UVA = UVData[0] / pow(2, IT - 1); // UVA light sensitivity increases linear with integration time
_UVB = UVData[2] / pow(2, IT - 1); // UVB light sensitivity increases linear with integration time
// float UVASensitivity = 0.93/((float) (IT + 1)); // UVA light sensitivity increases with integration time
// float UVBSensitivity = 2.10/((float) (IT + 1)); // UVB light sensitivity increases with integration time
if (loglevelActiveFor(LOG_LEVEL_DEBUG)) {
log = F("VEML6075: IT raw: 0x");
log += String(IT + 1, HEX);
addLog(LOG_LEVEL_DEBUG, log);
}
return true;
}
return false;
}
// **************************************************************************/
// Check VEML6075 presence and initialize
// **************************************************************************/
bool P114_data_struct::init_sensor() {
uint16_t deviceID = I2C_readS16_LE_reg(i2cAddress, VEML6075_UV_ID);
String log;
if (loglevelActiveFor(LOG_LEVEL_DEBUG)) {
log.reserve(60);
log = F("VEML6075: ID: 0x");
log += String(deviceID, HEX);
log += F(" / checked Address: 0x");
log += String(i2cAddress, HEX);
log += F(" / 0x");
log += String(VEML6075_UV_ID, HEX);
addLog(LOG_LEVEL_DEBUG, log);
}
if (deviceID != 0x26) {
log.reserve(60);
log = F("VEML6075: wrong deviceID: ");
log += String(deviceID, HEX);
addLog(LOG_LEVEL_ERROR, log);
return false;
} else {
log.reserve(60);
// log = F("VEML6075: found deviceID: 0x");
// log += String(deviceID, HEX);
if (!I2C_write16_LE_reg(i2cAddress, VEML6075_UV_CONF, (IT << 4) | (HD << 3))) { // Bit 3 must be 0, bit 0 is 0 for run and 1 for
// shutdown, LS Byte
log = F("VEML6075: setup failed!!");
log += F(" / CONF: ");
log += String(static_cast<uint16_t>(IT << 4) | (HD << 3), BIN);
addLog(LOG_LEVEL_ERROR, log);
return false;
} else if (loglevelActiveFor(LOG_LEVEL_INFO)) {
log = F("VEML6075: sensor initialised / CONF: ");
log += String((uint16_t)(IT << 4) | (HD << 3), BIN);
addLog(LOG_LEVEL_INFO, log);
}
}
return true;
}
#endif // ifdef USES_P114
+63
View File
@@ -0,0 +1,63 @@
#ifndef PLUGINSTRUCTS_P114_DATA_STRUCT_H
#define PLUGINSTRUCTS_P114_DATA_STRUCT_H
#include "../../_Plugin_Helper.h"
#ifdef USES_P114
////////////////////////////
// VEML6075 Command Codes //
////////////////////////////
# define VEML6075_UV_CONF 0x00 // command codes
# define VEML6075_UVA_DATA 0x07 // 2 bytes
# define VEML6075_UVDUMMY_DATA 0x08
# define VEML6075_UVB_DATA 0x09
# define VEML6075_UVCOMP1_DATA 0x0A
# define VEML6075_UVCOMP2_DATA 0x0B
# define VEML6075_UV_ID 0x0C // should retrn 0x26
// Calculation factors
# define ACoef 3.33f
# define BCoef 2.5f
# define CCoef 3.66f
# define DCoef 2.75f
# define UVAresponsivity 0.0011f
# define UVBresponsivity 0.00125f
enum IT {
IT_50 = 0, // 50 ms
IT_100 = 1, // 100 ms
IT_200 = 2, // 200 ms
IT_400 = 3, // 400 ms
IT_800 = 4 // 800 ms
};
struct P114_data_struct : public PluginTaskData_base {
public:
P114_data_struct(uint8_t i2c_addr,
uint8_t integration_time,
bool highDensity);
bool read_sensor(float& _UVA,
float& _UVB,
float& _UVIndex);
private:
bool init_sensor();
uint8_t i2cAddress;
// Specify VEML6075 Integration time
uint8_t IT;
bool HD;
uint16_t UVData[5] = { 0, 0, 0, 0, 0 }; // UVA, Dummy, UVB, UVComp1, UVComp2
float UVAComp;
float UVBComp;
bool initialised;
};
#endif // ifdef USES_P114
#endif // ifndef PLUGINSTRUCTS_P114_DATA_STRUCT_H