Pseudo real-time clock using Ticker interruption
PseudoRTC.h@1:fb8fd750e935, 2014-09-20 (annotated)
- Committer:
- s_inoue_mbed
- Date:
- Sat Sep 20 14:25:38 2014 +0000
- Revision:
- 1:fb8fd750e935
- Parent:
- 0:9ab044e24d20
Documentation fixed.
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 | 1:fb8fd750e935 | 24 | /** Example: |
s_inoue_mbed | 1:fb8fd750e935 | 25 | * @code |
s_inoue_mbed | 1:fb8fd750e935 | 26 | * #include "mbed.h" |
s_inoue_mbed | 1:fb8fd750e935 | 27 | * #include "PseudoRTC.h" |
s_inoue_mbed | 1:fb8fd750e935 | 28 | * |
s_inoue_mbed | 1:fb8fd750e935 | 29 | * PseudoRTC c; |
s_inoue_mbed | 1:fb8fd750e935 | 30 | * |
s_inoue_mbed | 1:fb8fd750e935 | 31 | * main() |
s_inoue_mbed | 1:fb8fd750e935 | 32 | * { |
s_inoue_mbed | 1:fb8fd750e935 | 33 | * /* Example: September 20, 2014, 21:05:30 |
s_inoue_mbed | 1:fb8fd750e935 | 34 | * c.setTime(2014, 09, 20, 21, 05, 30); |
s_inoue_mbed | 1:fb8fd750e935 | 35 | * |
s_inoue_mbed | 1:fb8fd750e935 | 36 | * while(true) { |
s_inoue_mbed | 1:fb8fd750e935 | 37 | * printf("%04d/%02d/%02d %02d:%02d:%02d\r\m", c.getYear(), c.getMonth(), c.getDay(), c.getHour(), c.getMinute(), c.getSecond()); |
s_inoue_mbed | 1:fb8fd750e935 | 38 | * wait(1); |
s_inoue_mbed | 1:fb8fd750e935 | 39 | * } |
s_inoue_mbed | 1:fb8fd750e935 | 40 | * } |
s_inoue_mbed | 1:fb8fd750e935 | 41 | * @endcode |
s_inoue_mbed | 1:fb8fd750e935 | 42 | */ |
s_inoue_mbed | 1:fb8fd750e935 | 43 | |
s_inoue_mbed | 0:9ab044e24d20 | 44 | class PseudoRTC |
s_inoue_mbed | 0:9ab044e24d20 | 45 | { |
s_inoue_mbed | 0:9ab044e24d20 | 46 | public: |
s_inoue_mbed | 0:9ab044e24d20 | 47 | /** Create a pseudo real-time clock */ |
s_inoue_mbed | 0:9ab044e24d20 | 48 | PseudoRTC(void); |
s_inoue_mbed | 0:9ab044e24d20 | 49 | |
s_inoue_mbed | 0:9ab044e24d20 | 50 | ~PseudoRTC(void); |
s_inoue_mbed | 0:9ab044e24d20 | 51 | |
s_inoue_mbed | 0:9ab044e24d20 | 52 | /** Set time in the pseudo real-time clock |
s_inoue_mbed | 0:9ab044e24d20 | 53 | * @param y Year |
s_inoue_mbed | 0:9ab044e24d20 | 54 | * @param mo Month |
s_inoue_mbed | 0:9ab044e24d20 | 55 | * @param d Day |
s_inoue_mbed | 0:9ab044e24d20 | 56 | * @param h Hour |
s_inoue_mbed | 0:9ab044e24d20 | 57 | * @param m Minute |
s_inoue_mbed | 0:9ab044e24d20 | 58 | * @param s Second |
s_inoue_mbed | 0:9ab044e24d20 | 59 | */ |
s_inoue_mbed | 0:9ab044e24d20 | 60 | void setTime(int y, int mo, int d, int h, int mi, int s); |
s_inoue_mbed | 0:9ab044e24d20 | 61 | |
s_inoue_mbed | 0:9ab044e24d20 | 62 | /** Get the year value */ |
s_inoue_mbed | 0:9ab044e24d20 | 63 | int getYear(void); |
s_inoue_mbed | 0:9ab044e24d20 | 64 | |
s_inoue_mbed | 0:9ab044e24d20 | 65 | /** Get the month value */ |
s_inoue_mbed | 0:9ab044e24d20 | 66 | int getMonth(void); |
s_inoue_mbed | 0:9ab044e24d20 | 67 | |
s_inoue_mbed | 0:9ab044e24d20 | 68 | /** Get the day value */ |
s_inoue_mbed | 0:9ab044e24d20 | 69 | int getDay(void); |
s_inoue_mbed | 0:9ab044e24d20 | 70 | |
s_inoue_mbed | 0:9ab044e24d20 | 71 | /** Get the hour value */ |
s_inoue_mbed | 0:9ab044e24d20 | 72 | int getHour(void); |
s_inoue_mbed | 0:9ab044e24d20 | 73 | |
s_inoue_mbed | 0:9ab044e24d20 | 74 | /** Get the minute value */ |
s_inoue_mbed | 0:9ab044e24d20 | 75 | int getMinute(void); |
s_inoue_mbed | 0:9ab044e24d20 | 76 | |
s_inoue_mbed | 0:9ab044e24d20 | 77 | /** Get the second value */ |
s_inoue_mbed | 0:9ab044e24d20 | 78 | int getSecond(void); |
s_inoue_mbed | 0:9ab044e24d20 | 79 | |
s_inoue_mbed | 0:9ab044e24d20 | 80 | private: |
s_inoue_mbed | 0:9ab044e24d20 | 81 | int year; |
s_inoue_mbed | 0:9ab044e24d20 | 82 | int month; |
s_inoue_mbed | 0:9ab044e24d20 | 83 | int day; |
s_inoue_mbed | 0:9ab044e24d20 | 84 | int hour; |
s_inoue_mbed | 0:9ab044e24d20 | 85 | int minute; |
s_inoue_mbed | 0:9ab044e24d20 | 86 | int second; |
s_inoue_mbed | 0:9ab044e24d20 | 87 | Ticker t; |
s_inoue_mbed | 0:9ab044e24d20 | 88 | void tictoc(void); |
s_inoue_mbed | 0:9ab044e24d20 | 89 | }; |
s_inoue_mbed | 0:9ab044e24d20 | 90 | |
s_inoue_mbed | 0:9ab044e24d20 | 91 | #endif |