Skip to content

Commit

Permalink
less modifications in SDM lib, formating
Browse files Browse the repository at this point in the history
  • Loading branch information
Adminius committed Sep 22, 2024
1 parent 9e8c7f1 commit cadb33a
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 39 deletions.
36 changes: 3 additions & 33 deletions lib/SdmEnergyMeter/SDM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@ SDM::SDM(HardwareSerial& serial, long baud, int dere_pin, int config, bool swapu
this->_config = config;
this->_swapuart = swapuart;
}
SDM::SDM(HardwareSerial &serial, long baud, int dere_pin, int re_pin, int config, bool swapuart) : sdmSer(serial)
{
this->_baud = baud;
this->_dere_pin = dere_pin;
this->_re_pin = re_pin;
this->_config = config;
this->_swapuart = swapuart;
}
#elif defined ( ESP32 )
SDM::SDM(HardwareSerial& serial, long baud, int dere_pin, int config, int8_t rx_pin, int8_t tx_pin) : sdmSer(serial) {
this->_baud = baud;
Expand All @@ -30,28 +22,12 @@ SDM::SDM(HardwareSerial& serial, long baud, int dere_pin, int config, int8_t rx_
this->_rx_pin = rx_pin;
this->_tx_pin = tx_pin;
}
SDM::SDM(HardwareSerial &serial, long baud, int dere_pin, int re_pin, int config, int8_t rx_pin, int8_t tx_pin) : sdmSer(serial)
{
this->_baud = baud;
this->_dere_pin = dere_pin;
this->_re_pin = re_pin;
this->_config = config;
this->_rx_pin = rx_pin;
this->_tx_pin = tx_pin;
}
#else
SDM::SDM(HardwareSerial& serial, long baud, int dere_pin, int config) : sdmSer(serial) {
this->_baud = baud;
this->_dere_pin = dere_pin;
this->_config = config;
}
SDM::SDM(HardwareSerial &serial, long baud, int dere_pin, int re_pin, int config) : sdmSer(serial)
{
this->_baud = baud;
this->_dere_pin = dere_pin;
this->_re_pin = re_pin;
this->_config = config;
}
#endif
#else
#if defined ( ESP8266 ) || defined ( ESP32 )
Expand All @@ -76,12 +52,6 @@ SDM::SDM(SoftwareSerial& serial, long baud, int dere_pin) : sdmSer(serial) {
this->_baud = baud;
this->_dere_pin = dere_pin;
}
SDM::SDM(SoftwareSerial &serial, long baud, int dere_pin, int re_pin) : sdmSer(serial)
{
this->_baud = baud;
this->_dere_pin = dere_pin;
this->_re_pin = re_pin;
}
#endif
#endif

Expand Down Expand Up @@ -111,13 +81,13 @@ void SDM::begin(void) {
#endif
if (_dere_pin != NOT_A_PIN)
{
pinMode(_dere_pin, OUTPUT); // set output pin mode for DE/RE pin when used (for control MAX485)
pinMode(_dere_pin, OUTPUT); // set output pin mode for DE/RE pin when used (for control MAX485)
}
if (_re_pin != NOT_A_PIN)
{
pinMode(_re_pin, OUTPUT); // set output pin mode /RE pin when used (for control MAX485)
pinMode(_re_pin, OUTPUT); // set output pin mode /RE pin when used (for control MAX485)
}
dereSet(LOW); // set init state to receive from SDM -> DE Disable, /RE Enable (for control MAX485)
dereSet(LOW); // set init state to receive from SDM -> DE Disable, /RE Enable (for control MAX485)
}

float SDM::readVal(uint16_t reg, uint8_t node) {
Expand Down
4 changes: 0 additions & 4 deletions lib/SdmEnergyMeter/SDM.h
Original file line number Diff line number Diff line change
Expand Up @@ -325,21 +325,17 @@ class SDM {
#if defined ( USE_HARDWARESERIAL ) // hardware serial
#if defined ( ESP8266 ) // on esp8266
SDM(HardwareSerial& serial, long baud = SDM_UART_BAUD, int dere_pin = DERE_PIN, int config = SDM_UART_CONFIG, bool swapuart = SWAPHWSERIAL);
SDM(HardwareSerial& serial, long baud = SDM_UART_BAUD, int dere_pin = DERE_PIN, int re_pin = RE_PIN, int config = SDM_UART_CONFIG, bool swapuart = SWAPHWSERIAL);
#elif defined ( ESP32 ) // on esp32
SDM(HardwareSerial& serial, long baud = SDM_UART_BAUD, int dere_pin = DERE_PIN, int config = SDM_UART_CONFIG, int8_t rx_pin = SDM_RX_PIN, int8_t tx_pin = SDM_TX_PIN);
SDM(HardwareSerial& serial, long baud = SDM_UART_BAUD, int dere_pin = DERE_PIN, int re_pin = RE_PIN, int config = SDM_UART_CONFIG, int8_t rx_pin = SDM_RX_PIN, int8_t tx_pin = SDM_TX_PIN);
#else // on avr
SDM(HardwareSerial& serial, long baud = SDM_UART_BAUD, int dere_pin = DERE_PIN, int config = SDM_UART_CONFIG);
SDM(HardwareSerial& serial, long baud = SDM_UART_BAUD, int dere_pin = DERE_PIN, int re_pin = RE_PIN, int config = SDM_UART_CONFIG);
#endif
#else // software serial
#if defined ( ESP8266 ) || defined ( ESP32 ) // on esp8266/esp32
SDM(SoftwareSerial& serial, long baud = SDM_UART_BAUD, int dere_pin = DERE_PIN, int config = SDM_UART_CONFIG, int8_t rx_pin = SDM_RX_PIN, int8_t tx_pin = SDM_TX_PIN);
SDM(SoftwareSerial& serial, long baud = SDM_UART_BAUD, int dere_pin = DERE_PIN, int re_pin = RE_PIN, int config = SDM_UART_CONFIG, int8_t rx_pin = SDM_RX_PIN, int8_t tx_pin = SDM_TX_PIN);
#else // on avr
SDM(SoftwareSerial& serial, long baud = SDM_UART_BAUD, int dere_pin = DERE_PIN);
SDM(SoftwareSerial& serial, long baud = SDM_UART_BAUD, int dere_pin = DERE_PIN, int re_pin = RE_PIN);
#endif
#endif
virtual ~SDM();
Expand Down
6 changes: 4 additions & 2 deletions src/PowerMeterSerialSdm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,12 @@ bool PowerMeterSerialSdm::init()

_upSdmSerial = std::make_unique<SoftwareSerial>();

if(pin.powermeter_rxen > -1 && pin.powermeter_txen > -1){
if (pin.powermeter_rxen > -1 && pin.powermeter_txen > -1){
_upSdm = std::make_unique<SDM>(*_upSdmSerial, 9600, pin.powermeter_rxen, pin.powermeter_txen,
SWSERIAL_8N1, pin.powermeter_rx, pin.powermeter_tx);
}else{
}
else
{
_upSdm = std::make_unique<SDM>(*_upSdmSerial, 9600, pin.powermeter_dere,
SWSERIAL_8N1, pin.powermeter_rx, pin.powermeter_tx);
}
Expand Down

0 comments on commit cadb33a

Please sign in to comment.