295 lines
8.8 KiB
C
295 lines
8.8 KiB
C
#include "mywin_user_lock.h"
|
|
#include "date.h"
|
|
#include "math.h"
|
|
#include "mywin_inc.h"
|
|
#include "random.h"
|
|
|
|
// 标准大气压
|
|
#define PA 101325.0f
|
|
|
|
// 获取海拔气压
|
|
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;
|
|
}
|
|
|
|
// 获取心率
|
|
static int get_heart_rate(void) { return 70 + RANDOM_Get() % 50; }
|
|
|
|
// 获取电量
|
|
static int get_electricity(void) { return 50 + RANDOM_Get() % 50; }
|
|
|
|
static const char *g_week[7] = {"星期一", "星期二", "星期三", "星期四",
|
|
"星期五", "星期六", "星期天"};
|
|
|
|
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) {
|
|
// 重设消息循环
|
|
if (msgLoop == 0) {
|
|
msgLoop = (void (*)(struct _WIN_WindowStruct *win,
|
|
WIN_MsgStruct *msg))LOCK_DefaultMsgLoop;
|
|
}
|
|
|
|
WIN_LockStruct *ret = mymalloc(sizeof(WIN_LockStruct));
|
|
// 调用父类的构造函数
|
|
if (ret) {
|
|
mymemset(ret, 0, sizeof(WIN_LockStruct));
|
|
if (0 == WIN_CreatTouchEx((WIN_TouchWinStruct *)ret, base, msgLoop, x, y,
|
|
x_size, y_size)) {
|
|
// 创建失败
|
|
myfree(ret);
|
|
ret = 0;
|
|
} else {
|
|
// 构造一个
|
|
((WIN_WindowStruct *)ret)->winType = "WIN_LockStruct";
|
|
((WIN_WindowStruct *)ret)->intercept = 1; // 不发送按键消息到父窗口
|
|
((WIN_WindowStruct *)ret)->bkcolor = 0;
|
|
((WIN_WindowStruct *)ret)->color = 0xd7c1ac;
|
|
ret->color1 = 0x7d7064;
|
|
ret->timerId = WIN_CreatTimer((WIN_WindowStruct *)ret, 1000);
|
|
}
|
|
}
|
|
|
|
ret->pic_altitude = "0:/png/lock/锁屏-海拔.png";
|
|
ret->pic_pressure = "0:/png/lock/锁屏-气压.png";
|
|
ret->pic_heart = "0:/png/lock/锁屏-心率.png";
|
|
ret->pic_battery = "0:/png/lock/锁屏-电量.png";
|
|
ret->pic_lock = "0:/png/lock/锁屏-锁.png";
|
|
LOCK_Updata(ret);
|
|
|
|
return ret;
|
|
}
|
|
|
|
// 按键消息处理函数
|
|
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) {
|
|
// 记录释放一个按键
|
|
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) {
|
|
// 记录释放一个按键
|
|
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)) {
|
|
// 记录两个按键同时按下
|
|
home->lock_relieve = KEY_VALUE_ENTER | KEY_VALUE_HOME;
|
|
}
|
|
return 0;
|
|
}
|
|
|
|
// 处理触屏消息
|
|
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;
|
|
}
|
|
|
|
// 触屏移动消息
|
|
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;
|
|
}
|
|
|
|
// 默认绘制函数
|
|
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);
|
|
uint32_t font_type = WIN_SetFontSize(10);
|
|
uint32_t color_bk = ((WIN_WindowStruct *)home)->bkcolor;
|
|
uint32_t color = ((WIN_WindowStruct *)home)->color;
|
|
|
|
// 显示日期
|
|
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);
|
|
|
|
// 显示时间
|
|
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);
|
|
|
|
// 显示锁屏字符
|
|
WIN_PicStruct *pic = 0;
|
|
int lock_y = y_size / 2;
|
|
int lock_x = x_size / 2;
|
|
char *lock_txt = "同时按下确定返回键解锁";
|
|
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);
|
|
WIN_DrawTxtHCenterAt("气压", x, y + pic->ysize / 2 + 2);
|
|
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);
|
|
WIN_DrawTxtHCenterAt("海拔", x, y + pic->ysize / 2 + 2);
|
|
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);
|
|
WIN_DrawTxtHCenterAt("心率", x, y + pic->ysize / 2 + 2);
|
|
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);
|
|
WIN_DrawTxtHCenterAt("电量", x, y + pic->ysize / 2 + 2);
|
|
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);
|
|
sprintf(home->date, "%02d月%02d日 %s", month, date, g_week[week - 1]);
|
|
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();
|
|
}
|
|
|
|
// 默认消息处理函数
|
|
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;
|
|
}
|
|
}
|
|
|
|
// 进入锁屏界面
|
|
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);
|
|
}
|
|
}
|