A simple WIP that logs data from a Grove sensor, and can send and receive information over USB and SMS.

Dependencies:   DHT DS_1337 SDFileSystem USBDevice mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers timers.h Source File

timers.h

00001 #ifndef __TIMERS_H__
00002 #define __TIMERS_H__
00003 
00004 #include "mbed.h"
00005 
00006 /*!
00007  * \brief The MyTimers class creates a Ticker and decrements a collection of unsigned longs that act as timers across the program
00008  *
00009  *  \sa eTimerType is used to link external callers with a collection of unsigned longs which are decremented
00010  *  each ms by \sa run().
00011  *  This acts as a collection of timers.
00012  *  This collection can be set by \sa SetTimer and retrieved by \sa GetTimer.
00013  */
00014 class MyTimers
00015 {
00016 public:
00017     MyTimers();
00018     ~MyTimers();
00019 
00020     ///< eTimerType identifies each of the timers in program, and is used to set and get a timer
00021     typedef enum
00022     {
00023         tmr_GroveMeasure,       ///< Used in GroveDht22 handler
00024         tmr_GprsPower,          ///< Used to power the SIM900 on and off
00025         tmr_GprsRxTx,           ///< Timeout waiting for a response from the SIM900 over the serial line
00026         tmr_SdWaitError,        ///< Sd card has hit an error, wait before retrying
00027         tmr_MeasFlash           ///< Flash once every 2 seconds for heartbeat
00028     } eTimerType ;
00029 
00030     //! run is called each time Ticker fires, which is every 1ms, and decrements all timers if necessary
00031     void run();
00032 
00033     /*!
00034      * \brief SetTimer sets the value of the timer
00035      * \param timertype identifies the timer whose value we want to set
00036      * \param time_ms is the value the timer will be set to, to start counting down from, in ms
00037      */
00038     void SetTimer(eTimerType  timertype, unsigned long time_ms);
00039 
00040     /*!
00041      * \brief GetTimer gets the value of a timer
00042      * \param timertype identifies the timer whose value we want to get
00043      * \return the value of the timer
00044      */
00045     unsigned long GetTimer(eTimerType  timertype);
00046 
00047 private:
00048     unsigned long groveMeasureTimer;    ///< current value of timer for \sa tmr_GroveMeasure
00049     unsigned long gprsPowerTimer;       ///< current value of timer for \sa tmr_GprsPower
00050     unsigned long gprsRxTxTimer;        ///< current value of timer for \sa tmr_GprsRxTx
00051     unsigned long sdWaitErrorTimer;     ///< current value of timer for \sa tmr_SdWaitError
00052     unsigned long measFlashTimer;       ///< current value of timer for \sa tmr_MeasFlash
00053 
00054     Ticker *m_tick;        ///< Used to call \a run a function periodically
00055 };
00056 
00057 #endif