Skip to content

Ticker::once_ms() warning when used with argument #6155

Closed
@mrengineer7777

Description

@mrengineer7777

Board

ESP32 Feather

Device Description

Adafruit ESP32 Feather dev board

Hardware Configuration

No

Version

v2.0.2

IDE Name

PlatformIO in Visual Studio Code

Operating System

Win10

Flash frequency

N/A

PSRAM enabled

no

Upload speed

115200

Description

Compiling Ticker give me a warning.

Calling this works fine, no warning:
Save_Ticker.once_ms(ms, EP_Save);

Calling this results in a worrisome warning message:
WiFiCtrl.SoftAP_Shutdown_Timer.once_ms(1000*timeout_secs, ShutdownSoftAP, u);

The difference is that the callback function "ShutdownSoftAP" has a parameter "u". It is this parameter that the compiler complains about. It seems to be an issue with the template in Ticker.h.

Background:
I am compiling under native IDF because I need access to functions that don't exist yet in Arduino. I have copied in arduinoespressif\cores and arduinoespressif\library\Ticker. I did fix many circular include dependencies. I am NOT compiling Arduino as IDF component. Tried that, finally gave up.

Targeting: platform = https://github.com/tasmota/platform-espressif32/releases/download/v2.0.2idf/platform-espressif32-2.0.2.zip
This uses IDF 4.4, Arduino 2.0.2
https://github.com/tasmota/platform-espressif32/releases/tag/v2.0.2idf

Sketch

void WiFiCtrlClass::ScheduleSoftAPShutdownTimeSecs(uint32_t timeout_secs, bool DisconnectClients) {
  //Serial.printf("Scheduling SoftAP shutdown for %u secs\r\n", timeout_secs);

  uint32_t u;
  DisconnectClients == true ? u=1 : u=0;

  if(timeout_secs == 0)
    WiFiCtrl.SoftAP_Shutdown_Timer.detach();
  else
    WiFiCtrl.SoftAP_Shutdown_Timer.once_ms(1000*timeout_secs, ShutdownSoftAP, u);
}

void static ShutdownSoftAP(uint32_t disconnect_clients) {
  if(disconnect_clients==0 && WiFi.softAPgetStationNum()>0) {                         //Client is still connected. Try again in 1 minute.
      Serial.printf("ShutdownSoftAP() Clients=%u\r\n",WiFi.softAPgetStationNum());
      WiFiCtrl.ScheduleSoftAPShutdownTimeSecs(10, false);
      return;
    }
    //Serial.println("Shutting down SoftAP");
    WiFi.enableAP(false);
}

---From Ticker.h---
template<typename TArg>
  void once_ms(uint32_t milliseconds, void (*callback)(TArg), TArg arg)
  {
    static_assert(sizeof(TArg) <= sizeof(uint32_t), "attach_ms() callback argument size must be <= 4 bytes");
    uint32_t arg32 = (uint32_t)(arg);
    _attach_ms(milliseconds, false, reinterpret_cast<callback_with_arg_t>(callback), arg32);
  }

Debug Message

lib/Ticker/Ticker.h:92:37: warning: cast between incompatible function types from 'void (*)(unsigned int)' to 'Ticker::callback_with_arg_t' {aka 'void (*)(void*)'} [-Wcast-function-type]
     _attach_ms(milliseconds, false, reinterpret_cast<callback_with_arg_t>(callback), arg32);

It appears to be unhappy with casting (unsigned int) to (void*).

Other Steps to Reproduce

Originally my callback function had a Boolean parameter, but I changed it to uint32_t because the template casts it to uint32_t. I get pretty much the same warning.

I have checked existing issues, online documentation and the Troubleshooting Guide

  • I confirm I have checked existing issues, online documentation and Troubleshooting guide.

Metadata

Metadata

Assignees

Labels

Status: Needs investigationWe need to do some research before taking next steps on this issue

Type

No type

Projects

Status

Done

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions