Pseudo real-time clock using Ticker interruption
PseudoRTC.h@0:9ab044e24d20, 2014-09-20 (annotated)
- Committer:
- s_inoue_mbed
- Date:
- Sat Sep 20 14:18:46 2014 +0000
- Revision:
- 0:9ab044e24d20
- Child:
- 1:fb8fd750e935
First version.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
s_inoue_mbed | 0:9ab044e24d20 | 1 | /* Copyright (c) 2014 Shigenori Inoue, MIT License |
s_inoue_mbed | 0:9ab044e24d20 | 2 | * |
s_inoue_mbed | 0:9ab044e24d20 | 3 | * Permission is hereby granted, free of charge, to any person obtaining a copy of this software |
s_inoue_mbed | 0:9ab044e24d20 | 4 | * and associated documentation files (the "Software"), to deal in the Software without restriction, |
s_inoue_mbed | 0:9ab044e24d20 | 5 | * including without limitation the rights to use, copy, modify, merge, publish, distribute, |
s_inoue_mbed | 0:9ab044e24d20 | 6 | * sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is |
s_inoue_mbed | 0:9ab044e24d20 | 7 | * furnished to do so, subject to the following conditions: |
s_inoue_mbed | 0:9ab044e24d20 | 8 | * |
s_inoue_mbed | 0:9ab044e24d20 | 9 | * The above copyright notice and this permission notice shall be included in all copies or |
s_inoue_mbed | 0:9ab044e24d20 | 10 | * substantial portions of the Software. |
s_inoue_mbed | 0:9ab044e24d20 | 11 | * |
s_inoue_mbed | 0:9ab044e24d20 | 12 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING |
s_inoue_mbed | 0:9ab044e24d20 | 13 | * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
s_inoue_mbed | 0:9ab044e24d20 | 14 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, |
s_inoue_mbed | 0:9ab044e24d20 | 15 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
s_inoue_mbed | 0:9ab044e24d20 | 16 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
s_inoue_mbed | 0:9ab044e24d20 | 17 | */ |
s_inoue_mbed | 0:9ab044e24d20 | 18 | |
s_inoue_mbed | 0:9ab044e24d20 | 19 | #ifndef __PseudoRTC__ |
s_inoue_mbed | 0:9ab044e24d20 | 20 | #define __PseudoRTC__ |
s_inoue_mbed | 0:9ab044e24d20 | 21 | |
s_inoue_mbed | 0:9ab044e24d20 | 22 | #include "mbed.h" |
s_inoue_mbed | 0:9ab044e24d20 | 23 | |
s_inoue_mbed | 0:9ab044e24d20 | 24 | class PseudoRTC |
s_inoue_mbed | 0:9ab044e24d20 | 25 | { |
s_inoue_mbed | 0:9ab044e24d20 | 26 | public: |
s_inoue_mbed | 0:9ab044e24d20 | 27 | /** Create a pseudo real-time clock */ |
s_inoue_mbed | 0:9ab044e24d20 | 28 | PseudoRTC(void); |
s_inoue_mbed | 0:9ab044e24d20 | 29 | |
s_inoue_mbed | 0:9ab044e24d20 | 30 | ~PseudoRTC(void); |
s_inoue_mbed | 0:9ab044e24d20 | 31 | |
s_inoue_mbed | 0:9ab044e24d20 | 32 | /** Set time in the pseudo real-time clock |
s_inoue_mbed | 0:9ab044e24d20 | 33 | * @param y Year |
s_inoue_mbed | 0:9ab044e24d20 | 34 | * @param mo Month |
s_inoue_mbed | 0:9ab044e24d20 | 35 | * @param d Day |
s_inoue_mbed | 0:9ab044e24d20 | 36 | * @param h Hour |
s_inoue_mbed | 0:9ab044e24d20 | 37 | * @param m Minute |
s_inoue_mbed | 0:9ab044e24d20 | 38 | * @param s Second |
s_inoue_mbed | 0:9ab044e24d20 | 39 | */ |
s_inoue_mbed | 0:9ab044e24d20 | 40 | void setTime(int y, int mo, int d, int h, int mi, int s); |
s_inoue_mbed | 0:9ab044e24d20 | 41 | |
s_inoue_mbed | 0:9ab044e24d20 | 42 | /** Get the year value */ |
s_inoue_mbed | 0:9ab044e24d20 | 43 | int getYear(void); |
s_inoue_mbed | 0:9ab044e24d20 | 44 | |
s_inoue_mbed | 0:9ab044e24d20 | 45 | /** Get the month value */ |
s_inoue_mbed | 0:9ab044e24d20 | 46 | int getMonth(void); |
s_inoue_mbed | 0:9ab044e24d20 | 47 | |
s_inoue_mbed | 0:9ab044e24d20 | 48 | /** Get the day value */ |
s_inoue_mbed | 0:9ab044e24d20 | 49 | int getDay(void); |
s_inoue_mbed | 0:9ab044e24d20 | 50 | |
s_inoue_mbed | 0:9ab044e24d20 | 51 | /** Get the hour value */ |
s_inoue_mbed | 0:9ab044e24d20 | 52 | int getHour(void); |
s_inoue_mbed | 0:9ab044e24d20 | 53 | |
s_inoue_mbed | 0:9ab044e24d20 | 54 | /** Get the minute value */ |
s_inoue_mbed | 0:9ab044e24d20 | 55 | int getMinute(void); |
s_inoue_mbed | 0:9ab044e24d20 | 56 | |
s_inoue_mbed | 0:9ab044e24d20 | 57 | /** Get the second value */ |
s_inoue_mbed | 0:9ab044e24d20 | 58 | int getSecond(void); |
s_inoue_mbed | 0:9ab044e24d20 | 59 | |
s_inoue_mbed | 0:9ab044e24d20 | 60 | private: |
s_inoue_mbed | 0:9ab044e24d20 | 61 | int year; |
s_inoue_mbed | 0:9ab044e24d20 | 62 | int month; |
s_inoue_mbed | 0:9ab044e24d20 | 63 | int day; |
s_inoue_mbed | 0:9ab044e24d20 | 64 | int hour; |
s_inoue_mbed | 0:9ab044e24d20 | 65 | int minute; |
s_inoue_mbed | 0:9ab044e24d20 | 66 | int second; |
s_inoue_mbed | 0:9ab044e24d20 | 67 | Ticker t; |
s_inoue_mbed | 0:9ab044e24d20 | 68 | void tictoc(void); |
s_inoue_mbed | 0:9ab044e24d20 | 69 | }; |
s_inoue_mbed | 0:9ab044e24d20 | 70 | |
s_inoue_mbed | 0:9ab044e24d20 | 71 | #endif |