TRC

Dependents:   RTC_terminal HorlogeSimple

Committer:
gr91
Date:
Wed Jun 03 08:12:04 2020 +0000
Revision:
5:25fccea872c4
Parent:
4:fc8f09c843e4
V6

Who changed what in which revision?

UserRevisionLine numberNew contents of line
gr91 5:25fccea872c4 1 /// @file IHM_
gr91 0:f17b3622fae1 2 /// @mainpage
gr91 0:f17b3622fae1 3 ///
gr91 0:f17b3622fae1 4 ///
gr91 0:f17b3622fae1 5 ///
gr91 5:25fccea872c4 6 ///
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 4:fc8f09c843e4 35 ///#include "mbed.h"
gr91 4:fc8f09c843e4 36 ///#include "RTC_IUT.h"
gr91 4:fc8f09c843e4 37 ///Rtc rtc;
gr91 0:f17b3622fae1 38 ///
gr91 1:b85409cf9f7b 39 ///int main()
gr91 1:b85409cf9f7b 40 ///{
gr91 1:b85409cf9f7b 41 /// //char TimeTest[] = "31/12/1999 23:59:50";
gr91 1:b85409cf9f7b 42 /// //char TimeTest[] = "19/01/2038 03:13:50";
gr91 1:b85409cf9f7b 43 /// char TimeTest[] = "03/06/1970 10:00:00";
gr91 1:b85409cf9f7b 44 /// time_t epoc;
gr91 1:b85409cf9f7b 45 /// char buf[50];
gr91 1:b85409cf9f7b 46 /// rtc.SetTimeString(TimeTest);
gr91 1:b85409cf9f7b 47 /// rtc.GetTimeString(buf);
gr91 1:b85409cf9f7b 48 /// epoc =rtc.GetTimeValue();
gr91 1:b85409cf9f7b 49 /// printf("epoc: %8X, time: %s\r\n", epoc, buf);
gr91 1:b85409cf9f7b 50 /// while(1) {
gr91 1:b85409cf9f7b 51 /// rtc.SetYear(2020); // Set the year
gr91 5:25fccea872c4 52 /// rtc.GetTimeString(buf); // read date time string DD:MM:YYY hh:mm:ss
gr91 1:b85409cf9f7b 53 /// epoc =rtc.GetTimeValue(); // Read second since 01/01/1970
gr91 1:b85409cf9f7b 54 /// printf("epoc: %8X, time: %s\r\n", epoc, buf);
gr91 1:b85409cf9f7b 55 /// wait(0.9999);
gr91 1:b85409cf9f7b 56 /// }
gr91 1:b85409cf9f7b 57 ///}
gr91 0:f17b3622fae1 58 /// @endcode
gr91 0:f17b3622fae1 59 ///
gr91 0:f17b3622fae1 60 class Rtc
gr91 0:f17b3622fae1 61 {
gr91 0:f17b3622fae1 62 public:
gr91 0:f17b3622fae1 63 /// Constructor for the RealTimeClock interface, usually implemented
gr91 0:f17b3622fae1 64 /// outside of main( )
gr91 0:f17b3622fae1 65 ///
gr91 0:f17b3622fae1 66 Rtc();
gr91 0:f17b3622fae1 67
gr91 0:f17b3622fae1 68 /// Destructor for the RealTimeClock, usually not executed
gr91 0:f17b3622fae1 69 ///
gr91 0:f17b3622fae1 70 ~Rtc();
gr91 0:f17b3622fae1 71
gr91 0:f17b3622fae1 72 /// GetTimeValue gets the current time in time_t format
gr91 0:f17b3622fae1 73 ///
gr91 0:f17b3622fae1 74 /// Gets the current time from the rtc and returns the time in time_t format.
gr91 0:f17b3622fae1 75 /// This is functionally identical to "return time(NULL);",
gr91 0:f17b3622fae1 76 /// simply wrapped in this class for convenience.
gr91 0:f17b3622fae1 77 ///
gr91 0:f17b3622fae1 78 /// @returns current time in time_t format
gr91 0:f17b3622fae1 79 ///
gr91 0:f17b3622fae1 80 time_t GetTimeValue();
gr91 0:f17b3622fae1 81
gr91 0:f17b3622fae1 82 /// SetTimeValue will set the current time in time_t format
gr91 0:f17b3622fae1 83 ///
gr91 0:f17b3622fae1 84 /// example SetTimeValue(1463673534) set the current time
gr91 0:f17b3622fae1 85 /// 19 May 2016 15:58:54
gr91 0:f17b3622fae1 86 /// the min value is 978307200 (01/01/2001 00:00:00)
gr91 0:f17b3622fae1 87 void SetTimeValue(time_t t);
gr91 0:f17b3622fae1 88
gr91 0:f17b3622fae1 89 /// GetTimeString gets the formatted time
gr91 0:f17b3622fae1 90 ///
gr91 0:f17b3622fae1 91 /// It places the formatted string into the buffer in the format of
gr91 0:f17b3622fae1 92 /// DD/MM/YYYY HH:MM:SS 30/12/2016 07:19:24
gr91 0:f17b3622fae1 93 ///
gr91 0:f17b3622fae1 94 /// @returns nothing
gr91 0:f17b3622fae1 95 ///
gr91 0:f17b3622fae1 96 void GetTimeString(char * buffer);
gr91 0:f17b3622fae1 97
gr91 0:f17b3622fae1 98
gr91 0:f17b3622fae1 99 /// SetTimeString will set the Real Time Clock from a well formatted string
gr91 0:f17b3622fae1 100 ///
gr91 0:f17b3622fae1 101 /// This will read a string, and if it is well formed, it will then
gr91 0:f17b3622fae1 102 /// set the RTC based on this string. The string should be of the form:
gr91 0:f17b3622fae1 103 /// 'DD/MM/YYYY HH:MM:SS'
gr91 0:f17b3622fae1 104 ///
gr91 0:f17b3622fae1 105 /// example: 30/12/2011 13:15:07
gr91 0:f17b3622fae1 106 ///
gr91 0:f17b3622fae1 107 /// @param timestring is the string to parse
gr91 0:f17b3622fae1 108 /// @returns true if the time was set
gr91 0:f17b3622fae1 109 ///
gr91 0:f17b3622fae1 110 bool SetTimeString(char * timestring);
gr91 0:f17b3622fae1 111
gr91 0:f17b3622fae1 112
gr91 0:f17b3622fae1 113 /// SetYear writes the year
gr91 0:f17b3622fae1 114 ///
gr91 2:1a77823cf4c9 115 /// year format YYYY (1970 - 2038)
gr91 0:f17b3622fae1 116 void SetYear(unsigned short yyyy);
gr91 0:f17b3622fae1 117
gr91 0:f17b3622fae1 118 /// GetYear reads the year
gr91 0:f17b3622fae1 119 ///
gr91 0:f17b3622fae1 120 /// @param void
gr91 0:f17b3622fae1 121 /// @returns the year unsigned short
gr91 0:f17b3622fae1 122 unsigned short GetYear(void);
gr91 0:f17b3622fae1 123
gr91 0:f17b3622fae1 124 /// SetMon writes the month
gr91 0:f17b3622fae1 125 ///
gr91 0:f17b3622fae1 126 /// month format mm (1 - 12)
gr91 0:f17b3622fae1 127 void SetMon(unsigned char mm);
gr91 0:f17b3622fae1 128
gr91 0:f17b3622fae1 129 /// GetMon reads the month
gr91 0:f17b3622fae1 130 ///
gr91 0:f17b3622fae1 131 /// @param void
gr91 0:f17b3622fae1 132 /// @returns the month unsigned char
gr91 0:f17b3622fae1 133 unsigned char GetMon(void);
gr91 0:f17b3622fae1 134
gr91 0:f17b3622fae1 135 /// SetDay writes the day
gr91 0:f17b3622fae1 136 ///
gr91 0:f17b3622fae1 137 /// day format dd (1 - 31)
gr91 0:f17b3622fae1 138 void SetDay(unsigned char dd);
gr91 0:f17b3622fae1 139
gr91 0:f17b3622fae1 140 /// GetDay reads the day
gr91 0:f17b3622fae1 141 ///
gr91 0:f17b3622fae1 142 /// @param void
gr91 0:f17b3622fae1 143 /// @returns the day unsigned char
gr91 0:f17b3622fae1 144 unsigned char GetDay(void);
gr91 0:f17b3622fae1 145
gr91 0:f17b3622fae1 146 /// SetHour writes the hour
gr91 0:f17b3622fae1 147 ///
gr91 0:f17b3622fae1 148 /// hour format hh (0 - 23)
gr91 0:f17b3622fae1 149 void SetHour(unsigned char hh);
gr91 0:f17b3622fae1 150
gr91 0:f17b3622fae1 151 /// GetHour reads the hour
gr91 0:f17b3622fae1 152 ///
gr91 0:f17b3622fae1 153 /// @param void
gr91 0:f17b3622fae1 154 /// @returns the hour unsigned char
gr91 0:f17b3622fae1 155 unsigned char GetHour(void);
gr91 0:f17b3622fae1 156
gr91 0:f17b3622fae1 157 /// SetMin writes the minutes
gr91 0:f17b3622fae1 158 ///
gr91 0:f17b3622fae1 159 /// minute format mm (0 - 59)
gr91 0:f17b3622fae1 160 void SetMin(unsigned char mm);
gr91 0:f17b3622fae1 161
gr91 0:f17b3622fae1 162 /// GetMin reads the minute
gr91 0:f17b3622fae1 163 ///
gr91 0:f17b3622fae1 164 /// @param void
gr91 0:f17b3622fae1 165 /// @returns the minute unsigned char
gr91 0:f17b3622fae1 166 unsigned char GetMin(void);
gr91 0:f17b3622fae1 167
gr91 0:f17b3622fae1 168 /// SetSec writes the seconds
gr91 0:f17b3622fae1 169 ///
gr91 0:f17b3622fae1 170 /// second format ss (0 - 59)
gr91 0:f17b3622fae1 171 void SetSec(unsigned char ss);
gr91 0:f17b3622fae1 172
gr91 0:f17b3622fae1 173 /// GetSec reads the second
gr91 0:f17b3622fae1 174 ///
gr91 0:f17b3622fae1 175 /// @param void
gr91 0:f17b3622fae1 176 /// @returns the second unsigned char
gr91 0:f17b3622fae1 177 unsigned char GetSec(void);
gr91 0:f17b3622fae1 178
gr91 0:f17b3622fae1 179 private:
gr91 0:f17b3622fae1 180
gr91 0:f17b3622fae1 181 };
gr91 0:f17b3622fae1 182
gr91 0:f17b3622fae1 183