IoT Home Alarm System

Dependents:   IoTBurglar_and_Fire_AlarmSystem

Committer:
kbrahmbhatt6
Date:
Fri Apr 29 06:59:59 2016 +0000
Revision:
0:2f388b030837
1

Who changed what in which revision?

UserRevisionLine numberNew contents of line
kbrahmbhatt6 0:2f388b030837 1 /* mbed Microcontroller Library
kbrahmbhatt6 0:2f388b030837 2 * Copyright (c) 2006-2013 ARM Limited
kbrahmbhatt6 0:2f388b030837 3 *
kbrahmbhatt6 0:2f388b030837 4 * Licensed under the Apache License, Version 2.0 (the "License");
kbrahmbhatt6 0:2f388b030837 5 * you may not use this file except in compliance with the License.
kbrahmbhatt6 0:2f388b030837 6 * You may obtain a copy of the License at
kbrahmbhatt6 0:2f388b030837 7 *
kbrahmbhatt6 0:2f388b030837 8 * http://www.apache.org/licenses/LICENSE-2.0
kbrahmbhatt6 0:2f388b030837 9 *
kbrahmbhatt6 0:2f388b030837 10 * Unless required by applicable law or agreed to in writing, software
kbrahmbhatt6 0:2f388b030837 11 * distributed under the License is distributed on an "AS IS" BASIS,
kbrahmbhatt6 0:2f388b030837 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
kbrahmbhatt6 0:2f388b030837 13 * See the License for the specific language governing permissions and
kbrahmbhatt6 0:2f388b030837 14 * limitations under the License.
kbrahmbhatt6 0:2f388b030837 15 */
kbrahmbhatt6 0:2f388b030837 16
kbrahmbhatt6 0:2f388b030837 17 #include <time.h>
kbrahmbhatt6 0:2f388b030837 18
kbrahmbhatt6 0:2f388b030837 19 #ifdef __cplusplus
kbrahmbhatt6 0:2f388b030837 20 extern "C" {
kbrahmbhatt6 0:2f388b030837 21 #endif
kbrahmbhatt6 0:2f388b030837 22
kbrahmbhatt6 0:2f388b030837 23 /** Implementation of the C time.h functions
kbrahmbhatt6 0:2f388b030837 24 *
kbrahmbhatt6 0:2f388b030837 25 * Provides mechanisms to set and read the current time, based
kbrahmbhatt6 0:2f388b030837 26 * on the microcontroller Real-Time Clock (RTC), plus some
kbrahmbhatt6 0:2f388b030837 27 * standard C manipulation and formating functions.
kbrahmbhatt6 0:2f388b030837 28 *
kbrahmbhatt6 0:2f388b030837 29 * Example:
kbrahmbhatt6 0:2f388b030837 30 * @code
kbrahmbhatt6 0:2f388b030837 31 * #include "mbed.h"
kbrahmbhatt6 0:2f388b030837 32 *
kbrahmbhatt6 0:2f388b030837 33 * int main() {
kbrahmbhatt6 0:2f388b030837 34 * set_time(1256729737); // Set RTC time to Wed, 28 Oct 2009 11:35:37
kbrahmbhatt6 0:2f388b030837 35 *
kbrahmbhatt6 0:2f388b030837 36 * while(1) {
kbrahmbhatt6 0:2f388b030837 37 * time_t seconds = time(NULL);
kbrahmbhatt6 0:2f388b030837 38 *
kbrahmbhatt6 0:2f388b030837 39 * printf("Time as seconds since January 1, 1970 = %d\n", seconds);
kbrahmbhatt6 0:2f388b030837 40 *
kbrahmbhatt6 0:2f388b030837 41 * printf("Time as a basic string = %s", ctime(&seconds));
kbrahmbhatt6 0:2f388b030837 42 *
kbrahmbhatt6 0:2f388b030837 43 * char buffer[32];
kbrahmbhatt6 0:2f388b030837 44 * strftime(buffer, 32, "%I:%M %p\n", localtime(&seconds));
kbrahmbhatt6 0:2f388b030837 45 * printf("Time as a custom formatted string = %s", buffer);
kbrahmbhatt6 0:2f388b030837 46 *
kbrahmbhatt6 0:2f388b030837 47 * wait(1);
kbrahmbhatt6 0:2f388b030837 48 * }
kbrahmbhatt6 0:2f388b030837 49 * }
kbrahmbhatt6 0:2f388b030837 50 * @endcode
kbrahmbhatt6 0:2f388b030837 51 */
kbrahmbhatt6 0:2f388b030837 52
kbrahmbhatt6 0:2f388b030837 53 /** Set the current time
kbrahmbhatt6 0:2f388b030837 54 *
kbrahmbhatt6 0:2f388b030837 55 * Initialises and sets the time of the microcontroller Real-Time Clock (RTC)
kbrahmbhatt6 0:2f388b030837 56 * to the time represented by the number of seconds since January 1, 1970
kbrahmbhatt6 0:2f388b030837 57 * (the UNIX timestamp).
kbrahmbhatt6 0:2f388b030837 58 *
kbrahmbhatt6 0:2f388b030837 59 * @param t Number of seconds since January 1, 1970 (the UNIX timestamp)
kbrahmbhatt6 0:2f388b030837 60 *
kbrahmbhatt6 0:2f388b030837 61 * Example:
kbrahmbhatt6 0:2f388b030837 62 * @code
kbrahmbhatt6 0:2f388b030837 63 * #include "mbed.h"
kbrahmbhatt6 0:2f388b030837 64 *
kbrahmbhatt6 0:2f388b030837 65 * int main() {
kbrahmbhatt6 0:2f388b030837 66 * set_time(1256729737); // Set time to Wed, 28 Oct 2009 11:35:37
kbrahmbhatt6 0:2f388b030837 67 * }
kbrahmbhatt6 0:2f388b030837 68 * @endcode
kbrahmbhatt6 0:2f388b030837 69 */
kbrahmbhatt6 0:2f388b030837 70 void set_time(time_t t);
kbrahmbhatt6 0:2f388b030837 71
kbrahmbhatt6 0:2f388b030837 72 #ifdef __cplusplus
kbrahmbhatt6 0:2f388b030837 73 }
kbrahmbhatt6 0:2f388b030837 74 #endif