Welcome to you !!
I did programming C ++ for analog clock but I am green. I
just wrote a second pointer that well flows through the background and
an additional hour pointer and pointer to the minute it looks bad.
So
the background of the hour indicator is fine and the background of the
minute indicator and the background of the secret indicator are wrong.
Something wrong with C ++?
Someone help me check and improve?
In the attachment is the source code - main.c and the photo 7 "TFT stm32F746IG
RTC_DateTypeDef sdatestructure;
RTC_TimeTypeDef stimestructure;
void SystemClock_Config(void);
extern GUI_CONST_STORAGE GUI_BITMAP bmtlo;
#define smoothing 6
#define DEG2RAD (3.1415926f/180)
#define x0 477
#define y0 170
static GUI_POINT _aNeedle_0[]={ //Hour pointer
static GUI_POINT _aNeedle_1[]={ //Minute pointer
static GUI_POINT _aNeedle_2[]={ //Second pointer
typedef struct{
GUI_AUTODEV_INFO AutoDevInfo;
GUI_POINT aPoints[30];
float Angle;
} PARAM;
typedef struct{
GUI_POINT*pPolygon;
int NumPoints;
} NEEDLE;
static NEEDLE _aNeedle[3]={
{_aNeedle_0,GUI_COUNTOF(_aNeedle_0)},
{_aNeedle_1,GUI_COUNTOF(_aNeedle_1)},
{_aNeedle_2,GUI_COUNTOF(_aNeedle_2)},
};
static float _GetAngle_0(int ttime, int m){
return 90-((ttime*30)+(m/2));
}
static float _GetAngle_1(int ttime, int m){
return 90-(6*ttime);
}
static float _GetAngle_2(int ttime, int m){
return 90-(6*ttime);
}
static float (* _pfGetAngle[3])(int ttime, int m) = {
_GetAngle_0,
_GetAngle_1,
_GetAngle_2
};
static void _Draw_0(void*p){
PARAM*pParam=(PARAM*)p;
if (pParam->AutoDevInfo.DrawFixed)
{
GUI_DrawBitmap(&bmtlo, 0, 0); //background
GUI_SetTextMode(GUI_TM_TRANS);//calendar
GUI_SetColor(GUI_BLACK);
GUI_SetFont(&GUI_Font32B_1);
GUI_DrawRect(x0+60,y0-11,x0+98,y0+14);
GUI_DrawRect(x0+61,y0-12,x0+99,y0+15);
GUI_DispDecAt(sdatestructure.Date,x0+65,y0-13,2);//calendar
}
GUI_SetColor(GUI_BLACK);
GUI_AA_FillPolygon(pParam->aPoints, GUI_COUNTOF(_aNeedle_0),smoothing*x0,smoothing*y0);
}
static void _Draw_1(void*p){
PARAM*pParam=(PARAM*)p;
GUI_SetColor(GUI_BLACK);
GUI_AA_FillPolygon(pParam->aPoints, GUI_COUNTOF(_aNeedle_1),smoothing*x0,smoothing*y0);
}
static void _Draw_2(void*p){
PARAM*pParam=(PARAM*)p;
GUI_SetColor(GUI_RED);
GUI_AA_FillPolygon(pParam->aPoints, GUI_COUNTOF(_aNeedle_2),smoothing*x0,smoothing*y0);
GUI_AA_FillCircle(smoothing*x0,smoothing*y0,smoothing*8);
}
void (*_pfDraw[3])(void*p) ={
_Draw_0,
_Draw_1,
_Draw_2,
};
static void _clock(int h, int m, int s)
{
GUI_AUTODEV aAutoDev [3];
PARAM aParam [3] = {0};
for (int i=0;i<=2;i++)
{
GUI_MEMDEV_CreateAuto(&aAutoDev);
if (i==0)aParam[i].Angle=_pfGetAngle[i](h,m)*DEG2RAD;
if (i==1)aParam[i].Angle=_pfGetAngle[i](m,m)*DEG2RAD;
if (i==2)aParam[i].Angle=_pfGetAngle[i](s,m)*DEG2RAD;
GUI_RotatePolygon(aParam[i].aPoints,_aNeedle[i].pPolygon,_aNeedle[i].NumPoints,aParam[i].Angle);
GUI_MEMDEV_DrawAuto(&aAutoDev[i],&aParam[i].AutoDevInfo,_pfDraw[i],&aParam[i]);
}
GUI_Exec();
for(int i=0;i<=2;i++)GUI_MEMDEV_DeleteAuto(&aAutoDev[i]);
}
int main(void)
{
GUI_Init();
int oldsec=-1;
GUI_SetBkColor(GUI_BLACK);
GUI_Clear();
GUI_AA_EnableHiRes();
GUI_AA_SetFactor(smoothing);
while (1)
{
HAL_RTC_GetTime(&hrtc, &stimestructure, RTC_FORMAT_BIN);
HAL_RTC_GetDate(&hrtc, &sdatestructure, RTC_FORMAT_BIN);
if (oldsec!=stimestructure.Seconds)
{
_clock(stimestructure.Hours,stimestructure.Minutes,stimestructure.Seconds);
oldsec=stimestructure.Seconds;
}
}[/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i]
I did programming C ++ for analog clock but I am green. I
just wrote a second pointer that well flows through the background and
an additional hour pointer and pointer to the minute it looks bad.
So
the background of the hour indicator is fine and the background of the
minute indicator and the background of the secret indicator are wrong.
Something wrong with C ++?
Someone help me check and improve?
In the attachment is the source code - main.c and the photo 7 "TFT stm32F746IG
RTC_DateTypeDef sdatestructure;
RTC_TimeTypeDef stimestructure;
void SystemClock_Config(void);
extern GUI_CONST_STORAGE GUI_BITMAP bmtlo;
#define smoothing 6
#define DEG2RAD (3.1415926f/180)
#define x0 477
#define y0 170
static GUI_POINT _aNeedle_0[]={ //Hour pointer
static GUI_POINT _aNeedle_1[]={ //Minute pointer
static GUI_POINT _aNeedle_2[]={ //Second pointer
typedef struct{
GUI_AUTODEV_INFO AutoDevInfo;
GUI_POINT aPoints[30];
float Angle;
} PARAM;
typedef struct{
GUI_POINT*pPolygon;
int NumPoints;
} NEEDLE;
static NEEDLE _aNeedle[3]={
{_aNeedle_0,GUI_COUNTOF(_aNeedle_0)},
{_aNeedle_1,GUI_COUNTOF(_aNeedle_1)},
{_aNeedle_2,GUI_COUNTOF(_aNeedle_2)},
};
static float _GetAngle_0(int ttime, int m){
return 90-((ttime*30)+(m/2));
}
static float _GetAngle_1(int ttime, int m){
return 90-(6*ttime);
}
static float _GetAngle_2(int ttime, int m){
return 90-(6*ttime);
}
static float (* _pfGetAngle[3])(int ttime, int m) = {
_GetAngle_0,
_GetAngle_1,
_GetAngle_2
};
static void _Draw_0(void*p){
PARAM*pParam=(PARAM*)p;
if (pParam->AutoDevInfo.DrawFixed)
{
GUI_DrawBitmap(&bmtlo, 0, 0); //background
GUI_SetTextMode(GUI_TM_TRANS);//calendar
GUI_SetColor(GUI_BLACK);
GUI_SetFont(&GUI_Font32B_1);
GUI_DrawRect(x0+60,y0-11,x0+98,y0+14);
GUI_DrawRect(x0+61,y0-12,x0+99,y0+15);
GUI_DispDecAt(sdatestructure.Date,x0+65,y0-13,2);//calendar
}
GUI_SetColor(GUI_BLACK);
GUI_AA_FillPolygon(pParam->aPoints, GUI_COUNTOF(_aNeedle_0),smoothing*x0,smoothing*y0);
}
static void _Draw_1(void*p){
PARAM*pParam=(PARAM*)p;
GUI_SetColor(GUI_BLACK);
GUI_AA_FillPolygon(pParam->aPoints, GUI_COUNTOF(_aNeedle_1),smoothing*x0,smoothing*y0);
}
static void _Draw_2(void*p){
PARAM*pParam=(PARAM*)p;
GUI_SetColor(GUI_RED);
GUI_AA_FillPolygon(pParam->aPoints, GUI_COUNTOF(_aNeedle_2),smoothing*x0,smoothing*y0);
GUI_AA_FillCircle(smoothing*x0,smoothing*y0,smoothing*8);
}
void (*_pfDraw[3])(void*p) ={
_Draw_0,
_Draw_1,
_Draw_2,
};
static void _clock(int h, int m, int s)
{
GUI_AUTODEV aAutoDev [3];
PARAM aParam [3] = {0};
for (int i=0;i<=2;i++)
{
GUI_MEMDEV_CreateAuto(&aAutoDev);
if (i==0)aParam[i].Angle=_pfGetAngle[i](h,m)*DEG2RAD;
if (i==1)aParam[i].Angle=_pfGetAngle[i](m,m)*DEG2RAD;
if (i==2)aParam[i].Angle=_pfGetAngle[i](s,m)*DEG2RAD;
GUI_RotatePolygon(aParam[i].aPoints,_aNeedle[i].pPolygon,_aNeedle[i].NumPoints,aParam[i].Angle);
GUI_MEMDEV_DrawAuto(&aAutoDev[i],&aParam[i].AutoDevInfo,_pfDraw[i],&aParam[i]);
}
GUI_Exec();
for(int i=0;i<=2;i++)GUI_MEMDEV_DeleteAuto(&aAutoDev[i]);
}
int main(void)
{
GUI_Init();
int oldsec=-1;
GUI_SetBkColor(GUI_BLACK);
GUI_Clear();
GUI_AA_EnableHiRes();
GUI_AA_SetFactor(smoothing);
while (1)
{
HAL_RTC_GetTime(&hrtc, &stimestructure, RTC_FORMAT_BIN);
HAL_RTC_GetDate(&hrtc, &sdatestructure, RTC_FORMAT_BIN);
if (oldsec!=stimestructure.Seconds)
{
_clock(stimestructure.Hours,stimestructure.Minutes,stimestructure.Seconds);
oldsec=stimestructure.Seconds;
}
}[/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i][/i]
The post was edited 1 time, last by ckupraca@wp.pl ().