Browse Source

sns/cse7766: fix pin naming

mcspr-patch-1
Maxim Prokhorov 4 years ago
committed by Max Prokhorov
parent
commit
57f5c7dc98
4 changed files with 21 additions and 12 deletions
  1. +3
    -3
      code/espurna/config/hardware.h
  2. +3
    -2
      code/espurna/config/sensors.h
  3. +1
    -1
      code/espurna/sensor.cpp
  4. +14
    -6
      code/espurna/sensors/CSE7766Sensor.h

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

@ -549,7 +549,7 @@
#ifndef CSE7766_SUPPORT #ifndef CSE7766_SUPPORT
#define CSE7766_SUPPORT 1 #define CSE7766_SUPPORT 1
#endif #endif
#define CSE7766_PIN 1
#define CSE7766_RX_PIN 3
#elif defined(ITEAD_SONOFF_DUAL) #elif defined(ITEAD_SONOFF_DUAL)
@ -975,7 +975,7 @@
// CSE7766 // CSE7766
#define CSE7766_SUPPORT 1 #define CSE7766_SUPPORT 1
#define CSE7766_PIN 1
#define CSE7766_RX_PIN 3
#elif defined(ITEAD_SONOFF_S31_LITE) #elif defined(ITEAD_SONOFF_S31_LITE)
@ -3201,7 +3201,7 @@
#ifndef CSE7766_SUPPORT #ifndef CSE7766_SUPPORT
#define CSE7766_SUPPORT 1 #define CSE7766_SUPPORT 1
#endif #endif
#define CSE7766_PIN 1
#define CSE7766_RX_PIN 3
// ----------------------------------------------------------------------------- // -----------------------------------------------------------------------------
// Teckin SP21 // Teckin SP21


+ 3
- 2
code/espurna/config/sensors.h View File

@ -284,8 +284,9 @@
#define CSE7766_SUPPORT 0 #define CSE7766_SUPPORT 0
#endif #endif
#ifndef CSE7766_PIN
#define CSE7766_PIN 1 // TX pin from the CSE7766
#ifndef CSE7766_RX_PIN
#define CSE7766_RX_PIN 3 // RX pin connected to the CSE7766
// As we never transmit anything, this is the only pin used
#endif #endif
#ifndef CSE7766_PIN_INVERSE #ifndef CSE7766_PIN_INVERSE


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

@ -1571,7 +1571,7 @@ void _sensorLoad() {
#if CSE7766_SUPPORT #if CSE7766_SUPPORT
{ {
CSE7766Sensor * sensor = new CSE7766Sensor(); CSE7766Sensor * sensor = new CSE7766Sensor();
sensor->setRX(CSE7766_PIN);
sensor->setRX(CSE7766_RX_PIN);
_sensors.push_back(sensor); _sensors.push_back(sensor);
} }
#endif #endif


+ 14
- 6
code/espurna/sensors/CSE7766Sensor.h View File

@ -132,8 +132,12 @@ class CSE7766Sensor : public BaseEmonSensor {
if (_serial) delete _serial; if (_serial) delete _serial;
if (1 == _pin_rx) {
if (3 == _pin_rx) {
Serial.begin(CSE7766_BAUDRATE); Serial.begin(CSE7766_BAUDRATE);
} else if (13 == _pin_rx) {
Serial.begin(CSE7766_BAUDRATE);
Serial.flush();
Serial.swap();
} else { } else {
_serial = new SoftwareSerial(_pin_rx, -1, _inverted); _serial = new SoftwareSerial(_pin_rx, -1, _inverted);
_serial->enableIntTx(false); _serial->enableIntTx(false);
@ -148,7 +152,7 @@ class CSE7766Sensor : public BaseEmonSensor {
// Descriptive name of the sensor // Descriptive name of the sensor
String description() { String description() {
char buffer[28]; char buffer[28];
if (1 == _pin_rx) {
if (_serial_is_hardware()) {
snprintf(buffer, sizeof(buffer), "CSE7766 @ HwSerial"); snprintf(buffer, sizeof(buffer), "CSE7766 @ HwSerial");
} else { } else {
snprintf(buffer, sizeof(buffer), "CSE7766 @ SwSerial(%u,NULL)", _pin_rx); snprintf(buffer, sizeof(buffer), "CSE7766 @ SwSerial(%u,NULL)", _pin_rx);
@ -368,8 +372,12 @@ class CSE7766Sensor : public BaseEmonSensor {
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
bool _serial_is_hardware() {
return (3 == _pin_rx) || (13 == _pin_rx);
}
bool _serial_available() { bool _serial_available() {
if (1 == _pin_rx) {
if (_serial_is_hardware()) {
return Serial.available(); return Serial.available();
} else { } else {
return _serial->available(); return _serial->available();
@ -377,7 +385,7 @@ class CSE7766Sensor : public BaseEmonSensor {
} }
void _serial_flush() { void _serial_flush() {
if (1 == _pin_rx) {
if (_serial_is_hardware()) {
return Serial.flush(); return Serial.flush();
} else { } else {
return _serial->flush(); return _serial->flush();
@ -385,7 +393,7 @@ class CSE7766Sensor : public BaseEmonSensor {
} }
uint8_t _serial_read() { uint8_t _serial_read() {
if (1 == _pin_rx) {
if (_serial_is_hardware()) {
return Serial.read(); return Serial.read();
} else { } else {
return _serial->read(); return _serial->read();
@ -394,7 +402,7 @@ class CSE7766Sensor : public BaseEmonSensor {
// --------------------------------------------------------------------- // ---------------------------------------------------------------------
unsigned int _pin_rx = CSE7766_PIN;
int _pin_rx = CSE7766_RX_PIN;
bool _inverted = CSE7766_PIN_INVERSE; bool _inverted = CSE7766_PIN_INVERSE;
SoftwareSerial * _serial = NULL; SoftwareSerial * _serial = NULL;


Loading…
Cancel
Save