Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 23 additions & 0 deletions lib/ESPEasySerial/ESPEasySerialConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,24 @@

#include "ESPEasySerialType.h"

bool ESPEasySerialConfig::operator==(const ESPEasySerialConfig& other) const
{
return port == other.port
&& baud == other.baud
&& receivePin == other.receivePin
&& transmitPin == other.transmitPin
&& inverse_logic == other.inverse_logic
&& rxBuffSize == other.rxBuffSize
&& txBuffSize == other.txBuffSize
&& forceSWserial == other.forceSWserial
&& timeout_ms == other.timeout_ms
&& config == other.config
#ifdef ESP8266
&& mode == other.mode
#endif
;
}

void ESPEasySerialConfig::validate()
{
port = ESPeasySerialType::getSerialType(port, receivePin, transmitPin);
Expand All @@ -18,6 +36,11 @@ void ESPEasySerialConfig::validate()
# endif // if USES_I2C_SC16IS752
}
#endif // if USES_SW_SERIAL
#if USES_HWCDC
if (port == ESPEasySerialPort::usb_hw_cdc) {
txBuffSize = 2048;
}
#endif
}

#ifdef ESP8266
Expand Down
4 changes: 4 additions & 0 deletions lib/ESPEasySerial/ESPEasySerialConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@
struct ESPEasySerialConfig {
ESPEasySerialConfig() = default;

bool operator==(const ESPEasySerialConfig& other) const;

ESPEasySerialConfig& operator=(const ESPEasySerialConfig& other) = default;

void validate();

#ifdef ESP8266
Expand Down
31 changes: 23 additions & 8 deletions lib/ESPEasySerial/Port_ESPEasySerial_USB_HWCDC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,20 @@ static void hwcdcEventCallback(void *arg, esp_event_base_t event_base, int32_t e
}
}

bool Port_ESPEasySerial_USB_HWCDC_t::isConnected() const
{
static bool connected_cache{};
static uint32_t lastChecked{};
if (!connected_cache) {
const int32_t timePassedSince = (int32_t) (millis() - lastChecked);
if (timePassedSince < 1000) return false;
lastChecked = millis();
}
connected_cache = _hwcdc_serial != nullptr && _hwcdc_serial->isConnected();
return connected_cache;
}


Port_ESPEasySerial_USB_HWCDC_t::Port_ESPEasySerial_USB_HWCDC_t(const ESPEasySerialConfig& config)

# if ARDUINO_USB_CDC_ON_BOOT // Serial used for USB CDC
Expand All @@ -71,7 +85,7 @@ Port_ESPEasySerial_USB_HWCDC_t::Port_ESPEasySerial_USB_HWCDC_t(const ESPEasySeri

// _hwcdc_serial->begin();

// _hwcdc_serial->onEvent(hwcdcEventCallback);
// _hwcdc_serial->onEvent(hwcdcEventCallback);
}
}

