A class to call a function at the main function at regular intervals (using Ticker class)

Dependents:   GPS_0002 optWingforHAPS_Eigen hexaTest_Eigen

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers LoopTicker.cpp Source File

LoopTicker.cpp

00001 #include "mbed.h"
00002 #include "LoopTicker.hpp"
00003 
00004 LoopTicker::LoopTicker()
00005 {
00006     fptr = NULL;
00007     time = 0.0f;
00008     updated = false;
00009 }
00010 
00011 void LoopTicker::attach(void (*fptr_)(), float time_)
00012 {
00013     fptr = fptr_;
00014     time = time_;
00015     ticker_.attach(this, &LoopTicker::interrupt, time);
00016 }
00017 
00018 void LoopTicker::detach()
00019 {
00020     fptr = NULL;
00021     time = 0.0f;
00022     updated = false;
00023     ticker_.detach();
00024 }
00025 
00026 void LoopTicker::loop()
00027 {
00028     if (updated)
00029     {
00030         fptr();
00031         updated = false;
00032     }
00033 }
00034 
00035 void LoopTicker::interrupt()
00036 {
00037     updated = true;
00038 }