227 lines
3.8 KiB
C
227 lines
3.8 KiB
C
|
#include "main.h"
|
||
|
#include "rtthread.h"
|
||
|
#include "mywin_demo.h"
|
||
|
#include "date.h"
|
||
|
#include "mywin_user_lock.h"
|
||
|
#include "nrf.h"
|
||
|
#include "bsp_init.h"
|
||
|
#include "stdlib.h"
|
||
|
|
||
|
volatile int32_t ITM_RxBuffer=ITM_RXBUFFER_EMPTY;
|
||
|
|
||
|
static void Touch_Task (void *p_arg);
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
//使用RTThread
|
||
|
|
||
|
void my_delay_ms(u32 ms)
|
||
|
{
|
||
|
rt_thread_delay (ms);
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
int main (void)
|
||
|
{
|
||
|
RTC_InitStruct rtc_init={0};
|
||
|
rtc_init.delay_ms=my_delay_ms;
|
||
|
RTC_InitNormal (&rtc_init);
|
||
|
bsp_init_all();
|
||
|
|
||
|
u8 ret=0;
|
||
|
static FATFS SD_FatFs; // 文件系统对象
|
||
|
ret=f_mount(&SD_FatFs,"0:",1);
|
||
|
|
||
|
SysFile_SetFileInit ();
|
||
|
|
||
|
void test_init(void);
|
||
|
test_init();
|
||
|
|
||
|
ALIGN(RT_ALIGN_SIZE)
|
||
|
static rt_uint8_t rt_gui_tack[40*1024]={0};
|
||
|
static struct rt_thread rt_gui_thread={0};
|
||
|
rt_thread_init (&rt_gui_thread,"gui_task",mywin_demo_test,0,rt_gui_tack,sizeof (rt_gui_tack),20,20);
|
||
|
rt_thread_startup(&rt_gui_thread);
|
||
|
|
||
|
ALIGN(RT_ALIGN_SIZE)
|
||
|
static rt_uint8_t rt_scan_tack[1024]={0};
|
||
|
static struct rt_thread rt_scan_thread={0};
|
||
|
rt_thread_init (&rt_scan_thread,"scan_task",Touch_Task,0,rt_scan_tack,sizeof (rt_scan_tack),2,20);
|
||
|
rt_thread_startup(&rt_scan_thread);
|
||
|
|
||
|
while (1)
|
||
|
{
|
||
|
my_delay_ms (1000);
|
||
|
if (SysFile_CheckAlarm()==1)
|
||
|
{
|
||
|
//发送闹钟时间到的消息
|
||
|
SysFile_StructType alarm;
|
||
|
alarm.structType=SYSFILE_TYPE_ALARM;
|
||
|
WIN_PlaceExtData (&alarm,sizeof (SysFile_StructType));
|
||
|
}
|
||
|
// printf ("memused:%.1f,%.1f,%.1f\r\n",mem_perused()/100.0,exmem_perused()/100.0,ccm_perused()/100.0);
|
||
|
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
static void creat_lock(void *ptr)
|
||
|
{
|
||
|
WIN_WindowStruct *win=WIN_GetCurrentWindow();
|
||
|
LOCK_EnterLock("0:/PIC/3.pic");
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
#define SEND_RIGHT 0x80
|
||
|
#define SEND_LEFT 0x40
|
||
|
#define SEND_DOWN 0x20
|
||
|
#define SEND_UP 0x10
|
||
|
#define SEND_START 0x08
|
||
|
#define SEND_SELECT 0x04
|
||
|
#define SEND_B 0x02
|
||
|
#define SEND_A 0x01
|
||
|
|
||
|
|
||
|
//把手柄键值转化为MYWIN的键值
|
||
|
const int keyTranslatTable[]=
|
||
|
{
|
||
|
SEND_UP,
|
||
|
KEY_VALUE_UP,
|
||
|
SEND_DOWN,
|
||
|
KEY_VALUE_DOWN,
|
||
|
SEND_SELECT,
|
||
|
KEY_VALUE_ENTER,
|
||
|
SEND_START,
|
||
|
KEY_VALUE_HOME,
|
||
|
SEND_B,
|
||
|
KEY_VALUE_DES,
|
||
|
SEND_A,
|
||
|
KEY_VALUE_LIGHT,
|
||
|
SEND_LEFT,
|
||
|
KEY_VALUE_LEFT,
|
||
|
SEND_RIGHT,
|
||
|
KEY_VALUE_RIGHT,
|
||
|
};
|
||
|
|
||
|
|
||
|
int getKeyMyWin (WIN_KeyStruct *k)
|
||
|
{
|
||
|
u8 key=0;
|
||
|
int mywin_key=0;
|
||
|
static int mywin_key_old=0;
|
||
|
key=USART3_GetKey();
|
||
|
for (int i=0;i<8;i++)
|
||
|
{
|
||
|
if (key&keyTranslatTable[i*2])
|
||
|
mywin_key|=keyTranslatTable[i*2+1];
|
||
|
}
|
||
|
if (mywin_key)
|
||
|
{
|
||
|
k->state=1;
|
||
|
k->key=mywin_key;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
k->key=mywin_key_old;
|
||
|
k->state=0;
|
||
|
}
|
||
|
mywin_key_old=mywin_key;
|
||
|
return key;
|
||
|
}
|
||
|
|
||
|
|
||
|
static void Touch_Task (void *p_arg)
|
||
|
{
|
||
|
(void)p_arg;
|
||
|
u8 key=0;
|
||
|
u8 key_state=0;
|
||
|
WIN_TouchStruct t={0};
|
||
|
WIN_KeyStruct k={0};
|
||
|
|
||
|
// 设置锁屏时间为5秒
|
||
|
SysFile_GetSysFile()->screenOffTime=15;
|
||
|
|
||
|
int screen_off_timer=0;
|
||
|
int key_shield_timer=0;
|
||
|
int key_press=0;
|
||
|
while(1)
|
||
|
{
|
||
|
//读取按键和触摸屏状态
|
||
|
Touch_Scan();
|
||
|
t.pressNum=Touch_GetState()->flag;
|
||
|
if (getKeyMyWin(&k)||t.pressNum)
|
||
|
{
|
||
|
screen_off_timer=0;ui_setScreenBackLightPower(1);
|
||
|
key_press=1;
|
||
|
}
|
||
|
else key_press=0;
|
||
|
if (t.pressNum)
|
||
|
{
|
||
|
t.x[0]=Touch_GetState()->x[0];
|
||
|
t.y[0]=Touch_GetState()->y[0];
|
||
|
LED1_ON;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
LED1_OFF;
|
||
|
}
|
||
|
|
||
|
//发送按键和触摸消息到GUI
|
||
|
if (key_shield_timer==0)
|
||
|
{
|
||
|
WIN_StorKeyStruct (&k);
|
||
|
WIN_StorTouchStruct (&t);
|
||
|
}
|
||
|
|
||
|
//自动熄屏超时
|
||
|
my_delay_ms (20);
|
||
|
if (SysFile_GetSysFile()->screenOffTime&&(SysFile_GetSysFile()->screenOffTime*1000<screen_off_timer))
|
||
|
{
|
||
|
ui_setScreenBackLightPower(0);
|
||
|
|
||
|
// 通知窗口线程调用函数
|
||
|
// WIN_RunInWindow("home",creat_lock,0);
|
||
|
key_shield_timer=1;
|
||
|
}
|
||
|
else
|
||
|
{
|
||
|
//在过了300ms并且按键和触屏没有按下时取消屏蔽
|
||
|
screen_off_timer+=20;
|
||
|
if ((screen_off_timer>300)&&key_press==0)
|
||
|
{
|
||
|
key_shield_timer=0;
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
/*--C语言库函数--*/
|
||
|
|
||
|
void exit(int err)
|
||
|
{
|
||
|
while(1);
|
||
|
}
|
||
|
|
||
|
int system(const char *cmd)
|
||
|
{
|
||
|
return 0;
|
||
|
}
|
||
|
|
||
|
|