24日間連続してカウントするタイマークラスです。クラスの実装が公開されていないので理由は不明ですが、mbed標準のTimerクラスは2148秒までしかカウントしてくれません。そのため、せめてArduinoと同等のカウントが可能なように作成しました。

Dependents:   gps_com

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers TimerExtended.h Source File

TimerExtended.h

00001 /***************************************
00002 TimerExtended
00003 Purpose: you can use timer untill 24 days in milli seconds.
00004 Author: Katsuhiro Morishita @2014
00005 License: apache license 2, or MIT, which you like
00006 ****************************************/
00007 #include "mbed.h"
00008 
00009 
00010 class TimerExtended
00011 {
00012 private:
00013     Timer _t;
00014     Ticker _tk;
00015     long milli_second;
00016     
00017     void update()
00018     {
00019         if(this->milli_second < 2147483645)
00020             this->milli_second += this->_t.read_ms();
00021         this->_t.reset();
00022     }
00023 public:
00024     TimerExtended()
00025     {
00026         this->milli_second = 0l;
00027     }
00028     
00029     // start timer
00030     void start()
00031     {
00032         this->_tk.attach(this, &TimerExtended::update, 2000.0);  // 2000.0 should be lower then max value of Timer obj.
00033         this->_t.start();
00034     }
00035     
00036     // like Arduino lib.
00037     long millis()
00038     {
00039         (void)this->update();
00040         return this->milli_second;
00041     }
00042     
00043     // return time [s] in double
00044     double read()
00045     {
00046         return (double)this->millis() / 1000.0;
00047     }
00048     
00049     // return time [ms]
00050     long read_ms()
00051     {
00052         return this->millis();
00053     }
00054     
00055 };