先说一下我的做法吧,我用UCOSii写了两个任务,分别来放音乐播放程序和切换图片程序,这两个任务基本是从历程里移过来的,可以实现触屏(我在屏幕下方画了三个触屏感应区域模拟左右和暂停键)左右切换歌曲和暂停同时切换背景图片,本来是想用再建一个任务完成扫描到触屏就发送消息队列OSTaskQPost,结果OSTaskQPend不知道为什么接收不到消息,然后我就在音乐播放程序和切换图片程序都加了触屏扫描检测,我用while(tp_dev.sta&TP_PRES_DOWN)
{
tp_dev.scan(0);
delay_ms(10);
}来设置松手检测会导致只能切换歌曲图片就切换不了了,
有什么更好的办法么?学STM32一个多月了才弄了这么残次的小东西,代码几乎都是摘取例程里的,感觉已经费了我好大的劲,会不会很LOW啊?求鼓励啊,前辈们给点心得,我这样做会不会没有什么意义。。。
void led0_task(void *pdata) //音乐播放任务
{
tp_dev.init();
while(1)
{
POINT_COLOR=RED;
while(font_init())
{
LCD_ShowString(30,50,200,16,16,"Font Error!");
delay_ms(200);
LCD_Fill(30,50,240,66,WHITE);//Çå3yÏÔê¾
delay_ms(200);
}
while(1)
{
audio_play();
}
}
}
//LED1èÎÎñ
void led1_task(void *pdata) 图片显示任务
{
INT8U err;
u8 *p;
u16 d1;
u32 tem1,tem2;
u16 d2;
u32 tem3,tem4;
u16 d3;
u32 tem5,tem6;
u8 res;
DIR picdir; //í¼Æ¬Ä¿Â¼
FILINFO picfileinfo;//ÎļtDÅÏ¢
u8 *fn; //3¤ÎļtÃû
u8 *pname; //′ø·¾¶μÄÎļtÃû
u16 totpicnum; //í¼Æ¬Îļt×üêy
u16 curindex; //í¼Æ¬μ±Ç°Ë÷òy
u8 key; //¼üÖμ
u8 pause=0; //ÔYí£±ê¼Ç
u8 t;
u16 temp;
u16 *picindextbl; //í¼Æ¬Ë÷òy±í ¡¡
NVIC_PriorityGroupConfig(NVIC_PriorityGroup_2);//éèÖÃÏμí3ÖD¶ÏóÅÏ輶·Ö×é2
delay_init(168); //3õê¼»ˉÑóê±oˉêy
uart_init(115200); //3õê¼»ˉ′®¿ú2¨ìØÂêÎa115200
LED_Init(); //3õê¼»ˉLED
usmart_dev.init(84); //3õê¼»ˉUSMART
LCD_Init(); //LCD3õê¼»ˉ
KEY_Init(); //°′¼ü3õê¼»ˉ
tp_dev.init();//******************************************************
W25QXX_Init(); //3õê¼»ˉW25Q128
my_mem_init(SRAMIN); //3õê¼»ˉÄú2¿Äú′æ3Ø
my_mem_init(SRAMCCM); //3õê¼»ˉCCMÄú′æ3Ø
exfuns_init(); //ÎafatfsÏà1رäá¿éêÇëÄú′æ
f_mount(fs[0],"0:",1); //1òÔØSD¿¨
f_mount(fs[1],"1:",1); //1òÔØFLASH.
POINT_COLOR=RED; delay_ms(10);
while(font_init()) //¼ì2é×Ö¿a
{
LCD_ShowString(30,50,200,16,16,"Font Error!");
delay_ms(200);
LCD_Fill(30,50,240,66,WHITE);//Çå3yÏÔê¾
delay_ms(200);
}
Show_Str(30,50,200,16,"Explorer STM32F4¿a·¢°å",16,0);
Show_Str(30,70,200,16,"í¼Æ¬ÏÔê¾3ìDò",16,0);
Show_Str(30,90,200,16,"KEY0:NEXT KEY1
REV",16,0);
Show_Str(30,110,200,16,"WK_UP
AUSE",16,0);
Show_Str(30,130,200,16,"ÕyμãÔ-×ó@ALIENTEK",16,0);
Show_Str(30,150,200,16,"2014Äê5ÔÂ15èÕ",16,0);
while(f_opendir(&picdir,"0:/PICTURE"))//′ò¿aí¼Æ¬Îļt¼D
{
Show_Str(30,170,240,16,"
ICTUREÎļt¼D′íÎó!",16,0);
delay_ms(200);
LCD_Fill(30,170,240,186,WHITE);//Çå3yÏÔê¾
delay_ms(200);
}
totpicnum=pic_get_tnum("0:/PICTURE"); //μÃμ½×üóDD§Îļtêy
while(totpicnum==NULL)//í¼Æ¬ÎļtÎa0
{
Show_Str(30,170,240,16,"ûóDí¼Æ¬Îļt!",16,0);
delay_ms(200);
LCD_Fill(30,170,240,186,WHITE);//Çå3yÏÔê¾
delay_ms(200);
}
picfileinfo.lfsize=_MAX_LFN*2+1; //3¤ÎļtÃû×î′ó3¤¶è
picfileinfo.lfname=mymalloc(SRAMIN,picfileinfo.lfsize); //Îa3¤Îļt»o′æÇø·ÖÅäÄú′æ
pname=mymalloc(SRAMIN,picfileinfo.lfsize); //Îa′ø·¾¶μÄÎļtÃû·ÖÅäÄú′æ
picindextbl=mymalloc(SRAMIN,2*totpicnum); //éêÇë2*totpicnum¸ö×Ö½úμÄÄú′æ,óÃóú′æ·Åí¼Æ¬Ë÷òy
while(picfileinfo.lfname==NULL||pname==NULL||picindextbl==NULL)//Äú′æ·ÖÅä3ö′í
{
Show_Str(30,170,240,16,"Äú′æ·ÖÅä꧰ü!",16,0);
delay_ms(200);
LCD_Fill(30,170,240,186,WHITE);//Çå3yÏÔê¾
delay_ms(200);
}
//¼Ç¼Ë÷òy
res=f_opendir(&picdir,"0:/PICTURE"); //′ò¿aĿ¼
if(res==FR_OK)
{
curindex=0;//μ±Ç°Ë÷òyÎa0
while(1)//è«2¿2éÑˉò»±é
{
temp=picdir.index; //¼Ç¼μ±Ç°index
res=f_readdir(&picdir,&picfileinfo); //¶áè¡Ä¿Â¼ÏÂμÄò»¸öÎļt
if(res!=FR_OK||picfileinfo.fname[0]==0)break; //′íÎóáË/μ½Ä©Î2áË,íË3ö
fn=(u8*)(*picfileinfo.lfname?picfileinfo.lfname:picfileinfo.fname);
res=f_typetell(fn);
if((res&0XF0)==0X50)//衸ßËÄλ,¿′¿′êÇ2»êÇí¼Æ¬Îļt
{
picindextbl[curindex]=temp;//¼Ç¼Ë÷òy
curindex++;
}
}
}
Show_Str(30,170,240,16,"¿aê¼ÏÔê¾...",16,0);
delay_ms(1500);
piclib_init(); //3õê¼»ˉ»-í¼
curindex=0; //′ó0¿aê¼ÏÔê¾
res=f_opendir(&picdir,(const TCHAR*)"0:/PICTURE"); //′ò¿aĿ¼
//tp_dev.init();
while(res==FR_OK)//′ò¿a3é1|
{
dir_sdi(&picdir,picindextbl[curindex]); //¸Ä±äμ±Ç°Ä¿Â¼Ë÷òy
res=f_readdir(&picdir,&picfileinfo); //¶áè¡Ä¿Â¼ÏÂμÄò»¸öÎļt
if(res!=FR_OK||picfileinfo.fname[0]==0)break; //′íÎóáË/μ½Ä©Î2áË,íË3ö
fn=(u8*)(*picfileinfo.lfname?picfileinfo.lfname:picfileinfo.fname);
strcpy((char*)pname,"0:/PICTURE/"); //¸′ÖÆ·¾¶(Ŀ¼)
strcat((char*)pname,(const char*)fn); //½«ÎļtÃû½óÔúoóÃæ
LCD_Clear(BLACK);
ai_load_picfile(pname,0,0,lcddev.width,lcddev.height,1);//ÏÔê¾í¼Æ¬
Show_Str(2,2,240,16,pname,16,1); //ÏÔê¾í¼Æ¬Ãû×Ö
t=0;
while(1)
{
if(key==WKUP_PRES) //°′ÏÂ,ÔòÖ′DDD£×¼3ìDò
{
LCD_Clear(WHITE); //ÇåÆá
TP_Adjust(); //ÆáÄ»D£×¼
TP_Save_Adjdata();
}
tp_dev.scan(0);
if(tp_dev.sta&TP_PRES_DOWN) //′¥ÃtÆá±»°′ÏÂ
{
delay_ms(10);
tem1=abs(tp_dev.x[0]-30);//x1-x2
tem2=abs(tp_dev.y[0]-450);//y1-y2
tem1*=tem1;
tem2*=tem2;
d1=sqrt(tem1+tem2);
tem3=abs(tp_dev.x[0]-290);//x1-x2
tem4=abs(tp_dev.y[0]-450);//y1-y2
tem3*=tem3;
tem4*=tem4;
d2=sqrt(tem3+tem4);
tem5=abs(tp_dev.x[0]-160);//x1-x2
tem6=abs(tp_dev.y[0]-450);//y1-y2
tem5*=tem5;
tem6*=tem6;
d3=sqrt(tem5+tem6);
if(tp_dev.x[0]<=80)
{
if(d1<=30)
{
key=KEY2_PRES;
if(curindex)curindex--;
else curindex=totpicnum-1;
break;
}
}
else if(tp_dev.x[0]>=240)
{
if(d2<=30)
{
key=KEY0_PRES;
curindex++;
if(curindex>=totpicnum)curindex=0;//μ½Ä©Î2μÄê±oò,×Ô¶ˉ′óí·¿aê¼
break;
}
}
// else
// {
// if(d3<=30)
// {
// key=WKUP_PRES;
// }
// }
}
delay_ms(10);
}
res=0;
}
myfree(SRAMIN,picfileinfo.lfname); //êí·ÅÄú′æ
myfree(SRAMIN,pname); //êí·ÅÄú′æ
myfree(SRAMIN,picindextbl); //êí·ÅÄú′æ
}[/mw_shl_code]
一周热门 更多>