using Ticker inside a class

08 Mar 2011

I have a class definition with a ticker object declard in the task as well as a function inside the task. I get a compile error when I call the attach function.

Sequence.h

class Sequence
{
public:

	// construction/destruction
	Sequencer( void );
	~Sequencer( void );
	
private:
	Ticker		tickSeq;
	
	// ticker
	void ProcessTicker( void );
}

Sequence.c

Sequence::Sequence( )
{
	// create the ticker
	tickSeq.attach( &ProcessTicker, 1.0 );
}
08 Mar 2011

If you want to use a method (as opposed to a plain function), you need to pass the class instance too. Try:

tickSeq.attach(this, &ProcessTicker, 1.0);

08 Mar 2011

I think it's actually:-

Sequence.c

Sequence::Sequence( )
{
	// create the ticker
	tickSeq.attach(this, &Sequence::ProcessTicker, 1.0 );
}
08 Mar 2011

Worked great. Thanks

23 Oct 2013

Thank you. :)

30 Dec 2016

The mbed-os now requires the callback to be added otherwise the function warning of depreciating will be indicated :

tickSeq.attach(callback(this, &Sequence::ProcessTicker, 1.0 );

09 Feb 2017

David Santana wrote:

tickSeq.attach(callback(this, &Sequence::ProcessTicker, 1.0 );

The correct Syntax will be:

tickSeq.attach(callback(this, &Sequence::ProcessTicker), 1.0 );

You missed closing bracket.

10 Feb 2017

Along those same lines, I have this simple class definition, which essentially inherits class USBSerial:

#include "mbed.h"
#include "USBSerial.h"
class inherit_USBSerial : public USBSerial {
  public:
    inherit_USBSerial() : USBSerial() {}
};

inherit_USBSerial xxx; // just completely inherit class USBSerial

int main(){ xxx.printf("Hello World\n"); }


I get this warning:

Warning

Function "mbed::FunctionPointerArg1::FunctionPointerArg1(R (*)()) [with R=void]" (declared at/extras/mbed_176b8275d35d/platform/FunctionPointer.h:67) was declared "deprecated" in "USBDevice/USBSerial/USBSerial.h", Line: 59, Col: 205>


Since the warning is about a void function pointer, can I do something to stop the warning?


10 Feb 2017

Also, changing USBSerial.h line 59 from

//
    USBSerial(uint16_t vendor_id = 0x1f00, uint16_t product_id = 0x2012, 
                             uint16_t product_release = 0x0001, bool connect_blocking = true)
      : USBCDC(vendor_id, product_id, product_release, connect_blocking)
    {  settingsChangedCallback = 0;    };

to

    typedef void (* fptr4)(int,int,int,int); // a void function pointer with 4 int parameters
    USBSerial(uint16_t vendor_id = 0x1f00, uint16_t product_id = 0x2012, 
                            uint16_t product_release = 0x0001, bool connect_blocking = true, fptr4 callback = 0)
      : USBCDC(vendor_id, product_id, product_release, connect_blocking)
    { settingsChangedCallback = callback;  };

did not make the the warning go away - even though the added callback does work when USB serial port settings are changed.