Mplayer--touch.c

触摸屏程序

#include"main.h"

/*********定义三个宏,歌曲、模式、控制**********/
#define SONG    1;
#define MOD     2;
#define CONTORL 3;

char cmd[200]="loadfile ./song/the_dream_up.mp3";
int fp,voice=40,pic_flag=0,voice_flag,N=0;
SONGNAME *namehead;

/*******************************************/
//函数功能:显示歌取名字,打印在屏幕上
//参数: 	歌曲名链表的头指针
//返回值:	void
/********************************************/
void disp_song_name(SONGNAME *head){//显示歌曲名字
	int i;
	char *temp;
	SONGNAME *pa=head;
	TFT_File_Picture(windowHZ, 97, 289, "./picture/song_back.bmp", 1);
	for(i=0;i<8&&pa!=NULL;i++){
		temp=pa->songname+7;
		if(i==0)
			printHZ_color(windowHZ,temp,110,300+25*i);
		else
			printNAME(windowHZ,temp,110,300+25*i);
		pa=pa->next;
	}
}
/*******************************************/
//函数功能:判断触摸位置
//参数: 	触摸点的坐标(x,y)
//返回值:	void
/********************************************/
void judge_place(int x,int y){
	int place;
	char second[20];
	char *voice_table[6]={"./picture/voice0.bmp","./picture/voice1.bmp",
		"./picture/voice2.bmp","./picture/voice3.bmp",
		"./picture/voice4.bmp","./picture/voice5.bmp",};
	
	if(x>=741&&x<800&&y>=0&&y<=35){// 右上角的关机部位
		TFT_ClearWindow(windowHZ);
		execlp("poweroff","poweroff",NULL);
	}						
	
	if((x>=105&&x<380)&&(y>=300&&y<=460)){//歌曲栏
		place=SONG;
		SONGNAME *namecmd=namehead;
		printf("%d\n",place);
		char p[255]="loadfile ";
		int fp=open("./fifo_cmd",O_WRONLY);
		if(x>=110&&x<370&&y>=300&&y<325){		/*******1*********/
			while(namecmd!=NULL){
				if(namecmd->num==N){
					strcat(p,namecmd->songname);
					disp_song_name(namecmd);//歌曲名字显示
					break;
				}
				namecmd=namecmd->next;
			}
			strcat(p,"\n");
			write(fp,p,strlen(p));
			TFT_File_Picture(windowHZ, 400, 0, "./picture/lrc.bmp", 1);
			TFT_File_Picture(windowHZ, 25, 106, "./picture/title.bmp", 1);
		}
		if(x>=110&&x<370&&y>=325&&y<350){	/***********2***********/
			while(namecmd!=NULL){
				if(namecmd->num==(N+1)){
					N=N+1;
					strcat(p,namecmd->songname);
					disp_song_name(namecmd);//歌曲名字显示
					break;
				}
				namecmd=namecmd->next;
			}
			strcat(p,"\n");
			write(fp,p,strlen(p));
			TFT_File_Picture(windowHZ, 400, 0, "./picture/lrc.bmp", 1);
			TFT_File_Picture(windowHZ, 25, 106, "./picture/title.bmp", 1);
		}
		if(x>=110&&x<370&&y>=350&&y<375){	/*************3***********/
			while(namecmd!=NULL){
				if(namecmd->num==(N+2)){N=N+2;
				strcat(p,namecmd->songname);
				disp_song_name(namecmd);//歌曲名字显示
				break;
				}
				namecmd=namecmd->next;
			}
			strcat(p,"\n");
			write(fp,p,strlen(p));
			TFT_File_Picture(windowHZ, 400, 0, "./picture/lrc.bmp", 1);
			TFT_File_Picture(windowHZ, 25, 106, "./picture/title.bmp", 1);
		}
		if(x>=110&&x<370&&y>=375&&y<400){	/************4***********/
			while(namecmd!=NULL){
				if(namecmd->num==(N+3)){N=N+3;
				strcat(p,namecmd->songname);
				disp_song_name(namecmd);//歌曲名字显示
				break;
				}
				namecmd=namecmd->next;
			}
			strcat(p,"\n");
			write(fp,p,strlen(p));
			TFT_File_Picture(windowHZ, 400, 0, "./picture/lrc.bmp", 1);
			TFT_File_Picture(windowHZ, 25, 106, "./picture/title.bmp", 1);
		}
		if(x>=110&&x<370&&y>=400&&y<425){	/************5*********/
			while(namecmd!=NULL){
				if(namecmd->num==(N+4)){N=N+4;
				strcat(p,namecmd->songname);
				disp_song_name(namecmd);//歌曲名字显示
				break;
				}
				namecmd=namecmd->next;
			}
			strcat(p,"\n");
			write(fp,p,strlen(p));
			TFT_File_Picture(windowHZ, 400, 0, "./picture/lrc.bmp", 1);
			TFT_File_Picture(windowHZ, 25, 106, "./picture/title.bmp", 1);
		}
		if(x>=110&&x<370&&y>=425&&y<450){	/***********6***********/
			while(namecmd!=NULL){
				if(namecmd->num==(N+5)){N=N+5;
				strcat(p,namecmd->songname);
				disp_song_name(namecmd);//歌曲名字显示
				break;
				}
				namecmd=namecmd->next;
			}
			strcat(p,"\n");
			write(fp,p,strlen(p));
			TFT_File_Picture(windowHZ, 400, 0, "./picture/lrc.bmp", 1);
			TFT_File_Picture(windowHZ, 25, 106, "./picture/title.bmp", 1);
		}
		if(x>=110&&x<370&&y>=450&&y<475){	/************7**********/
			while(namecmd!=NULL){
				if(namecmd->num==(N+6)){N=N+6;
				strcat(p,namecmd->songname);
				disp_song_name(namecmd);//歌曲名字显示
				break;
				}
				namecmd=namecmd->next;
			}
			strcat(p,"\n");
			write(fp,p,strlen(p));
			TFT_File_Picture(windowHZ, 400, 0, "./picture/lrc.bmp", 1);
			TFT_File_Picture(windowHZ, 25, 106, "./picture/title.bmp", 1);
		}
		
	}
	//=====================歌曲模式==========================/
	else if((x>=20&&x<=380)&&(y>=260&&y<=280)){
		place=MOD;
		printf("%d\n",place);
	}
	//=====================歌曲控制==========================/
	else if((x>=20&&x<=375)&&(y>195&&y<=250)){//歌曲控制
		place=CONTORL;
		printf("%d\n",place);
		
		/*********按键的坐标********************/
		//	快退:(69,189)-(118,241)
		//	快进:(118,189)-(167,241)
		//	上一曲:(167,189)-(216,241)
		//	下一曲:(216,189)-(265,241)
		/****************************************/
		if(x>=20&&x<=69&&y>195&&y<=250){		//暂停键
			write(fp,"pause\n",strlen("pause\n"));
			if(voice_flag){
				TFT_File_Picture(windowHZ,265, 189, "./picture/voice.bmp", 1);
			}
			if(!pic_flag){
				pic_flag=~pic_flag;
				TFT_File_Picture(windowHZ, 20, 189, "./picture/11.bmp", 1);
			}
			else {
				pic_flag=~pic_flag;
				TFT_File_Picture(windowHZ, 20, 189, "./picture/1.bmp", 1);
			}
		}
		else if(x>69&&x<118&&y>195&&y<=250){	//快退
			write(fp,"seek -5\n",strlen("seek -5\n"));
			if(voice_flag){
				TFT_File_Picture(windowHZ,265, 189, "./picture/voice.bmp", 1);
			}
			TFT_File_Picture(windowHZ, 69, 189, "./picture/21.bmp", 1);
			if(!voice_flag){
				TFT_File_Picture(windowHZ,265, 189, "./picture/voice.bmp", 1);
			}
			TFT_File_Picture(windowHZ, 69, 189, "./picture/2.bmp", 1);
		}
		else if(x>118&&x<167&&y>195&&y<=250){	//快进
			write(fp,"seek 5\n",strlen("seek 5\n"));
			if(voice_flag){
				TFT_File_Picture(windowHZ,265, 189, "./picture/voice.bmp", 1);
			}
			TFT_File_Picture(windowHZ, 118, 189, "./picture/31.bmp", 1);
			if(!voice_flag){
				TFT_File_Picture(windowHZ,265, 189, "./picture/voice.bmp", 1);
			}
			TFT_File_Picture(windowHZ, 118, 189, "./picture/3.bmp", 1);
			
		}
		else if(x>167&&x<216&&y>195&&y<=250){	//上一曲
			N--;
			if(N<0)N=10;
			if(voice_flag){
				TFT_File_Picture(windowHZ,265, 189, "./picture/voice.bmp", 1);
			}
			TFT_File_Picture(windowHZ, 167, 189, "./picture/41.bmp", 1);
			SONGNAME *namecmd;
			if(N>10)N=0;
			if(!voice_flag){
				TFT_File_Picture(windowHZ,265, 189, "./picture/voice.bmp", 1);
			}
			char p[255]="loadfile ";
			namecmd=namehead;
			while(namecmd!=NULL){
				if(namecmd->num==N){
					strcat(p,namecmd->songname);
					disp_song_name(namecmd);//歌曲名字显示
					break;
				}
				namecmd=namecmd->next;
			}
			strcat(p,"\n");
			write(fp,p,strlen(p));
			TFT_File_Picture(windowHZ, 400, 0, "./picture/lrc.bmp", 1);
			TFT_File_Picture(windowHZ, 25, 106, "./picture/title.bmp", 1);
			TFT_File_Picture(windowHZ, 167, 189, "./picture/4.bmp", 1);
		}
		else if(x>216&&x<265&&y>195&&y<=250){	//下一曲
			N++;
			SONGNAME *namecmd;
			if(voice_flag){
				TFT_File_Picture(windowHZ,265, 189, "./picture/voice.bmp", 1);
			}
			if(N>10)N=0;
			TFT_File_Picture(windowHZ, 216, 189, "./picture/51.bmp", 1);
			if(!voice_flag){
				TFT_File_Picture(windowHZ,265, 189, "./picture/voice.bmp", 1);
			}
			char p[255]="loadfile ";
			namecmd=namehead;
			while(namecmd!=NULL){
				if(namecmd->num==N){
					strcat(p,namecmd->songname);
					disp_song_name(namecmd);//歌曲名字显示
					break;
				}
				namecmd=namecmd->next;
			}
			strcat(p,"\n");
			write(fp,p,strlen(p));
			TFT_File_Picture(windowHZ, 400, 0, "./picture/lrc.bmp", 1);
			TFT_File_Picture(windowHZ, 25, 106, "./picture/title.bmp", 1);
			TFT_File_Picture(windowHZ, 216, 189, "./picture/5.bmp", 1);
		}
		else if(x>=270&&x<=314&&y>195&&y<=250){//静音键
			
			if(voice_flag){
				voice_flag=~voice_flag;
				TFT_File_Picture(windowHZ,265, 189, "./picture/voice.bmp", 1);
				write(fp,"mute 0\n",strlen("mute 0\n"));
			}
			else {
				voice_flag=~voice_flag;
				TFT_File_Picture(windowHZ, 265, 189, "./picture/no_voice.bmp", 1);
				write(fp,"mute 1\n",strlen("mute 1\n"));
			}
		}
		
		else if(x>=314&&x<=375&&y>195&&y<=250){//调节音量
			
			voice=voice+20;
			if(voice_flag){
				TFT_File_Picture(windowHZ,265, 189, "./picture/voice.bmp", 1);
			}
			if(voice>100){
				voice=0;
				write(fp,"volume  0\n",strlen("volume  0\n"));
			}
			printf("voice= %d\n",voice);
			TFT_File_Picture(windowHZ, 314, 189, voice_table[voice/20], 1);
			if(voice==0)
				write(fp,"volume  0 1\n",strlen("volume  0 1\n"));
			if(voice==20)
				write(fp,"volume  20 1\n",strlen("volume  20 1\n"));
			if(voice==40)
				write(fp,"volume  40 1\n",strlen("volume  40 1\n"));
			if(voice==60)
				write(fp,"volume  60 1\n",strlen("volume  60 1\n"));
			if(voice==80)
				write(fp,"volume  80 1\n",strlen("volume  80 1\n"));
			if(voice==100)
				write(fp,"volume  100 1\n",strlen("volume  100 1\n"));
		}
		
	}
}

void *touch_screen(void *p){
	int x,y,up_down;
	CUR_VAL val_single;	
	//打开触摸屏设备文件
	int touch_fd = open_touch_dev("/dev/event1"); 
	
	x = val_single.current_x;
	y = val_single.current_y;
	up_down = val_single.key;
	
	namehead=readsongname();
	//voice=60;
	
	while(1){
		//the_next_song();
		//scond=time((time_t*) NULL);
		analysis_event_single(touch_fd, &val_single);//返回值为当前触摸点的坐标
		x = val_single.current_x;
		y = val_single.current_y;
		
		up_down = val_single.key;
		fp=open("./fifo_cmd",O_WRONLY);
		up_down=val_single.key;//按下,up_down为1
		if(up_down){
			usleep(100*1000);//去抖
			analysis_event_single(touch_fd, &val_single);
			up_down=val_single.key;//按下,up_down为1
			if(up_down){
				judge_place(x,y);
				
				while(up_down){//判断松手
					analysis_event_single(touch_fd, &val_single);
					up_down=val_single.key;
				}
			}
			
		}
		
	}
	
	
}


 

你可能感兴趣的:(Mplayer--touch.c)