fuck this
Dependencies: BMP280
TimeInterface.cpp
00001 #include "mbed.h" 00002 #include "TimeInterface.h" 00003 00004 void SetDate(int DD, int MM, int YYYY) 00005 { 00006 time_t currentTime = time(0); //Get the currenttime 00007 tm* current_tm = localtime(¤tTime); //Convert the time integer to a stuct 00008 tm newtime = *current_tm; //structure holding new time 00009 newtime.tm_year = YYYY - 1900; //Year since 1900 00010 newtime.tm_mon = MM - 1; //month of the year (0-11) 00011 newtime.tm_mday = DD; //day of month 00012 //All other parameters remain unchanged 00013 00014 int timeint = mktime(&newtime); //Convert time strucutre to int 00015 if (timeint == -1) 00016 { 00017 //error code 00018 } else { 00019 set_time(timeint); //Set the new time 00020 } 00021 } 00022 00023 void SetTime(int HH, int mm, int ss) 00024 { 00025 time_t currentTime = time(0); //Get the currenttime 00026 tm* current_tm = localtime(¤tTime); //Convert the time integer to a stuct 00027 tm newtime = *current_tm; //structure holding new time 00028 00029 newtime.tm_hour = HH; //Set hours 00030 newtime.tm_min = mm; //Set mins 00031 newtime.tm_sec = ss; //Set secs 00032 //All other parameters remain unchanged 00033 00034 int timeint = mktime(&newtime); //Convert time strucutre to int 00035 if (timeint == -1) 00036 { 00037 //error code 00038 } else { 00039 set_time(timeint); //Set the new time 00040 } 00041 } 00042 00043 struct tm ReturnDateTimeStruct(time_t seconds) 00044 { 00045 tm* ltm = localtime(&seconds); //Turn given time integer into time structure pointer 00046 ltm->tm_mon += 1; //adjust from the standard of 0-11 for months to 1-12 00047 ltm->tm_year += 1900; 00048 return *ltm; //Return the data held at this address. 00049 }
Generated on Tue Jul 26 2022 07:29:23 by 1.7.2