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);
    }
}

Files at this revision

API Documentation at this revision

Comitter:
sam_grove
Date:
Sat Mar 08 00:35:16 2014 +0000
Parent:
1:e9a4765b560f
Child:
3:e0f19cdaa46e
Commit message:
added param of void * to forward declared list

Changed in this revision

FP.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/FP.cpp	Tue May 14 23:16:09 2013 +0000
+++ b/FP.cpp	Sat Mar 08 00:35:16 2014 +0000
@@ -71,6 +71,7 @@
 template class FP<void,float*>;
 template class FP<void,double>;
 template class FP<void,double*>;
+template class FP<void,void*>;
 
 template class FP<int8_t,char>;
 template class FP<int8_t,char*>;