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
#define CSE7766_SUPPORT 1
#endif
#define CSE7766_PIN 1
#define CSE7766_RX_PIN 3
#elif defined(ITEAD_SONOFF_DUAL)
@ -975,7 +975,7 @@
// CSE7766
#define CSE7766_SUPPORT 1
#define CSE7766_PIN 1
#define CSE7766_RX_PIN 3
#elif defined(ITEAD_SONOFF_S31_LITE)
@ -3201,7 +3201,7 @@
#ifndef CSE7766_SUPPORT
#define CSE7766_SUPPORT 1
#endif
#define CSE7766_PIN 1
#define CSE7766_RX_PIN 3
// -----------------------------------------------------------------------------
// Teckin SP21


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

@ -284,8 +284,9 @@
#define CSE7766_SUPPORT 0
#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
#ifndef CSE7766_PIN_INVERSE


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

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


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

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


Loading…
Cancel
Save