Browse Source

Add support for VEML6075

pull/1112/head
Rui Marinho 5 years ago
parent
commit
e2b7f953a7
8 changed files with 160 additions and 20 deletions
  1. +13
    -5
      code/espurna/config/progmem.h
  2. +25
    -1
      code/espurna/config/sensors.h
  3. +14
    -11
      code/espurna/config/types.h
  4. +8
    -0
      code/espurna/sensor.ino
  5. +1
    -1
      code/espurna/sensors/GUVAS12SDSensor.h
  6. +96
    -0
      code/espurna/sensors/VEML6075Sensor.h
  7. +2
    -2
      code/html/custom.js
  8. +1
    -0
      code/platformio.ini

+ 13
- 5
code/espurna/config/progmem.h View File

@ -223,6 +223,9 @@ PROGMEM const char espurna_sensors[] =
#if V9261F_SUPPORT
"V9261F "
#endif
#if VEML6075_SUPPORT
"VEML6075 "
#endif
"";
@ -232,7 +235,9 @@ PROGMEM const unsigned char magnitude_decimals[] = {
3, 0, 0, 0, 0, 0, 0, 0, // Power decimals
0, 0, 0, // analog, digital, event
0, 0, 0, // PM
0, 0, 3, 3, 0,
0, 0,
0, 0, 3, // UVA, UVB, UVI
3, 0,
4, 4, // Geiger Counter decimals
0,
0, 0, 0 // NO2, CO, Ohms
@ -258,7 +263,9 @@ PROGMEM const char magnitude_pm2dot5_topic[] = "pm2dot5";
PROGMEM const char magnitude_pm10_topic[] = "pm10";
PROGMEM const char magnitude_co2_topic[] = "co2";
PROGMEM const char magnitude_lux_topic[] = "lux";
PROGMEM const char magnitude_uv_topic[] = "uv";
PROGMEM const char magnitude_uva_topic[] = "uva";
PROGMEM const char magnitude_uvb_topic[] = "uvb";
PROGMEM const char magnitude_uvi_topic[] = "uvi";
PROGMEM const char magnitude_distance_topic[] = "distance";
PROGMEM const char magnitude_hcho_topic[] = "hcho";
PROGMEM const char magnitude_geiger_cpm_topic[] = "ldr_cpm"; // local dose rate [Counts per minute]
@ -275,7 +282,8 @@ PROGMEM const char* const magnitude_topics[] = {
magnitude_power_factor_topic, magnitude_energy_topic, magnitude_energy_delta_topic,
magnitude_analog_topic, magnitude_digital_topic, magnitude_event_topic,
magnitude_pm1dot0_topic, magnitude_pm2dot5_topic, magnitude_pm10_topic,
magnitude_co2_topic, magnitude_lux_topic, magnitude_uv_topic,
magnitude_co2_topic, magnitude_lux_topic,
magnitude_uva_topic, magnitude_uvb_topic, magnitude_uvi_topic,
magnitude_distance_topic, magnitude_hcho_topic,
magnitude_geiger_cpm_topic, magnitude_geiger_sv_topic,
magnitude_count_topic,
@ -296,7 +304,6 @@ PROGMEM const char magnitude_kwh[] = "kWh";
PROGMEM const char magnitude_ugm3[] = "µg/m³";
PROGMEM const char magnitude_ppm[] = "ppm";
PROGMEM const char magnitude_lux[] = "lux";
PROGMEM const char magnitude_uv[] = "uv";
PROGMEM const char magnitude_distance[] = "m";
PROGMEM const char magnitude_mgm3[] = "mg/m³";
PROGMEM const char magnitude_geiger_cpm[] = "cpm"; // Counts per Minute: Unit of local dose rate (Geiger counting)
@ -311,7 +318,8 @@ PROGMEM const char* const magnitude_units[] = {
magnitude_percentage, magnitude_joules, magnitude_joules,
magnitude_empty, magnitude_empty, magnitude_empty,
magnitude_ugm3, magnitude_ugm3, magnitude_ugm3,
magnitude_ppm, magnitude_lux, magnitude_uv,
magnitude_ppm, magnitude_lux,
magnitude_empty, magnitude_empty, magnitude_empty,
magnitude_distance, magnitude_mgm3,
magnitude_geiger_cpm, magnitude_geiger_sv, // Geiger counter units
magnitude_empty, //


+ 25
- 1
code/espurna/config/sensors.h View File

@ -690,6 +690,25 @@
#define V9261F_POWER_FACTOR 153699.0
#define V9261F_RPOWER_FACTOR V9261F_CURRENT_FACTOR
//------------------------------------------------------------------------------
// VEML6075 based power sensor
// Enable support by passing VEML6075_SUPPORT=1 build flag
//------------------------------------------------------------------------------
#ifndef VEML6075_SUPPORT
#define VEML6075_SUPPORT 0
#endif
#ifndef VEML6075_INTEGRATION_TIME
#define VEML6075_INTEGRATION_TIME VEML6075::IT_100MS // The time, in milliseconds, allocated for a single
#endif // measurement. A longer timing budget allows for more
// accurate results at the cost of power.
#ifndef VEML6075_DYNAMIC_MODE
#define VEML6075_DYNAMIC_MODE VEML6075::DYNAMIC_NORMAL // The dynamic mode can either be normal or high. In high
#endif // dynamic mode, the resolution increases by about two
// times.
// =============================================================================
// Sensor helpers configuration - can't move to dependencies.h
// =============================================================================
@ -724,7 +743,8 @@
SI7021_SUPPORT || \
SONAR_SUPPORT || \
TMP3X_SUPPORT || \
V9261F_SUPPORT \
V9261F_SUPPORT || \
VEML6075_SUPPORT \
)
#endif
@ -882,4 +902,8 @@
#include "../sensors/V9261FSensor.h"
#endif
#if VEML6075_SUPPORT
#include "../sensors/VEML6075Sensor.h"
#endif
#endif // SENSOR_SUPPORT

+ 14
- 11
code/espurna/config/types.h View File

@ -279,6 +279,7 @@
#define SENSOR_SDS011_ID 0x27
#define SENSOR_MICS2710_ID 0x28
#define SENSOR_MICS5525_ID 0x29
#define SENSOR_VEML6075_ID 0x30
//--------------------------------------------------------------------------------
// Magnitudes
@ -304,14 +305,16 @@
#define MAGNITUDE_PM10 17
#define MAGNITUDE_CO2 18
#define MAGNITUDE_LUX 19
#define MAGNITUDE_UV 20
#define MAGNITUDE_DISTANCE 21
#define MAGNITUDE_HCHO 22
#define MAGNITUDE_GEIGER_CPM 23
#define MAGNITUDE_GEIGER_SIEVERT 24
#define MAGNITUDE_COUNT 25
#define MAGNITUDE_NO2 26
#define MAGNITUDE_CO 27
#define MAGNITUDE_RESISTANCE 28
#define MAGNITUDE_MAX 29
#define MAGNITUDE_UVA 20
#define MAGNITUDE_UVB 21
#define MAGNITUDE_UVI 22
#define MAGNITUDE_DISTANCE 23
#define MAGNITUDE_HCHO 24
#define MAGNITUDE_GEIGER_CPM 25
#define MAGNITUDE_GEIGER_SIEVERT 26
#define MAGNITUDE_COUNT 27
#define MAGNITUDE_NO2 28
#define MAGNITUDE_CO 29
#define MAGNITUDE_RESISTANCE 30
#define MAGNITUDE_MAX 31

+ 8
- 0
code/espurna/sensor.ino View File

@ -637,6 +637,14 @@ void _sensorLoad() {
}
#endif
#if VEML6075_SUPPORT
{
VEML6075Sensor * sensor = new VEML6075Sensor();
sensor->setIntegrationTime(VEML6075_INTEGRATION_TIME);
sensor->setDynamicMode(VEML6075_DYNAMIC_MODE);
_sensors.push_back(sensor);
}
#endif
}
void _sensorCallback(unsigned char i, unsigned char type, double value) {


+ 1
- 1
code/espurna/sensors/GUVAS12SDSensor.h View File

@ -104,7 +104,7 @@ class GUVAS12SDSensor : public BaseSensor {
// Type for slot # index
unsigned char type(unsigned char index) {
if (index == 0) return MAGNITUDE_UV;
if (index == 0) return MAGNITUDE_UVI;
return MAGNITUDE_NONE;
}


+ 96
- 0
code/espurna/sensors/VEML6075Sensor.h View File

@ -0,0 +1,96 @@
// -----------------------------------------------------------------------------
// VEML6075 Sensor over I2C
// Copyright (C) 2017-2018 by Xose Pérez <xose dot perez at gmail dot com>
// -----------------------------------------------------------------------------
#if SENSOR_SUPPORT && VEML6075_SUPPORT
#pragma once
#undef I2C_SUPPORT
#define I2C_SUPPORT 1 // Explicitly request I2C support.
#include "Arduino.h"
#include "I2CSensor.h"
#include "SparkFun_VEML6075_Arduino_Library.h"
class VEML6075Sensor : public I2CSensor {
public:
// ---------------------------------------------------------------------
// Public
// ---------------------------------------------------------------------
VEML6075Sensor(): I2CSensor() {
_count = 3;
_sensor_id = SENSOR_VEML6075_ID;
_veml6075 = new VEML6075();
}
~VEML6075Sensor() {
delete _veml6075;
}
void begin() {
if (!_veml6075->begin()) {
return;
};
_ready = true;
}
// ---------------------------------------------------------------------
// Sensor API
// ---------------------------------------------------------------------
// Descriptive name of the sensor
String description() {
char buffer[25];
snprintf(buffer, sizeof(buffer), "VEML6075 @ I2C (0x%02X)", _address);
return String(buffer);
}
// Descriptive name of the slot # index
String slot(unsigned char index) {
return description();
};
// Type for slot # index
unsigned char type(unsigned char index) {
if (index == 0) return MAGNITUDE_UVA;
if (index == 1) return MAGNITUDE_UVB;
if (index == 2) return MAGNITUDE_UVI;
return MAGNITUDE_NONE;
}
// Pre-read hook (usually to populate registers with up-to-date data)
void pre() {
_error = SENSOR_ERROR_OK;
}
// Current value for slot # index
double value(unsigned char index) {
if (index == 0) return _veml6075->a();
if (index == 1) return _veml6075->b();
if (index == 2) return _veml6075->index();
return 0;
}
void setIntegrationTime(VEML6075::veml6075_uv_it_t integration_time) {
_veml6075->setIntegrationTime(integration_time);
}
void setDynamicMode(VEML6075::veml6075_hd_t dynamic_mode) {
_veml6075->setHighDynamic(dynamic_mode);
}
protected:
VEML6075 * _veml6075 = NULL;
};
#endif // SENSOR_SUPPORT && VEML6075_SUPPORT

+ 2
- 2
code/html/custom.js View File

@ -47,7 +47,7 @@ function sensorName(id) {
"Events", "PMSX003", "BMX280", "MHZ19", "SI7021",
"SHT3X I2C", "BH1750", "PZEM004T", "AM2320 I2C", "GUVAS12SD",
"TMP3X", "Sonar", "SenseAir", "GeigerTicks", "GeigerCPM",
"NTC", "SDS011", "MICS2710", "MICS5525"
"NTC", "SDS011", "MICS2710", "MICS5525", "VEML6075"
];
if (1 <= id && id <= names.length) {
return names[id - 1];
@ -61,7 +61,7 @@ function magnitudeType(type) {
"Current", "Voltage", "Active Power", "Apparent Power",
"Reactive Power", "Power Factor", "Energy", "Energy (delta)",
"Analog", "Digital", "Event",
"PM1.0", "PM2.5", "PM10", "CO2", "Lux", "UV", "Distance" , "HCHO",
"PM1.0", "PM2.5", "PM10", "CO2", "Lux", "UVA", "UVB", "UV Index", "Distance" , "HCHO",
"Local Dose Rate", "Local Dose Rate",
"Count",
"NO2", "CO", "Resistance"


+ 1
- 0
code/platformio.ini View File

@ -97,6 +97,7 @@ lib_deps =
https://github.com/LowPowerLab/RFM69#1.1.3
https://github.com/xoseperez/Time
NewPing
https://github.com/sparkfun/SparkFun_VEML6075_Arduino_Library#V_1.0.3
lib_ignore =
# ------------------------------------------------------------------------------


Loading…
Cancel
Save