Browse Source

Clean up code

ech1560
Xose Pérez 6 years ago
parent
commit
af4bfa7ac8
5 changed files with 42 additions and 46 deletions
  1. +3
    -3
      README.md
  2. +1
    -1
      code/espurna/config/arduino.h
  3. +5
    -8
      code/espurna/config/hardware.h
  4. +30
    -30
      code/espurna/config/sensors.h
  5. +3
    -4
      code/espurna/sensors/SonarSensor.h

+ 3
- 3
README.md View File

@ -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. 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) [![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) [![license](https://img.shields.io/github/license/xoseperez/espurna.svg)](LICENSE)
<br /> <br />
[![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&currency_code=EUR&bn=PP%2dDonationsBF%3abtn_donate_LG%2egif%3aNonHostedGuest) [![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&currency_code=EUR&bn=PP%2dDonationsBF%3abtn_donate_LG%2egif%3aNonHostedGuest)


+ 1
- 1
code/espurna/config/arduino.h View File

@ -142,7 +142,6 @@
//#define EMON_ANALOG_SUPPORT 1 //#define EMON_ANALOG_SUPPORT 1
//#define EVENTS_SUPPORT 1 //#define EVENTS_SUPPORT 1
//#define GUVAS12SD_SUPPORT 1 //#define GUVAS12SD_SUPPORT 1
//#define SONAR_SUPPORT 1
//#define HLW8012_SUPPORT 1 //#define HLW8012_SUPPORT 1
//#define MHZ19_SUPPORT 1 //#define MHZ19_SUPPORT 1
//#define NTC_SUPPORT 1 //#define NTC_SUPPORT 1
@ -150,6 +149,7 @@
//#define PZEM004T_SUPPORT 1 //#define PZEM004T_SUPPORT 1
//#define SHT3X_I2C_SUPPORT 1 //#define SHT3X_I2C_SUPPORT 1
//#define SI7021_SUPPORT 1 //#define SI7021_SUPPORT 1
//#define SONAR_SUPPORT 1
//#define TMP3X_SUPPORT 1 //#define TMP3X_SUPPORT 1
//#define V9261F_SUPPORT 1 //#define V9261F_SUPPORT 1
//#define GEIGER_SUPPORT 1 //#define GEIGER_SUPPORT 1

+ 5
- 8
code/espurna/config/hardware.h View File

@ -132,9 +132,6 @@
#define I2C_SDA_PIN 12 // D6 #define I2C_SDA_PIN 12 // D6
#define I2C_SCL_PIN 14 // D5 #define I2C_SCL_PIN 14 // D5
#define SONAR_TRIGGER 12 // D6
#define SONAR_ECHO 13 // D7
#elif defined(WEMOS_D1_TARPUNA_SHIELD) #elif defined(WEMOS_D1_TARPUNA_SHIELD)
// Info // Info
@ -2198,7 +2195,7 @@
#define BUTTON1_PIN 12 #define BUTTON1_PIN 12
#define BUTTON1_RELAY 1 #define BUTTON1_RELAY 1
#define BUTTON1_MODE BUTTON_SWITCH | BUTTON_DEFAULT_HIGH //Hardware Pullup #define BUTTON1_MODE BUTTON_SWITCH | BUTTON_DEFAULT_HIGH //Hardware Pullup
#define BUTTON1_PRESS BUTTON_MODE_NONE #define BUTTON1_PRESS BUTTON_MODE_NONE
#define BUTTON1_CLICK BUTTON_MODE_TOGGLE #define BUTTON1_CLICK BUTTON_MODE_TOGGLE
#define BUTTON1_DBLCLICK BUTTON_MODE_NONE #define BUTTON1_DBLCLICK BUTTON_MODE_NONE
@ -2431,7 +2428,7 @@
//Red LED: 0 //Red LED: 0
//Green LED: 12 //Green LED: 12
//Blue LED: 2 //Blue LED: 2
// Blue // Blue
#define LED1_PIN 2 #define LED1_PIN 2
#define LED1_PIN_INVERSE 0 #define LED1_PIN_INVERSE 0
@ -2440,7 +2437,7 @@
#define LED2_PIN 12 #define LED2_PIN 12
#define LED2_PIN_INVERSE 1 #define LED2_PIN_INVERSE 1
#define LED2_MODE LED_MODE_RELAY #define LED2_MODE LED_MODE_RELAY
// Red // Red
#define LED3_PIN 0 #define LED3_PIN 0
#define LED3_PIN_INVERSE 0 #define LED3_PIN_INVERSE 0
@ -2459,8 +2456,8 @@
#define HLW8012_VOLTAGE_RATIO 313400 #define HLW8012_VOLTAGE_RATIO 313400
#define HLW8012_POWER_RATIO 3414290 #define HLW8012_POWER_RATIO 3414290
#define HLW8012_INTERRUPT_ON FALLING #define HLW8012_INTERRUPT_ON FALLING
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// VANZAVANZU Smart Outlet Socket (based on BL0937 or HJL-01) // VANZAVANZU Smart Outlet Socket (based on BL0937 or HJL-01)
// https://www.amazon.com/Smart-Plug-Wifi-Mini-VANZAVANZU/dp/B078PHD6S5 // https://www.amazon.com/Smart-Plug-Wifi-Mini-VANZAVANZU/dp/B078PHD6S5


+ 30
- 30
code/espurna/config/sensors.h View File

@ -342,31 +342,6 @@
#define GUVAS12SD_PIN 14 #define GUVAS12SD_PIN 14
#endif #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 // HLW8012 Energy monitor IC
// Enable support by passing HLW8012_SUPPORT=1 build flag // Enable support by passing HLW8012_SUPPORT=1 build flag
@ -576,6 +551,31 @@
#define SI7021_ADDRESS 0x00 // 0x00 means auto #define SI7021_ADDRESS 0x00 // 0x00 means auto
#endif #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 // TMP3X analog temperature sensor
// Enable support by passing TMP3X_SUPPORT=1 build flag // Enable support by passing TMP3X_SUPPORT=1 build flag
@ -636,7 +636,6 @@
EVENTS_SUPPORT || \ EVENTS_SUPPORT || \
GEIGER_SUPPORT || \ GEIGER_SUPPORT || \
GUVAS12SD_SUPPORT || \ GUVAS12SD_SUPPORT || \
SONAR_SUPPORT || \
HLW8012_SUPPORT || \ HLW8012_SUPPORT || \
MHZ19_SUPPORT || \ MHZ19_SUPPORT || \
NTC_SUPPORT || \ NTC_SUPPORT || \
@ -645,6 +644,7 @@
PZEM004T_SUPPORT || \ PZEM004T_SUPPORT || \
SHT3X_I2C_SUPPORT || \ SHT3X_I2C_SUPPORT || \
SI7021_SUPPORT || \ SI7021_SUPPORT || \
SONAR_SUPPORT || \
TMP3X_SUPPORT || \ TMP3X_SUPPORT || \
V9261F_SUPPORT \ V9261F_SUPPORT \
) )
@ -756,10 +756,6 @@
#include "../sensors/GUVAS12SDSensor.h" #include "../sensors/GUVAS12SDSensor.h"
#endif #endif
#if SONAR_SUPPORT
#include "../sensors/SonarSensor.h"
#endif
#if HLW8012_SUPPORT #if HLW8012_SUPPORT
#include <HLW8012.h> #include <HLW8012.h>
#include "../sensors/HLW8012Sensor.h" #include "../sensors/HLW8012Sensor.h"
@ -798,6 +794,10 @@
#include "../sensors/SHT3XI2CSensor.h" #include "../sensors/SHT3XI2CSensor.h"
#endif #endif
#if SONAR_SUPPORT
#include "../sensors/SonarSensor.h"
#endif
#if TMP3X_SUPPORT #if TMP3X_SUPPORT
#include "../sensors/TMP3XSensor.h" #include "../sensors/TMP3XSensor.h"
#endif #endif


+ 3
- 4
code/espurna/sensors/SonarSensor.h View File

@ -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 <xose dot perez at gmail dot com> // Copyright (C) 2018 by Xose Pérez <xose dot perez at gmail dot com>
// Enhancements by Rui Marinho
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#if SENSOR_SUPPORT && SONAR_SUPPORT #if SENSOR_SUPPORT && SONAR_SUPPORT
@ -101,11 +102,9 @@ class SonarSensor : public BaseSensor {
// Current value for slot # index // Current value for slot # index
double value(unsigned char index) { double value(unsigned char index) {
if (index != 0) return 0; if (index != 0) return 0;
if (getIterations() > 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; return _sonar->ping_cm() / 100.0;
} }


Loading…
Cancel
Save