当用户进入到系统主界面之后,能够使用触摸屏来实现智能家居功能模块的切换以及选择,控制家庭娱乐相册的显示切换上下图像,切换音频播放,切换视频播放。整个项目综合运用了目前主流的嵌入式开发技术,包括linux驱动,音视频开发等等。
#include <stdio.h>//fopen
#include <errno.h>//perror
#include <stdlib.h>//exit
#include <sys/types.h>//open
#include <sys/stat.h>//open
#include <fcntl.h>//open
#include <sys/mman.h>//mmap
#include <linux/input.h>//struct input event
#include <stdlib.h>
#include <strings.h>
int fd_event0 = 0;
char video_path[100]="/root/smart_home/video_file/1.avi";
char audio_path[100]="/root/smart_home/audio_file/1.mp3";
int flag=0;
int open_touch_screen(void);
int close_touch_screen(void);
int read_touch_screen_information(int *x, int *y);
int S5P6818_bmp_24_800_480(const char *path);
int picture_system(void);
int main_system(void);
int pic_circular_spread_right(char *pathname);
int video_system(void);
int audio_system(void);
int play(char *mp3path, int select);
int stop(int select);
int cont(int select);
int quit(int select);
int next(int select);
int last(int select);
int back(void);
int main(int argc, char *argv[])
{
main_system();
return 0;
}
int main_system(void)
{
int get_x=0, get_y=0;
char bmp_path[100]="/root/smart_home/images/jiemian.bmp";
S5P6818_bmp_24_800_480(bmp_path);
open_touch_screen();
while(1)
{
read_touch_screen_information(&get_x, &get_y);
printf("(x,y):(%d,%d)\n", get_x, get_y);
if(get_x>=640&&get_x<=760&&get_y>=35&&get_y<=130){
picture_system();
}
else if(get_x>=640&&get_x<=760&&get_y>=195&&get_y<=295){
video_system();
}
else if(get_x>=640&&get_x<=760&&get_y>=300&&get_y<=455)
{
audio_system();
}
else{
printf("============\n");
}
}
close_touch_screen();
}
int picture_system(void)
{
int get_x=0, get_y=0;
char bmp_path[100]="/root/smart_home/images/001.bmp";
S5P6818_bmp_24_800_480(bmp_path);
open_touch_screen();
while(1)
{
read_touch_screen_information(&get_x, &get_y);
printf("(x,y):(%d,%d)\n", get_x, get_y);
if(get_x>=0&&get_x<=310&&get_y>45&&get_y<=480){
bmp_path[26]=bmp_path[26]-1;
if(bmp_path[26]== '0'){
bmp_path[26]= '9';
}
pic_circular_spread_right(bmp_path);
}
else if(get_x>=500&&get_x<=775&&get_y>45&&get_y<=480){
bmp_path[26]=bmp_path[26]+1;
if(bmp_path[26]=='9'){
bmp_path[26]='0';
}
pic_circular_spread_right(bmp_path);
}
else if(get_x>755&&get_x<=800&&get_y>=0&&get_y<=45){
back();
}
else
{
printf("=============\n");
}
}
close_touch_screen();
}
int video_system(void)
{
int ts_x, ts_y;
int get_x=0, get_y=0;
char bmp_path[100]="/root/smart_home/images/video.bmp";
S5P6818_bmp_24_800_480(bmp_path);
open_touch_screen();
while(1)
{
read_touch_screen_information(&get_x, &get_y);
printf("(x,y):(%d,%d)\n", get_x, get_y);
if(get_x>=290&&get_x<=480&&get_y>=300&&get_y<=480&&flag==0){
printf("====play======\n");
play(video_path,1);
}
else if(get_x>=290&&get_x<=480&&get_y>=300&&get_y<=480&&flag==1){
printf("====stop======\n");
stop(1);
}
else if(get_x>=290&&get_x<=480&&get_y>=300&&get_y<=480&&flag==2){
printf("====continue======\n");
cont(1);
}
else if(get_x>=200&&get_x<290&&get_y>=300&&get_y<=480){
printf("====last======\n");
last(1);
}
else if(get_x>510&&get_x<=610&&get_y>=300&&get_y<=480){
printf("====next======\n");
next(1);
}
else if(get_x>700&&get_x<=780&&get_y>=390&&get_y<=480){
quit(1);
back();
}
else{
printf("=============\n");
}
}
close_touch_screen();
}
int audio_system(void)
{
int ts_x, ts_y;
int get_x=0, get_y=0;
char bmp_path[100]="/root/smart_home/images/music.bmp";
S5P6818_bmp_24_800_480(bmp_path);
open_touch_screen();
while(1)
{
read_touch_screen_information(&get_x, &get_y);
printf("(x,y):(%d,%d)\n", get_x, get_y);
if(get_x>=370&&get_x<=440&&get_y>=390&&get_y<=480&&flag==0){
printf("====play======\n");
play(audio_path,2);
}
else if(get_x>=370&&get_x<=440&&get_y>=390&&get_y<=480&&flag==1){
printf("====stop======\n");
stop(2);
}
else if(get_x>=370&&get_x<=440&&get_y>=390&&get_y<=480&&flag==2){
printf("====continue======\n");
cont(2);
}
else if(get_x>=290&&get_x<350&&get_y>=390&&get_y<=480){
printf("====last======\n");
last(2);
}
else if(get_x>460&&get_x<=520&&get_y>=390&&get_y<=480){
printf("====next======\n");
next(2);
}
else if(get_x>755&&get_x<=800&&get_y>=0&&get_y<=45){
quit(2);
back();
}
else{
printf("================\n");
}
}
close_touch_screen();
}
int back(void)
{
flag=0;
main_system();
return 0;
}
int play(char *mp3path, int select)
{
char cmd[100]={0};
switch(select)
{
case 1:
sprintf(cmd," mplayer %s -zoom -x 800 -y 385 &",video_path);
break;
case 2:
sprintf(cmd," madplay %s &",audio_path);
break;
default:
break;
}
printf("%s\n", cmd);
system(cmd);
flag=1;
return 0;
}
int stop(int select)
{
switch(select)
{
case 1:
system("killall -STOP mplayer");
break;
case 2:
system("killall -STOP madplay");
break;
default:
break;
}
flag=2;
return 0;
}
int cont(int select)
{
switch(select)
{
case 1:
system("killall -CONT mplayer");
break;
case 2:
system("killall -CONT madplay");
break;
default:
break;
}
flag=1;
return 0;
}
|