Skip to content

Commit

Permalink
LwipIntfDev - method end() to enable repeated begin
Browse files Browse the repository at this point in the history
  • Loading branch information
JAndrassy committed Nov 10, 2023
1 parent 31c1592 commit 757dda7
Showing 1 changed file with 27 additions and 6 deletions.
33 changes: 27 additions & 6 deletions cores/esp8266/LwipIntfDev.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class LwipIntfDev: public LwipIntf, public RawDev

// default mac-address is inferred from esp8266's STA interface
boolean begin(const uint8_t* macAddress = nullptr, const uint16_t mtu = DEFAULT_MTU);
void end();

const netif* getNetIf() const
{
Expand Down Expand Up @@ -272,22 +273,42 @@ boolean LwipIntfDev<RawDev>::begin(const uint8_t* macAddress, const uint16_t mtu
}
}

if (_intrPin < 0
&& !schedule_recurrent_function_us(
static bool _scheduled = false;

if (_intrPin < 0 && !_scheduled)
{
_scheduled = schedule_recurrent_function_us(
[&]()
{
this->handlePackets();
if (!_started) {
_scheduled = false;
return false;
}
return true;
},
100))
{
netif_remove(&_netif);
return false;
100);
if (!_scheduled)
{
netif_remove(&_netif);
return false;
}
}

return true;
}

template<class RawDev>
void LwipIntfDev<RawDev>::end()
{
netif_remove(&_netif);
ip_addr_copy(_netif.ip_addr, ip_addr_any); // to allow DHCP at next begin
ip_addr_copy(_netif.netmask, ip_addr_any);
ip_addr_copy(_netif.gw, ip_addr_any);
_started = false;
RawDev::end();
}

template<class RawDev>
wl_status_t LwipIntfDev<RawDev>::status()
{
Expand Down

0 comments on commit 757dda7

Please sign in to comment.