Class that makes for easy scheduling of regular tasks in a soft real-time context.

Committer:
symbiotic
Date:
Mon May 26 17:09:32 2014 +0000
Revision:
0:9015010b5125
original version of library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
symbiotic 0:9015010b5125 1 /**
symbiotic 0:9015010b5125 2 Generic Ticker implementation that sets a boolean flag at a regular interval
symbiotic 0:9015010b5125 3
symbiotic 0:9015010b5125 4 9/12/13 Andrew H. Fagg Original
symbiotic 0:9015010b5125 5
symbiotic 0:9015010b5125 6 */
symbiotic 0:9015010b5125 7
symbiotic 0:9015010b5125 8 #include "BooleanTicker.h"
symbiotic 0:9015010b5125 9
symbiotic 0:9015010b5125 10 /**
symbiotic 0:9015010b5125 11 Constructor. Immediately starts the ticker.
symbiotic 0:9015010b5125 12
symbiotic 0:9015010b5125 13 \param interval Interval from one flag setting to the next
symbiotic 0:9015010b5125 14 */
symbiotic 0:9015010b5125 15
symbiotic 0:9015010b5125 16 BooleanTicker::BooleanTicker(float interval){
symbiotic 0:9015010b5125 17 value = false;
symbiotic 0:9015010b5125 18 ticker.attach(this, &BooleanTicker::BooleanTickerCallback, interval);
symbiotic 0:9015010b5125 19 }
symbiotic 0:9015010b5125 20
symbiotic 0:9015010b5125 21 /**
symbiotic 0:9015010b5125 22 Deconstructor
symbiotic 0:9015010b5125 23 */
symbiotic 0:9015010b5125 24
symbiotic 0:9015010b5125 25 BooleanTicker::~BooleanTicker(){
symbiotic 0:9015010b5125 26 ticker.detach();
symbiotic 0:9015010b5125 27 }
symbiotic 0:9015010b5125 28
symbiotic 0:9015010b5125 29 /**
symbiotic 0:9015010b5125 30 Callback function: sets the flag
symbiotic 0:9015010b5125 31 */
symbiotic 0:9015010b5125 32
symbiotic 0:9015010b5125 33 void BooleanTicker::BooleanTickerCallback(){
symbiotic 0:9015010b5125 34 value = true;
symbiotic 0:9015010b5125 35 }
symbiotic 0:9015010b5125 36
symbiotic 0:9015010b5125 37 /**
symbiotic 0:9015010b5125 38 Clear the flag (public)
symbiotic 0:9015010b5125 39 */
symbiotic 0:9015010b5125 40
symbiotic 0:9015010b5125 41 void BooleanTicker::clear(){
symbiotic 0:9015010b5125 42 __disable_irq();
symbiotic 0:9015010b5125 43 value = false;
symbiotic 0:9015010b5125 44 __enable_irq();
symbiotic 0:9015010b5125 45 }
symbiotic 0:9015010b5125 46
symbiotic 0:9015010b5125 47 /**
symbiotic 0:9015010b5125 48 Set the flag (public)
symbiotic 0:9015010b5125 49 */
symbiotic 0:9015010b5125 50
symbiotic 0:9015010b5125 51 void BooleanTicker::set(){
symbiotic 0:9015010b5125 52 __disable_irq();
symbiotic 0:9015010b5125 53 value = true;
symbiotic 0:9015010b5125 54 __enable_irq();
symbiotic 0:9015010b5125 55 }
symbiotic 0:9015010b5125 56
symbiotic 0:9015010b5125 57 /**
symbiotic 0:9015010b5125 58 Get the current flag state
symbiotic 0:9015010b5125 59
symbiotic 0:9015010b5125 60 \return The current value of the flag.
symbiotic 0:9015010b5125 61 */
symbiotic 0:9015010b5125 62
symbiotic 0:9015010b5125 63 bool BooleanTicker::getValue(){
symbiotic 0:9015010b5125 64 return value;
symbiotic 0:9015010b5125 65 }