TRC

Dependents:   RTC_terminal HorlogeSimple

Committer:
gr91
Date:
Fri May 29 16:45:33 2020 +0000
Revision:
0:f17b3622fae1
Child:
1:b85409cf9f7b
RTCIUT 1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gr91 0:f17b3622fae1 1 /// @file IHM_L476.h Bibliothéque de classe pour la carte L476 compatible IHM NBOARD
gr91 0:f17b3622fae1 2 /// @mainpage
gr91 0:f17b3622fae1 3 ///
gr91 0:f17b3622fae1 4 ///
gr91 0:f17b3622fae1 5 ///
gr91 0:f17b3622fae1 6 /// @author Bruno LARNAUDIE, IUT Cachan
gr91 0:f17b3622fae1 7 ///
gr91 0:f17b3622fae1 8 /// @note
gr91 0:f17b3622fae1 9 /// History
gr91 0:f17b3622fae1 10 /// v3.00 31/10/2019
gr91 0:f17b3622fae1 11
gr91 0:f17b3622fae1 12
gr91 0:f17b3622fae1 13 #include "mbed.h"
gr91 0:f17b3622fae1 14
gr91 0:f17b3622fae1 15 typedef int int32_t;
gr91 0:f17b3622fae1 16
gr91 0:f17b3622fae1 17
gr91 0:f17b3622fae1 18 #include <time.h>
gr91 0:f17b3622fae1 19
gr91 0:f17b3622fae1 20 /// RealTimeClock is an interface to the mbed RTC module
gr91 0:f17b3622fae1 21 ///
gr91 0:f17b3622fae1 22 /// It provides interfaces to get and set the time in text representation
gr91 0:f17b3622fae1 23 /// as well as a means to get and set the timezone offset so that it
gr91 0:f17b3622fae1 24 /// maintains time in UTC format.
gr91 0:f17b3622fae1 25 ///
gr91 0:f17b3622fae1 26
gr91 0:f17b3622fae1 27 ///
gr91 0:f17b3622fae1 28 /// @note It is recommended that the system has a battery connected to
gr91 0:f17b3622fae1 29 /// the mbed battery backup pin.
gr91 0:f17b3622fae1 30 ///
gr91 0:f17b3622fae1 31
gr91 0:f17b3622fae1 32 ///
gr91 0:f17b3622fae1 33 /// Example:
gr91 0:f17b3622fae1 34 /// @code
gr91 0:f17b3622fae1 35 /// RTC rtc;
gr91 0:f17b3622fae1 36 ///
gr91 0:f17b3622fae1 37 /// void main() {
gr91 0:f17b3622fae1 38 /// bool success;
gr91 0:f17b3622fae1 39 /// char TimeTest[] = "05/29/2011 14:15:18 (-6:00)";
gr91 0:f17b3622fae1 40 /// char buf[50];
gr91 0:f17b3622fae1 41 /// success = rtc.SetTime(TimeTest);
gr91 0:f17b3622fae1 42 /// rtc.GetTimeString(buf);
gr91 0:f17b3622fae1 43 /// printf("success: %i, time: %s\n", success, buf);
gr91 0:f17b3622fae1 44 /// }
gr91 0:f17b3622fae1 45 /// prints the following:
gr91 0:f17b3622fae1 46 /// success: 1, time: Sun May 29 14:15:18 2011 (tzo: -6:00)
gr91 0:f17b3622fae1 47 /// @endcode
gr91 0:f17b3622fae1 48 ///
gr91 0:f17b3622fae1 49 class Rtc
gr91 0:f17b3622fae1 50 {
gr91 0:f17b3622fae1 51 public:
gr91 0:f17b3622fae1 52 /// Constructor for the RealTimeClock interface, usually implemented
gr91 0:f17b3622fae1 53 /// outside of main( )
gr91 0:f17b3622fae1 54 ///
gr91 0:f17b3622fae1 55 Rtc();
gr91 0:f17b3622fae1 56
gr91 0:f17b3622fae1 57 /// Destructor for the RealTimeClock, usually not executed
gr91 0:f17b3622fae1 58 ///
gr91 0:f17b3622fae1 59 ~Rtc();
gr91 0:f17b3622fae1 60
gr91 0:f17b3622fae1 61 /// GetTimeValue gets the current time in time_t format
gr91 0:f17b3622fae1 62 ///
gr91 0:f17b3622fae1 63 /// Gets the current time from the rtc and returns the time in time_t format.
gr91 0:f17b3622fae1 64 /// This is functionally identical to "return time(NULL);",
gr91 0:f17b3622fae1 65 /// simply wrapped in this class for convenience.
gr91 0:f17b3622fae1 66 ///
gr91 0:f17b3622fae1 67 /// @returns current time in time_t format
gr91 0:f17b3622fae1 68 ///
gr91 0:f17b3622fae1 69 time_t GetTimeValue();
gr91 0:f17b3622fae1 70
gr91 0:f17b3622fae1 71 /// SetTimeValue will set the current time in time_t format
gr91 0:f17b3622fae1 72 ///
gr91 0:f17b3622fae1 73 /// example SetTimeValue(1463673534) set the current time
gr91 0:f17b3622fae1 74 /// 19 May 2016 15:58:54
gr91 0:f17b3622fae1 75 /// the min value is 978307200 (01/01/2001 00:00:00)
gr91 0:f17b3622fae1 76 void SetTimeValue(time_t t);
gr91 0:f17b3622fae1 77
gr91 0:f17b3622fae1 78 /// GetTimeString gets the formatted time
gr91 0:f17b3622fae1 79 ///
gr91 0:f17b3622fae1 80 /// It places the formatted string into the buffer in the format of
gr91 0:f17b3622fae1 81 /// DD/MM/YYYY HH:MM:SS 30/12/2016 07:19:24
gr91 0:f17b3622fae1 82 ///
gr91 0:f17b3622fae1 83 /// @returns nothing
gr91 0:f17b3622fae1 84 ///
gr91 0:f17b3622fae1 85 void GetTimeString(char * buffer);
gr91 0:f17b3622fae1 86
gr91 0:f17b3622fae1 87
gr91 0:f17b3622fae1 88 /// SetTimeString will set the Real Time Clock from a well formatted string
gr91 0:f17b3622fae1 89 ///
gr91 0:f17b3622fae1 90 /// This will read a string, and if it is well formed, it will then
gr91 0:f17b3622fae1 91 /// set the RTC based on this string. The string should be of the form:
gr91 0:f17b3622fae1 92 /// 'DD/MM/YYYY HH:MM:SS'
gr91 0:f17b3622fae1 93 ///
gr91 0:f17b3622fae1 94 /// example: 30/12/2011 13:15:07
gr91 0:f17b3622fae1 95 ///
gr91 0:f17b3622fae1 96 /// @param timestring is the string to parse
gr91 0:f17b3622fae1 97 /// @returns true if the time was set
gr91 0:f17b3622fae1 98 ///
gr91 0:f17b3622fae1 99 bool SetTimeString(char * timestring);
gr91 0:f17b3622fae1 100
gr91 0:f17b3622fae1 101
gr91 0:f17b3622fae1 102 /// SetYear writes the year
gr91 0:f17b3622fae1 103 ///
gr91 0:f17b3622fae1 104 /// year format YYYY (2001 - 2106)
gr91 0:f17b3622fae1 105 void SetYear(unsigned short yyyy);
gr91 0:f17b3622fae1 106
gr91 0:f17b3622fae1 107 /// GetYear reads the year
gr91 0:f17b3622fae1 108 ///
gr91 0:f17b3622fae1 109 /// @param void
gr91 0:f17b3622fae1 110 /// @returns the year unsigned short
gr91 0:f17b3622fae1 111 unsigned short GetYear(void);
gr91 0:f17b3622fae1 112
gr91 0:f17b3622fae1 113 /// SetMon writes the month
gr91 0:f17b3622fae1 114 ///
gr91 0:f17b3622fae1 115 /// month format mm (1 - 12)
gr91 0:f17b3622fae1 116 void SetMon(unsigned char mm);
gr91 0:f17b3622fae1 117
gr91 0:f17b3622fae1 118 /// GetMon reads the month
gr91 0:f17b3622fae1 119 ///
gr91 0:f17b3622fae1 120 /// @param void
gr91 0:f17b3622fae1 121 /// @returns the month unsigned char
gr91 0:f17b3622fae1 122 unsigned char GetMon(void);
gr91 0:f17b3622fae1 123
gr91 0:f17b3622fae1 124 /// SetDay writes the day
gr91 0:f17b3622fae1 125 ///
gr91 0:f17b3622fae1 126 /// day format dd (1 - 31)
gr91 0:f17b3622fae1 127 void SetDay(unsigned char dd);
gr91 0:f17b3622fae1 128
gr91 0:f17b3622fae1 129 /// GetDay reads the day
gr91 0:f17b3622fae1 130 ///
gr91 0:f17b3622fae1 131 /// @param void
gr91 0:f17b3622fae1 132 /// @returns the day unsigned char
gr91 0:f17b3622fae1 133 unsigned char GetDay(void);
gr91 0:f17b3622fae1 134
gr91 0:f17b3622fae1 135 /// SetHour writes the hour
gr91 0:f17b3622fae1 136 ///
gr91 0:f17b3622fae1 137 /// hour format hh (0 - 23)
gr91 0:f17b3622fae1 138 void SetHour(unsigned char hh);
gr91 0:f17b3622fae1 139
gr91 0:f17b3622fae1 140 /// GetHour reads the hour
gr91 0:f17b3622fae1 141 ///
gr91 0:f17b3622fae1 142 /// @param void
gr91 0:f17b3622fae1 143 /// @returns the hour unsigned char
gr91 0:f17b3622fae1 144 unsigned char GetHour(void);
gr91 0:f17b3622fae1 145
gr91 0:f17b3622fae1 146 /// SetMin writes the minutes
gr91 0:f17b3622fae1 147 ///
gr91 0:f17b3622fae1 148 /// minute format mm (0 - 59)
gr91 0:f17b3622fae1 149 void SetMin(unsigned char mm);
gr91 0:f17b3622fae1 150
gr91 0:f17b3622fae1 151 /// GetMin reads the minute
gr91 0:f17b3622fae1 152 ///
gr91 0:f17b3622fae1 153 /// @param void
gr91 0:f17b3622fae1 154 /// @returns the minute unsigned char
gr91 0:f17b3622fae1 155 unsigned char GetMin(void);
gr91 0:f17b3622fae1 156
gr91 0:f17b3622fae1 157 /// SetSec writes the seconds
gr91 0:f17b3622fae1 158 ///
gr91 0:f17b3622fae1 159 /// second format ss (0 - 59)
gr91 0:f17b3622fae1 160 void SetSec(unsigned char ss);
gr91 0:f17b3622fae1 161
gr91 0:f17b3622fae1 162 /// GetSec reads the second
gr91 0:f17b3622fae1 163 ///
gr91 0:f17b3622fae1 164 /// @param void
gr91 0:f17b3622fae1 165 /// @returns the second unsigned char
gr91 0:f17b3622fae1 166 unsigned char GetSec(void);
gr91 0:f17b3622fae1 167
gr91 0:f17b3622fae1 168 private:
gr91 0:f17b3622fae1 169
gr91 0:f17b3622fae1 170 };
gr91 0:f17b3622fae1 171
gr91 0:f17b3622fae1 172