Browse Source

Further map devices to images

v2
Xose Pérez 6 years ago
parent
commit
ad1dfad61c
7 changed files with 738 additions and 1143 deletions
  1. +406
    -893
      code/espurna/config/hardware.h
  2. +10
    -5
      code/espurna/config/sensors.h
  3. +22
    -8
      code/espurna/config/types.h
  4. +45
    -5
      code/espurna/hardware.ino
  5. +230
    -225
      code/espurna/sensor.ino
  6. +25
    -4
      code/espurna/sensors/HLW8012Sensor.h
  7. +0
    -3
      code/espurna/sensors/PMSX003Sensor.h

+ 406
- 893
code/espurna/config/hardware.h
File diff suppressed because it is too large
View File


+ 10
- 5
code/espurna/config/sensors.h View File

@ -238,6 +238,10 @@
#define EMON_REPORT_POWER 1 // Report power #define EMON_REPORT_POWER 1 // Report power
#define EMON_REPORT_ENERGY 1 // Report energy #define EMON_REPORT_ENERGY 1 // Report energy
#define EMON_PROVIDER_ANALOG 1
#define EMON_PROVIDER_ADC121 2
#define EMON_PROVIDER_ADS1X15 3
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// Energy Monitor based on ADC121 // Energy Monitor based on ADC121
// Enable support by passing EMON_ADC121_SUPPORT=1 build flag // Enable support by passing EMON_ADC121_SUPPORT=1 build flag
@ -310,7 +314,7 @@
#endif #endif
#ifndef GEIGER_PIN #ifndef GEIGER_PIN
#define GEIGER_PIN D1 // GPIO to monitor "D1" => "GPIO5"
#define GEIGER_PIN 5 // GPIO to monitor "D1" => "GPIO5"
#endif #endif
#ifndef GEIGER_PIN_MODE #ifndef GEIGER_PIN_MODE
@ -493,20 +497,21 @@
#endif #endif
#ifndef PMS_USE_SOFT #ifndef PMS_USE_SOFT
#define PMS_USE_SOFT 0 // If PMS_USE_SOFT == 1, DEBUG_SERIAL_SUPPORT must be 0
#define PMS_USE_SOFT 0 // If PMS_USE_SOFT == 1, DEBUG_SERIAL_SUPPORT must be 0
#endif #endif
#ifndef PMS_RX_PIN #ifndef PMS_RX_PIN
#define PMS_RX_PIN 13 // Software serial RX GPIO (if PMS_USE_SOFT == 1)
#define PMS_RX_PIN 13 // Software serial RX GPIO (if PMS_USE_SOFT == 1)
#endif #endif
#ifndef PMS_TX_PIN #ifndef PMS_TX_PIN
#define PMS_TX_PIN 15 // Software serial TX GPIO (if PMS_USE_SOFT == 1)
#define PMS_TX_PIN 15 // Software serial TX GPIO (if PMS_USE_SOFT == 1)
#endif #endif
#ifndef PMS_HW_PORT #ifndef PMS_HW_PORT
#define PMS_HW_PORT Serial // Hardware serial port (if PMS_USE_SOFT == 0)
#define PMS_HW_PORT Serial // Hardware serial port (if PMS_USE_SOFT == 0)
#endif #endif
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
// PZEM004T based power monitor // PZEM004T based power monitor
// Enable support by passing PZEM004T_SUPPORT=1 build flag // Enable support by passing PZEM004T_SUPPORT=1 build flag


+ 22
- 8
code/espurna/config/types.h View File

@ -7,16 +7,30 @@
// IMAGES // IMAGES
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Basics
#define ESPURNA_CORE 0 // minimal #define ESPURNA_CORE 0 // minimal
#define ESPURNA_BASIC 1 // relay, button, led #define ESPURNA_BASIC 1 // relay, button, led
#define ESPURNA_LIGHT 2 // ESPURNA_BASIC + light drivers
#define ESPURNA_POWER 3 // ESPURNA_BASIC + power monitoring sensors
#define ESPURNA_SENSOR 4 // ESPURNA_BASIC + basic sensors
#define ESPURNA_SONOFF_DUAL 10 // Device specific
#define ESPURNA_SONOFF_RFBRIDGE 11 // Device specific
#define ESPURNA_RFM69 12 // Device specific
#define ESPURNA_STM 13 // Device specific
#define ESPURNA_GEIGER 14 // Device specific
// Lights
#define ESPURNA_DIMMER 10
#define ESPURNA_MY92XX 11
// Power monitoring
#define ESPURNA_EMON 20
#define ESPURNA_HLW8012 21
#define ESPURNA_CSE77XX 22
#define ESPURNA_V9261F 23
#define ESPURNA_ECH1560 24
// Sensors
#define ESPURNA_SENSOR 30
// Device specific
#define ESPURNA_SONOFF_DUAL 40
#define ESPURNA_SONOFF_RFBRIDGE 41
#define ESPURNA_RFM69 42
#define ESPURNA_STM 43
#define ESPURNA_GEIGER 44
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// WIFI // WIFI


+ 45
- 5
code/espurna/hardware.ino View File

