diff --git a/CSE7766.cpp b/CSE7766.cpp index 04c3748..522358d 100644 --- a/CSE7766.cpp +++ b/CSE7766.cpp @@ -130,8 +130,14 @@ if (1 == _pin_rx) { Serial.begin(CSE7766_BAUDRATE); - } else { - _serial = new SoftwareSerial(_pin_rx, SW_SERIAL_UNUSED_PIN, _inverted, 32); + } +#ifdef ESP32 + else if (16== _pin_rx){ + Serial2.begin(CSE7766_BAUDRATE); + } +#endif + else { + _serial = new SoftwareSerial(_pin_rx, -1, _inverted); _serial->enableIntTx(false); _serial->begin(CSE7766_BAUDRATE); } @@ -308,7 +314,13 @@ bool CSE7766::_serial_available() { if (1 == _pin_rx) { return Serial.available(); - } else { + } +#ifdef ESP32 + else if (16== _pin_rx){ + return Serial2.available(); + } +#endif + else { return _serial->available(); } } @@ -316,7 +328,13 @@ void CSE7766::_serial_flush() { if (1 == _pin_rx) { return Serial.flush(); - } else { + } +#ifdef ESP32 + else if (16== _pin_rx){ + return Serial2.flush(); + } +#endif + else { return _serial->flush(); } } @@ -324,8 +342,13 @@ uint8_t CSE7766::_serial_read() { if (1 == _pin_rx) { return Serial.read(); - } else { + } +#ifdef ESP32 + else if (16== _pin_rx){ + return Serial2.read(); + } +#endif + else { return _serial->read(); } } - diff --git a/CSE7766.h b/CSE7766.h index 86ce506..e5b95d2 100644 --- a/CSE7766.h +++ b/CSE7766.h @@ -8,7 +8,7 @@ #define CSE7766_h #include "Arduino.h" -#include "debug.h" +#include "debug_cse.h" #include #ifndef CSE7766_PIN diff --git a/debug.h b/debug_cse.h similarity index 100% rename from debug.h rename to debug_cse.h diff --git a/library.json b/library.json new file mode 100644 index 0000000..4fc59ee --- /dev/null +++ b/library.json @@ -0,0 +1,25 @@ +{ + "name": "CSE7766", + "keywords": "cse7766, power, sonoff-s31, sensor", + "description": "Arduino Library for CSE7766 (Used in Sonoff S31)", + "repository": + { + "type": "git", + "url": "https://github.com/ingeniuske/CSE7766.git" + }, + "authors": + [ + { + "name": "Ingeniuske", + "email": "ingeniuske@gmail.com", + "url": "https://github.com/ingeniuske/CSE7766", + "maintainer": true + } + ], + "dependencies": + { + }, + "version": "1.0.0", + "frameworks": "arduino", + "platforms": "*" +}