diff --git a/README.md b/README.md index afd47e87..e4c3e044 100644 --- a/README.md +++ b/README.md @@ -4,9 +4,9 @@ ESPurna ("spark" in Catalan) is a custom firmware for ESP8285/ESP8266 based smar It uses the Arduino Core for ESP8266 framework and a number of 3rd party libraries. [![version](https://img.shields.io/badge/version-1.13.1-brightgreen.svg)](CHANGELOG.md) -[![branch](https://img.shields.io/badge/branch-sensors-orange.svg)](https://github.com/xoseperez/espurna/tree/sensors/) -[![travis](https://travis-ci.org/xoseperez/espurna.svg?branch=sensors)](https://travis-ci.org/xoseperez/espurna) -[![codacy](https://img.shields.io/codacy/grade/c9496e25cf07434cba786b462cb15f49/sensors.svg)](https://www.codacy.com/app/xoseperez/espurna/dashboard) +[![branch](https://img.shields.io/badge/branch-dev-orange.svg)](https://github.com/xoseperez/espurna/tree/dev/) +[![travis](https://travis-ci.org/xoseperez/espurna.svg?branch=dev)](https://travis-ci.org/xoseperez/espurna) +[![codacy](https://img.shields.io/codacy/grade/c9496e25cf07434cba786b462cb15f49/dev.svg)](https://www.codacy.com/app/xoseperez/espurna/dashboard) [![license](https://img.shields.io/github/license/xoseperez/espurna.svg)](LICENSE)
[![donate](https://img.shields.io/badge/donate-PayPal-blue.svg)](https://www.paypal.com/cgi-bin/webscr?cmd=_donations&business=xose%2eperez%40gmail%2ecom&lc=US&no_note=0¤cy_code=EUR&bn=PP%2dDonationsBF%3abtn_donate_LG%2egif%3aNonHostedGuest) diff --git a/code/espurna/config/arduino.h b/code/espurna/config/arduino.h index 03b48cf2..f5d5313f 100644 --- a/code/espurna/config/arduino.h +++ b/code/espurna/config/arduino.h @@ -142,7 +142,6 @@ //#define EMON_ANALOG_SUPPORT 1 //#define EVENTS_SUPPORT 1 //#define GUVAS12SD_SUPPORT 1 -//#define SONAR_SUPPORT 1 //#define HLW8012_SUPPORT 1 //#define MHZ19_SUPPORT 1 //#define NTC_SUPPORT 1 @@ -150,6 +149,7 @@ //#define PZEM004T_SUPPORT 1 //#define SHT3X_I2C_SUPPORT 1 //#define SI7021_SUPPORT 1 +//#define SONAR_SUPPORT 1 //#define TMP3X_SUPPORT 1 //#define V9261F_SUPPORT 1 //#define GEIGER_SUPPORT 1 diff --git a/code/espurna/config/hardware.h b/code/espurna/config/hardware.h index 6788d1d2..e1d9c8f6 100644 --- a/code/espurna/config/hardware.h +++ b/code/espurna/config/hardware.h @@ -132,9 +132,6 @@ #define I2C_SDA_PIN 12 // D6 #define I2C_SCL_PIN 14 // D5 - #define SONAR_TRIGGER 12 // D6 - #define SONAR_ECHO 13 // D7 - #elif defined(WEMOS_D1_TARPUNA_SHIELD) // Info @@ -2198,7 +2195,7 @@ #define BUTTON1_PIN 12 #define BUTTON1_RELAY 1 #define BUTTON1_MODE BUTTON_SWITCH | BUTTON_DEFAULT_HIGH //Hardware Pullup - + #define BUTTON1_PRESS BUTTON_MODE_NONE #define BUTTON1_CLICK BUTTON_MODE_TOGGLE #define BUTTON1_DBLCLICK BUTTON_MODE_NONE @@ -2431,7 +2428,7 @@ //Red LED: 0 //Green LED: 12 //Blue LED: 2 - + // Blue #define LED1_PIN 2 #define LED1_PIN_INVERSE 0 @@ -2440,7 +2437,7 @@ #define LED2_PIN 12 #define LED2_PIN_INVERSE 1 #define LED2_MODE LED_MODE_RELAY - + // Red #define LED3_PIN 0 #define LED3_PIN_INVERSE 0 @@ -2459,8 +2456,8 @@ #define HLW8012_VOLTAGE_RATIO 313400 #define HLW8012_POWER_RATIO 3414290 #define HLW8012_INTERRUPT_ON FALLING - - + + // ----------------------------------------------------------------------------- // VANZAVANZU Smart Outlet Socket (based on BL0937 or HJL-01) // https://www.amazon.com/Smart-Plug-Wifi-Mini-VANZAVANZU/dp/B078PHD6S5 diff --git a/code/espurna/config/sensors.h b/code/espurna/config/sensors.h index f8ff56e2..ab0e4e96 100644 --- a/code/espurna/config/sensors.h +++ b/code/espurna/config/sensors.h @@ -342,31 +342,6 @@ #define GUVAS12SD_PIN 14 #endif -//------------------------------------------------------------------------------ -// Sonar -// Enable support by passing SONAR_SUPPORT=1 build flag -//------------------------------------------------------------------------------ - -#ifndef SONAR_SUPPORT -#define SONAR_SUPPORT 0 -#endif - -#ifndef SONAR_TRIGGER -#define SONAR_TRIGGER 12 // GPIO for the trigger pin (output) -#endif - -#ifndef SONAR_ECHO -#define SONAR_ECHO 14 // GPIO for the echo pin (input) -#endif - -#ifndef SONAR_MAX_DISTANCE -#define SONAR_MAX_DISTANCE MAX_SENSOR_DISTANCE // Max sensor distance in cm -#endif - -#ifndef SONAR_ITERATIONS -#define SONAR_ITERATIONS 5 // Number of iterations to ping for -#endif // error correction. - //------------------------------------------------------------------------------ // HLW8012 Energy monitor IC // Enable support by passing HLW8012_SUPPORT=1 build flag @@ -576,6 +551,31 @@ #define SI7021_ADDRESS 0x00 // 0x00 means auto #endif +//------------------------------------------------------------------------------ +// Sonar +// Enable support by passing SONAR_SUPPORT=1 build flag +//------------------------------------------------------------------------------ + +#ifndef SONAR_SUPPORT +#define SONAR_SUPPORT 0 +#endif + +#ifndef SONAR_TRIGGER +#define SONAR_TRIGGER 12 // GPIO for the trigger pin (output) +#endif + +#ifndef SONAR_ECHO +#define SONAR_ECHO 14 // GPIO for the echo pin (input) +#endif + +#ifndef SONAR_MAX_DISTANCE +#define SONAR_MAX_DISTANCE MAX_SENSOR_DISTANCE // Max sensor distance in cm +#endif + +#ifndef SONAR_ITERATIONS +#define SONAR_ITERATIONS 5 // Number of iterations to ping for +#endif // error correction. + //------------------------------------------------------------------------------ // TMP3X analog temperature sensor // Enable support by passing TMP3X_SUPPORT=1 build flag @@ -636,7 +636,6 @@ EVENTS_SUPPORT || \ GEIGER_SUPPORT || \ GUVAS12SD_SUPPORT || \ - SONAR_SUPPORT || \ HLW8012_SUPPORT || \ MHZ19_SUPPORT || \ NTC_SUPPORT || \ @@ -645,6 +644,7 @@ PZEM004T_SUPPORT || \ SHT3X_I2C_SUPPORT || \ SI7021_SUPPORT || \ + SONAR_SUPPORT || \ TMP3X_SUPPORT || \ V9261F_SUPPORT \ ) @@ -756,10 +756,6 @@ #include "../sensors/GUVAS12SDSensor.h" #endif -#if SONAR_SUPPORT - #include "../sensors/SonarSensor.h" -#endif - #if HLW8012_SUPPORT #include #include "../sensors/HLW8012Sensor.h" @@ -798,6 +794,10 @@ #include "../sensors/SHT3XI2CSensor.h" #endif +#if SONAR_SUPPORT + #include "../sensors/SonarSensor.h" +#endif + #if TMP3X_SUPPORT #include "../sensors/TMP3XSensor.h" #endif diff --git a/code/espurna/sensors/SonarSensor.h b/code/espurna/sensors/SonarSensor.h index 7ec6edeb..f26f2156 100644 --- a/code/espurna/sensors/SonarSensor.h +++ b/code/espurna/sensors/SonarSensor.h @@ -1,6 +1,7 @@ // ----------------------------------------------------------------------------- -// HC-SR04 Ultrasonic sensor +// HC-SR04, SRF05, SRF06, DYP-ME007, JSN-SR04T & Parallax PING)))™ // Copyright (C) 2018 by Xose Pérez +// Enhancements by Rui Marinho // ----------------------------------------------------------------------------- #if SENSOR_SUPPORT && SONAR_SUPPORT @@ -101,11 +102,9 @@ class SonarSensor : public BaseSensor { // Current value for slot # index double value(unsigned char index) { if (index != 0) return 0; - if (getIterations() > 0) { - return NewPing::convert_cm(_sonar->ping_median(getIterations())) / 100.0; + return NewPing::convert_cm(_sonar->ping_median(getIterations())) / 100.0; } - return _sonar->ping_cm() / 100.0; }