@ -12,7 +12,7 @@ Copyright (C) 2016-2018 by Xose Pérez <xose dot perez at gmail dot com>
// //
// Configuration settings for each device, the most common ones are: // Configuration settings for each device, the most common ones are:
// //
// board: ID of the board according to XXX
// board: ID of the board according to boards enum in hardware.h
// device: Name of the device ("string") // device: Name of the device ("string")
// btnGPIO <n>: GPIO for the n-th button (0-based) // btnGPIO <n>: GPIO for the n-th button (0-based)
// btnRelay <n>: Relay index linked to the n-th button // btnRelay <n>: Relay index linked to the n-th button
@ -94,6 +94,7 @@ void _hardwareLoad() {
setSetting("btnMode", 0, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH); setSetting("btnMode", 0, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH);
setSetting("btnRelay", 0, 0); setSetting("btnRelay", 0, 0);
// Jack is connected to GPIO14 (and with a small hack to GPIO4)
setSetting("dhtEnabled", 1); setSetting("dhtEnabled", 1);
setSetting("dhtGPIO", 0, 14); setSetting("dhtGPIO", 0, 14);
@ -1247,6 +1248,7 @@ void _hardwareLoad() {
setSetting("hlwSELGPIO", 3); setSetting("hlwSELGPIO", 3);
setSetting("hlwCF1GPIO", 14); setSetting("hlwCF1GPIO", 14);
setSetting("hlwCFGPIO", 5); setSetting("hlwCFGPIO", 5);
setSetting("hlwCurRes", 0.001);
setSetting("hlwVolResUp", 2400000); setSetting("hlwVolResUp", 2400000);
#elif defined(TONBUX_XSSSA06) #elif defined(TONBUX_XSSSA06)
@ -1613,6 +1615,7 @@ void _hardwareLoad() {
setSetting("rlyType", 2, RELAY_TYPE_NORMAL); setSetting("rlyType", 2, RELAY_TYPE_NORMAL);
setSetting("rlyType", 3, RELAY_TYPE_NORMAL); setSetting("rlyType", 3, RELAY_TYPE_NORMAL);
// Disable UART noise since this board uses GPIO3
setSetting("dbgSerial", 0); setSetting("dbgSerial", 0);
#elif defined(BH_ONOFRE) #elif defined(BH_ONOFRE)
@ -1666,12 +1669,46 @@ void _hardwareLoad() {
setSetting("hlwSELGPIO", 12); setSetting("hlwSELGPIO", 12);
setSetting("hlwCF1GPIO", 14); setSetting("hlwCF1GPIO", 14);
setSetting("hlwCFGPIO", 5); setSetting("hlwCFGPIO", 5);
setSetting("hlwCurLevel", LOW);
setSetting("hlwInt", FALLING);
setSetting("hlwCurSel", LOW);
setSetting("hlwIntMode", FALLING);
setSetting("curRatio", 25740); setSetting("curRatio", 25740);
setSetting("volRatio", 313400); setSetting("volRatio", 313400);
setSetting("pwrRatio", 3414290); setSetting("pwrRatio", 3414290);
#elif defined(HOMECUBE_16A)
// Homecube 16A is similar to BLITZWOLF_BWSHP2 but some pins differ and it also has RGB LEDs
// https://www.amazon.de/gp/product/B07D7RVF56/ref=oh_aui_detailpage_o00_s01?ie=UTF8&psc=1
setSetting("board", BOARD_HOMECUBE_16A);
setSetting("device", "HOMECUBE_16A");
setSetting("btnGPIO", 0, 13);
setSetting("btnMode", 0, BUTTON_PUSHBUTTON | BUTTON_DEFAULT_HIGH);
setSetting("btnRelay", 0, 0);
setSetting("ledGPIO", 0, 2);
setSetting("ledGPIO", 1, 12);
setSetting("ledGPIO", 2, 0);
setSetting("ledLogic", 0, GPIO_LOGIC_DIRECT);
setSetting("ledLogic", 1, GPIO_LOGIC_DIRECT);
setSetting("ledLogic", 2, GPIO_LOGIC_DIRECT);
setSetting("ledMode", 0, LED_MODE_WIFI);
setSetting("ledMode", 1, LED_MODE_FINDME);
setSetting("ledMode", 2, LED_MODE_OFF);
setSetting("ledRelay", 1, 0);
setSetting("rlyGPIO", 0, 15);
setSetting("rlyType", 0, RELAY_TYPE_NORMAL);
setSetting("hlwSELGPIO", 16);
setSetting("hlwCF1GPIO", 14);
setSetting("hlwCFGPIO", 5);
setSetting("hlwCurSel", LOW);
setSetting("hlwIntMode", FALLING);
setSetting("curRatio", 25740);
setSetting("volRatio", 313400);
setSetting("pwrRatio", 3414290);
#elif defined(TINKERMAN_ESPURNA_SWITCH) #elif defined(TINKERMAN_ESPURNA_SWITCH)
@ -1749,18 +1786,21 @@ void _hardwareLoad() {
setSetting("hlwSELGPIO", 3); setSetting("hlwSELGPIO", 3);
setSetting("hlwCF1GPIO", 14); setSetting("hlwCF1GPIO", 14);
setSetting("hlwCFGPIO", 5); setSetting("hlwCFGPIO", 5);
setSetting("hlwCurLevel", LOW);
setSetting("hlwInt", FALLING);
setSetting("hlwCurSel", LOW);
setSetting("hlwIntMode", FALLING);
setSetting("curRatio", 25740); setSetting("curRatio", 25740);
setSetting("volRatio", 313400); setSetting("volRatio", 313400);
setSetting("pwrRatio", 3414290); setSetting("pwrRatio", 3414290);
setSetting("dbgSerial", 0);
#elif defined(GENERIC_GEIGER_COUNTER) #elif defined(GENERIC_GEIGER_COUNTER)
setSetting("board", BOARD_GENERIC_GEIGER_COUNTER); setSetting("board", BOARD_GENERIC_GEIGER_COUNTER);
setSetting("device", "GENERIC_GEIGER_COUNTER"); setSetting("device", "GENERIC_GEIGER_COUNTER");
setSetting("geiEnabled", 1); setSetting("geiEnabled", 1);
setSetting("geiGPIO", 5);
#elif defined(TINKERMAN_RFM69GW) #elif defined(TINKERMAN_RFM69GW)


+ 230
- 225
code/espurna/sensor.ino View File

@ -6,7 +6,7 @@ Copyright (C) 2016-2018 by Xose Pérez <xose dot perez at gmail dot com>
Module key prefix: sns Module key prefix: sns
Magnitude-based key prefix: pwr ene cur vol tmp hum Magnitude-based key prefix: pwr ene cur vol tmp hum
Sensor-based key previs: hlw bme dht ds cse v92 pze ech gei
Sensor-based key previs: air am ana bh bmx cse dht dig ds ech emon evt gei guv hlw mhz ntc pms pzem sht son tmp3x v92
*/ */
@ -302,290 +302,334 @@ void _sensorReset() {
void _sensorLoad() { void _sensorLoad() {
/* /*
Only loaded (those with *_SUPPORT to 1) and enabled (*Enabled setting to 1)
sensors are being initialized here.
*/
This is temporal, in the future sensors will be initialized based on
soft configuration (data stored in EEPROM config) so you will be able
to define and configure new sensors on the fly
At the time being, only enabled sensors (those with *_SUPPORT to 1) are being
loaded and initialized here. If you want to add new sensors of the same type
just duplicate the block and change the arguments for the set* methods.
Check the DHT block below for an example
*/
unsigned char index = 0;
unsigned char gpio = GPIO_NONE;
#if AM2320_SUPPORT
{
#if AM2320_SUPPORT
if (getSetting("amEnabled", 0).toInt() == 1) {
AM2320Sensor * sensor = new AM2320Sensor(); AM2320Sensor * sensor = new AM2320Sensor();
sensor->setAddress(AM2320_ADDRESS);
sensor->setAddress(getSetting("amAddress", AM2320_ADDRESS).toInt());
_sensors.push_back(sensor); _sensors.push_back(sensor);
}
#endif
}
#endif
#if ANALOG_SUPPORT #if ANALOG_SUPPORT
{
if (getSetting("anaEnabled", 0).toInt() == 1) {
AnalogSensor * sensor = new AnalogSensor(); AnalogSensor * sensor = new AnalogSensor();
sensor->setSamples(ANALOG_SAMPLES);
sensor->setDelay(ANALOG_DELAY);
sensor->setSamples(getSetting("anaSamples", ANALOG_SAMPLES).toInt());
sensor->setDelay(getSetting("anaDelay", ANALOG_DELAY).toInt());
_sensors.push_back(sensor); _sensors.push_back(sensor);
} }
#endif #endif
#if BH1750_SUPPORT #if BH1750_SUPPORT
{
if (getSetting("bhEnabled", 0).toInt() == 1) {
BH1750Sensor * sensor = new BH1750Sensor(); BH1750Sensor * sensor = new BH1750Sensor();
sensor->setAddress(BH1750_ADDRESS);
sensor->setMode(BH1750_MODE);
sensor->setAddress(getSetting("bhAddress", BH1750_ADDRESS).toInt());
sensor->setMode(getSetting("bhMode", BH1750_MODE).toInt());
_sensors.push_back(sensor); _sensors.push_back(sensor);
} }
#endif #endif
#if BMX280_SUPPORT #if BMX280_SUPPORT
{
if (getSetting("bmx280Enabled", 0).toInt() == 1) {
BMX280Sensor * sensor = new BMX280Sensor(); BMX280Sensor * sensor = new BMX280Sensor();
sensor->setAddress(BMX280_ADDRESS);
sensor->setAddress(getSetting("bmx280Address", BMX280_ADDRESS).toInt());
_sensors.push_back(sensor); _sensors.push_back(sensor);
} }
#endif #endif
#if CSE7766_SUPPORT #if CSE7766_SUPPORT
{
CSE7766Sensor * sensor = new CSE7766Sensor();
sensor->setRX(CSE7766_PIN);
_sensors.push_back(sensor);
}
#endif
if (getSetting("cseEnabled", 0).toInt() == 1) {
if ((gpio = getSetting("cseGPIO", GPIO_NONE).toInt()) != GPIO_NONE) {
#if DALLAS_SUPPORT
{
DallasSensor * sensor = new DallasSensor();
sensor->setGPIO(DALLAS_PIN);
_sensors.push_back(sensor);
CSE7766Sensor * sensor = new CSE7766Sensor();
sensor->setRX(gpio);
double value;
value = getSetting("curRatio", 0).toFloat();
if (value > 0) sensor->setCurrentRatio(value);
value = getSetting("volRatio", 0).toFloat();
if (value > 0) sensor->setVoltageRatio(value);
value = getSetting("pwrRatio", 0).toFloat();
if (value > 0) sensor->setPowerRatio(value);
_sensors.push_back(sensor);
}
} }
#endif #endif
#if DHT_SUPPORT
{
DHTSensor * sensor = new DHTSensor();
sensor->setGPIO(DHT_PIN);
sensor->setType(DHT_TYPE);
_sensors.push_back(sensor);
#if DALLAS_SUPPORT
if (getSetting("dsEnabled", 0).toInt() == 1) {
index = 0;
while ((gpio = getSetting("dsGPIO", index, GPIO_NONE).toInt()) != GPIO_NONE) {
DallasSensor * sensor = new DallasSensor();
sensor->setGPIO(gpio);
_sensors.push_back(sensor);
index++;
}
} }
#endif #endif
/*
// Example on how to add a second DHT sensor
// DHT2_PIN and DHT2_TYPE should be defined in sensors.h file
#if DHT_SUPPORT #if DHT_SUPPORT
{
DHTSensor * sensor = new DHTSensor();
sensor->setGPIO(DHT2_PIN);
sensor->setType(DHT2_TYPE);
_sensors.push_back(sensor);
if (getSetting("dhtEnabled", 0).toInt() == 1) {
index = 0;
while ((gpio = getSetting("dhtGPIO", index, GPIO_NONE).toInt()) != GPIO_NONE) {
DHTSensor * sensor = new DHTSensor();
sensor->setGPIO(gpio);
sensor->setType(getSetting("dhtType", index, DHT_CHIP_DHT22).toInt());
_sensors.push_back(sensor);
index++;
}
} }
#endif #endif
*/
#if DIGITAL_SUPPORT #if DIGITAL_SUPPORT
{
DigitalSensor * sensor = new DigitalSensor();
sensor->setGPIO(DIGITAL_PIN);
sensor->setMode(DIGITAL_PIN_MODE);
sensor->setDefault(DIGITAL_DEFAULT_STATE);
_sensors.push_back(sensor);
if (getSetting("digEnabled", 0).toInt() == 1) {
index = 0;
while ((gpio = getSetting("digGPIO", index, GPIO_NONE).toInt()) != GPIO_NONE) {
DigitalSensor * sensor = new DigitalSensor();
sensor->setGPIO(gpio);
sensor->setMode(getSetting("digMode", index, DIGITAL_PIN_MODE).toInt());
sensor->setDefault(getSetting("digDefault", index, DIGITAL_DEFAULT_STATE).toInt());
_sensors.push_back(sensor);
index++;
}
} }
#endif #endif
#if ECH1560_SUPPORT #if ECH1560_SUPPORT
{
if (getSetting("echEnabled", 0).toInt() == 1) {
ECH1560Sensor * sensor = new ECH1560Sensor(); ECH1560Sensor * sensor = new ECH1560Sensor();
sensor->setCLK(ECH1560_CLK_PIN);
sensor->setMISO(ECH1560_MISO_PIN);
sensor->setInverted(ECH1560_INVERTED);
sensor->setCLK(getSetting("echCLKGPIO", ECH1560_CLK_PIN).toInt());
sensor->setMISO(getSetting("echMISOGPIO", ECH1560_MISO_PIN).toInt());
sensor->setInverted(getSetting("echLogic", ECH1560_INVERTED).toInt());
_sensors.push_back(sensor); _sensors.push_back(sensor);
} }
#endif #endif
#if EMON_ADC121_SUPPORT
{
EmonADC121Sensor * sensor = new EmonADC121Sensor();
sensor->setAddress(EMON_ADC121_I2C_ADDRESS);
sensor->setVoltage(EMON_MAINS_VOLTAGE);
sensor->setReference(EMON_REFERENCE_VOLTAGE);
sensor->setCurrentRatio(0, EMON_CURRENT_RATIO);
_sensors.push_back(sensor);
}
#endif
#if EMON_ADC121_SUPPORT || EMON_ADS1X15_SUPPORT || EMON_ANALOG_SUPPORT
#if EMON_ADS1X15_SUPPORT
{
EmonADS1X15Sensor * sensor = new EmonADS1X15Sensor();
sensor->setAddress(EMON_ADS1X15_I2C_ADDRESS);
sensor->setType(EMON_ADS1X15_TYPE);
sensor->setMask(EMON_ADS1X15_MASK);
sensor->setGain(EMON_ADS1X15_GAIN);
sensor->setVoltage(EMON_MAINS_VOLTAGE);
sensor->setCurrentRatio(0, EMON_CURRENT_RATIO);
sensor->setCurrentRatio(1, EMON_CURRENT_RATIO);
sensor->setCurrentRatio(2, EMON_CURRENT_RATIO);
sensor->setCurrentRatio(3, EMON_CURRENT_RATIO);
_sensors.push_back(sensor);
}
#endif
if (getSetting("emonEnabled", 0).toInt() == 1) {
#if EMON_ADC121_SUPPORT
if (getSetting("emonProvider", 0).toInt() == EMON_PROVIDER_ADC121) {
EmonADC121Sensor * sensor = new EmonADC121Sensor();
sensor->setAddress(getSetting("emonAddress", EMON_ADC121_I2C_ADDRESS).toInt());
sensor->setReference(getSetting("emonReference", EMON_REFERENCE_VOLTAGE).toInt());
sensor->setCurrentRatio(0, getSetting("curRatio", EMON_CURRENT_RATIO).toFloat());
sensor->setVoltage(getSetting("volNominal", EMON_MAINS_VOLTAGE).toInt());
_sensors.push_back(sensor);
}
#endif
#if EMON_ADS1X15_SUPPORT
if (getSetting("emonProvider", 0).toInt() == EMON_PROVIDER_ADS1X15) {
EmonADS1X15Sensor * sensor = new EmonADS1X15Sensor();
sensor->setAddress(getSetting("emonAddress", EMON_ADS1X15_I2C_ADDRESS).toInt());
sensor->setType(getSetting("emonType", EMON_ADS1X15_TYPE).toInt());
sensor->setMask(getSetting("emonMask", EMON_ADS1X15_MASK).toInt());
sensor->setGain(getSetting("emonGain", EMON_ADS1X15_GAIN).toInt());
sensor->setReference(getSetting("emonReference", EMON_REFERENCE_VOLTAGE).toInt());
double curRatio = getSetting("curRatio", EMON_CURRENT_RATIO).toFloat();
sensor->setCurrentRatio(0, getSetting("curRatio", 0, curRatio).toFloat());
sensor->setCurrentRatio(1, getSetting("curRatio", 1, curRatio).toFloat());
sensor->setCurrentRatio(2, getSetting("curRatio", 2, curRatio).toFloat());
sensor->setCurrentRatio(3, getSetting("curRatio", 3, curRatio).toFloat());
sensor->setVoltage(getSetting("volNominal", EMON_MAINS_VOLTAGE).toInt());
_sensors.push_back(sensor);
}
#endif
#if EMON_ANALOG_SUPPORT
if (getSetting("emonProvider", 0).toInt() == EMON_PROVIDER_ANALOG) {
EmonAnalogSensor * sensor = new EmonAnalogSensor();
sensor->setReference(getSetting("emonReference", EMON_REFERENCE_VOLTAGE).toInt());
sensor->setCurrentRatio(0, getSetting("curRatio", EMON_CURRENT_RATIO).toFloat());
sensor->setVoltage(getSetting("volNominal", EMON_MAINS_VOLTAGE).toInt());
_sensors.push_back(sensor);
}
#endif
#if EMON_ANALOG_SUPPORT
{
EmonAnalogSensor * sensor = new EmonAnalogSensor();
sensor->setVoltage(EMON_MAINS_VOLTAGE);
sensor->setReference(EMON_REFERENCE_VOLTAGE);
sensor->setCurrentRatio(0, EMON_CURRENT_RATIO);
_sensors.push_back(sensor);
} }
#endif #endif
#if EVENTS_SUPPORT #if EVENTS_SUPPORT
{
EventSensor * sensor = new EventSensor();
sensor->setGPIO(EVENTS_PIN);
sensor->setTrigger(EVENTS_TRIGGER);
sensor->setPinMode(EVENTS_PIN_MODE);
sensor->setDebounceTime(EVENTS_DEBOUNCE);
sensor->setInterruptMode(EVENTS_INTERRUPT_MODE);
_sensors.push_back(sensor);
if (getSetting("evtEnabled", 0).toInt() == 1) {
index = 0;
while ((gpio = getSetting("evtGPIO", index, GPIO_NONE).toInt()) != GPIO_NONE) {
EventSensor * sensor = new EventSensor();
sensor->setGPIO(gpio);
sensor->setTrigger(getSetting("evtTrigger", index, EVENTS_TRIGGER).toInt());
sensor->setPinMode(getSetting("evtMode", index, EVENTS_PIN_MODE).toInt());
sensor->setDebounceTime(getSetting("evtDebounce", index, EVENTS_DEBOUNCE).toInt());
sensor->setInterruptMode(getSetting("evtIntMode", index, EVENTS_INTERRUPT_MODE).toInt());
_sensors.push_back(sensor);
index++;
}
} }
#endif #endif
#if GEIGER_SUPPORT #if GEIGER_SUPPORT
{
GeigerSensor * sensor = new GeigerSensor(); // Create instance of thr Geiger module.
sensor->setGPIO(GEIGER_PIN); // Interrupt pin of the attached geiger counter board.
sensor->setMode(GEIGER_PIN_MODE); // This pin is an input.
sensor->setDebounceTime(GEIGER_DEBOUNCE); // Debounce time 25ms, because https://github.com/Trickx/espurna/wiki/Geiger-counter
sensor->setInterruptMode(GEIGER_INTERRUPT_MODE); // Interrupt triggering: edge detection rising.
sensor->setCPM2SievertFactor(GEIGER_CPM2SIEVERT); // Conversion factor from counts per minute to µSv/h
_sensors.push_back(sensor);
if (getSetting("geiEnabled", 0).toInt() == 1) {
if ((gpio = getSetting("geiGPIO", GPIO_NONE).toInt()) != GPIO_NONE) {
GeigerSensor * sensor = new GeigerSensor(); // Create instance of the Geiger module.
sensor->setGPIO(gpio); // Interrupt pin of the attached geiger counter board.
sensor->setMode(getSetting("geiMode", GEIGER_PIN_MODE).toInt()); // This pin is an input.
sensor->setDebounceTime(getSetting("geiDebounce", GEIGER_DEBOUNCE).toInt()); // Debounce time 25ms, because https://github.com/Trickx/espurna/wiki/Geiger-counter
sensor->setInterruptMode(getSetting("geiIntMode", GEIGER_INTERRUPT_MODE).toInt()); // Interrupt triggering: edge detection rising.
sensor->setCPM2SievertFactor(getSetting("geiRatio", GEIGER_CPM2SIEVERT).toInt()); // Conversion factor from counts per minute to µSv/h
_sensors.push_back(sensor);
}
} }
#endif #endif
#if GUVAS12SD_SUPPORT #if GUVAS12SD_SUPPORT
{
GUVAS12SDSensor * sensor = new GUVAS12SDSensor();
sensor->setGPIO(GUVAS12SD_PIN);
_sensors.push_back(sensor);
if (getSetting("guvEnabled", 0).toInt() == 1) {
if ((gpio = getSetting("guvGPIO", GPIO_NONE).toInt()) != GPIO_NONE) {
GUVAS12SDSensor * sensor = new GUVAS12SDSensor();
sensor->setGPIO(gpio);
_sensors.push_back(sensor);
}
} }
#endif #endif
#if SONAR_SUPPORT #if SONAR_SUPPORT
{
if (getSetting("sonEnabled", 0).toInt() == 1) {
SonarSensor * sensor = new SonarSensor(); SonarSensor * sensor = new SonarSensor();
sensor->setEcho(SONAR_ECHO);
sensor->setIterations(SONAR_ITERATIONS);
sensor->setMaxDistance(SONAR_MAX_DISTANCE);
sensor->setTrigger(SONAR_TRIGGER);
sensor->setEcho(getSetting("sonEcho", SONAR_ECHO).toInt());
sensor->setTrigger(getSetting("sonTrigger", SONAR_TRIGGER).toInt());
sensor->setIterations(getSetting("sonIterations", SONAR_ITERATIONS).toInt());
sensor->setMaxDistance(getSetting("sonMaxDist", SONAR_MAX_DISTANCE0).toInt());
_sensors.push_back(sensor); _sensors.push_back(sensor);
} }
#endif #endif
#if HLW8012_SUPPORT #if HLW8012_SUPPORT
{
if (getSetting("hlwEnabled", 0).toInt() == 1) {
HLW8012Sensor * sensor = new HLW8012Sensor(); HLW8012Sensor * sensor = new HLW8012Sensor();
sensor->setSEL(HLW8012_SEL_PIN);
sensor->setCF(HLW8012_CF_PIN);
sensor->setCF1(HLW8012_CF1_PIN);
sensor->setSELCurrent(HLW8012_SEL_CURRENT);
sensor->setSEL(getSetting("hlwSELGPIO", HLW8012_SEL_PIN).toInt());
sensor->setCF(getSetting("hlwCFGPIO", HLW8012_CF_PIN).toInt());
sensor->setCF1(getSetting("hlwCF1GPIO", HLW8012_CF1_PIN).toInt());
sensor->setCurrentSEL(getSetting("hlwCurSel", HLW8012_SEL_CURRENT).toInt());
sensor->setInterruptMode(getSetting("hlwIntMode", HLW8012_INTERRUPT_ON).toInt());
sensor->setCurrentResistor(getSetting("hlwCurRes", HLW8012_CURRENT_R ).toFloat());
sensor->setUpstreamResistor(getSetting("hlwVolResUp", HLW8012_VOLTAGE_R_UP).toFloat());
sensor->setDownstreamResistor(getSetting("hlwVolResDw", HLW8012_VOLTAGE_R_DOWN).toFloat());
double value;
value = getSetting("curRatio", HLW8012_CURRENT_RATIO).toFloat();
if (value > 0) sensor->setCurrentRatio(value);
value = getSetting("volRatio", HLW8012_VOLTAGE_RATIO).toFloat();
if (value > 0) sensor->setVoltageRatio(value);
value = getSetting("pwrRatio", HLW8012_POWER_RATIO).toFloat();
if (value > 0) sensor->setPowerRatio(value);
_sensors.push_back(sensor); _sensors.push_back(sensor);
} }
#endif #endif
#if MHZ19_SUPPORT #if MHZ19_SUPPORT
{
if (getSetting("mhzEnabled", 0).toInt() == 1) {
MHZ19Sensor * sensor = new MHZ19Sensor(); MHZ19Sensor * sensor = new MHZ19Sensor();
sensor->setRX(MHZ19_RX_PIN);
sensor->setTX(MHZ19_TX_PIN);
sensor->setRX(getSetting("mhzRX", MHZ19_RX_PIN).toInt());
sensor->setTX(getSetting("mhzTX", MHZ19_TX_PIN).toInt());
_sensors.push_back(sensor); _sensors.push_back(sensor);
} }
#endif #endif
#if NTC_SUPPORT #if NTC_SUPPORT
{
if (getSetting("ntcEnabled", 0).toInt() == 1) {
NTCSensor * sensor = new NTCSensor(); NTCSensor * sensor = new NTCSensor();
sensor->setSamples(NTC_SAMPLES);
sensor->setDelay(NTC_DELAY);
sensor->setUpstreamResistor(NTC_R_UP);
sensor->setDownstreamResistor(NTC_R_DOWN);
sensor->setBeta(NTC_BETA);
sensor->setR0(NTC_R0);
sensor->setT0(NTC_T0);
sensor->setSamples(getSetting("ntcSamples", NTC_SAMPLES).toInt());
sensor->setDelay(getSetting("ntcDelay", NTC_DELAY).toInt());
sensor->setUpstreamResistor(getSetting("ntcResUp", NTC_R_UP).toInt());
sensor->setDownstreamResistor(getSetting("ntcResDown", NTC_R_DOWN).toInt());
sensor->setBeta(getSetting("ntcBeta", NTC_BETA).toInt());
sensor->setR0(getSetting("ntcR0", NTC_R0).toInt());
sensor->setT0(getSetting("ntcT0", NTC_T0).toFloat());
_sensors.push_back(sensor); _sensors.push_back(sensor);
} }
#endif #endif
#if SENSEAIR_SUPPORT #if SENSEAIR_SUPPORT
{
if (getSetting("airEnabled", 0).toInt() == 1) {
SenseAirSensor * sensor = new SenseAirSensor(); SenseAirSensor * sensor = new SenseAirSensor();
sensor->setRX(SENSEAIR_RX_PIN);
sensor->setTX(SENSEAIR_TX_PIN);
sensor->setRX(getSetting("airRX", SENSEAIR_RX_PIN).toInt());
sensor->setTX(getSetting("airTX", SENSEAIR_TX_PIN).toInt());
_sensors.push_back(sensor); _sensors.push_back(sensor);
} }
#endif #endif
#if PMSX003_SUPPORT #if PMSX003_SUPPORT
{
if (getSetting("pmsEnabled", 0).toInt() == 1) {
PMSX003Sensor * sensor = new PMSX003Sensor(); PMSX003Sensor * sensor = new PMSX003Sensor();
#if PMS_USE_SOFT
sensor->setRX(PMS_RX_PIN);
sensor->setTX(PMS_TX_PIN);
#else
if (getSetting("pmsSoft", PMS_USE_SOFT).toInt() == 1) {
sensor->setRX(getSetting("pmsRX", PMS_RX_PIN).toInt());
sensor->setTX(getSetting("pmsTX", PMS_TX_PIN).toInt());
} else {
sensor->setSerial(& PMS_HW_PORT); sensor->setSerial(& PMS_HW_PORT);
#endif
sensor->setType(PMS_TYPE);
}
sensor->setType(getSetting("pmsType", PMS_TYPE).toInt());
_sensors.push_back(sensor); _sensors.push_back(sensor);
} }
#endif #endif
#if PZEM004T_SUPPORT #if PZEM004T_SUPPORT
{
if (getSetting("pzemEnabled", 0).toInt() == 1) {
PZEM004TSensor * sensor = new PZEM004TSensor(); PZEM004TSensor * sensor = new PZEM004TSensor();
#if PZEM004T_USE_SOFT
sensor->setRX(PZEM004T_RX_PIN);
sensor->setTX(PZEM004T_TX_PIN);
#else
if (getSetting("pzemSoft", PZEM004T_USE_SOFT).toInt() == 1) {
sensor->setRX(getSetting("pzemRX", PZEM004T_RX_PIN).toInt());
sensor->setTX(getSetting("pzemTX", PZEM004T_TX_PIN).toInt());
} else {
sensor->setSerial(& PZEM004T_HW_PORT); sensor->setSerial(& PZEM004T_HW_PORT);
#endif
}
_sensors.push_back(sensor); _sensors.push_back(sensor);
} }
#endif #endif
#if SHT3X_I2C_SUPPORT #if SHT3X_I2C_SUPPORT
{
SHT3XI2CSensor * sensor = new SHT3XI2CSensor();
sensor->setAddress(SHT3X_I2C_ADDRESS);
_sensors.push_back(sensor);
if (getSetting("shtEnabled", 0).toInt() == 1) {
SHT3XI2CSensor * sensor = new SHT3XI2CSensor();
sensor->setAddress(getSetting("shtAddress", SHT3X_I2C_ADDRESS).toInt());
_sensors.push_back(sensor);
} }
#endif #endif
#if SI7021_SUPPORT #if SI7021_SUPPORT
{
SI7021Sensor * sensor = new SI7021Sensor();
sensor->setAddress(SI7021_ADDRESS);
_sensors.push_back(sensor);
if (getSetting("si7021Enabled", 0).toInt() == 1) {
SI7021Sensor * sensor = new SI7021Sensor();
sensor->setAddress(getSetting("si7021Address", SI7021_ADDRESS).toInt());
_sensors.push_back(sensor);
} }
#endif #endif
#if TMP3X_SUPPORT #if TMP3X_SUPPORT
{
TMP3XSensor * sensor = new TMP3XSensor();
sensor->setType(TMP3X_TYPE);
_sensors.push_back(sensor);
if (getSetting("tmp3xEnabled", 0).toInt() == 1) {
TMP3XSensor * sensor = new TMP3XSensor();
sensor->setType(getSetting("tmp3xType", TMP3X_TYPE).toInt());
_sensors.push_back(sensor);
} }
#endif #endif
#if V9261F_SUPPORT #if V9261F_SUPPORT
{
V9261FSensor * sensor = new V9261FSensor();
sensor->setRX(V9261F_PIN);
sensor->setInverted(V9261F_PIN_INVERSE);
_sensors.push_back(sensor);
if (getSetting("v92Enabled", 0).toInt() == 1) {
if ((gpio = getSetting("v92GPIO", GPIO_NONE).toInt()) != GPIO_NONE) {
V9261FSensor * sensor = new V9261FSensor();
sensor->setRX(gpio);
sensor->setInverted(getSetting("v92Inverse", V9261F_PIN_INVERSE).toInt());
_sensors.push_back(sensor);
}
} }
#endif #endif
@ -657,60 +701,6 @@ void _sensorInit() {
_sensorCallback(i, type, value); _sensorCallback(i, type, value);
}); });
// Custom initializations
#if EMON_ANALOG_SUPPORT
if (_sensors[i]->getID() == SENSOR_EMON_ANALOG_ID) {
EmonAnalogSensor * sensor = (EmonAnalogSensor *) _sensors[i];
sensor->setCurrentRatio(0, getSetting("curRatio", EMON_CURRENT_RATIO).toFloat());
sensor->setVoltage(getSetting("volNominal", EMON_MAINS_VOLTAGE).toInt());
}
#endif // EMON_ANALOG_SUPPORT
#if HLW8012_SUPPORT
if (_sensors[i]->getID() == SENSOR_HLW8012_ID) {
HLW8012Sensor * sensor = (HLW8012Sensor *) _sensors[i];
double value;
value = getSetting("curRatio", HLW8012_CURRENT_RATIO).toFloat();
if (value > 0) sensor->setCurrentRatio(value);
value = getSetting("volRatio", HLW8012_VOLTAGE_RATIO).toFloat();
if (value > 0) sensor->setVoltageRatio(value);
value = getSetting("pwrRatio", HLW8012_POWER_RATIO).toFloat();
if (value > 0) sensor->setPowerRatio(value);
}
#endif // HLW8012_SUPPORT
#if CSE7766_SUPPORT
if (_sensors[i]->getID() == SENSOR_CSE7766_ID) {
CSE7766Sensor * sensor = (CSE7766Sensor *) _sensors[i];
double value;
value = getSetting("curRatio", 0).toFloat();
if (value > 0) sensor->setCurrentRatio(value);
value = getSetting("volRatio", 0).toFloat();
if (value > 0) sensor->setVoltageRatio(value);
value = getSetting("pwrRatio", 0).toFloat();
if (value > 0) sensor->setPowerRatio(value);
}
#endif // CSE7766_SUPPORT
} }
} }
@ -883,17 +873,32 @@ bool _sensorKeyCheck(const char * key) {
if (strncmp(key, "tmp", 3) == 0) return true; if (strncmp(key, "tmp", 3) == 0) return true;
if (strncmp(key, "hum", 3) == 0) return true; if (strncmp(key, "hum", 3) == 0) return true;
if (strncmp(key, "bme", 3) == 0) return true;
if (strncmp(key, "air", 3) == 0) return true;
if (strncmp(key, "am", 2) == 0) return true;
if (strncmp(key, "ana", 3) == 0) return true;
if (strncmp(key, "bh", 2) == 0) return true;
if (strncmp(key, "bmx", 3) == 0) return true;
if (strncmp(key, "cse", 3) == 0) return true;
if (strncmp(key, "dht", 3) == 0) return true; if (strncmp(key, "dht", 3) == 0) return true;
if (strncmp(key, "dig", 3) == 0) return true;
if (strncmp(key, "ds" , 2) == 0) return true; if (strncmp(key, "ds" , 2) == 0) return true;
if (strncmp(key, "hlw", 3) == 0) return true;
if (strncmp(key, "cse", 3) == 0) return true;
if (strncmp(key, "v92", 3) == 0) return true;
if (strncmp(key, "ech", 3) == 0) return true; if (strncmp(key, "ech", 3) == 0) return true;
if (strncmp(key, "emon", 4) == 0) return true;
if (strncmp(key, "evt", 3) == 0) return true;
if (strncmp(key, "gei", 3) == 0) return true; if (strncmp(key, "gei", 3) == 0) return true;
if (strncmp(key, "pze", 3) == 0) return true;
if (strncmp(key, "guv", 3) == 0) return true;
if (strncmp(key, "hlw", 3) == 0) return true;
if (strncmp(key, "mhz", 3) == 0) return true;
if (strncmp(key, "ntc", 3) == 0) return true;
if (strncmp(key, "pms", 3) == 0) return true;
if (strncmp(key, "pzem", 4) == 0) return true;
if (strncmp(key, "sht", 3) == 0) return true;
if (strncmp(key, "son", 3) == 0) return true;
if (strncmp(key, "tmp3x", 4) == 0) return true;
if (strncmp(key, "v92", 3) == 0) return true;
return false; return false;
} }
void _sensorBackwards() { void _sensorBackwards() {


+ 25
- 4
code/espurna/sensors/HLW8012Sensor.h View File

@ -72,10 +72,14 @@ class HLW8012Sensor : public BaseSensor {
_dirty = true; _dirty = true;
} }
void setSELCurrent(bool value) {
void setCurrentSEL(bool value) {
_sel_current = value; _sel_current = value;
} }
void setInterruptMode(unsigned char mode) {
_interrupt_mode = mode;
}
void setCurrentRatio(double value) { void setCurrentRatio(double value) {
_hlw8012->setCurrentMultiplier(value); _hlw8012->setCurrentMultiplier(value);
}; };
@ -88,6 +92,18 @@ class HLW8012Sensor : public BaseSensor {
_hlw8012->setPowerMultiplier(value); _hlw8012->setPowerMultiplier(value);
}; };
void setCurrentResistor(double value) {
_current_resistor = value;
};
void setUpstreamResistor(double value) {
_upstream_resistor = value;
};
void setDownstreamResistor(double value) {
_downstream_resistor = value;
};
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
unsigned char getSEL() { unsigned char getSEL() {
@ -143,7 +159,7 @@ class HLW8012Sensor : public BaseSensor {
// * The CURRENT_RESISTOR is the 1milliOhm copper-manganese resistor in series with the main line // * The CURRENT_RESISTOR is the 1milliOhm copper-manganese resistor in series with the main line
// * The VOLTAGE_RESISTOR_UPSTREAM are the 5 470kOhm resistors in the voltage divider that feeds the V2P pin in the HLW8012 // * The VOLTAGE_RESISTOR_UPSTREAM are the 5 470kOhm resistors in the voltage divider that feeds the V2P pin in the HLW8012
// * The VOLTAGE_RESISTOR_DOWNSTREAM is the 1kOhm resistor in the voltage divider that feeds the V2P pin in the HLW8012 // * The VOLTAGE_RESISTOR_DOWNSTREAM is the 1kOhm resistor in the voltage divider that feeds the V2P pin in the HLW8012
_hlw8012->setResistors(HLW8012_CURRENT_R, HLW8012_VOLTAGE_R_UP, HLW8012_VOLTAGE_R_DOWN);
_hlw8012->setResistors(_current_resistor, _upstream_resistor, _downstream_resistor);
// Handle interrupts // Handle interrupts
#if HLW8012_USE_INTERRUPTS #if HLW8012_USE_INTERRUPTS
@ -234,13 +250,13 @@ class HLW8012Sensor : public BaseSensor {
if (_interrupt_cf != _cf) { if (_interrupt_cf != _cf) {
if (_interrupt_cf != GPIO_NONE) _detach(_interrupt_cf); if (_interrupt_cf != GPIO_NONE) _detach(_interrupt_cf);
_attach(this, _cf, HLW8012_INTERRUPT_ON);
_attach(this, _cf, _interrupt_mode);
_interrupt_cf = _cf; _interrupt_cf = _cf;
} }
if (_interrupt_cf1 != _cf1) { if (_interrupt_cf1 != _cf1) {
if (_interrupt_cf1 != GPIO_NONE) _detach(_interrupt_cf1); if (_interrupt_cf1 != GPIO_NONE) _detach(_interrupt_cf1);
_attach(this, _cf1, HLW8012_INTERRUPT_ON);
_attach(this, _cf1, _interrupt_mode);
_interrupt_cf1 = _cf1; _interrupt_cf1 = _cf1;
} }
@ -260,7 +276,12 @@ class HLW8012Sensor : public BaseSensor {
unsigned char _sel = GPIO_NONE; unsigned char _sel = GPIO_NONE;
unsigned char _cf = GPIO_NONE; unsigned char _cf = GPIO_NONE;
unsigned char _cf1 = GPIO_NONE; unsigned char _cf1 = GPIO_NONE;
bool _sel_current = true; bool _sel_current = true;
unsigned char _interrupt_mode = HLW8012_INTERRUPT_ON;
double _current_resistor = HLW8012_CURRENT_R;
double _upstream_resistor = HLW8012_VOLTAGE_R_UP;
double _downstream_resistor = HLW8012_VOLTAGE_R_DOWN;
HLW8012 * _hlw8012 = NULL; HLW8012 * _hlw8012 = NULL;


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

@ -11,10 +11,7 @@
#include "Arduino.h" #include "Arduino.h"
#include "BaseSensor.h" #include "BaseSensor.h"
#if PMS_USE_SOFT
#include <SoftwareSerial.h> #include <SoftwareSerial.h>
#endif
// Generic data // Generic data
#define PMS_BAUD_RATE 9600 #define PMS_BAUD_RATE 9600


Loading…
Cancel
Save