Programme d'utilisation des AX12 avec rajout de l'MX12
Fork of test_carteAToutFaire_PR by
mbed/rtc_time.h@1:f3f702086a30, 2017-05-11 (annotated)
- Committer:
- ClementBreteau
- Date:
- Thu May 11 11:49:50 2017 +0000
- Revision:
- 1:f3f702086a30
test de la carte ? tout faire du petit robot
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
ClementBreteau | 1:f3f702086a30 | 1 | /* Title: time |
ClementBreteau | 1:f3f702086a30 | 2 | * Implementation of the C time.h functions |
ClementBreteau | 1:f3f702086a30 | 3 | * |
ClementBreteau | 1:f3f702086a30 | 4 | * Provides mechanisms to set and read the current time, based |
ClementBreteau | 1:f3f702086a30 | 5 | * on the microcontroller Real-Time Clock (RTC), plus some |
ClementBreteau | 1:f3f702086a30 | 6 | * standard C manipulation and formating functions. |
ClementBreteau | 1:f3f702086a30 | 7 | * |
ClementBreteau | 1:f3f702086a30 | 8 | * Example: |
ClementBreteau | 1:f3f702086a30 | 9 | * > #include "mbed.h" |
ClementBreteau | 1:f3f702086a30 | 10 | * > |
ClementBreteau | 1:f3f702086a30 | 11 | * > int main() { |
ClementBreteau | 1:f3f702086a30 | 12 | * > set_time(1256729737); // Set RTC time to Wed, 28 Oct 2009 11:35:37 |
ClementBreteau | 1:f3f702086a30 | 13 | * > |
ClementBreteau | 1:f3f702086a30 | 14 | * > while(1) { |
ClementBreteau | 1:f3f702086a30 | 15 | * > time_t seconds = time(NULL); |
ClementBreteau | 1:f3f702086a30 | 16 | * > |
ClementBreteau | 1:f3f702086a30 | 17 | * > printf("Time as seconds since January 1, 1970 = %d\n", seconds); |
ClementBreteau | 1:f3f702086a30 | 18 | * > |
ClementBreteau | 1:f3f702086a30 | 19 | * > printf("Time as a basic string = %s", ctime(&seconds)); |
ClementBreteau | 1:f3f702086a30 | 20 | * > |
ClementBreteau | 1:f3f702086a30 | 21 | * > char buffer[32]; |
ClementBreteau | 1:f3f702086a30 | 22 | * > strftime(buffer, 32, "%I:%M %p\n", localtime(&seconds)); |
ClementBreteau | 1:f3f702086a30 | 23 | * > printf("Time as a custom formatted string = %s", buffer); |
ClementBreteau | 1:f3f702086a30 | 24 | * > |
ClementBreteau | 1:f3f702086a30 | 25 | * > wait(1); |
ClementBreteau | 1:f3f702086a30 | 26 | * > } |
ClementBreteau | 1:f3f702086a30 | 27 | * > } |
ClementBreteau | 1:f3f702086a30 | 28 | */ |
ClementBreteau | 1:f3f702086a30 | 29 | |
ClementBreteau | 1:f3f702086a30 | 30 | /* mbed Microcontroller Library - rtc_time |
ClementBreteau | 1:f3f702086a30 | 31 | * Copyright (c) 2009 ARM Limited. All rights reserved. |
ClementBreteau | 1:f3f702086a30 | 32 | */ |
ClementBreteau | 1:f3f702086a30 | 33 | |
ClementBreteau | 1:f3f702086a30 | 34 | #include <time.h> |
ClementBreteau | 1:f3f702086a30 | 35 | |
ClementBreteau | 1:f3f702086a30 | 36 | #ifdef __cplusplus |
ClementBreteau | 1:f3f702086a30 | 37 | extern "C" { |
ClementBreteau | 1:f3f702086a30 | 38 | #endif |
ClementBreteau | 1:f3f702086a30 | 39 | |
ClementBreteau | 1:f3f702086a30 | 40 | #if 0 // for documentation only |
ClementBreteau | 1:f3f702086a30 | 41 | /* Function: time |
ClementBreteau | 1:f3f702086a30 | 42 | * Get the current time |
ClementBreteau | 1:f3f702086a30 | 43 | * |
ClementBreteau | 1:f3f702086a30 | 44 | * Returns the current timestamp as the number of seconds since January 1, 1970 |
ClementBreteau | 1:f3f702086a30 | 45 | * (the UNIX timestamp). The value is based on the current value of the |
ClementBreteau | 1:f3f702086a30 | 46 | * microcontroller Real-Time Clock (RTC), which can be set using <set_time>. |
ClementBreteau | 1:f3f702086a30 | 47 | * |
ClementBreteau | 1:f3f702086a30 | 48 | * Example: |
ClementBreteau | 1:f3f702086a30 | 49 | * > #include "mbed.h" |
ClementBreteau | 1:f3f702086a30 | 50 | * > |
ClementBreteau | 1:f3f702086a30 | 51 | * > int main() { |
ClementBreteau | 1:f3f702086a30 | 52 | * > time_t seconds = time(NULL); |
ClementBreteau | 1:f3f702086a30 | 53 | * > printf("It is %d seconds since January 1, 1970\n", seconds); |
ClementBreteau | 1:f3f702086a30 | 54 | * > } |
ClementBreteau | 1:f3f702086a30 | 55 | * |
ClementBreteau | 1:f3f702086a30 | 56 | * Variables: |
ClementBreteau | 1:f3f702086a30 | 57 | * t - Pointer to a time_t to be set, or NULL if not used |
ClementBreteau | 1:f3f702086a30 | 58 | * returns - Number of seconds since January 1, 1970 (the UNIX timestamp) |
ClementBreteau | 1:f3f702086a30 | 59 | */ |
ClementBreteau | 1:f3f702086a30 | 60 | time_t time(time_t *t); |
ClementBreteau | 1:f3f702086a30 | 61 | #endif |
ClementBreteau | 1:f3f702086a30 | 62 | |
ClementBreteau | 1:f3f702086a30 | 63 | /* Function: set_time |
ClementBreteau | 1:f3f702086a30 | 64 | * Set the current time |
ClementBreteau | 1:f3f702086a30 | 65 | * |
ClementBreteau | 1:f3f702086a30 | 66 | * Initialises and sets the time of the microcontroller Real-Time Clock (RTC) |
ClementBreteau | 1:f3f702086a30 | 67 | * to the time represented by the number of seconds since January 1, 1970 |
ClementBreteau | 1:f3f702086a30 | 68 | * (the UNIX timestamp). |
ClementBreteau | 1:f3f702086a30 | 69 | * |
ClementBreteau | 1:f3f702086a30 | 70 | * Example: |
ClementBreteau | 1:f3f702086a30 | 71 | * > #include "mbed.h" |
ClementBreteau | 1:f3f702086a30 | 72 | * > |
ClementBreteau | 1:f3f702086a30 | 73 | * > int main() { |
ClementBreteau | 1:f3f702086a30 | 74 | * > set_time(1256729737); // Set time to Wed, 28 Oct 2009 11:35:37 |
ClementBreteau | 1:f3f702086a30 | 75 | * > } |
ClementBreteau | 1:f3f702086a30 | 76 | * |
ClementBreteau | 1:f3f702086a30 | 77 | * Variables: |
ClementBreteau | 1:f3f702086a30 | 78 | * t - Number of seconds since January 1, 1970 (the UNIX timestamp) |
ClementBreteau | 1:f3f702086a30 | 79 | */ |
ClementBreteau | 1:f3f702086a30 | 80 | void set_time(time_t t); |
ClementBreteau | 1:f3f702086a30 | 81 | |
ClementBreteau | 1:f3f702086a30 | 82 | #if 0 // for documentation only |
ClementBreteau | 1:f3f702086a30 | 83 | /* Function: mktime |
ClementBreteau | 1:f3f702086a30 | 84 | * Converts a tm structure in to a timestamp |
ClementBreteau | 1:f3f702086a30 | 85 | * |
ClementBreteau | 1:f3f702086a30 | 86 | * Converts the tm structure in to a timestamp in seconds since January 1, 1970 |
ClementBreteau | 1:f3f702086a30 | 87 | * (the UNIX timestamp). The values of tm_wday and tm_yday of the tm structure |
ClementBreteau | 1:f3f702086a30 | 88 | * are also updated to their appropriate values. |
ClementBreteau | 1:f3f702086a30 | 89 | * |
ClementBreteau | 1:f3f702086a30 | 90 | * Example: |
ClementBreteau | 1:f3f702086a30 | 91 | * > #include "mbed.h" |
ClementBreteau | 1:f3f702086a30 | 92 | * > |
ClementBreteau | 1:f3f702086a30 | 93 | * > int main() { |
ClementBreteau | 1:f3f702086a30 | 94 | * > // setup time structure for Wed, 28 Oct 2009 11:35:37 |
ClementBreteau | 1:f3f702086a30 | 95 | * > struct tm t; |
ClementBreteau | 1:f3f702086a30 | 96 | * > t.tm_sec = 37; // 0-59 |
ClementBreteau | 1:f3f702086a30 | 97 | * > t.tm_min = 35; // 0-59 |
ClementBreteau | 1:f3f702086a30 | 98 | * > t.tm_hour = 11; // 0-23 |
ClementBreteau | 1:f3f702086a30 | 99 | * > t.tm_mday = 28; // 1-31 |
ClementBreteau | 1:f3f702086a30 | 100 | * > t.tm_mon = 9; // 0-11 |
ClementBreteau | 1:f3f702086a30 | 101 | * > t.tm_year = 109; // year since 1900 |
ClementBreteau | 1:f3f702086a30 | 102 | * > |
ClementBreteau | 1:f3f702086a30 | 103 | * > // convert to timestamp and display (1256729737) |
ClementBreteau | 1:f3f702086a30 | 104 | * > time_t seconds = mktime(&t); |
ClementBreteau | 1:f3f702086a30 | 105 | * > printf("Time as seconds since January 1, 1970 = %d\n", seconds); |
ClementBreteau | 1:f3f702086a30 | 106 | * > } |
ClementBreteau | 1:f3f702086a30 | 107 | * |
ClementBreteau | 1:f3f702086a30 | 108 | * Variables: |
ClementBreteau | 1:f3f702086a30 | 109 | * t - The tm structure to convert |
ClementBreteau | 1:f3f702086a30 | 110 | * returns - The converted timestamp |
ClementBreteau | 1:f3f702086a30 | 111 | */ |
ClementBreteau | 1:f3f702086a30 | 112 | time_t mktime(struct tm *t); |
ClementBreteau | 1:f3f702086a30 | 113 | #endif |
ClementBreteau | 1:f3f702086a30 | 114 | |
ClementBreteau | 1:f3f702086a30 | 115 | #if 0 // for documentation only |
ClementBreteau | 1:f3f702086a30 | 116 | /* Function: localtime |
ClementBreteau | 1:f3f702086a30 | 117 | * Converts a timestamp in to a tm structure |
ClementBreteau | 1:f3f702086a30 | 118 | * |
ClementBreteau | 1:f3f702086a30 | 119 | * Converts the timestamp pointed to by t to a (statically allocated) |
ClementBreteau | 1:f3f702086a30 | 120 | * tm structure. |
ClementBreteau | 1:f3f702086a30 | 121 | * |
ClementBreteau | 1:f3f702086a30 | 122 | * Example: |
ClementBreteau | 1:f3f702086a30 | 123 | * > #include "mbed.h" |
ClementBreteau | 1:f3f702086a30 | 124 | * > |
ClementBreteau | 1:f3f702086a30 | 125 | * > int main() { |
ClementBreteau | 1:f3f702086a30 | 126 | * > time_t seconds = 1256729737; |
ClementBreteau | 1:f3f702086a30 | 127 | * > struct tm *t = localtime(&seconds); |
ClementBreteau | 1:f3f702086a30 | 128 | * > } |
ClementBreteau | 1:f3f702086a30 | 129 | * |
ClementBreteau | 1:f3f702086a30 | 130 | * Variables: |
ClementBreteau | 1:f3f702086a30 | 131 | * t - Pointer to the timestamp |
ClementBreteau | 1:f3f702086a30 | 132 | * returns - Pointer to the (statically allocated) tm structure |
ClementBreteau | 1:f3f702086a30 | 133 | */ |
ClementBreteau | 1:f3f702086a30 | 134 | struct tm *localtime(const time_t *t); |
ClementBreteau | 1:f3f702086a30 | 135 | #endif |
ClementBreteau | 1:f3f702086a30 | 136 | |
ClementBreteau | 1:f3f702086a30 | 137 | #if 0 // for documentation only |
ClementBreteau | 1:f3f702086a30 | 138 | /* Function: ctime |
ClementBreteau | 1:f3f702086a30 | 139 | * Converts a timestamp to a human-readable string |
ClementBreteau | 1:f3f702086a30 | 140 | * |
ClementBreteau | 1:f3f702086a30 | 141 | * Converts a time_t timestamp in seconds since January 1, 1970 (the UNIX |
ClementBreteau | 1:f3f702086a30 | 142 | * timestamp) to a human readable string format. The result is of the |
ClementBreteau | 1:f3f702086a30 | 143 | * format: "Wed Oct 28 11:35:37 2009\n" |
ClementBreteau | 1:f3f702086a30 | 144 | * |
ClementBreteau | 1:f3f702086a30 | 145 | * Example: |
ClementBreteau | 1:f3f702086a30 | 146 | * > #include "mbed.h" |
ClementBreteau | 1:f3f702086a30 | 147 | * > |
ClementBreteau | 1:f3f702086a30 | 148 | * > int main() { |
ClementBreteau | 1:f3f702086a30 | 149 | * > time_t seconds = time(NULL); |
ClementBreteau | 1:f3f702086a30 | 150 | * > printf("Time as a string = %s", ctime(&seconds)); |
ClementBreteau | 1:f3f702086a30 | 151 | * > } |
ClementBreteau | 1:f3f702086a30 | 152 | * |
ClementBreteau | 1:f3f702086a30 | 153 | * Variables: |
ClementBreteau | 1:f3f702086a30 | 154 | * t - The timestamp to convert |
ClementBreteau | 1:f3f702086a30 | 155 | * returns - Pointer to a (statically allocated) string containing the |
ClementBreteau | 1:f3f702086a30 | 156 | * human readable representation, including a '\n' character |
ClementBreteau | 1:f3f702086a30 | 157 | */ |
ClementBreteau | 1:f3f702086a30 | 158 | char *ctime(const time_t *t); |
ClementBreteau | 1:f3f702086a30 | 159 | #endif |
ClementBreteau | 1:f3f702086a30 | 160 | |
ClementBreteau | 1:f3f702086a30 | 161 | #if 0 // for documentation only |
ClementBreteau | 1:f3f702086a30 | 162 | /* Function: strftime |
ClementBreteau | 1:f3f702086a30 | 163 | * Converts a tm structure to a custom format human-readable string |
ClementBreteau | 1:f3f702086a30 | 164 | * |
ClementBreteau | 1:f3f702086a30 | 165 | * Creates a formated string from a tm structure, based on a string format |
ClementBreteau | 1:f3f702086a30 | 166 | * specifier provided. |
ClementBreteau | 1:f3f702086a30 | 167 | * |
ClementBreteau | 1:f3f702086a30 | 168 | * Format Specifiers: |
ClementBreteau | 1:f3f702086a30 | 169 | * %S - Second (00-59) |
ClementBreteau | 1:f3f702086a30 | 170 | * %M - Minute (00-59) |
ClementBreteau | 1:f3f702086a30 | 171 | * %H - Hour (00-23) |
ClementBreteau | 1:f3f702086a30 | 172 | * %d - Day (01-31) |
ClementBreteau | 1:f3f702086a30 | 173 | * %m - Month (01-12) |
ClementBreteau | 1:f3f702086a30 | 174 | * %Y/%y - Year (2009/09) |
ClementBreteau | 1:f3f702086a30 | 175 | * |
ClementBreteau | 1:f3f702086a30 | 176 | * %A/%a - Weekday Name (Monday/Mon) |
ClementBreteau | 1:f3f702086a30 | 177 | * %B/%b - Month Name (January/Jan) |
ClementBreteau | 1:f3f702086a30 | 178 | * %I - 12 Hour Format (01-12) |
ClementBreteau | 1:f3f702086a30 | 179 | * %p - "AM" or "PM" |
ClementBreteau | 1:f3f702086a30 | 180 | * %X - Time (14:55:02) |
ClementBreteau | 1:f3f702086a30 | 181 | * %x - Date (08/23/01) |
ClementBreteau | 1:f3f702086a30 | 182 | * |
ClementBreteau | 1:f3f702086a30 | 183 | * Example: |
ClementBreteau | 1:f3f702086a30 | 184 | * > #include "mbed.h" |
ClementBreteau | 1:f3f702086a30 | 185 | * > |
ClementBreteau | 1:f3f702086a30 | 186 | * > int main() { |
ClementBreteau | 1:f3f702086a30 | 187 | * > time_t seconds = time(NULL); |
ClementBreteau | 1:f3f702086a30 | 188 | * > |
ClementBreteau | 1:f3f702086a30 | 189 | * > char buffer[32]; |
ClementBreteau | 1:f3f702086a30 | 190 | * > strftime(buffer, 32, "%I:%M %p\n", localtime(&seconds)); |
ClementBreteau | 1:f3f702086a30 | 191 | * > printf("Time as a formatted string = %s", buffer); |
ClementBreteau | 1:f3f702086a30 | 192 | * > } |
ClementBreteau | 1:f3f702086a30 | 193 | * |
ClementBreteau | 1:f3f702086a30 | 194 | * Variables: |
ClementBreteau | 1:f3f702086a30 | 195 | * buffer - String buffer to store the result |
ClementBreteau | 1:f3f702086a30 | 196 | * max - Maximum number of characters to store in the buffer |
ClementBreteau | 1:f3f702086a30 | 197 | * format - Format specifier string |
ClementBreteau | 1:f3f702086a30 | 198 | * t - Pointer to the tm structure to convert |
ClementBreteau | 1:f3f702086a30 | 199 | * returns - Number of characters copied |
ClementBreteau | 1:f3f702086a30 | 200 | */ |
ClementBreteau | 1:f3f702086a30 | 201 | size_t strftime(char *buffer, size_t max, const char *format, const struct tm *t); |
ClementBreteau | 1:f3f702086a30 | 202 | #endif |
ClementBreteau | 1:f3f702086a30 | 203 | |
ClementBreteau | 1:f3f702086a30 | 204 | #ifdef __cplusplus |
ClementBreteau | 1:f3f702086a30 | 205 | } |
ClementBreteau | 1:f3f702086a30 | 206 | #endif |