PokittoLib is the library needed for programming the Pokitto DIY game console (www.pokitto.com)
Dependents: YATTT sd_map_test cPong SnowDemo ... more
PokittoLib
Library for programming Pokitto hardware
How to Use
- Import this library to online compiler (see button "import" on the right hand side
- DO NOT import mbed-src anymore, a better version is now included inside PokittoLib
- Change My_settings.h according to your project
- Start coding!
mbed-pokitto/api/rtc_time.h@5:ea7377f3d1af, 2017-10-11 (annotated)
- Committer:
- Pokitto
- Date:
- Wed Oct 11 20:35:27 2017 +0000
- Revision:
- 5:ea7377f3d1af
Fixed PokittoLib. Includes a working custom mbed-src
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Pokitto | 5:ea7377f3d1af | 1 | /* mbed Microcontroller Library |
Pokitto | 5:ea7377f3d1af | 2 | * Copyright (c) 2006-2013 ARM Limited |
Pokitto | 5:ea7377f3d1af | 3 | * |
Pokitto | 5:ea7377f3d1af | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
Pokitto | 5:ea7377f3d1af | 5 | * you may not use this file except in compliance with the License. |
Pokitto | 5:ea7377f3d1af | 6 | * You may obtain a copy of the License at |
Pokitto | 5:ea7377f3d1af | 7 | * |
Pokitto | 5:ea7377f3d1af | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
Pokitto | 5:ea7377f3d1af | 9 | * |
Pokitto | 5:ea7377f3d1af | 10 | * Unless required by applicable law or agreed to in writing, software |
Pokitto | 5:ea7377f3d1af | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
Pokitto | 5:ea7377f3d1af | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
Pokitto | 5:ea7377f3d1af | 13 | * See the License for the specific language governing permissions and |
Pokitto | 5:ea7377f3d1af | 14 | * limitations under the License. |
Pokitto | 5:ea7377f3d1af | 15 | */ |
Pokitto | 5:ea7377f3d1af | 16 | |
Pokitto | 5:ea7377f3d1af | 17 | #include <time.h> |
Pokitto | 5:ea7377f3d1af | 18 | |
Pokitto | 5:ea7377f3d1af | 19 | #ifdef __cplusplus |
Pokitto | 5:ea7377f3d1af | 20 | extern "C" { |
Pokitto | 5:ea7377f3d1af | 21 | #endif |
Pokitto | 5:ea7377f3d1af | 22 | |
Pokitto | 5:ea7377f3d1af | 23 | /** Implementation of the C time.h functions |
Pokitto | 5:ea7377f3d1af | 24 | * |
Pokitto | 5:ea7377f3d1af | 25 | * Provides mechanisms to set and read the current time, based |
Pokitto | 5:ea7377f3d1af | 26 | * on the microcontroller Real-Time Clock (RTC), plus some |
Pokitto | 5:ea7377f3d1af | 27 | * standard C manipulation and formating functions. |
Pokitto | 5:ea7377f3d1af | 28 | * |
Pokitto | 5:ea7377f3d1af | 29 | * Example: |
Pokitto | 5:ea7377f3d1af | 30 | * @code |
Pokitto | 5:ea7377f3d1af | 31 | * #include "mbed.h" |
Pokitto | 5:ea7377f3d1af | 32 | * |
Pokitto | 5:ea7377f3d1af | 33 | * int main() { |
Pokitto | 5:ea7377f3d1af | 34 | * set_time(1256729737); // Set RTC time to Wed, 28 Oct 2009 11:35:37 |
Pokitto | 5:ea7377f3d1af | 35 | * |
Pokitto | 5:ea7377f3d1af | 36 | * while(1) { |
Pokitto | 5:ea7377f3d1af | 37 | * time_t seconds = time(NULL); |
Pokitto | 5:ea7377f3d1af | 38 | * |
Pokitto | 5:ea7377f3d1af | 39 | * printf("Time as seconds since January 1, 1970 = %d\n", seconds); |
Pokitto | 5:ea7377f3d1af | 40 | * |
Pokitto | 5:ea7377f3d1af | 41 | * printf("Time as a basic string = %s", ctime(&seconds)); |
Pokitto | 5:ea7377f3d1af | 42 | * |
Pokitto | 5:ea7377f3d1af | 43 | * char buffer[32]; |
Pokitto | 5:ea7377f3d1af | 44 | * strftime(buffer, 32, "%I:%M %p\n", localtime(&seconds)); |
Pokitto | 5:ea7377f3d1af | 45 | * printf("Time as a custom formatted string = %s", buffer); |
Pokitto | 5:ea7377f3d1af | 46 | * |
Pokitto | 5:ea7377f3d1af | 47 | * wait(1); |
Pokitto | 5:ea7377f3d1af | 48 | * } |
Pokitto | 5:ea7377f3d1af | 49 | * } |
Pokitto | 5:ea7377f3d1af | 50 | * @endcode |
Pokitto | 5:ea7377f3d1af | 51 | */ |
Pokitto | 5:ea7377f3d1af | 52 | |
Pokitto | 5:ea7377f3d1af | 53 | /** Set the current time |
Pokitto | 5:ea7377f3d1af | 54 | * |
Pokitto | 5:ea7377f3d1af | 55 | * Initialises and sets the time of the microcontroller Real-Time Clock (RTC) |
Pokitto | 5:ea7377f3d1af | 56 | * to the time represented by the number of seconds since January 1, 1970 |
Pokitto | 5:ea7377f3d1af | 57 | * (the UNIX timestamp). |
Pokitto | 5:ea7377f3d1af | 58 | * |
Pokitto | 5:ea7377f3d1af | 59 | * @param t Number of seconds since January 1, 1970 (the UNIX timestamp) |
Pokitto | 5:ea7377f3d1af | 60 | * |
Pokitto | 5:ea7377f3d1af | 61 | * Example: |
Pokitto | 5:ea7377f3d1af | 62 | * @code |
Pokitto | 5:ea7377f3d1af | 63 | * #include "mbed.h" |
Pokitto | 5:ea7377f3d1af | 64 | * |
Pokitto | 5:ea7377f3d1af | 65 | * int main() { |
Pokitto | 5:ea7377f3d1af | 66 | * set_time(1256729737); // Set time to Wed, 28 Oct 2009 11:35:37 |
Pokitto | 5:ea7377f3d1af | 67 | * } |
Pokitto | 5:ea7377f3d1af | 68 | * @endcode |
Pokitto | 5:ea7377f3d1af | 69 | */ |
Pokitto | 5:ea7377f3d1af | 70 | void set_time(time_t t); |
Pokitto | 5:ea7377f3d1af | 71 | |
Pokitto | 5:ea7377f3d1af | 72 | /** Attach an external RTC to be used for the C time functions |
Pokitto | 5:ea7377f3d1af | 73 | * |
Pokitto | 5:ea7377f3d1af | 74 | * Do not call this function from an interrupt while an RTC read/write operation may be occurring |
Pokitto | 5:ea7377f3d1af | 75 | * |
Pokitto | 5:ea7377f3d1af | 76 | * @param read_rtc pointer to function which returns current UNIX timestamp |
Pokitto | 5:ea7377f3d1af | 77 | * @param write_rtc pointer to function which sets current UNIX timestamp, can be NULL |
Pokitto | 5:ea7377f3d1af | 78 | * @param init_rtc pointer to funtion which initializes RTC, can be NULL |
Pokitto | 5:ea7377f3d1af | 79 | * @param isenabled_rtc pointer to function wich returns if the rtc is enabled, can be NULL |
Pokitto | 5:ea7377f3d1af | 80 | */ |
Pokitto | 5:ea7377f3d1af | 81 | void attach_rtc(time_t (*read_rtc)(void), void (*write_rtc)(time_t), void (*init_rtc)(void), int (*isenabled_rtc)(void)); |
Pokitto | 5:ea7377f3d1af | 82 | |
Pokitto | 5:ea7377f3d1af | 83 | #ifdef __cplusplus |
Pokitto | 5:ea7377f3d1af | 84 | } |
Pokitto | 5:ea7377f3d1af | 85 | #endif |