Files
player/Project/Src/MyWinApp/mywin_user_lock.c

366 lines
8.4 KiB
C
Raw Normal View History

2025-06-27 00:32:57 +08:00
#include "mywin_inc.h"
#include "mywin_user_lock.h"
#include "date.h"
#include "random.h"
#include "math.h"
2025-07-05 19:47:28 +08:00
//<2F><>׼<EFBFBD><D7BC><EFBFBD><EFBFBD>ѹ
2025-06-27 00:32:57 +08:00
#define PA 101325.0f
2025-07-05 19:47:28 +08:00
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ѹ
2025-06-27 00:32:57 +08:00
static int get_pressure_altitude(float *pre,int *alt)
{
float fSplPressure;
//spl1301_get_raw_pressure();
//fSplPressure = spl1301_get_pressure();
fSplPressure = (990000+RANDOM_Get()%20000)/10.0f;
*pre=fSplPressure;
*alt = 18400.f * (1.f + 34.f / 273.f) * log10f(PA / fSplPressure);
return 0;
}
2025-07-05 19:47:28 +08:00
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
2025-06-27 00:32:57 +08:00
static int get_heart_rate(void)
{
return 70+RANDOM_Get()%50;
}
2025-07-05 19:47:28 +08:00
//<2F><>ȡ<EFBFBD><C8A1><EFBFBD><EFBFBD>
2025-06-27 00:32:57 +08:00
static int get_electricity(void)
{
return 50+RANDOM_Get()%50;
}
2025-07-05 19:47:28 +08:00
static const char *g_week[7]={"<EFBFBD><EFBFBD><EFBFBD><EFBFBD>һ","<EFBFBD><EFBFBD><EFBFBD>ڶ<EFBFBD>","<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>","<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>","<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>","<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>","<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>"};
2025-06-27 00:32:57 +08:00
void LOCK_Updata(WIN_LockStruct *home);
WIN_LockStruct *WIN_CreatLock (WIN_WindowStruct *base,
void (*msgLoop)(struct _WIN_WindowStruct *win,WIN_MsgStruct *msg),
int x,int y,int x_size,int y_size)
{
2025-07-05 19:47:28 +08:00
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣѭ<CFA2><D1AD>
2025-06-27 00:32:57 +08:00
if (msgLoop==0)
{
msgLoop=(void (*)(struct _WIN_WindowStruct *win,WIN_MsgStruct *msg))LOCK_DefaultMsgLoop;
}
WIN_LockStruct *ret=mymalloc (sizeof ( WIN_LockStruct));
2025-07-05 19:47:28 +08:00
//<2F><><EFBFBD>ø<EFBFBD><C3B8><EFBFBD><EFBFBD>Ĺ<EFBFBD><C4B9><EFBFBD><ECBAAF>
2025-06-27 00:32:57 +08:00
if (ret)
{
mymemset (ret,0,sizeof ( WIN_LockStruct));
if (0==WIN_CreatTouchEx((WIN_TouchWinStruct *)ret,base,msgLoop,x,y,x_size,y_size))
{
2025-07-05 19:47:28 +08:00
//<2F><><EFBFBD><EFBFBD>ʧ<EFBFBD><CAA7>
2025-06-27 00:32:57 +08:00
myfree (ret);
ret=0;
}
else
{
2025-07-05 19:47:28 +08:00
//<2F><><EFBFBD><EFBFBD>һ<EFBFBD><D2BB>
2025-06-27 00:32:57 +08:00
((WIN_WindowStruct *)ret)->winType="WIN_LockStruct";
2025-07-05 19:47:28 +08:00
((WIN_WindowStruct *)ret)->intercept=1;//<2F><><EFBFBD><EFBFBD><EFBFBD>Ͱ<EFBFBD><CDB0><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2025-06-27 00:32:57 +08:00
((WIN_WindowStruct *)ret)->bkcolor=0;
((WIN_WindowStruct *)ret)->color=0xd7c1ac;
ret->color1=0x7d7064;
ret->timerId= WIN_CreatTimer ((WIN_WindowStruct *)ret,1000);
}
}
2025-07-05 19:47:28 +08:00
ret->pic_altitude="0:/png/lock/<2F><><EFBFBD><EFBFBD>-<2D><><EFBFBD><EFBFBD>.png";
ret->pic_pressure="0:/png/lock/<2F><><EFBFBD><EFBFBD>-<2D><>ѹ.png";
ret->pic_heart="0:/png/lock/<2F><><EFBFBD><EFBFBD>-<2D><><EFBFBD><EFBFBD>.png";
ret->pic_battery="0:/png/lock/<2F><><EFBFBD><EFBFBD>-<2D><><EFBFBD><EFBFBD>.png";
ret->pic_lock="0:/png/lock/<2F><><EFBFBD><EFBFBD>-<2D><>.png";
2025-06-27 00:32:57 +08:00
LOCK_Updata(ret);
return ret;
}
2025-07-05 19:47:28 +08:00
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2025-06-27 00:32:57 +08:00
int LOCK_KeyBord (WIN_LockStruct *home,WIN_KeyStruct *k)
{
WIN_WindowStruct *win=(WIN_WindowStruct *)home;
if (k->shortPress&KEY_VALUE_ENTER)
{
if(home->lock_relieve&KEY_VALUE_ENTER)
{
2025-07-05 19:47:28 +08:00
//<2F><>¼<EFBFBD>ͷ<EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2025-06-27 00:32:57 +08:00
home->lock_relieve&=~KEY_VALUE_ENTER;
if(home->lock_relieve==0)
win->deleteWindow(win);
}
}
if (k->shortPress&KEY_VALUE_HOME)
{
if(home->lock_relieve&KEY_VALUE_HOME)
{
2025-07-05 19:47:28 +08:00
//<2F><>¼<EFBFBD>ͷ<EFBFBD>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2025-06-27 00:32:57 +08:00
home->lock_relieve&=~KEY_VALUE_HOME;
if(home->lock_relieve==0)
win->deleteWindow(win);
}
}
if((k->key&KEY_VALUE_ENTER)&&(k->key&KEY_VALUE_HOME))
{
2025-07-05 19:47:28 +08:00
//<2F><>¼<EFBFBD><C2BC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͬʱ<CDAC><CAB1><EFBFBD><EFBFBD>
2025-06-27 00:32:57 +08:00
home->lock_relieve=KEY_VALUE_ENTER|KEY_VALUE_HOME;
}
return 0;
}
2025-07-05 19:47:28 +08:00
//<2F><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
2025-06-27 00:32:57 +08:00
int LOCK_TouchBord (WIN_LockStruct *home,WIN_MsgStruct *msg)
{
switch (msg->data.v)
{
case CHID_DELETE:
break;
case CHID_USER:
{
if (msg->data2.v==BUTTON_PRESSED)
{
}
}
break;
default:
break;
}
return 0;
}
2025-07-05 19:47:28 +08:00
//<2F><><EFBFBD><EFBFBD><EFBFBD>ƶ<EFBFBD><C6B6><EFBFBD>Ϣ
2025-06-27 00:32:57 +08:00
int LOCK_TouchMove(WIN_LockStruct *home,WIN_MoveStruct *m)
{
WIN_WindowStruct *win=(WIN_WindowStruct *)home;
switch(m->moveType)
{
case MOVE_DATA_MOVED:
break;
case MOVE_DATA_TOUCHIN:
break;
case MOVE_DATA_TOUCHOUT:
break;
}
return 0;
}
2025-07-05 19:47:28 +08:00
//Ĭ<>ϻ<EFBFBD><CFBB>ƺ<EFBFBD><C6BA><EFBFBD>
2025-06-27 00:32:57 +08:00
void LOCK_DefaultPaint (WIN_LockStruct *home)
{
int x=0;
int y=0;
int x_size=((WIN_WindowStruct *)home)->x_size;
int y_size=((WIN_WindowStruct *)home)->y_size;
WIN_PaintBackGround ((WIN_WindowStruct *)home);
u32 font_type=WIN_SetFontSize(10);
u32 color_bk=((WIN_WindowStruct *)home)->bkcolor;
u32 color=((WIN_WindowStruct *)home)->color;
2025-07-05 19:47:28 +08:00
//<2F><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD>
2025-06-27 00:32:57 +08:00
WIN_SetLcdBkColor (color_bk);
WIN_SetLcdColor (color);
WIN_SetFontMode (WIN_DRAWMODE_ALONE);
WIN_SetFontSize(16);
int dat_x=x_size-5;
int dat_y=8;
dat_x-=strlen(home->date)*WIN_GetFontWidth()/2;
WIN_SetLcdColor (color_bk);
WIN_DrawTxtAt (home->date,dat_x-1,dat_y-1);
WIN_DrawTxtAt (home->date,dat_x+1,dat_y+1);
WIN_SetLcdColor (color);
WIN_DrawTxtAt (home->date,dat_x,dat_y);
2025-07-05 19:47:28 +08:00
//<2F><>ʾʱ<CABE><CAB1>
2025-06-27 00:32:57 +08:00
int time_x=x_size;
int time_y=25;
WIN_SetFontSize(65);
int min_xsize=strlen(home->time)*WIN_GetFontWidth()/2;
WIN_SetLcdColor (color_bk);
WIN_DrawTxtAt(home->time,time_x-min_xsize-1,time_y-1);
WIN_DrawTxtAt(home->time,time_x-min_xsize+1,time_y+1);
WIN_SetLcdColor (color);
WIN_DrawTxtAt(home->time,time_x-min_xsize,time_y);
2025-07-05 19:47:28 +08:00
//<2F><>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD>
2025-06-27 00:32:57 +08:00
WIN_PicStruct *pic=0;
int lock_y=y_size/2;
int lock_x=x_size/2;
2025-07-05 19:47:28 +08:00
char *lock_txt="ͬʱ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȷ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ؼ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>";
2025-06-27 00:32:57 +08:00
WIN_SetFontSize(16);
int lock_txt_len=strlen(lock_txt)*WIN_GetFontWidth()/2;
pic=WIN_GetPic(home->pic_lock);
if(pic) WIN_DrawPic(pic,lock_x-lock_txt_len/2-2-pic->xsize,lock_y-pic->ysize/2,pic->xsize,pic->ysize);
WIN_SetLcdColor (color_bk);
WIN_DrawTxtHCenterAt(lock_txt,lock_x+1,lock_y-WIN_GetFontHight()/2+1);
WIN_SetLcdColor (color);
WIN_DrawTxtHCenterAt(lock_txt,lock_x,lock_y-WIN_GetFontHight()/2);
WIN_SetLcdColor (color_bk);
WIN_FillRectByColorAlpha(0,y_size-80,x_size,80,16);
WIN_SetLcdColor ((243<<16)|(152<<8));
WIN_SetFontSize(12);
int pic_x_step=x_size/4;
int pic_y=y_size-40;
y=pic_y;
pic=WIN_GetPic(home->pic_altitude);
char txt[20]={0};
if(pic)
{
x=pic_x_step/2;
sprintf(txt,"%.1fpa",home->pressure);
WIN_DrawTxtHCenterAt(txt,x,y-pic->ysize/2-WIN_GetFontHight()-2);
2025-07-05 19:47:28 +08:00
WIN_DrawTxtHCenterAt("<EFBFBD><EFBFBD>ѹ",x,y+pic->ysize/2+2);
2025-06-27 00:32:57 +08:00
WIN_DrawPic(pic,x-pic->xsize/2,pic_y-pic->ysize/2,pic->xsize,pic->ysize);
}
pic=WIN_GetPic(home->pic_pressure);
if(pic)
{
x=pic_x_step+pic_x_step/2;
sprintf(txt,"%dm",home->altitude);
WIN_DrawTxtHCenterAt(txt,x,y-pic->ysize/2-WIN_GetFontHight()-2);
2025-07-05 19:47:28 +08:00
WIN_DrawTxtHCenterAt("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>",x,y+pic->ysize/2+2);
2025-06-27 00:32:57 +08:00
WIN_DrawPic(pic,x-pic->xsize/2,pic_y-pic->ysize/2,pic->xsize,pic->ysize);
}
pic=WIN_GetPic(home->pic_heart);
if(pic)
{
x=pic_x_step*2+pic_x_step/2;
sprintf(txt,"%d",home->heart);
WIN_DrawTxtHCenterAt(txt,x,y-pic->ysize/2-WIN_GetFontHight()-2);
2025-07-05 19:47:28 +08:00
WIN_DrawTxtHCenterAt("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>",x,y+pic->ysize/2+2);
2025-06-27 00:32:57 +08:00
WIN_DrawPic(pic,x-pic->xsize/2,pic_y-pic->ysize/2,pic->xsize,pic->ysize);
}
pic=WIN_GetPic(home->pic_battery);
if(pic)
{
x=pic_x_step*3+pic_x_step/2;
sprintf(txt,"%d",home->electricity);
WIN_DrawTxtHCenterAt(txt,x,y-pic->ysize/2-WIN_GetFontHight()-2);
2025-07-05 19:47:28 +08:00
WIN_DrawTxtHCenterAt("<EFBFBD><EFBFBD><EFBFBD><EFBFBD>",x,y+pic->ysize/2+2);
2025-06-27 00:32:57 +08:00
WIN_DrawPic(pic,x-pic->xsize/2,pic_y-pic->ysize/2,pic->xsize,pic->ysize);
}
WIN_SetFontSize(font_type);
}
void LOCK_Updata(WIN_LockStruct *home)
{
int year,month,date;
int hour,min,sec;
int week;
date_rtc_get_date(&year,&month,&date);
week=date_get_week_by_day(year,month,date);
date_rtc_get_time(&hour,&min,&sec);
2025-07-05 19:47:28 +08:00
sprintf (home->date,"%02d<32><64>%02d<32><64> %s",month,date,g_week[week-1]);
2025-06-27 00:32:57 +08:00
sprintf (home->time,"%02d:%02d",hour,min);
WIN_SetInvalidWhenTop ((WIN_WindowStruct *)home);
get_pressure_altitude(&home->pressure,&home->altitude);
home->heart=get_heart_rate();
home->electricity=get_electricity();
}
2025-07-05 19:47:28 +08:00
//Ĭ<><C4AC><EFBFBD><EFBFBD>Ϣ<EFBFBD><CFA2><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2025-06-27 00:32:57 +08:00
void LOCK_DefaultMsgLoop (WIN_LockStruct *home,WIN_MsgStruct *msg)
{
WIN_KeyStruct *k=0;
WIN_MoveStruct *m;
switch (msg->msg)
{
case WIN_MSG_PAINT:
LOCK_DefaultPaint(home);
break;
case WIN_MSG_INIT:
{
}
break;
case WIN_MSG_TIMER:
if (msg->data.v==home->timerId)
{
LOCK_Updata(home);
}
break;
case WIN_MSG_CHID:
LOCK_TouchBord (home,msg);
break;
case WIN_MSG_KEY:
k=msg->data.p;
LOCK_KeyBord (home,k);
break;//case WIN_MSG_KEY:
case WIN_MSG_MOVE:
m=msg->data.p;
LOCK_TouchMove(home,m);
break;
default:
WIN_DefaultMsgLoop((WIN_WindowStruct *)home,msg);
break;
}
}
2025-07-05 19:47:28 +08:00
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
2025-06-27 00:32:57 +08:00
void LOCK_EnterLock(const char *path)
{
WIN_LockStruct *home=0;
WIN_WindowStruct *win=0;
if(win=WIN_GetWinByTitle(0,"lock"),win==0)
{
WIN_WindowStruct *base=WIN_GetWinByTitle(0,"home" );
home=WIN_CreatLock (base,0,0,0,base->x_size,base->y_size);
// home=WIN_CreatLock (base,0,0,0,320,240);
WIN_SetBackPicPath ((WIN_WindowStruct*)home,(char *)path);
WIN_SetWinTitle((WIN_WindowStruct*)home,"lock");
WIN_ShowWindow((WIN_WindowStruct*)home);
}
else
{
WIN_SetChidWinTop(win->baseWin,win);
WIN_ShowWindow(win);
}
}