void CCalendarHelper::GetCalendar(int year, int month, DayTraffic calendar[CALENDAR_HEIGHT][CALENDAR_WIDTH]) { memset(calendar, 0, sizeof(DayTraffic)*CALENDAR_HEIGHT*CALENDAR_WIDTH); int days{ DaysInMonth(year, month) }; int first_weak_day{ CaculateWeekDay(year, month, 1) }; int i{}, j{}; for (int n{}; n < 37; n++) { if (n < first_weak_day) { calendar[i][j].day = 0; } else { int day = n - first_weak_day + 1; if (day <= days) calendar[i][j].day = day; } j++; if (j >= 7) { j = 0; i++; } } }
//------------------------------------------------------------------ void RTC_Set_datetime(uint8_t * data) { uint8_t temp[3]; RTC_DateTypeDef sdatestructure; RTC_TimeTypeDef stimestructure; if(data!=NULL) { osMutexWait(rtc_mutex, osWaitForever); sdatestructure.Year =data[0]; sdatestructure.Month = data[1]; sdatestructure.Date = data[2]; sdatestructure.WeekDay= CaculateWeekDay(data[0],data[1],data[2]); if(HAL_RTC_SetDate(&hrtc,&sdatestructure,RTC_FORMAT_BIN) != HAL_OK) { /* Initialization Error */ Error_Handler("set time error"); } stimestructure.Hours = data[3]; stimestructure.Minutes = data[4]; stimestructure.Seconds = data[5]; stimestructure.TimeFormat = RTC_HOURFORMAT12_AM; stimestructure.DayLightSaving = RTC_DAYLIGHTSAVING_NONE; stimestructure.StoreOperation = RTC_STOREOPERATION_RESET; if(HAL_RTC_SetTime(&hrtc,&stimestructure,RTC_FORMAT_BIN) != HAL_OK) { /* Initialization Error */ Error_Handler("set date error"); } #if 0 //flash lcd HAL_RTC_GetTime(&hrtc, &stimestructure, RTC_FORMAT_BIN); temp[0]=stimestructure.Hours; temp[1]=stimestructure.Minutes; temp[2]=stimestructure.Seconds; memcpy(¤t_datetime[3],temp,3); /* Get the RTC current Date */ HAL_RTC_GetDate(&hrtc, &sdatestructure, RTC_FORMAT_BIN); data[0]=sdatestructure.Year; data[1]=sdatestructure.Month; data[2]=sdatestructure.Date; current_datetime[6]=sdatestructure.WeekDay; memcpy(¤t_datetime[0],data,3); #endif if(disp_sort==0) send_message(4); osMutexRelease(rtc_mutex); }//data=null }