| 222 | } |
| 223 | |
| 224 | struct tm cplus_RTC::getTimeStruct() { |
| 225 | RTC_TimeTypeDef timeStruct; |
| 226 | RTC_DateTypeDef dateStruct; |
| 227 | struct tm timeinfo = {0}; |
| 228 | |
| 229 | // Get current time and date from RTC |
| 230 | GetTime(&timeStruct); |
| 231 | GetDate(&dateStruct); |
| 232 | |
| 233 | // Populate tm structure |
| 234 | timeinfo.tm_sec = timeStruct.Seconds; |
| 235 | timeinfo.tm_min = timeStruct.Minutes; |
| 236 | timeinfo.tm_hour = timeStruct.Hours; |
| 237 | timeinfo.tm_mday = dateStruct.Date; |
| 238 | timeinfo.tm_mon = dateStruct.Month - 1; // tm_mon is 0-11, RTC month is 1-12 |
| 239 | timeinfo.tm_year = dateStruct.Year - 1900; // tm_year is years since 1900 |
| 240 | timeinfo.tm_wday = dateStruct.WeekDay; |
| 241 | |
| 242 | // Calculate day of year |
| 243 | mktime(&timeinfo); // This normalizes the struct and calculates tm_yday |
| 244 | |
| 245 | return timeinfo; |
| 246 | } |
no outgoing calls
no test coverage detected