Home > Back-end >  ESP32 - Arduino questions about c overloaded function parameters does not match
ESP32 - Arduino questions about c overloaded function parameters does not match

Time:10-07

I recently in refactoring my microcontroller c + + code, there is a need to invoke the callback function, which has been submitted to the argument types do not match, I wonder, in the original program, all write together is no problem, now in the class to this fault, bosses ball ball to help me take a look at what went wrong,

This is the wrong code, in the bottom attach_ms there I call the wrong
 
# pragma once

# include "mSensorData. H"

#include
#include
#include
#include
#include
#include

The class SensorCharacteristicBase {




BLE2902 * m_p_s_2902=new BLE2902;
//BLE2904 * m_2904=new BLE2904;


Virtual void startTicker ()=0;
Public:
Uint32_t m_SampleRate=30;


Protected:
Ticker * m_p_s_Ticker=new Ticker.

SensorDataCollectorBase * m_SensorData;

Uint32_t m_SensorProperties=BLECharacteristic: : PROPERTY_NOTIFY
| BLECharacteristic: : PROPERTY_READ;
Uint32_t m_ControlProperties=BLECharacteristic: : PROPERTY_READ
| BLECharacteristic: : PROPERTY_WRITE;
BLEUUID m_SensorCharacteristicUUID;
BLEUUID m_ControlCharacteristicUUID;
BLECharacteristic * m_p_SensorCharateristic;
BLECharacteristic * m_p_ControlCharateristic;

STD: : string m_Data;
Virtual ~ SensorCharacteristicBase () {};
};

/* *
* @ brief, the characteristics of ecg signal encapsulation
*
*/
The class ECG_SensorCharacteristic: protected SensorCharacteristicBase
{
ECG_SensorCharacteristic (STD: : string sensorUUID, STD: : string controlUUID, int ECG_PinOUT) {

M_SensorData=https://bbs.csdn.net/topics/new ECG_SensorDataCollector (ECG_PinOUT);
M_Data=https://bbs.csdn.net/topics/m_SensorData-> getData (). C_str ();

M_SensorCharacteristicUUID=BLEUUID (sensorUUID);
M_ControlCharacteristicUUID=BLEUUID (controlUUID);
M_p_SensorCharateristic=& amp; BLECharacteristic (m_SensorCharacteristicUUID m_SensorProperties);
M_p_ControlCharateristic=& amp; BLECharacteristic (m_ControlCharacteristicUUID m_ControlProperties);
}

Void m_TickerCallBack () {
M_p_SensorCharateristic - & gt; SetValue (m_Data);
M_p_SensorCharateristic - & gt; Notify ();
}
//* * * * * * * * * * * * * * * * * * * * * * * * * * out where the problem * * * * * * * * * * * * * * * * * * * * * * * * *
Void startTicker () {
M_p_s_Ticker - & gt; Attach_ms (m_SampleRate m_TickerCallBack);//not overloaded function to match the parameter list "Ticker: : attach_ms instance - type: (uint32_t, void ()), object types are: TickerC/c + + (304)
}
Public:

};



Below is the Ticker. H
part of the source code
 
The class Ticker
{
Public:
Ticker ();
~ Ticker ();
Callback_t typedef void (*) (void);//define the void is heavy, here I use void is arguably also no problem, because I did just that, before very smoothly passed the
Callback_with_arg_t typedef void (*) (void *).

Void the attach (float seconds, callback_t callback)
{
_attach_ms (seconds * 1000, true, reinterpret_cast & lt; Callback_with_arg_t & gt; (the callback), 0);
}
//* * * * * * * * * * * * * * * * * * * used function here * * * * * * * * * * * * * * * * * * * * * * * * * * * *
Void attach_ms (uint32_t milliseconds, callback_t callback)
{
_attach_ms (milliseconds, true, reinterpret_cast & lt; Callback_with_arg_t & gt; (the callback), 0);
}

Template
Void the attach (float seconds, void * callback (TArg), TArg arg)
{
Static_assert (sizeof (TArg) & lt;=sizeof (uint32_t), "the attach () callback argument the size must be & lt; 4 bytes=");
//C - cast serves two purposes:
//static_cast for smaller integer types,
//reinterpret_cast + const_cast for pointer types
Uint32_t arg32=(arg uint32_t);
_attach_ms (seconds * 1000, true, reinterpret_cast & lt; Callback_with_arg_t & gt; (the callback), arg32);
}

Template
Void attach_ms (uint32_t milliseconds, void * callback (TArg), TArg arg)
{
Static_assert (sizeof (TArg) & lt;=sizeof (uint32_t), "attach_ms () callback argument the size must be & lt; 4 bytes=");
Uint32_t arg32=(arg uint32_t);
_attach_ms (milliseconds, true, reinterpret_cast & lt; Callback_with_arg_t & gt; (the callback), arg32);
}

Void once (float seconds, callback_t callback)
{
_attach_ms (seconds * 1000, false, reinterpret_cast & lt; Callback_with_arg_t & gt; (the callback), 0);
}

Void once_ms (uint32_t milliseconds, callback_t callback)
{
_attach_ms (milliseconds, false, reinterpret_cast & lt; Callback_with_arg_t & gt; (the callback), 0);
}

Template
Void once (float seconds, void * callback (TArg), TArg arg)
{
Static_assert (sizeof (TArg) & lt;=sizeof (uint32_t), "the attach () callback argument the size must be & lt; 4 bytes=");
Uint32_t arg32=(uint32_t) (arg);
_attach_ms (seconds * 1000, false, reinterpret_cast & lt; Callback_with_arg_t & gt; (the callback), arg32);
}

Template
Void once_ms (uint32_t milliseconds, void * callback (TArg), TArg arg)
{
Static_assert (sizeof (TArg) & lt;=sizeof (uint32_t), "attach_ms () callback argument the size must be & lt; 4 bytes=");
Uint32_t arg32=(uint32_t) (arg);
nullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnullnull
  • Related