Browse Source

sns: add SI1145 sensor (#2216)

Co-authored-by: Joop Hilverink <33230021+HilverinkJ@users.noreply.github.com>
mcspr-patch-1
Max Prokhorov 4 years ago
committed by GitHub
parent
commit
b500273029
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 130 additions and 14 deletions
  1. +3
    -0
      code/espurna/board.ino
  2. +28
    -13
      code/espurna/config/sensors.h
  3. +1
    -0
      code/espurna/config/types.h
  4. +4
    -0
      code/espurna/sensor.h
  5. +9
    -1
      code/espurna/sensor.ino
  6. +3
    -0
      code/espurna/sensors/I2CSensor.h
  7. +80
    -0
      code/espurna/sensors/SI1145Sensor.h
  8. +1
    -0
      code/platformio.ini
  9. +1
    -0
      code/test/build/sensor.h

+ 3
- 0
code/espurna/board.ino View File

@ -294,6 +294,9 @@ PROGMEM const char espurna_sensors[] =
#if ADE7953_SUPPORT #if ADE7953_SUPPORT
"ADE7953 " "ADE7953 "
#endif #endif
#if SI1145_SUPPORT
"SI1145 "
#endif
""; "";
#endif // SENSOR_SUPPORT == 1 #endif // SENSOR_SUPPORT == 1


+ 28
- 13
code/espurna/config/sensors.h View File

@ -1225,6 +1225,32 @@
#define EZOPH_SYNC_INTERVAL 1000 // Amount of time (in ms) sync new readings. #define EZOPH_SYNC_INTERVAL 1000 // Amount of time (in ms) sync new readings.
#endif #endif
// -----------------------------------------------------------------------------
// ADE7953 Shelly Sensor
// Enable support by passing ADE7953_SUPPORT=1 build flag
// -----------------------------------------------------------------------------
#ifndef ADE7953_SUPPORT
#define ADE7953_SUPPORT 0
#endif
#ifndef ADE7953_ADDRESS
#define ADE7953_ADDRESS 0x38
#endif
// -----------------------------------------------------------------------------
// SI1145 UV Sensor over I2C
// Enable support by passing SI1145_SUPPORT=1 build flag
// -----------------------------------------------------------------------------
#ifndef SI1145_SUPPORT
#define SI1145_SUPPORT 0
#endif
#ifndef SI1145_ADDRESS
#define SI1145_ADDRESS 0x60
#endif
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// ADC // ADC
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
@ -1268,19 +1294,6 @@
#define I2C_PERFORM_SCAN 1 // Perform a bus scan on boot #define I2C_PERFORM_SCAN 1 // Perform a bus scan on boot
#endif #endif
// -----------------------------------------------------------------------------
// ADE7953 Shelly Sensor
// Enable support by passing ADE7953_SUPPORT=1 build flag
// -----------------------------------------------------------------------------
#ifndef ADE7953_SUPPORT
#define ADE7953_SUPPORT 0
#endif
#ifndef ADE7953_ADDRESS
#define ADE7953_ADDRESS 0x38
#endif
// ============================================================================= // =============================================================================
// Configuration helpers // Configuration helpers
// ============================================================================= // =============================================================================
@ -1294,6 +1307,7 @@
EMON_ADC121_SUPPORT || \ EMON_ADC121_SUPPORT || \
EMON_ADS1X15_SUPPORT || \ EMON_ADS1X15_SUPPORT || \
SHT3X_I2C_SUPPORT || \ SHT3X_I2C_SUPPORT || \
SI1145_SUPPORT || \
SI7021_SUPPORT || \ SI7021_SUPPORT || \
VEML6075_SUPPORT || \ VEML6075_SUPPORT || \
VL53L1X_SUPPORT \ VL53L1X_SUPPORT \
@ -1350,6 +1364,7 @@
SDS011_SUPPORT || \ SDS011_SUPPORT || \
SENSEAIR_SUPPORT || \ SENSEAIR_SUPPORT || \
SHT3X_I2C_SUPPORT || \ SHT3X_I2C_SUPPORT || \
SI1145_SUPPORT || \
SI7021_SUPPORT || \ SI7021_SUPPORT || \
SONAR_SUPPORT || \ SONAR_SUPPORT || \
T6613_SUPPORT || \ T6613_SUPPORT || \


+ 1
- 0
code/espurna/config/types.h View File

@ -330,6 +330,7 @@
#define SENSOR_LDR_ID 36 #define SENSOR_LDR_ID 36
#define SENSOR_ADE7953_ID 37 #define SENSOR_ADE7953_ID 37
#define SENSOR_T6613_ID 38 #define SENSOR_T6613_ID 38
#define SENSOR_SI1145_ID 39
//-------------------------------------------------------------------------------- //--------------------------------------------------------------------------------
// Magnitudes // Magnitudes


+ 4
- 0
code/espurna/sensor.h View File

@ -311,5 +311,9 @@ void sensorLoop();
#include "sensors/ADE7953Sensor.h" #include "sensors/ADE7953Sensor.h"
#endif #endif
#if SI1145_SUPPORT
#include "sensors/SI1145Sensor.h"
#endif
//-------------------------------------------------------------------------------- //--------------------------------------------------------------------------------

+ 9
- 1
code/espurna/sensor.ino View File

@ -1532,7 +1532,7 @@ void _sensorLoad() {
} }
#endif #endif
#if ADE7953_SUPPORT
#if ADE7953_SUPPORT
{ {
ADE7953Sensor * sensor = new ADE7953Sensor(); ADE7953Sensor * sensor = new ADE7953Sensor();
sensor->setAddress(ADE7953_ADDRESS); sensor->setAddress(ADE7953_ADDRESS);
@ -1540,6 +1540,14 @@ void _sensorLoad() {
} }
#endif #endif
#if SI1145_SUPPORT
{
SI1145Sensor * sensor = new SI1145Sensor();
sensor->setAddress(SI1145_ADDRESS);
_sensors.push_back(sensor);
}
#endif
} }
void _sensorCallback(unsigned char i, unsigned char type, double value) { void _sensorCallback(unsigned char i, unsigned char type, double value) {


+ 3
- 0
code/espurna/sensors/I2CSensor.h View File

@ -27,6 +27,9 @@
#include "BaseSensor.h" #include "BaseSensor.h"
// TODO: Must inherit from I2CSensor<>, not just I2CSensor. Even with default value :(
// Perhaps I2CSensor should be alias for I2CSensorBase?
template <typename T = BaseSensor> template <typename T = BaseSensor>
class I2CSensor : public T { class I2CSensor : public T {


+ 80
- 0
code/espurna/sensors/SI1145Sensor.h View File

@ -0,0 +1,80 @@
// -----------------------------------------------------------------------------
// SI1145 Sensor over I2C
// Copyright (C) 2020 by @HilverinkJ (https://github.com/HilverinkJ)
// Based on https://github.com/xoseperez/espurna/issues/2192#issuecomment-603430308
// -----------------------------------------------------------------------------
#if SENSOR_SUPPORT && SI1145_SUPPORT
#pragma once
#include <Arduino.h>
#include <Adafruit_SI1145.h>
#include "I2CSensor.h"
class SI1145Sensor : public I2CSensor<> {
public:
SI1145Sensor() {
_count = 1;
_sensor_id = SENSOR_SI1145_ID;
_si1145 = new Adafruit_SI1145();
}
void begin() {
static unsigned char addresses[1] = { SI1145_ADDRESS };
_address = _begin_i2c(_address, sizeof(addresses), addresses);
if (_address == 0) return;
if (!_si1145->begin()) {
_ready = false;
return;
}
// Adafruit library never sets any errors
_error = SENSOR_ERROR_OK;
_ready = true;
}
// ---------------------------------------------------------------------
// Sensor API
// ---------------------------------------------------------------------
// Descriptive name of the sensor
String description() {
char buffer[25];
snprintf(buffer, sizeof(buffer), "SI1145 @ 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_UVI;
return MAGNITUDE_NONE;
}
// Pre-read hook (usually to populate registers with up-to-date data)
void pre() {
_uvi = _si1145->readUV() / 100.0;
}
// Current value for slot # index
double value(unsigned char index) {
if (index == 0) return _uvi;
return 0.0;
}
protected:
Adafruit_SI1145 * _si1145 = nullptr;
double _uvi = 0.0;
};
#endif // SENSOR_SUPPORT && SI1145_SUPPORT

+ 1
- 0
code/platformio.ini View File

@ -157,6 +157,7 @@ lib_deps =
https://github.com/pololu/vl53l1x-arduino#1.0.1 https://github.com/pololu/vl53l1x-arduino#1.0.1
https://github.com/mcleng/MAX6675-Library#2.0.1 https://github.com/mcleng/MAX6675-Library#2.0.1
https://github.com/ThingPulse/esp8266-oled-ssd1306#3398c97 https://github.com/ThingPulse/esp8266-oled-ssd1306#3398c97
Adafruit SI1145 Library@~1.1.1
lib_ignore = lib_ignore =
AsyncTCP AsyncTCP


+ 1
- 0
code/test/build/sensor.h View File

@ -20,6 +20,7 @@
#define SDS011_SUPPORT 1 #define SDS011_SUPPORT 1
#define SENSEAIR_SUPPORT 1 #define SENSEAIR_SUPPORT 1
#define SHT3X_I2C_SUPPORT 1 #define SHT3X_I2C_SUPPORT 1
#define SI1145_SUPPORT 1
#define SI7021_SUPPORT 1 #define SI7021_SUPPORT 1
#define SONAR_SUPPORT 1 #define SONAR_SUPPORT 1
#define T6613_SUPPORT 1 #define T6613_SUPPORT 1


Loading…
Cancel
Save