Expand Down Expand Up @@ -106,31 +120,31 @@ void Port_ESPEasySerial_USB_HWCDC_t::end() {

int Port_ESPEasySerial_USB_HWCDC_t::available(void)
{
if (_hwcdc_serial != nullptr && _hwcdc_serial->isConnected()) {
if (isConnected()) {
return _hwcdc_serial->available();
}
return 0;
}

int Port_ESPEasySerial_USB_HWCDC_t::availableForWrite(void)
{
if (_hwcdc_serial != nullptr && _hwcdc_serial->isConnected()) {
if (isConnected()) {
return _hwcdc_serial->availableForWrite();
}
return 0;
}

int Port_ESPEasySerial_USB_HWCDC_t::peek(void)
{
if (_hwcdc_serial != nullptr && _hwcdc_serial->isConnected()) {
if (isConnected()) {
return _hwcdc_serial->peek();
}
return 0;
}

int Port_ESPEasySerial_USB_HWCDC_t::read(void)
{
if (_hwcdc_serial != nullptr && _hwcdc_serial->isConnected()) {
if (isConnected()) {
return _hwcdc_serial->read();
}
return 0;
Expand All @@ -139,15 +153,15 @@ int Port_ESPEasySerial_USB_HWCDC_t::read(void)
size_t Port_ESPEasySerial_USB_HWCDC_t::read(uint8_t *buffer,
size_t size)
{
if (_hwcdc_serial != nullptr && _hwcdc_serial->isConnected()) {
if (isConnected()) {
return _hwcdc_serial->read(buffer, size);
}
return 0;
}

void Port_ESPEasySerial_USB_HWCDC_t::flush(void)
{
if (_hwcdc_serial != nullptr && _hwcdc_serial->isConnected()) {
if (isConnected()) {
return _hwcdc_serial->flush();
}
}
Expand Down Expand Up @@ -176,7 +190,7 @@ size_t Port_ESPEasySerial_USB_HWCDC_t::write(const uint8_t *buffer,

Port_ESPEasySerial_USB_HWCDC_t::operator bool() const
{
if (_hwcdc_serial != nullptr && _hwcdc_serial->isConnected()) {
if (isConnected()) {
// return usbActive;
return true;
}
Expand Down Expand Up @@ -212,4 +226,5 @@ bool Port_ESPEasySerial_USB_HWCDC_t::setRS485Mode(int8_t rtsPin, bool enableColl
return false;
}


#endif // if USES_HWCDC
3 changes: 3 additions & 0 deletions lib/ESPEasySerial/Port_ESPEasySerial_USB_HWCDC.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ class Port_ESPEasySerial_USB_HWCDC_t : public Port_ESPEasySerial_base {
bool setRS485Mode(int8_t rtsPin, bool enableCollisionDetection = false);

private:

bool isConnected() const;

#if !ARDUINO_USB_CDC_ON_BOOT
HWCDC myUsbSerial;
#endif
Expand Down
3 changes: 2 additions & 1 deletion platformio_core_defs.ini
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,10 @@ extra_scripts = ${esp82xx_common.extra_scripts}
;platform_packages = framework-arduinoespressif32 @ https://github.com/Jason2866/esp32-arduino-lib-builder/releases/download/2904-2115-5.5/framework-arduinoespressif32-release_v5.5-f2a3fa2b.tar.xz

platform = https://github.com/Jason2866/platform-espressif32.git#Arduino/IDF55_gcc152
platform_packages =
platform_packages = framework-arduinoespressif32 @ https://github.com/Jason2866/esp32-arduino-lib-builder/releases/download/1807-0842-5.5/framework-arduinoespressif32-release_v5.5-67336dba.tar.xz
;platform_packages = framework-arduinoespressif32 @ https://github.com/Jason2866/esp32-arduino-lib-builder/releases/download/2805-1324-5.5/framework-arduinoespressif32-release_v5.5-f3cdb9d0.tar.xz


custom_remove_include = true

custom_component_remove =
Expand Down
2 changes: 1 addition & 1 deletion src/_P040_ID12.ino
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ boolean Plugin_040(uint8_t function, struct EventStruct *event, String& string)
{
if (Plugin_040_init)
{
success = true;
uint8_t val = 0;
uint8_t code[6];
uint8_t checksum = 0;
Expand Down Expand Up @@ -187,7 +188,6 @@ boolean Plugin_040(uint8_t function, struct EventStruct *event, String& string)
Scheduler.setPluginTaskTimer(500, event->TaskIndex, event->Par1);
}
}
success = true;
}
break;
}
Expand Down
2 changes: 1 addition & 1 deletion src/_P091_SerSwitch.ino
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ boolean Plugin_091(uint8_t function, struct EventStruct *event, String& string)

if (Plugin_091_init)
{
success = true;
while (ESPEASY_SERIAL_0.available() > 0) {
yield();

Expand Down Expand Up @@ -533,7 +534,6 @@ boolean Plugin_091(uint8_t function, struct EventStruct *event, String& string)
}
}
} // plugin initialized end
success = true;
break;
}

Expand Down
Loading
Loading