Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: MFRC522 NextionLCD
Fork of ProjectCardDisplay by
Time.cpp
00001 #include "mbed.h" 00002 #include "Time.h" 00003 #include <string> 00004 00005 00006 00007 00008 00009 int Date_Time_Setting(struct tm curt,char *str) 00010 { 00011 int len=0; 00012 len= strlen(str); 00013 // printf("len = %d",len); 00014 if(len < 14) 00015 return 0; 00016 00017 curt.tm_mday = ( str[0]-0x30)*10+(str[1]-0x30); 00018 curt.tm_mon = ( str[2]-0x30)*10+(str[3]-0x30) -1; 00019 curt.tm_year = (( str[4]-0x30)*1000 + (str[5]-0x30)*100 + (str[6]-0x30)*10 + (str[7]-0x30)) -1900 ; 00020 00021 curt.tm_hour=(str[8]-0x30)*10+(str[9]-0x30); 00022 curt.tm_min=(str[10]-0x30)*10+(str[11]-0x30); 00023 curt.tm_sec=(str[12]-0x30)*10+(str[13]-0x30); 00024 00025 time_t epoch = mktime(&curt); 00026 if (epoch == (time_t) -1) { 00027 error("Error in clock setting\n"); 00028 // Stop here 00029 } 00030 set_time(epoch); 00031 return 1; 00032 } 00033 00034 00035 int iSetTerminalTime(char *tstring) 00036 { 00037 int ret=0; 00038 struct tm curt; 00039 00040 ret = Date_Time_Setting(curt,tstring); 00041 00042 if(ret == 1) { 00043 wait(1); 00044 00045 // Display_LCD(0,0," DATE-TIME "); 00046 // Display_LCD(0,1," SET SUCCESS "); 00047 printf("Date Time Set succesfully\r\n"); 00048 00049 } else { 00050 // Display_LCD(0,0," DATE-TIME "); 00051 // Display_LCD(0,1," SET FAILURE "); 00052 printf("Date Time Set Failure \r\n"); 00053 00054 } 00055 wait(2); 00056 // Clear_LCD(); 00057 00058 return ret; 00059 } 00060 00061 00062 int chk_time (char *str) 00063 { 00064 int HH,MM,SS; 00065 HH=(str[0]-0x30)*10+(str[1]-0x30); 00066 MM=(str[2]-0x30)*10+(str[3]-0x30); 00067 SS=(str[4]-0x30)*10+(str[5]-0x30); 00068 if ( HH < 0 || HH > 23 || MM < 0 || MM > 59 || SS < 0 || SS > 59 ) 00069 return -1; 00070 return 1; 00071 } 00072 00073 int chk_date (char *str) 00074 { 00075 int epos_date=0,epos_month=0,epos_year=0; 00076 epos_date = ( str[0]-0x30)*10+(str[1]-0x30); 00077 epos_month = ( str[2]-0x30)*10+(str[3]-0x30); 00078 epos_year = ( str[4]-0x30)*1000+ (str[5]-0x30)*100 + (str[6]-0x30)*10 + (str[7]-0x30); 00079 00080 00081 if ( epos_month < 1 || epos_date < 1 || epos_date > 31 || epos_month > 12 || epos_year < 2008 ) return ERROR ; 00082 00083 else if(epos_month == 1 || epos_month == 3 || epos_month == 5 || epos_month == 7 || epos_month == 8 || epos_month ==10 ||epos_month == 12) { 00084 00085 if (epos_date > 31) 00086 return -1; 00087 } 00088 00089 else if (epos_month == 4 || epos_month == 6 || epos_month == 9 || epos_month == 11) { 00090 00091 if (epos_date > 30) 00092 return -1; 00093 } 00094 00095 else if (epos_month == 2 ) 00096 00097 { 00098 if ( !(epos_year%400) || (epos_year%100 != 0 && epos_year%4==0 ) ) { 00099 if (epos_date > 29 ) return -1; 00100 } 00101 00102 else if( epos_date > 28 ) return -1; 00103 } 00104 return 1; 00105 } 00106 00107 void Get_Date_Time(char *date_string,char *time_string, char *DTSTRING) 00108 { 00109 time_t curr_time; 00110 tm * curr_tm; 00111 time(&curr_time); 00112 curr_tm = localtime(&curr_time); 00113 strftime(date_string,10,"%Y%m%d",curr_tm); 00114 strftime(time_string,10,"%H%M%S",curr_tm); 00115 strftime(DTSTRING,20,"%Y%m%d%H%M%S",curr_tm); 00116 } 00117 00118 void Get_Date_Time(char *date_string,char *time_string) 00119 { 00120 time_t curr_time; 00121 tm * curr_tm; 00122 time(&curr_time); 00123 curr_tm = localtime(&curr_time); 00124 strftime(date_string,10,"%Y%m%d",curr_tm); 00125 strftime(time_string,10,"%H%M%S",curr_tm); 00126 00127 } 00128 00129 void Get_Date_Time_Display( char *DTSTRING) 00130 { 00131 time_t curr_time; 00132 tm * curr_tm; 00133 time(&curr_time); 00134 curr_tm = localtime(&curr_time); 00135 strftime(DTSTRING,29,"%Y/%m/%d %H:%M",curr_tm); 00136 00137 } 00138 00139 void Get_Date_Time( char *DTSTRING) 00140 { 00141 time_t curr_time; 00142 tm * curr_tm; 00143 time(&curr_time); 00144 curr_tm = localtime(&curr_time); 00145 strftime(DTSTRING,20,"%Y%m%d%H%M%S",curr_tm); 00146 } 00147 00148 void Get_Date_Time_Trns( char *DTSTRING) 00149 { 00150 time_t curr_time; 00151 tm * curr_tm; 00152 time(&curr_time); 00153 curr_tm = localtime(&curr_time); 00154 strftime(DTSTRING,20,"%d%m%Y%H%M%S",curr_tm); 00155 } 00156 00157 00158 00159 int is_6_O_Clock(void) 00160 { 00161 char dat[9]={'\0'}; 00162 char tim[9]={'\0'}; 00163 int HH,MM; 00164 Get_Date_Time(dat,tim); 00165 HH=(tim[0]-0x30)*10+(tim[1]-0x30); 00166 MM=(tim[2]-0x30)*10+(tim[3]-0x30); 00167 00168 if((HH==6) &&(MM <30)) 00169 { 00170 // printf("%d:%d\r\n",HH,MM); 00171 return 1; 00172 } 00173 else 00174 { 00175 00176 // printf("%d:%d\r\n",HH,MM); 00177 return 0; 00178 } 00179 } 00180 00181 int Get_Hours(void) 00182 { 00183 char dat[9]={'\0'}; 00184 char tim[9]={'\0'}; 00185 int HH,MM; 00186 Get_Date_Time(dat,tim); 00187 HH=(tim[0]-0x30)*10+(tim[1]-0x30); 00188 MM=(tim[2]-0x30)*10+(tim[3]-0x30); 00189 return HH; 00190 }
Generated on Wed Jul 13 2022 14:24:19 by
1.7.2
