Templated function pointer class. Common utility that other classes are built on / with

Dependents:   Waldo_Embed_V2 MQTT MQTTSN MQTT ... more

Good resource about declaring templated types for the linker

Basic Use

#include "mbed.h"
#include "FP.h"
  
FP<void,bool>fp;
DigitalOut myled(LED1);
  
void handler(bool value)
{
    myled = value;
    return;
}
  
int main()
{
    fp.attach(&handler);
      
    while(1) 
    {
        fp(1);
        wait(0.2);
        fp(0);
        wait(0.2);
    }
}

Example using the FP Class with different class member functions

#include "mbed.h"
#include "FP.h"
  
FP<void,bool>fp;
DigitalOut myled(LED4);
  
class Wrapper
{
public:
    Wrapper(){}
  
    void handler(bool value)
    {
        myled = value;
        return;
    }
};
  
int main()
{
    Wrapper wrapped;
    fp.attach(&wrapped, &Wrapper::handler);
    
    while(1) 
    {
        fp(1);
        wait(0.2);
        fp(0);
        wait(0.2);
    }
}

Example using the FP Class with member FP and member function

#include "mbed.h"
#include "FP.h"
  
DigitalOut myled(LED2);
  
class Wrapper
{
public:
    Wrapper()
    {
        fp.attach(this, &Wrapper::handler);
    }
  
    void handler(bool value)
    {
        myled = value;
        return;
    }
      
    FP<void,bool>fp;
};
  
int main()
{
    Wrapper wrapped;
      
    while(1) 
    {
        wrapped.fp(1);
        wait(0.2);
        wrapped.fp(0);
        wait(0.2);
    }
}

History

Moved all implementations to FP.h to not pre-define all templated data types for the linker default tip

2014-07-30, by sam_grove [Wed, 30 Jul 2014 19:10:31 +0000] rev 4

Moved all implementations to FP.h to not pre-define all templated data types for the linker


Add detach and "attached" member functions

2014-04-13, by icraggs [Sun, 13 Apr 2014 22:31:44 +0000] rev 3

Add detach and "attached" member functions


added param of void * to forward declared list

2014-03-08, by sam_grove [Sat, 08 Mar 2014 00:35:16 +0000] rev 2

added param of void * to forward declared list


Updated comments;

2013-05-14, by sam_grove [Tue, 14 May 2013 23:16:09 +0000] rev 1

Updated comments;


Uploaded source from a different project and updated documentation for mbed site

2013-04-05, by sam_grove [Fri, 05 Apr 2013 22:21:33 +0000] rev 0

Uploaded source from a different project and updated documentation for mbed site