Browse Source

Trying to fix some issues reported by codacy

softuart
Xose Pérez 6 years ago
parent
commit
4029ee73da
10 changed files with 194 additions and 98 deletions
  1. +10
    -12
      code/espurna/button.ino
  2. +90
    -9
      code/espurna/config/defaults.h
  3. +44
    -10
      code/espurna/config/general.h
  4. +2
    -2
      code/espurna/config/hardware.h
  5. +8
    -8
      code/espurna/led.ino
  6. +9
    -9
      code/espurna/relay.ino
  7. +1
    -1
      code/espurna/sensor.ino
  8. +0
    -2
      code/espurna/sensors/BaseSensor.h
  9. +9
    -9
      code/espurna/settings.ino
  10. +21
    -36
      code/espurna/wifi.ino

+ 10
- 12
code/espurna/button.ino View File

@ -22,14 +22,14 @@ typedef struct {
std::vector<button_t> _buttons; std::vector<button_t> _buttons;
#if MQTT_SUPPORT #if MQTT_SUPPORT
#ifdef MQTT_TOPIC_BUTTON
void buttonMQTT(unsigned char id, uint8_t event) { void buttonMQTT(unsigned char id, uint8_t event) {
if (id >= _buttons.size()) return; if (id >= _buttons.size()) return;
char payload[2]; char payload[2];
itoa(event, payload, 10); itoa(event, payload, 10);
mqttSend(MQTT_TOPIC_BUTTON, id, payload); mqttSend(MQTT_TOPIC_BUTTON, id, payload);
} }
#endif
#endif #endif
int buttonFromRelay(unsigned int relayID) { int buttonFromRelay(unsigned int relayID) {
@ -84,10 +84,8 @@ void buttonEvent(unsigned int id, unsigned char event) {
if (event == 0) return; if (event == 0) return;
#if MQTT_SUPPORT #if MQTT_SUPPORT
#ifdef MQTT_TOPIC_BUTTON
buttonMQTT(id, event); buttonMQTT(id, event);
#endif #endif
#endif
unsigned char action = buttonAction(id, event); unsigned char action = buttonAction(id, event);
@ -131,49 +129,49 @@ void buttonSetup() {
unsigned long btnDelay = getSetting("btnDelay", BUTTON_DBLCLICK_DELAY).toInt(); unsigned long btnDelay = getSetting("btnDelay", BUTTON_DBLCLICK_DELAY).toInt();
#ifdef BUTTON1_PIN
#if BUTTON1_PIN != GPIO_NONE
{ {
unsigned int actions = buttonStore(BUTTON1_PRESS, BUTTON1_CLICK, BUTTON1_DBLCLICK, BUTTON1_LNGCLICK, BUTTON1_LNGLNGCLICK); unsigned int actions = buttonStore(BUTTON1_PRESS, BUTTON1_CLICK, BUTTON1_DBLCLICK, BUTTON1_LNGCLICK, BUTTON1_LNGLNGCLICK);
_buttons.push_back({new DebounceEvent(BUTTON1_PIN, BUTTON1_MODE, BUTTON_DEBOUNCE_DELAY, btnDelay), actions, BUTTON1_RELAY}); _buttons.push_back({new DebounceEvent(BUTTON1_PIN, BUTTON1_MODE, BUTTON_DEBOUNCE_DELAY, btnDelay), actions, BUTTON1_RELAY});
} }
#endif #endif
#ifdef BUTTON2_PIN
#if BUTTON2_PIN != GPIO_NONE
{ {
unsigned int actions = buttonStore(BUTTON2_PRESS, BUTTON2_CLICK, BUTTON2_DBLCLICK, BUTTON2_LNGCLICK, BUTTON2_LNGLNGCLICK); unsigned int actions = buttonStore(BUTTON2_PRESS, BUTTON2_CLICK, BUTTON2_DBLCLICK, BUTTON2_LNGCLICK, BUTTON2_LNGLNGCLICK);
_buttons.push_back({new DebounceEvent(BUTTON2_PIN, BUTTON2_MODE, BUTTON_DEBOUNCE_DELAY, btnDelay), actions, BUTTON2_RELAY}); _buttons.push_back({new DebounceEvent(BUTTON2_PIN, BUTTON2_MODE, BUTTON_DEBOUNCE_DELAY, btnDelay), actions, BUTTON2_RELAY});
} }
#endif #endif
#ifdef BUTTON3_PIN
#if BUTTON3_PIN != GPIO_NONE
{ {
unsigned int actions = buttonStore(BUTTON3_PRESS, BUTTON3_CLICK, BUTTON3_DBLCLICK, BUTTON3_LNGCLICK, BUTTON3_LNGLNGCLICK); unsigned int actions = buttonStore(BUTTON3_PRESS, BUTTON3_CLICK, BUTTON3_DBLCLICK, BUTTON3_LNGCLICK, BUTTON3_LNGLNGCLICK);
_buttons.push_back({new DebounceEvent(BUTTON3_PIN, BUTTON3_MODE, BUTTON_DEBOUNCE_DELAY, btnDelay), actions, BUTTON3_RELAY}); _buttons.push_back({new DebounceEvent(BUTTON3_PIN, BUTTON3_MODE, BUTTON_DEBOUNCE_DELAY, btnDelay), actions, BUTTON3_RELAY});
} }
#endif #endif
#ifdef BUTTON4_PIN
#if BUTTON4_PIN != GPIO_NONE
{ {
unsigned int actions = buttonStore(BUTTON4_PRESS, BUTTON4_CLICK, BUTTON4_DBLCLICK, BUTTON4_LNGCLICK, BUTTON4_LNGLNGCLICK); unsigned int actions = buttonStore(BUTTON4_PRESS, BUTTON4_CLICK, BUTTON4_DBLCLICK, BUTTON4_LNGCLICK, BUTTON4_LNGLNGCLICK);
_buttons.push_back({new DebounceEvent(BUTTON4_PIN, BUTTON4_MODE, BUTTON_DEBOUNCE_DELAY, btnDelay), actions, BUTTON4_RELAY}); _buttons.push_back({new DebounceEvent(BUTTON4_PIN, BUTTON4_MODE, BUTTON_DEBOUNCE_DELAY, btnDelay), actions, BUTTON4_RELAY});
} }
#endif #endif
#ifdef BUTTON5_PIN
#if BUTTON5_PIN != GPIO_NONE
{ {
unsigned int actions = buttonStore(BUTTON5_PRESS, BUTTON5_CLICK, BUTTON5_DBLCLICK, BUTTON5_LNGCLICK, BUTTON5_LNGLNGCLICK); unsigned int actions = buttonStore(BUTTON5_PRESS, BUTTON5_CLICK, BUTTON5_DBLCLICK, BUTTON5_LNGCLICK, BUTTON5_LNGLNGCLICK);
_buttons.push_back({new DebounceEvent(BUTTON5_PIN, BUTTON5_MODE, BUTTON_DEBOUNCE_DELAY, btnDelay), actions, BUTTON5_RELAY}); _buttons.push_back({new DebounceEvent(BUTTON5_PIN, BUTTON5_MODE, BUTTON_DEBOUNCE_DELAY, btnDelay), actions, BUTTON5_RELAY});
} }
#endif #endif
#ifdef BUTTON6_PIN
#if BUTTON6_PIN != GPIO_NONE
{ {
unsigned int actions = buttonStore(BUTTON6_PRESS, BUTTON6_CLICK, BUTTON6_DBLCLICK, BUTTON6_LNGCLICK, BUTTON6_LNGLNGCLICK); unsigned int actions = buttonStore(BUTTON6_PRESS, BUTTON6_CLICK, BUTTON6_DBLCLICK, BUTTON6_LNGCLICK, BUTTON6_LNGLNGCLICK);
_buttons.push_back({new DebounceEvent(BUTTON6_PIN, BUTTON6_MODE, BUTTON_DEBOUNCE_DELAY, btnDelay), actions, BUTTON6_RELAY}); _buttons.push_back({new DebounceEvent(BUTTON6_PIN, BUTTON6_MODE, BUTTON_DEBOUNCE_DELAY, btnDelay), actions, BUTTON6_RELAY});
} }
#endif #endif
#ifdef BUTTON7_PIN
#if BUTTON7_PIN != GPIO_NONE
{ {
unsigned int actions = buttonStore(BUTTON7_PRESS, BUTTON7_CLICK, BUTTON7_DBLCLICK, BUTTON7_LNGCLICK, BUTTON7_LNGLNGCLICK); unsigned int actions = buttonStore(BUTTON7_PRESS, BUTTON7_CLICK, BUTTON7_DBLCLICK, BUTTON7_LNGCLICK, BUTTON7_LNGLNGCLICK);
_buttons.push_back({new DebounceEvent(BUTTON7_PIN, BUTTON7_MODE, BUTTON_DEBOUNCE_DELAY, btnDelay), actions, BUTTON7_RELAY}); _buttons.push_back({new DebounceEvent(BUTTON7_PIN, BUTTON7_MODE, BUTTON_DEBOUNCE_DELAY, btnDelay), actions, BUTTON7_RELAY});
} }
#endif #endif
#ifdef BUTTON8_PIN
#if BUTTON8_PIN != GPIO_NONE
{ {
unsigned int actions = buttonStore(BUTTON8_PRESS, BUTTON8_CLICK, BUTTON8_DBLCLICK, BUTTON8_LNGCLICK, BUTTON8_LNGLNGCLICK); unsigned int actions = buttonStore(BUTTON8_PRESS, BUTTON8_CLICK, BUTTON8_DBLCLICK, BUTTON8_LNGCLICK, BUTTON8_LNGLNGCLICK);
_buttons.push_back({new DebounceEvent(BUTTON8_PIN, BUTTON8_MODE, BUTTON_DEBOUNCE_DELAY, btnDelay), actions, BUTTON8_RELAY}); _buttons.push_back({new DebounceEvent(BUTTON8_PIN, BUTTON8_MODE, BUTTON_DEBOUNCE_DELAY, btnDelay), actions, BUTTON8_RELAY});


+ 90
- 9
code/espurna/config/defaults.h View File

@ -2,10 +2,37 @@
// Hardware default values // Hardware default values
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#define GPIO_NONE 0x99
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Buttons // Buttons
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#ifndef BUTTON1_PIN
#define BUTTON1_PIN GPIO_NONE
#endif
#ifndef BUTTON2_PIN
#define BUTTON2_PIN GPIO_NONE
#endif
#ifndef BUTTON3_PIN
#define BUTTON3_PIN GPIO_NONE
#endif
#ifndef BUTTON4_PIN
#define BUTTON4_PIN GPIO_NONE
#endif
#ifndef BUTTON5_PIN
#define BUTTON5_PIN GPIO_NONE
#endif
#ifndef BUTTON6_PIN
#define BUTTON6_PIN GPIO_NONE
#endif
#ifndef BUTTON7_PIN
#define BUTTON7_PIN GPIO_NONE
#endif
#ifndef BUTTON8_PIN
#define BUTTON8_PIN GPIO_NONE
#endif
#ifndef BUTTON1_PRESS #ifndef BUTTON1_PRESS
#define BUTTON1_PRESS BUTTON_MODE_NONE #define BUTTON1_PRESS BUTTON_MODE_NONE
#endif #endif
@ -160,6 +187,35 @@
// Relays // Relays
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#ifndef DUMMY_RELAY_COUNT
#define DUMMY_RELAY_COUNT 0
#endif
#ifndef RELAY1_PIN
#define RELAY1_PIN GPIO_NONE
#endif
#ifndef RELAY2_PIN
#define RELAY2_PIN GPIO_NONE
#endif
#ifndef RELAY3_PIN
#define RELAY3_PIN GPIO_NONE
#endif
#ifndef RELAY4_PIN
#define RELAY4_PIN GPIO_NONE
#endif
#ifndef RELAY5_PIN
#define RELAY5_PIN GPIO_NONE
#endif
#ifndef RELAY6_PIN
#define RELAY6_PIN GPIO_NONE
#endif
#ifndef RELAY7_PIN
#define RELAY7_PIN GPIO_NONE
#endif
#ifndef RELAY8_PIN
#define RELAY8_PIN GPIO_NONE
#endif
#ifndef RELAY1_TYPE #ifndef RELAY1_TYPE
#define RELAY1_TYPE RELAY_TYPE_NORMAL #define RELAY1_TYPE RELAY_TYPE_NORMAL
#endif #endif
@ -175,7 +231,7 @@
#ifndef RELAY5_TYPE #ifndef RELAY5_TYPE
#define RELAY5_TYPE RELAY_TYPE_NORMAL #define RELAY5_TYPE RELAY_TYPE_NORMAL
#endif #endif
#ifndef RELAY6_TYPE
#ifndef RELAY6_TYPE
#define RELAY6_TYPE RELAY_TYPE_NORMAL #define RELAY6_TYPE RELAY_TYPE_NORMAL
#endif #endif
#ifndef RELAY7_TYPE #ifndef RELAY7_TYPE
@ -186,28 +242,28 @@
#endif #endif
#ifndef RELAY1_RESET_PIN #ifndef RELAY1_RESET_PIN
#define RELAY1_RESET_PIN 0
#define RELAY1_RESET_PIN GPIO_NONE
#endif #endif
#ifndef RELAY2_RESET_PIN #ifndef RELAY2_RESET_PIN
#define RELAY2_RESET_PIN 0
#define RELAY2_RESET_PIN GPIO_NONE
#endif #endif
#ifndef RELAY3_RESET_PIN #ifndef RELAY3_RESET_PIN
#define RELAY3_RESET_PIN 0
#define RELAY3_RESET_PIN GPIO_NONE
#endif #endif
#ifndef RELAY4_RESET_PIN #ifndef RELAY4_RESET_PIN
#define RELAY4_RESET_PIN 0
#define RELAY4_RESET_PIN GPIO_NONE
#endif #endif
#ifndef RELAY5_RESET_PIN #ifndef RELAY5_RESET_PIN
#define RELAY5_RESET_PIN 0
#define RELAY5_RESET_PIN GPIO_NONE
#endif #endif
#ifndef RELAY6_RESET_PIN #ifndef RELAY6_RESET_PIN
#define RELAY6_RESET_PIN 0
#define RELAY6_RESET_PIN GPIO_NONE
#endif #endif
#ifndef RELAY7_RESET_PIN #ifndef RELAY7_RESET_PIN
#define RELAY7_RESET_PIN 0
#define RELAY7_RESET_PIN GPIO_NONE
#endif #endif
#ifndef RELAY8_RESET_PIN #ifndef RELAY8_RESET_PIN
#define RELAY8_RESET_PIN 0
#define RELAY8_RESET_PIN GPIO_NONE
#endif #endif
#ifndef RELAY1_DELAY_ON #ifndef RELAY1_DELAY_ON
@ -264,6 +320,31 @@
// LEDs // LEDs
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
#ifndef LED1_PIN
#define LED1_PIN GPIO_NONE
#endif
#ifndef LED2_PIN
#define LED2_PIN GPIO_NONE
#endif
#ifndef LED3_PIN
#define LED3_PIN GPIO_NONE
#endif
#ifndef LED4_PIN
#define LED4_PIN GPIO_NONE
#endif
#ifndef LED5_PIN
#define LED5_PIN GPIO_NONE
#endif
#ifndef LED6_PIN
#define LED6_PIN GPIO_NONE
#endif
#ifndef LED7_PIN
#define LED7_PIN GPIO_NONE
#endif
#ifndef LED8_PIN
#define LED8_PIN GPIO_NONE
#endif
#ifndef LED1_MODE #ifndef LED1_MODE
#define LED1_MODE LED_MODE_WIFI #define LED1_MODE LED_MODE_WIFI
#endif #endif


+ 44
- 10
code/espurna/config/general.h View File

@ -73,9 +73,15 @@
// Second serial port (used for RX) // Second serial port (used for RX)
//#define SERIAL_RX_PORT Serial // This setting is usually defined
#ifndef SERIAL_RX_ENABLED
#define SERIAL_RX_ENABLED 0 // Secondary serial port for RX
#endif
#ifndef SERIAL_RX_PORT
#define SERIAL_RX_PORT Serial // This setting is usually defined
// in the hardware.h file for those // in the hardware.h file for those
// boards that require it // boards that require it
#endif
#ifndef SERIAL_RX_BAUDRATE #ifndef SERIAL_RX_BAUDRATE
#define SERIAL_RX_BAUDRATE 115200 // Default baudrate #define SERIAL_RX_BAUDRATE 115200 // Default baudrate
@ -335,15 +341,43 @@ PROGMEM const char* const custom_reset_string[] = {
#define WIFI_SLEEP_ENABLED 1 // Enable WiFi light sleep #define WIFI_SLEEP_ENABLED 1 // Enable WiFi light sleep
#define WIFI_SCAN_NETWORKS 1 // Perform a network scan before connecting #define WIFI_SCAN_NETWORKS 1 // Perform a network scan before connecting
// Optional hardcoded configuration (up to 2 different networks)
//#define WIFI1_SSID "..."
//#define WIFI1_PASS "..."
//#define WIFI1_IP "192.168.1.201"
//#define WIFI1_GW "192.168.1.1"
//#define WIFI1_MASK "255.255.255.0"
//#define WIFI1_DNS "8.8.8.8"
//#define WIFI2_SSID "..."
//#define WIFI2_PASS "..."
// Optional hardcoded configuration (up to 2 networks)
#ifndef WIFI1_SSID
#define WIFI1_SSID ""
#endif
#ifndef WIFI1_PASS
#define WIFI1_PASS ""
#endif
#ifndef WIFI1_IP
#define WIFI1_IP ""
#endif
#ifndef WIFI1_GW
#define WIFI1_GW ""
#endif
#ifndef WIFI1_MASK
#define WIFI1_MASK ""
#endif
#ifndef WIFI1_DNS
#define WIFI1_DNS ""
#endif
#ifndef WIFI2_SSID
#define WIFI2_SSID ""
#endif
#ifndef WIFI2_PASS
#define WIFI2_PASS ""
#endif
#ifndef WIFI2_IP
#define WIFI2_IP ""
#endif
#ifndef WIFI2_GW
#define WIFI2_GW ""
#endif
#ifndef WIFI2_MASK
#define WIFI2_MASK ""
#endif
#ifndef WIFI2_DNS
#define WIFI2_DNS ""
#endif
#define WIFI_RSSI_1M -30 // Calibrate it with your router reading the RSSI at 1m #define WIFI_RSSI_1M -30 // Calibrate it with your router reading the RSSI at 1m
#define WIFI_PROPAGATION_CONST 4 // This is typically something between 2.7 to 4.3 (free space is 2) #define WIFI_PROPAGATION_CONST 4 // This is typically something between 2.7 to 4.3 (free space is 2)


+ 2
- 2
code/espurna/config/hardware.h View File

@ -927,7 +927,7 @@
#define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER #define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER
#define DUMMY_RELAY_COUNT 1 #define DUMMY_RELAY_COUNT 1
#define DEBUG_PORT Serial1 #define DEBUG_PORT Serial1
#define SERIAL_RX_PORT Serial
#define SERIAL_RX_ENABLED 1
// LEDs // LEDs
#define LED1_PIN 5 #define LED1_PIN 5
@ -955,7 +955,7 @@
#define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER #define LIGHT_PROVIDER LIGHT_PROVIDER_DIMMER
#define DUMMY_RELAY_COUNT 1 #define DUMMY_RELAY_COUNT 1
#define DEBUG_PORT Serial1 #define DEBUG_PORT Serial1
#define SERIAL_RX_PORT Serial
#define SERIAL_RX_ENABLED 1
// Light // Light
#define LIGHT_CHANNELS 4 #define LIGHT_CHANNELS 4


+ 8
- 8
code/espurna/led.ino View File

@ -124,28 +124,28 @@ void ledUpdate(bool value) {
void ledSetup() { void ledSetup() {
#ifdef LED1_PIN
#if LED1_PIN != GPIO_NONE
_leds.push_back((led_t) { LED1_PIN, LED1_PIN_INVERSE, LED1_MODE, LED1_RELAY }); _leds.push_back((led_t) { LED1_PIN, LED1_PIN_INVERSE, LED1_MODE, LED1_RELAY });
#endif #endif
#ifdef LED2_PIN
#if LED2_PIN != GPIO_NONE
_leds.push_back((led_t) { LED2_PIN, LED2_PIN_INVERSE, LED2_MODE, LED2_RELAY }); _leds.push_back((led_t) { LED2_PIN, LED2_PIN_INVERSE, LED2_MODE, LED2_RELAY });
#endif #endif
#ifdef LED3_PIN
#if LED3_PIN != GPIO_NONE
_leds.push_back((led_t) { LED3_PIN, LED3_PIN_INVERSE, LED3_MODE, LED3_RELAY }); _leds.push_back((led_t) { LED3_PIN, LED3_PIN_INVERSE, LED3_MODE, LED3_RELAY });
#endif #endif
#ifdef LED4_PIN
#if LED4_PIN != GPIO_NONE
_leds.push_back((led_t) { LED4_PIN, LED4_PIN_INVERSE, LED4_MODE, LED4_RELAY }); _leds.push_back((led_t) { LED4_PIN, LED4_PIN_INVERSE, LED4_MODE, LED4_RELAY });
#endif #endif
#ifdef LED5_PIN
#if LED5_PIN != GPIO_NONE
_leds.push_back((led_t) { LED5_PIN, LED5_PIN_INVERSE, LED5_MODE, LED5_RELAY }); _leds.push_back((led_t) { LED5_PIN, LED5_PIN_INVERSE, LED5_MODE, LED5_RELAY });
#endif #endif
#ifdef LED6_PIN
#if LED6_PIN != GPIO_NONE
_leds.push_back((led_t) { LED6_PIN, LED6_PIN_INVERSE, LED6_MODE, LED6_RELAY }); _leds.push_back((led_t) { LED6_PIN, LED6_PIN_INVERSE, LED6_MODE, LED6_RELAY });
#endif #endif
#ifdef LED7_PIN
#if LED7_PIN != GPIO_NONE
_leds.push_back((led_t) { LED7_PIN, LED7_PIN_INVERSE, LED7_MODE, LED7_RELAY }); _leds.push_back((led_t) { LED7_PIN, LED7_PIN_INVERSE, LED7_MODE, LED7_RELAY });
#endif #endif
#ifdef LED8_PIN
#if LED8_PIN != GPIO_NONE
_leds.push_back((led_t) { LED8_PIN, LED8_PIN_INVERSE, LED8_MODE, LED8_RELAY }); _leds.push_back((led_t) { LED8_PIN, LED8_PIN_INVERSE, LED8_MODE, LED8_RELAY });
#endif #endif


+ 9
- 9
code/espurna/relay.ino View File

@ -799,7 +799,7 @@ void relaySetup() {
// Dummy relays for AI Light, Magic Home LED Controller, H801, // Dummy relays for AI Light, Magic Home LED Controller, H801,
// Sonoff Dual and Sonoff RF Bridge // Sonoff Dual and Sonoff RF Bridge
#ifdef DUMMY_RELAY_COUNT
#if DUMMY_RELAY_COUNT > 0
for (unsigned char i=0; i < DUMMY_RELAY_COUNT; i++) { for (unsigned char i=0; i < DUMMY_RELAY_COUNT; i++) {
_relays.push_back((relay_t) {0, RELAY_TYPE_NORMAL}); _relays.push_back((relay_t) {0, RELAY_TYPE_NORMAL});
@ -807,28 +807,28 @@ void relaySetup() {
#else #else
#ifdef RELAY1_PIN
#if RELAY1_PIN != GPIO_NONE
_relays.push_back((relay_t) { RELAY1_PIN, RELAY1_TYPE, RELAY1_RESET_PIN, RELAY1_DELAY_ON, RELAY1_DELAY_OFF }); _relays.push_back((relay_t) { RELAY1_PIN, RELAY1_TYPE, RELAY1_RESET_PIN, RELAY1_DELAY_ON, RELAY1_DELAY_OFF });
#endif #endif
#ifdef RELAY2_PIN
#if RELAY2_PIN != GPIO_NONE
_relays.push_back((relay_t) { RELAY2_PIN, RELAY2_TYPE, RELAY2_RESET_PIN, RELAY2_DELAY_ON, RELAY2_DELAY_OFF }); _relays.push_back((relay_t) { RELAY2_PIN, RELAY2_TYPE, RELAY2_RESET_PIN, RELAY2_DELAY_ON, RELAY2_DELAY_OFF });
#endif #endif
#ifdef RELAY3_PIN
#if RELAY3_PIN != GPIO_NONE
_relays.push_back((relay_t) { RELAY3_PIN, RELAY3_TYPE, RELAY3_RESET_PIN, RELAY3_DELAY_ON, RELAY3_DELAY_OFF }); _relays.push_back((relay_t) { RELAY3_PIN, RELAY3_TYPE, RELAY3_RESET_PIN, RELAY3_DELAY_ON, RELAY3_DELAY_OFF });
#endif #endif
#ifdef RELAY4_PIN
#if RELAY4_PIN != GPIO_NONE
_relays.push_back((relay_t) { RELAY4_PIN, RELAY4_TYPE, RELAY4_RESET_PIN, RELAY4_DELAY_ON, RELAY4_DELAY_OFF }); _relays.push_back((relay_t) { RELAY4_PIN, RELAY4_TYPE, RELAY4_RESET_PIN, RELAY4_DELAY_ON, RELAY4_DELAY_OFF });
#endif #endif
#ifdef RELAY5_PIN
#if RELAY5_PIN != GPIO_NONE
_relays.push_back((relay_t) { RELAY5_PIN, RELAY5_TYPE, RELAY5_RESET_PIN, RELAY5_DELAY_ON, RELAY5_DELAY_OFF }); _relays.push_back((relay_t) { RELAY5_PIN, RELAY5_TYPE, RELAY5_RESET_PIN, RELAY5_DELAY_ON, RELAY5_DELAY_OFF });
#endif #endif
#ifdef RELAY6_PIN
#if RELAY6_PIN != GPIO_NONE
_relays.push_back((relay_t) { RELAY6_PIN, RELAY6_TYPE, RELAY6_RESET_PIN, RELAY6_DELAY_ON, RELAY6_DELAY_OFF }); _relays.push_back((relay_t) { RELAY6_PIN, RELAY6_TYPE, RELAY6_RESET_PIN, RELAY6_DELAY_ON, RELAY6_DELAY_OFF });
#endif #endif
#ifdef RELAY7_PIN
#if RELAY7_PIN != GPIO_NONE
_relays.push_back((relay_t) { RELAY7_PIN, RELAY7_TYPE, RELAY7_RESET_PIN, RELAY7_DELAY_ON, RELAY7_DELAY_OFF }); _relays.push_back((relay_t) { RELAY7_PIN, RELAY7_TYPE, RELAY7_RESET_PIN, RELAY7_DELAY_ON, RELAY7_DELAY_OFF });
#endif #endif
#ifdef RELAY8_PIN
#if RELAY8_PIN != GPIO_NONE
_relays.push_back((relay_t) { RELAY8_PIN, RELAY8_TYPE, RELAY8_RESET_PIN, RELAY8_DELAY_ON, RELAY8_DELAY_OFF }); _relays.push_back((relay_t) { RELAY8_PIN, RELAY8_TYPE, RELAY8_RESET_PIN, RELAY8_DELAY_ON, RELAY8_DELAY_OFF });
#endif #endif


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

@ -413,7 +413,7 @@ void _sensorConfigure() {
double value; double value;
EmonAnalogSensor * sensor = (EmonAnalogSensor *) _sensors[i]; EmonAnalogSensor * sensor = (EmonAnalogSensor *) _sensors[i];
if (value = getSetting("pwrExpectedP", 0).toInt() == 0) {
if (value = (getSetting("pwrExpectedP", 0).toInt() == 0)) {
value = getSetting("pwrRatioC", EMON_CURRENT_RATIO).toFloat(); value = getSetting("pwrRatioC", EMON_CURRENT_RATIO).toFloat();
if (value > 0) sensor->setCurrentRatio(0, value); if (value > 0) sensor->setCurrentRatio(0, value);
} else { } else {


+ 0
- 2
code/espurna/sensors/BaseSensor.h View File

@ -10,8 +10,6 @@
#include <Arduino.h> #include <Arduino.h>
#include <ArduinoJson.h> #include <ArduinoJson.h>
#define GPIO_NONE 0x99
#define SENSOR_ERROR_OK 0 // No error #define SENSOR_ERROR_OK 0 // No error
#define SENSOR_ERROR_OUT_OF_RANGE 1 // Result out of sensor range #define SENSOR_ERROR_OUT_OF_RANGE 1 // Result out of sensor range
#define SENSOR_ERROR_WARM_UP 2 // Sensor is warming-up #define SENSOR_ERROR_WARM_UP 2 // Sensor is warming-up


+ 9
- 9
code/espurna/settings.ino View File

@ -27,11 +27,11 @@ Copyright (C) 2016-2018 by Xose Pérez <xose dot perez at gmail dot com>
EmbedisWrap embedis(EMBEDIS_PORT, TERMINAL_BUFFER_SIZE); EmbedisWrap embedis(EMBEDIS_PORT, TERMINAL_BUFFER_SIZE);
#if TERMINAL_SUPPORT #if TERMINAL_SUPPORT
#ifdef SERIAL_RX_PORT
#if SERIAL_RX_ENABLED
char _serial_rx_buffer[TERMINAL_BUFFER_SIZE]; char _serial_rx_buffer[TERMINAL_BUFFER_SIZE];
static unsigned char _serial_rx_pointer = 0; static unsigned char _serial_rx_pointer = 0;
#endif
#endif
#endif // SERIAL_RX_ENABLED
#endif // TERMINAL_SUPPORT
bool _settings_save = false; bool _settings_save = false;
@ -408,10 +408,10 @@ void settingsSetup() {
_settingsInitCommands(); _settingsInitCommands();
#if TERMINAL_SUPPORT #if TERMINAL_SUPPORT
#ifdef SERIAL_RX_PORT
SERIAL_RX_PORT.begin(SERIAL_RX_BAUDRATE);
#endif
#endif
#if SERIAL_RX_ENABLED
SERIAL_RX_PORT.begin(SERIAL_RX_BAUDRATE);
#endif // SERIAL_RX_ENABLED
#endif // TERMINAL_SUPPORT
// Register loop // Register loop
espurnaRegisterLoop(settingsLoop); espurnaRegisterLoop(settingsLoop);
@ -429,7 +429,7 @@ void settingsLoop() {
embedis.process(); embedis.process();
#ifdef SERIAL_RX_PORT
#if SERIAL_RX_ENABLED
while (SERIAL_RX_PORT.available() > 0) { while (SERIAL_RX_PORT.available() > 0) {
char rc = Serial.read(); char rc = Serial.read();
@ -440,7 +440,7 @@ void settingsLoop() {
} }
} }
#endif // SERIAL_RX_PORT
#endif // SERIAL_RX_ENABLED
#endif // TERMINAL_SUPPORT #endif // TERMINAL_SUPPORT


+ 21
- 36
code/espurna/wifi.ino View File

@ -171,44 +171,29 @@ bool _wifiClean(unsigned char num) {
// Inject hardcoded networks // Inject hardcoded networks
void _wifiInject() { void _wifiInject() {
#ifdef WIFI1_SSID
if (getSetting("ssid", 0, "").length() == 0) setSetting("ssid", 0, WIFI1_SSID);
#endif
#ifdef WIFI1_PASS
if (getSetting("pass", 0, "").length() == 0) setSetting("pass", 0, WIFI1_PASS);
#endif
#ifdef WIFI1_IP
if (getSetting("ip", 0, "").length() == 0) setSetting("ip", 0, WIFI1_IP);
#endif
#ifdef WIFI1_GW
if (getSetting("gw", 0, "").length() == 0) setSetting("gw", 0, WIFI1_GW);
#endif
#ifdef WIFI1_MASK
if (getSetting("mask", 0, "").length() == 0) setSetting("mask", 0, WIFI1_MASK);
#endif
#ifdef WIFI1_DNS
if (getSetting("dns", 0, "").length() == 0) setSetting("dns", 0, WIFI1_DNS);
#endif
if (strlen(WIFI1_SSID)) {
if (!hasSetting("ssid", 0)) {
setSetting("ssid", 0, WIFI1_SSID);
setSetting("pass", 0, WIFI1_PASS);
setSetting("ip", 0, WIFI1_IP);
setSetting("gw", 0, WIFI1_GW);
setSetting("mask", 0, WIFI1_MASK);
setSetting("dns", 0, WIFI1_DNS);
}
#ifdef WIFI2_SSID
if (getSetting("ssid", 1, "").length() == 0) setSetting("ssid", 1, WIFI2_SSID);
#endif
#ifdef WIFI2_PASS
if (getSetting("pass", 1, "").length() == 0) setSetting("pass", 1, WIFI2_PASS);
#endif
#ifdef WIFI2_IP
if (getSetting("ip", 1, "").length() == 0) setSetting("ip", 1, WIFI2_IP);
#endif
#ifdef WIFI2_GW
if (getSetting("gw", 1, "").length() == 0) setSetting("gw", 1, WIFI2_GW);
#endif
#ifdef WIFI2_MASK
if (getSetting("mask", 1, "").length() == 0) setSetting("mask", 1, WIFI2_MASK);
#endif
#ifdef WIFI2_DNS
if (getSetting("dns", 1, "").length() == 0) setSetting("dns", 1, WIFI2_DNS);
#endif
if (strlen(WIFI2_SSID)) {
if (!hasSetting("ssid", 1)) {
setSetting("ssid", 1, WIFI2_SSID);
setSetting("pass", 1, WIFI2_PASS);
setSetting("ip", 1, WIFI2_IP);
setSetting("gw", 1, WIFI2_GW);
setSetting("mask", 1, WIFI2_MASK);
setSetting("dns", 1, WIFI2_DNS);
}
}
}
} }
#if DEBUG_SUPPORT #if DEBUG_SUPPORT


Loading…
Cancel
Save