一、需求分析 智能家居系统是一种近年来兴起的智能化系统,在家庭场合基本都能看到它的身影,各种家居通过一个智能控制终端来进行人机交互。本课题基于粤嵌GEC-6818开发平台,定制的Linux系统,通过C语言的编程,经过交叉编译环境,让编译的文件能够直接适用于ARM开发板。用7寸LCD电容式触摸屏作为人机互交的方式,做到可以LED控制、液晶屏检测、报警控制、电子相册、音乐播放、视频播放器、的功能,显示相应的界面。具有音频输出的功能,获取屏幕触摸点的坐标,实现界面上相应的功能。 本次为智能家居项目的进阶设计,在此基础上加入了zigbee温度采集,滑动控制,手势识别模块PAJ7620U2进行人机交互,UDP通信等。进一步加强了本人的中型工程的整合能力。 通过这次的设计,掌握了ARM的结构体系,了解了部分的Linux命令,对文件的读写操作等,初步掌握了交叉编译方式,加强了对嵌入式产品的认知。同时,在本课程设计时的调试、排错,让我们对C语言进行了一次查漏补缺,也巩固了C语言基础。让我们能够用团队的力量,对ARM系列的开发板进行开发,用固定的硬件设备实现多种功能,了解ARM开发的文件读取方式、交叉编译环境。扩大了我们的眼界,学会了无显示界面时使用Linux命令操作设备。
二、功能设计 1、实现液晶屏显示界面 2、电子相册功能-可以触屏控制相册的浏览也可以手势控制相册的浏览、滑屏控制(拓展(触屏):顺序播放和随机播放相片),也可以在相册中添加图片和册删除图片 3、MP3播放器功能-可以触屏控制音乐的播放、暂停、播放上一首、播放下一首;滑屏控制播放上一首、播放下一首;同时可以手势控制 4、视频播放器功能 -①触屏控制视频的播放、暂停、快进、快退、调节音量+- 、静音;同时可以手势控制 -②滑屏控制快进、快退;③同时使用手势控制 (拓展(触屏):播放下一个上一个视频,可以顺序播放和随机播放) 5、通过串口与zigbee进行通信,能够通过zigbee检测温湿度并把温湿度数据传输给开发板,并且当温度高于一定阈值使得板载蜂鸣器响,同时可以手势控制 6、可以通过开发板对另一个开发板进行操作(UDP通信),同时可以手势控制
三、运行结果及分析(图片多为gif图,加载可能会缓慢 ) 1、电子相册功能-可以触屏控制相册的浏览也可以手势控制相册的浏览、滑屏控制(拓展(触屏):顺序播放和随机播放相片),也可以在相册中添加图片和册删除图片
2、MP3播放器功能与视频播放器功能-仅做视频演示,因为均是同Mplayer实现。
程序运行效果如上,功能正常,屏幕内容完美显示。 3、通过串口与zigbee进行通信,能够通过zigbee检测温湿度并把温湿度数据传输给开发板,并且当温度高于一定阈值使得板载蜂鸣器响,同时可以手势控制
4、可以通过开发板对另一个开发板进行操作(UDP通信),同时可以手势控制
附录:项目核心源程序 从机程序: IAR(zigbee):
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 #include <ioCC2530.h> #include "DHT11.h" #include <stdlib.h> #define YLED P1_1 #define BLED P1_0 #define BUT P1_2 #define DHT11 P0_4 #define LEDCLOSE 0 #define LEDOPEN 1 char RxBuf;char Rx_flag; unsigned char s1[6 ]="te" ; void uart0_send_string (unsigned char *p, int len) ;void delay_time (unsigned int n) { unsigned int i; for (i=0 ; i<n; i++); } void delay_us (unsigned int n) { unsigned int i; for (i=0 ; i<n; i++) { asm ("NOP" ); asm ("NOP" ); asm ("NOP" ); } } void delay_ms (unsigned int n) { while (n--) { delay_us(1000 ); } } void init_led () { P1SEL &= 0 ; P1DIR |= 3 ; BLED=LEDCLOSE; YLED=LEDCLOSE; } void init_key () { P1SEL &= ~0x4 ; P1DIR &= ~0x4 ; P1INP &= ~0x4 ; } void init_key_INT () { P1IEN |= 0x4 ; PICTL |= 0x2 ; P1IFG = 0 ; IEN2 = 0x10 ; EA = 1 ; } #pragma vector = P1INT_VECTOR __interrupt void P1_ISR (void ) { YLED=!YLED; int t=55 ; int h=99 ; s1[0 ]=t/10 +'0' ; s1[1 ]=t%10 +'0' ; s1[2 ]='\n' ; s1[3 ]=h/10 +'0' ; s1[4 ]=h%10 +'0' ; s1[5 ]='\n' ; while (!BUT) { uart0_send_string(s1,6 ); BLED=!BLED; delay_ms(100 ); BLED=!BLED; delay_ms(100 ); } P1IFG=0 ; P1IF=0 ; } void init_clock () { CLKCONCMD &= ~0x40 ; while (CLKCONSTA & 0x40 ); CLKCONCMD &= ~0x47 ; } void init_uart0 () { PERCFG &= ~0x01 ; P0SEL |= 0x0c ; U0CSR |= 0x80 ; U0GCR |= 11 ; U0BAUD |= 216 ; U0UCR |= 0x80 ; U0CSR |= 0X40 ; UTX0IF = 0 ; URX0IF = 0 ; URX0IE = 1 ; EA=1 ; } #pragma vector = URX0_VECTOR __interrupt void URX0_ISR () { URX0IF = 0 ; RxBuf = U0DBUF; Rx_flag = 1 ; Rx_flag=0 ; switch (RxBuf) { case 'o' : BLED = 1 ; break ; case 'p' : BLED = 0 ; break ; } BLED=!BLED; delay_ms(100 ); BLED=!BLED; delay_ms(100 ); } void uart0_send_char (unsigned char data) { U0DBUF = data; while (UTX0IF == 0 ); UTX0IF = 0 ; } void uart0_send_string (unsigned char *p, int len) { int i; for (i=0 ; i<len; i++) { U0DBUF = *p; p++; while (UTX0IF == 0 ); UTX0IF = 0 ; } } unsigned char DHT11_ReadByte (void ) { unsigned char bit_value; unsigned char value=0 ; unsigned char count; for (count=0 ;count<8 ;count++) { if (!DHT11) { while (!DHT11); delay_us(30 ); if (DHT11) bit_value = 1 ; else bit_value = 0 ; } value <<= 1 ; value |= bit_value; while (DHT11); } return value; } int DHT11_Read (unsigned char *pTemp,unsigned char *pHum) { P0SEL &= ~(0x1 << 4 ); P0DIR |= (0x1 << 4 ); DHT11 = 0 ; delay_ms(19 ); DHT11 = 1 ; P0DIR |= (0x1 << 4 ); while (DHT11); if (!DHT11) { while (!DHT11); while (DHT11); *pHum = DHT11_ReadByte(); DHT11_ReadByte(); *pTemp = DHT11_ReadByte(); DHT11_ReadByte(); DHT11_ReadByte(); DHT11 = 1 ; } return 1 ; } void main () { unsigned char tem; unsigned char hum; int t; int h; init_clock(); init_led(); init_key(); init_key_INT(); init_uart0(); while (1 ) { YLED=!YLED; DHT11_Read(&tem,&hum); t=(int )tem; s1[0 ]=t/10 +'0' ; s1[1 ]=t%10 +'0' ; s1[2 ]='\n' ; h=(int )hum; s1[3 ]=h/10 +'0' ; s1[4 ]=h%10 +'0' ; s1[5 ]='\n' ; uart0_send_string(s1,6 ); if (t>32 ) { BLED=!BLED; delay_ms(100 ); BLED=!BLED; delay_ms(100 ); BLED=!BLED; delay_ms(100 ); BLED=!BLED; delay_ms(100 ); } t=0 ; h=0 ; delay_ms(1500 ); } }
udpre.c
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 #include <stdio.h> #include <sys/socket.h> #include <sys/types.h> #include <netinet/in.h> #include <arpa/inet.h> #include <string.h> #include <fcntl.h> #include <unistd.h> #include <malloc.h> #include <stdio.h> #include <sys/stat.h> #include <linux/input.h> #include <stdlib.h> #define LED1 7 #define LED2 8 #define LED3 9 #define LED4 10 #define LED_ON 1 #define LED_OFF 2 #define OWNADDR "10.12.94.159" #define OWNPORT 10000 #define SERVERADDR "10.12.94.249" #define SERVERPORT 20000 int led_ctrl (unsigned char led_num, unsigned char led_state) { int led_fd; led_fd = open("/dev/led_drv" ,O_RDWR); if (led_fd == -1 ) { perror("open led failed" ); return -1 ; } char led_buf[2 ]; led_buf[1 ]=led_num;led_buf[0 ]=led_state; write(led_fd, led_buf, 2 ); close(led_fd); return 0 ; } int main () { int socketfd = socket(AF_INET,SOCK_DGRAM,0 ); if (socketfd == -1 ) { printf ("socketfd error\n" ); return -1 ; } struct sockaddr_in ownAddr ; ownAddr.sin_family = AF_INET; ownAddr.sin_port = htons(OWNPORT); ownAddr.sin_addr.s_addr = inet_addr(OWNADDR); bind(socketfd,(struct sockaddr *)&ownAddr,sizeof (struct sockaddr_in)); struct sockaddr_in otherAddr ; int len = sizeof (struct sockaddr_in); while (1 ) { sleep(1 ); char buf[1024 ]={0 }; int ret = recvfrom(socketfd,buf,sizeof (buf),0 , (struct sockaddr *)&otherAddr,&len); if (ret <=0 ) break ; switch (buf[0 ]) { case 'a' : led_ctrl(LED1,LED_ON); break ; case 'b' : led_ctrl(LED2,LED_ON); break ; case 'c' : led_ctrl(LED3,LED_ON); break ; case 'd' : led_ctrl(LED4,LED_ON); break ; case 'e' : led_ctrl(LED1,LED_OFF); break ; case 'f' : led_ctrl(LED2,LED_OFF); break ; case 'g' : led_ctrl(LED3,LED_OFF); break ; case 'h' : led_ctrl(LED4,LED_OFF); break ; default : break ; } printf ("com[%s]:[%u]:%s\n" ,inet_ntoa(otherAddr.sin_addr),ntohs(otherAddr.sin_port),buf); } close(socketfd); return 0 ; }
gec6818主机程序(写的比较匆忙,总共用时3天,运用了很多flag,还没做代码优化,仅供参考):
beep跟led的程序请参考上一篇博客:https://jasblog.top/posts/10006/
main.c
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 #include <stdio.h> #include <stdlib.h> #include <time.h> #include "arm_serial.h" #include "touch.h" #include "lcd.h" #include "pthread.h" #include "font.h" #include "beep.h" #include "video.h" #include "dir.h" #include "photo.h" #include "music.h" #include "dht11usart.h" #include "gesture.h" #include "udp.h" #define MAIN 0 #define PHOTO 1 #define UDP 4 #define HUMITURE 5 void *gs_catch_pthread (void *arg) { while (1 ) { if (mode == MAIN) { if (gs == Up || IIC_gs == Up) { gs=0 ; IIC_gs=0 ; mode = PHOTO; } if (gs == Down || IIC_gs == Down) { gs=0 ; IIC_gs=0 ; mode = VIDEO; } if (gs == Left || IIC_gs == Left) { gs=0 ; IIC_gs=0 ; mode = MUSIC; } if (gs == Right || IIC_gs == Right) { gs=0 ; IIC_gs=0 ; mode = UDP; } if (IIC_gs == Wave) { mode == HUMITURE; IIC_gs=0 ; Humiture_control(); printf ("HUMITURE open!\n" ); } } if (mode == PHOTO) { if (gs == Up || IIC_gs == Up) { delflag=1 ; gs=0 ; IIC_gs=0 ; } if (gs == Down || IIC_gs == Down) { gs=0 ; IIC_gs=0 ; printf ("photo close!\n" ); mode=MAIN; lcd_show_bmp("ui/main.bmp" ); } if (gs == Left || IIC_gs == Left) { IIC_gs=0 ; gs=0 ; pic_flag++; if (pic_flag > num) { pic_flag = num; printf ("Last picture!\n" ); } else printf ("Next picture\n" ); } if (gs == Right || IIC_gs == Right) { gs=0 ; IIC_gs=0 ; pic_flag--; if (pic_flag < 0 ) { printf ("First picture!\n" ); pic_flag=0 ; } else printf ("Prev picture\n" ); } if (IIC_gs == Wave) { loopflag = 1 ; IIC_gs=0 ; } if (IIC_gs == Forward) { addflag = 1 ; IIC_gs=0 ; } } if (mode == VIDEO) { if (gs == Up || IIC_gs == Up) { gs=0 ; IIC_gs=0 ; } if (gs == Down || IIC_gs == Down) { gs=0 ; printf ("video close!\n" ); mode=MAIN; lcd_show_bmp("ui/main.bmp" ); IIC_gs=0 ; } if (gs == Left || IIC_gs == Left) { gs=0 ; IIC_gs=0 ; videonextflag=1 ; } if (gs == Right || IIC_gs == Right) { gs=0 ; IIC_gs=0 ; videopreflag=1 ; } if (IIC_gs == Wave) { IIC_gs=0 ; videospflag=2 ; } if (IIC_gs == Forward) { IIC_gs=0 ; videospflag=1 ; } } if (mode == MUSIC) { if (gs == Up || IIC_gs == Up) { gs=0 ; IIC_gs=0 ; } if (gs == Down || IIC_gs == Down) { gs=0 ; IIC_gs=0 ; printf ("photo close!\n" ); mode=MAIN; lcd_show_bmp("ui/main.bmp" ); } if (gs == Left || IIC_gs == Left) { gs=0 ; IIC_gs=0 ; musicnextflag=1 ; } if (gs == Right || IIC_gs == Right) { gs=0 ; IIC_gs=0 ; musicpreflag=1 ; } if (IIC_gs == Forward) { IIC_gs=0 ; musicspflag=1 ; } } if (mode == UDP) { if (gs == Up || IIC_gs == Up) { gs=0 ; IIC_gs=0 ; } if (gs == Down || IIC_gs == Down) { gs=0 ; IIC_gs=0 ; printf ("UDP close!\n" ); mode=MAIN; lcd_show_bmp("ui/main.bmp" ); } if (gs == Left || IIC_gs == Left) { gs=0 ; IIC_gs=0 ; open_serial(); send_char('p' ); close_serial(); } if (gs == Right || IIC_gs == Right) { gs=0 ; IIC_gs=0 ; open_serial(); send_char('o' ); close_serial(); } } } } int gs_catch_init () { pthread_t tid_gsc; int gsc_ret; gsc_ret = pthread_create(&tid_gsc, NULL ,gs_catch_pthread, NULL ); if (gsc_ret < 0 ) { perror("create thread gs_catch_catch error" ); return -1 ; } return tid_gsc; } int main () { Lcd_Init(); mode = MAIN; get_gs_pthread_init(); get_xy_pthread_init(); IIC_gesture_init(); gs_catch_init(); lcd_show_bmp("ui/main.bmp" ); while (1 ) { if (ts.x > 0 && ts.x < 150 && ts.y > 420 && ts.y < 480 && mode == MAIN || mode == HUMITURE) { ts.x=0 ;ts.y=0 ; printf ("real open!" ); Humiture_control(); mode=MAIN; } if (ts.x > 144 && ts.x < 359 && ts.y > 80 && ts.y < 227 && mode == MAIN || mode == PHOTO) { Humiture_thread_uninit(); get_name(PIC); mode = PHOTO; ts.x=0 ;ts.y=0 ; photoshow(); lcd_show_bmp("ui/main.bmp" ); bzero(file_name,sizeof (file_name)); for (int i = 0 ;i<15 ;i++) { printf ("file_name[%d] = %s\n" ,i,file_name[i]); } mode=MAIN; } if (ts.x > 460 && ts.x < 643 && ts.y > 80 && ts.y < 227 && mode == MAIN || mode == VIDEO) { mode = VIDEO; ts.x=0 ;ts.y=0 ; get_name(VIDEO); lcd_show_bmp("ui/videotool.bmp" ); video_ts_show(); lcd_show_bmp("ui/main.bmp" ); mode=MAIN; } if (ts.x > 146 && ts.x < 359 && ts.y > 280 && ts.y < 631 && mode == MAIN || mode == MUSIC) { mode = MUSIC; ts.x=0 ;ts.y=0 ; lcd_show_bmp("ui/musictool.bmp" ); musicplay(); mode=MAIN; } if (ts.x > 460 && ts.x < 643 && ts.y > 280 && ts.y < 631 && mode == MAIN || mode == UDP) { mode = UDP; ts.x=0 ;ts.y=0 ; lcd_show_bmp("ui/cameratool.bmp" ); udp_init(); mode=MAIN; } } fontUnload(f); destroyBitmap(bm); Lcd_UnInit(); return 0 ; }
arm_serial.c
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 #include "arm_serial.h" int set_serial_uart1 (int ser_fd) { struct termios termios_new ; bzero( &termios_new, sizeof (termios_new)); cfmakeraw(&termios_new); termios_new.c_cflag=(B115200); termios_new.c_cflag |= CLOCAL | CREAD; termios_new.c_cflag &= ~CSIZE; termios_new.c_cflag |= CS8; termios_new.c_cflag &= ~PARENB; termios_new.c_cflag &= ~CSTOPB; tcflush( ser_fd,TCIOFLUSH); termios_new.c_cc[VTIME] = 0 ; termios_new.c_cc[VMIN] = 4 ; tcflush ( ser_fd, TCIOFLUSH); tcsetattr( ser_fd ,TCSANOW,&termios_new); } int open_serial () { ser_fd = open(DEVICE_NAME,O_RDWR); if (ser_fd<0 ) { printf ("open serial1 failed!\n" ); return -1 ; } set_serial_uart1(ser_fd); if (fcntl(ser_fd, F_SETFL,0 )<0 ) { exit (1 ); } tcdrain(ser_fd); tcflush(ser_fd,TCIOFLUSH); return 0 ; } int send_msg (char msg[16 ]) { write(ser_fd,msg,16 ); tcflush(ser_fd,TCIOFLUSH); return 0 ; } int send_char (char msg) { printf ("%c" ,msg); write(ser_fd,&msg,8 ); tcflush(ser_fd,TCIOFLUSH); return 0 ; } int recv_msg (char msg[16 ]) { read(ser_fd,msg,16 ); } int close_serial () { close(ser_fd); }
arm_serial.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 #ifndef __ARM_SERIAL_H_ #define __ARM_SERIAL_H_ #include <stdio.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <unistd.h> #include <sys/mman.h> #include <linux/videodev2.h> #include <termios.h> #include <string.h> #include <stdlib.h> #define DEVICE_NAME "/dev/ttySAC1" int ser_fd;int open_serial () ;int send_msg (char msg[16 ]) ;int recv_msg (char msg[16 ]) ;int close_serial () ;int send_char (char msg) ;#endif
dht11usart.c
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 #include "dht11usart.h" pthread_t tid_dht=0 ;int dht11flag=0 ;void *Humiture_thread (void *arg) { font_init(24 ); char str[64 ]; char str1[64 ]; char DHT11_buf[6 ] = {0 }; open_serial(); while (1 ) { recv_msg(DHT11_buf); sprintf (str,DHT11_buf); sprintf (str1,"当前温度:\n当前湿度:" ); create_map(100 ,50 ,WHITE); create_font(81 ,0 ,str,RED); create_font(0 ,0 ,str1,RED); show_font_to_lcd(lcd->mp,0 ,430 ,bm); if ((DHT11_buf[0 ]-'0' )>3 && (DHT11_buf[1 ]-'0' )>2 || (DHT11_buf[4 ]-'0' )>9 && (DHT11_buf[5 ]-'0' )>2 ) { printf ("dangrous humiture!" ); beep_ctrl(BEEP_ON); usleep(100000 ); beep_ctrl(BEEP_OFF); usleep(100000 ); beep_ctrl(BEEP_ON); usleep(100000 ); beep_ctrl(BEEP_OFF); } } close_serial(); } int Humiture_thread_init () { int ret2 = pthread_create(&tid_dht, NULL ,Humiture_thread, NULL ); if (ret2 < 0 ) { perror("create ts_thread error" ); return -1 ; } } int Humiture_thread_uninit () { if (dht11flag) { dht11flag = 0 ; pthread_cancel(tid_dht); close_serial(); } } int Humiture_control () { if (!dht11flag) { Humiture_thread_init(); dht11flag = 1 ; } else if (dht11flag) { dht11flag = 0 ; pthread_cancel(tid_dht); lcd_show_bmp("ui/main.bmp" ); fontUnload(f); destroyBitmap(bm); close_serial(); } }
dht11usart.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 #ifndef __DHT11USART_H__ #define __DHT11USART_H__ #include <stdio.h> #include <stdlib.h> #include <string.h> #include "lcd.h" #include "pthread.h" #include "beep.h" #include "arm_serial.h" #include "font.h" extern int dht11flag;int Humiture_control () ;int Humiture_thread_uninit () ;#endif
dir.c
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 #include "dir.h" char file_name[15 ][20 ] = {0 };void get_name (char dirname) { int i = 0 ; char buf[5 ] = {0 }; DIR *dir_fd; struct dirent *readdirs = calloc (1 ,sizeof (struct dirent)); if (dirname == PIC) dir_fd = opendir("pic/" ); else if (dirname == UI) dir_fd = opendir("ui/" ); else if (dirname == VIDEO) dir_fd = opendir("video/" ); else if (dirname == MUSIC) dir_fd = opendir("music/" ); while ((readdirs = readdir(dir_fd)) != NULL ) { if (strlen (readdirs->d_name)<=4 ) continue ; bzero(buf,0 ); memcpy (buf,&(readdirs->d_name[strlen (readdirs->d_name) - 4 ]),4 ); buf[4 ] = '\0' ; printf ("buf= %s \n" ,buf); if (strcmp (buf,".bmp" ) == 0 && (dirname == PIC || UI )) { strcpy (file_name[i],readdirs->d_name); i++; printf ("%s\n" ,readdirs->d_name); } if (strcmp (buf,".mp4" ) == 0 && (dirname == VIDEO)) { strcpy (file_name[i],readdirs->d_name); i++; printf ("%s\n" ,readdirs->d_name); } if (strcmp (buf,".mp3" ) == 0 && (dirname == MUSIC)) { strcpy (file_name[i],readdirs->d_name); i++; printf ("%s\n" ,readdirs->d_name); } } for (int i = 0 ;i<15 ;i++) { printf ("file_name[%d] = %s\n" ,i,file_name[i]); } closedir(dir_fd); }
dir.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 #ifndef __DIR_h__ #define __DIR_h__ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <dirent.h> #define PIC 0 #define UI 1 #define VIDEO 2 #define MUSIC 3 extern char file_name[15 ][20 ];void get_name (char dirname) ;#endif
特别注意:LCD字库libfont.a等可以在网上寻找此处不在贴出 font.c
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 #include "font.h" struct LcdDevice * lcd =NULL ;font *f=NULL ; bitmap *bm=NULL ; struct LcdDevice *init_lcd (const char *device) { struct LcdDevice * lcd = malloc (sizeof (struct LcdDevice)); if (lcd == NULL ) { return NULL ; } lcd->fd = open(device, O_RDWR); if (lcd->fd < 0 ) { perror("open lcd fail" ); free (lcd); return NULL ; } lcd->mp = mmap(NULL ,800 *480 *4 ,PROT_READ|PROT_WRITE,MAP_SHARED,lcd->fd,0 ); return lcd; } void font_init (int num) { lcd = init_lcd("/dev/fb0" ); f = fontLoad("/usr/share/fonts/DroidSansFallback.ttf" ); fontSetSize(f,num); } void create_map (int W,int H,unsigned int mapcolor) { unsigned int A,R,G,B; A= (mapcolor>>24 ); R= (mapcolor>>16 )&0xff ; G= (mapcolor>> 8 )&0xff ; B= (mapcolor>> 0 )&0xff ; bm = createBitmapWithInit(W,H,4 ,getColor(A,B,G,R)); } void create_font (int X,int Y,char *buf,unsigned int fontcolor) { unsigned int A,R,G,B; A= fontcolor>>24 ; R= (fontcolor>>16 )&0xff ; G= (fontcolor>> 8 )&0xff ; B= (fontcolor>> 0 )&0xff ; fontPrint(f,bm,X,Y,buf,getColor(A,B,G,R),0 ); }
font.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 #ifndef __font_h__ #define __font_h__ #include <stdio.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <stdlib.h> #include <sys/mman.h> #define color u32 #define getColor(a, b, c, d) (a|b<<8|c<<16|d<<24) typedef unsigned char u8;typedef unsigned short u16;typedef unsigned int u32;typedef unsigned long long u64;typedef char s8;typedef short s16;typedef int s32;typedef long long s64;typedef struct stbtt_fontinfo { void * userdata; unsigned char * data; int fontstart; int numGlyphs; int loca,head,glyf,hhea,hmtx,kern; int index_map; int indexToLocFormat; } stbtt_fontinfo; typedef struct { u32 height; u32 width; u32 byteperpixel; u8 *map ; }bitmap; typedef struct { stbtt_fontinfo *info; u8 *buffer; float scale; }font; extern struct LcdDevice * lcd ;extern font *f;extern bitmap *bm;struct LcdDevice { int fd; unsigned int *mp; }; void font_init (int num) ;void create_map (int W,int H,unsigned int mapcolor) ;void create_font (int X,int Y,char *buf,unsigned int fontcolor) ;font *fontLoad (char *fontPath) ; void fontSetSize (font *f, s32 pixels) ;bitmap *createBitmap (u32 width, u32 height, u32 byteperpixel) ; bitmap *createBitmapWithInit (u32 width, u32 height, u32 byteperpixel, color c) ; struct LcdDevice *init_lcd (const char *device) ;void fontPrint (font *f, bitmap *screen, s32 x, s32 y, char *text, color c, s32 maxWidth) ;void show_font_to_lcd (unsigned int *p,int px,int py,bitmap *bm) ;void fontUnload (font *f) ;void destroyBitmap (bitmap *bm) ;#endif
gesture.c
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 #include "gesture.h" int fd;pthread_t tid_iicgs;char IIC_gs=-1 ;char IIC_gesture_get () { char tmp=-1 ; read(fd,&tmp,1 ); if (tmp>=1 && tmp<=9 ) { printf ("%x\n" ,tmp); switch (tmp) { case 1 :printf ("Up\n" );break ; case 2 :printf ("Down\n" );break ; case 3 :printf ("Left\n" );break ; case 4 :printf ("Right\n" );break ; case 5 :printf ("Forward\n" );break ; case 6 :printf ("Backward\n" );break ; case 7 :printf ("Clockwise\n" );break ; case 8 :printf ("AntiClockwise\n" );break ; case 9 :printf ("Wave\n" );break ; default :break ; } } return tmp; } void *get_IIC_gesture (void *arg) { while (1 ) { IIC_gs=IIC_gesture_get(); } } int IIC_gesture_init () { fd = open("/dev/IIC_drv" , O_RDWR); if (fd < 0 ) { perror("open" ); return -1 ; } else printf ("devok!\n" ); int get_iicgs_ret; get_iicgs_ret = pthread_create(&tid_iicgs, NULL ,get_IIC_gesture, NULL ); if (get_iicgs_ret < 0 ) { perror("create thread get_xy error" ); return -1 ; } } int IIC_gesture_uninit () { close(fd); pthread_cancel(tid_iicgs); }
gesture.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 #ifndef __GESTURE_H__ #define __GESTURE_H__ #include <stdio.h> #include <fcntl.h> #include <unistd.h> #include "pthread.h" #define Up 1 #define Down 2 #define Left 3 #define Right 4 #define Forward 5 #define Backward 6 #define Clockwise 7 #define AntiClockwise 8 #define Wave 9 extern char IIC_gs;int IIC_gesture_init () ;int IIC_gesture_uninit () ;char IIC_gesture_get () ;#endif
music.c
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 #include "music.h" char musicpreflag=0 ;char musicnextflag=0 ;char musicspflag=0 ;int init_mplayer2 () { int ret = mkfifo("/tmp/myfifo2" , 0777 ); if (-1 == ret) { perror("mkfifo failed" ); } int fd = open("/tmp/myfifo2" , O_RDWR); if (-1 == fd) { perror("open fifo failed" ); return -1 ; } return fd; } int musicplay (void ) { int fd_fifo = init_mplayer2(); char a[]={"mplayer -slave -quiet -input file=/tmp/myfifo2 music/" }; char b[]={" &" }; get_name(MUSIC); char strCat1[15 ][100 ]={0 }; for (int i = 0 ; i < 15 ; i++) { sprintf (strCat1[i],"%s%s%s" ,a,file_name[i],b); } printf ("--------------------------------%d-----------------------\n" , __LINE__); bool spflag = 0 ; int flag2 = 0 ; int vflag = 0 ; while (1 ) { if (ts.x>320 && ts.x<460 && ts.y>111 && ts.y<270 ) { ts.x=0 ;ts.y=0 ; if (flag2 == 0 ) { flag2++; printf ("play!\n" ); system(strCat1[vflag]); } if (mode == MAIN) { flag2=0 ; break ; } } if (ts.y>360 && ts.y<480 || mode == MAIN || musicpreflag==1 || musicnextflag==1 || musicspflag==1 ) { if (ts.x>342 && ts.x<430 || musicspflag==1 ) { musicspflag =0 ; printf ("--------line:%d---------------\n" , __LINE__); if (spflag == 0 ) { printf ("--------line:%d--------flag:%d-------\n" , __LINE__, spflag); system("killall -SIGSTOP mplayer" ); spflag = 1 ; } else if (spflag== 1 ) { printf ("--------line:%d--------flag:%d-------\n" , __LINE__, spflag); system("killall -SIGCONT mplayer" ); spflag = 0 ; } } if (ts.x>550 && ts.x<600 ) { printf ("volume-10.........................\n" ); write(fd_fifo,"volume -10\n" ,strlen ("volume -10\n" )); } if (ts.x>615 && ts.x<668 ) { printf ("volume+10.........................\n" ); write(fd_fifo,"volume 10\n" ,strlen ("volume 10\n" )); } if (ts.x>253 && ts.x<330 || musicpreflag==1 ) { musicpreflag=0 ; system("killall -SIGKILL mplayer" ); sleep(1 ); vflag--; if (vflag < 0 ) { vflag=0 ; printf ("First music!.........................\n" ); } system(strCat1[vflag]); } if (ts.x>447 && ts.x<526 || musicnextflag==1 ) { musicnextflag=0 ; system("killall -SIGKILL mplayer" ); sleep(1 ); vflag++; if (vflag > 3 ) { vflag =3 ; printf ("Last video!.........................\n" ); } system(strCat1[vflag]); } if (ts.x>700 && ts.x<800 && ts.y>380 && ts.y<480 || mode == MAIN ) { printf ("back!\n" ); system("killall -SIGKILL mplayer" ); mode=MAIN; lcd_show_bmp("ui/main.bmp" ); sleep(1 ); flag2 = 0 ; break ; } ts.x=0 ;ts.y=0 ; } } }
music.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 #ifndef __MUSIC_H__ #define __MUSIC_H__ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <stdbool.h> #include "dir.h" #include "touch.h" int musicplay (void ) ;extern int mode;extern char musicpreflag;extern char musicnextflag;extern char musicspflag;#endif
photo.c
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 #include "photo.h" char strCat[15 ][30 ]={0 };void *photo_thread (void *arg) { num=0 ; char a[]={"pic/" }; for (int i = 0 ; i < 15 ; i++) { sprintf (strCat[i],"%s%s" ,a,file_name[i]); } for (int i = 0 ; i < 15 ; i++) { num++; if (file_name[i][0 ]=='\0' ) { num--; printf ("last num=%d\n" ,num); num--; printf ("numflag=%d\n" ,num); break ; } } while (mode == PHOTO) { lcd_show_bmp(strCat[pic_flag]); } } int photoshow (void ) { gs=0 ; IIC_gs=0 ; loopflag = 0 ; pthread_t tid_ts; int ret; ret = pthread_create(&tid_ts, NULL , photo_thread, NULL ); if (ret < 0 ) { perror("create ts_thread error" ); return -1 ; } while (1 ) { if (650 < ts.x && ts.x < 800 && 0 < ts.y && ts.y < 100 || loopflag) { printf ("loop on!\n" ); loopflag = 0 ; ts.x=0 ;ts.y=0 ; while (1 ) { pic_flag++; sleep(1 ); if (pic_flag == num) { pic_flag=0 ; } if (650 <ts.x && ts.x<800 && 150 <ts.y && ts.y<300 || loopflag ) { printf ("loop out!\n" ); loopflag = 0 ; ts.x=0 ;ts.y=0 ; break ; } } } if (650 <ts.x && ts.x<800 && 0 <ts.y && ts.y<100 ) { ts.x=0 ;ts.y=0 ; pic_flag++; if (pic_flag > num) { pic_flag = num; printf ("Last picture!\n" ); } else printf ("Next picture\n" ); } if (0 <ts.x && ts.x<150 && 0 <ts.y && ts.y<100 ) { ts.x=0 ;ts.y=0 ; pic_flag--; if (pic_flag < 0 ) { printf ("First picture!\n" ); pic_flag=0 ; } else printf ("Prev picture\n" ); } if (delflag && num!=1 ) { delflag = 0 ; num--; char a[]={"pic/" }; char newfile_name[15 ][30 ]={0 }; for (int i=0 ; i<num+1 ; ++i) { if (i < pic_flag) { strcpy (newfile_name[i],file_name[i]); } else { strcpy (newfile_name[i],file_name[i+1 ]); } } for (int i = 0 ;i < 15 ; i++) { sprintf (strCat[i],"%s%s" ,a,newfile_name[i]); } for (int i = 0 ;i < 15 ; i++) { printf ("strCat[%d] = %s\n" ,i,strCat[i]); } } if (addflag) { addflag = 0 ; char buf[1 ][6 ]={0 }; printf ("Please write the name of the picture\n" ); printf ("data:" ); scanf ("%s" ,buf[1 ]); printf ("buf=%s\n" ,buf[1 ]); num++; char a[]={"pic/" }; char newfile_name[15 ][30 ]={0 }; for (int i=0 ; i<num+1 ; ++i) { if (i < pic_flag) { strcpy (newfile_name[i],file_name[i]); } else if (i == pic_flag) { strcpy (newfile_name[i],buf[1 ]); } else { strcpy (newfile_name[i],file_name[i-1 ]); } } for (int i = 0 ; i < 15 ; i++) { sprintf (strCat[i],"%s%s" ,a,newfile_name[i]); } for (int i = 0 ;i<15 ;i++) { printf ("strCat[%d] = %s\n" ,i,strCat[i]); } } if (ts.x > 700 && ts.x < 800 && ts.y > 420 && ts.y < 480 || mode == MAIN) { ts.x=0 ;ts.y=0 ; pthread_cancel(tid_ts); mode=MAIN; break ; } } }
photo.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 #ifndef __PHOTO_H__ #define __PHOTO_H__ #include <stdio.h> #include <stdlib.h> #include <string.h> #include "dir.h" #include "touch.h" #include "gesture.h" #define PIC 0 #define UI 1 #define VIDEO 2 #define MUSIC 3 #define MAIN 0 #define PHOTO 1 #define CAMERA 4 #define HUMITURE 5 int photoshow (void ) ;void *photo_thread (void *arg) ;extern struct xy ts ;extern int mode;int loopflag;int addflag;int delflag;int num;#endif
touch.c
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 #include "touch.h" int mode=MAIN;int pic_flag=0 ;pthread_t tid_gxy;struct xy ts ;int x,y;int s_x = 0 ;int s_y = 0 ;int e_x = 0 ;int e_y = 0 ;int gs=0 ;void *gesture_status_catch (void *arg) { while (1 ) { gs = Slide_Pos(); } } int get_gs_pthread_init (void ) { pthread_t tid_gs; int gs_ret; gs_ret = pthread_create(&tid_gs, NULL ,gesture_status_catch, NULL ); if (gs_ret < 0 ) { perror("create thread gesture_status_catch error" ); return -1 ; } return tid_gs; } void *get_xy (void *arg) { while (1 ) { ts=ts_get_xy(); } } int get_xy_pthread_init (void ) { int get_xy_ret; get_xy_ret = pthread_create(&tid_gxy, NULL ,get_xy, NULL ); if (get_xy_ret < 0 ) { perror("create thread get_xy error" ); return -1 ; } else { printf ("create thread get_xy ok!" ); } } void get_xy_pthread_uninit (void ) { pthread_cancel(tid_gxy); } int Slide_Pos (void ) { int fd_ts; fd_ts = open("/dev/input/event0" , O_RDONLY); if (fd_ts == -1 ) { perror("open ts" ); exit (-1 ); } struct input_event ts_data ; for (int i = 0 ; i < 6 ; i++) { read(fd_ts, &ts_data, sizeof (struct input_event)); if (ts_data.type == EV_ABS) { if (ts_data.code == ABS_X) x = ts_data.value*800 /1024 ; if (ts_data.code == ABS_Y) y = ts_data.value*480 /600 ; } else if (ts_data.type == EV_KEY && ts_data.code == BTN_TOUCH && ts_data.value == 1 ) { s_x = x ; s_y = y ; printf ("finger down:(%d,%d)--\n" , x , y); } else if ( ts_data.code == BTN_TOUCH && ts_data.value == 0 ) { e_x = x ; e_y = y ; printf ("finger up:(%d,%d)--\n" , x , y); int DifferenceX = s_x - e_x ; int DifferenceY = s_y - e_y ; printf ("Difference:(%d,%d)--\n" , DifferenceX , DifferenceY); if (abs (DifferenceX) > abs (DifferenceY)) { if ( DifferenceX > 10 ) { printf ("left\n" ); return Left; } else if ( DifferenceX < -10 ) { printf ("right\n" ); return Right; } } else { if (DifferenceY > 10 ) { printf ("up\n" ); return Up; } else if (DifferenceY < -10 ) { printf ("down\n" ); return Down; } } } } close(fd_ts); return 0 ; } struct xy ts_get_xy (void ) { struct xy z ; int x,y; int fd_ts; fd_ts = open("/dev/input/event0" , O_RDONLY); if (fd_ts == -1 ) { perror("open ts" ); exit (-1 ); } struct input_event ts_data ; for (int i = 0 ; i < 6 ; i++) { read(fd_ts, &ts_data, sizeof (struct input_event)); if (ts_data.type == EV_ABS) { if (ts_data.code == ABS_X) x = ts_data.value*800 /1024 ; else if (ts_data.code == ABS_Y) y = ts_data.value*480 /600 ; } } z.x=x; z.y=y; close(fd_ts); return z; }
touch.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 #ifndef __TOUCH_H_ #define __TOUCH_H_ #include <stdio.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <unistd.h> #include <linux/input.h> #include <stdlib.h> #include "pthread.h" #include "lcd.h" #define Up 1 #define Down 2 #define Left 3 #define Right 4 #define PIC 0 #define UI 1 #define VIDEO 2 #define MUSIC 3 #define MAIN 0 #define PHOTO 1 #define CAMERA 4 #define HUMITURE 5 struct xy { int x; int y; }; int get_xy_pthread_init (void ) ;void get_xy_pthread_uninit (void ) ;int get_gs_pthread_init (void ) ;void get_gs_pthread_uninit (void ) ;extern struct xy ts ;struct xy ts_get_xy () ;extern int pic_flag,gs;int Slide_Pos () ;#endif
udp.c
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 #include "udp.h" #include "arm_serial.h" int udp_init () { int socketfd = socket(AF_INET,SOCK_DGRAM,0 ); if (socketfd == -1 ) { printf ("socketfd error\n" ); return -1 ; } struct sockaddr_in ownAddr ; ownAddr.sin_family = AF_INET; ownAddr.sin_port = htons(OWNPORT); ownAddr.sin_addr.s_addr = inet_addr(OWNADDR); bind(socketfd,(struct sockaddr *)&ownAddr,sizeof (struct sockaddr_in)); struct sockaddr_in serverAddr ; serverAddr.sin_family = AF_INET; serverAddr.sin_port = htons(SERVERPORT); serverAddr.sin_addr.s_addr = inet_addr(SERVERADDR); while (mode == UDP) { char buf[1024 ]={0 }; if (ts.y>300 && ts.y<480 && ts.x>370 && ts.x<450 ) { ts.y=0 ;ts.x=0 ; printf ("data:" ); scanf ("%s" ,buf); sendto(socketfd,buf,strlen (buf),0 ,(struct sockaddr *)&serverAddr,sizeof (struct sockaddr_in)); } if (ts.y>380 && ts.y<480 && ts.x>700 && ts.x<800 || mode == MAIN ) { ts.y=0 ;ts.x=0 ; printf ("back!\n" ); mode=MAIN; lcd_show_bmp("ui/main.bmp" ); break ; } } close(socketfd); return 0 ; }
udp.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 #ifndef __UDP_H__ #define __UDP_H__ #include <stdio.h> #include <sys/socket.h> #include <sys/types.h> #include <netinet/in.h> #include <arpa/inet.h> #include <string.h> #include <fcntl.h> #include <unistd.h> #include <malloc.h> #include "touch.h" #define OWNADDR "10.12.94.196" #define OWNPORT 20000 #define SERVERADDR "10.12.94.159" #define SERVERPORT 10000 #define UDP 4 extern struct xy ts ;extern int mode;int udp_init () ;#endif
video.c
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 #include "video.h" char videopreflag=0 ;char videonextflag=0 ;char videospflag; int init_mplayer () { int ret = mkfifo("/tmp/myfifo" , 0777 ); if (-1 == ret) { perror("mkfifo failed" ); } int fd = open("/tmp/myfifo" , O_RDWR); if (-1 == fd) { perror("open fifo failed" ); return -1 ; } return fd; } int video_ts_show (void ) { int fd_fifo = init_mplayer(); char a[]={"mplayer -slave -quiet -input file=/tmp/myfifo -zoom -x 800 -y 420 video/" }; char b[]={" &" }; char strCat1[15 ][100 ]={0 }; for (int i = 0 ; i < 15 ; i++) { sprintf (strCat1[i],"%s%s%s" ,a,file_name[i],b); } printf ("--------------------------------%d-----------------------\n" , __LINE__); videospflag=0 ; int spflag = 0 ; int playingflag = 0 ; int muteflag = 0 ; int vflag = 0 ; while (1 ) { if (ts.x>260 && ts.x<500 && ts.y>108 && ts.y<320 || videospflag == 2 ) { ts.x=0 ;ts.y=0 ; videospflag = 0 ; if (playingflag == 0 ) { playingflag++; printf ("play!\n" ); system(strCat1[vflag]); } if (mode == MAIN) { playingflag=0 ; break ; } } if (ts.y>380 && ts.y<480 || mode == MAIN || videonextflag==1 || videopreflag==1 || videospflag == 1 ) { if (ts.x>100 && ts.x<184 ) { printf ("back 10s......................\n" ); write(fd_fifo,"seek -10\n" , strlen ("seek -10\n" )); } if (ts.x>184 && ts.x<285 || videospflag == 1 ) { videospflag = 0 ; if (spflag == 0 ) { printf ("pause.................\n" ); system("killall -19 mplayer" ); spflag = 1 ; } else if (spflag == 1 ) { printf ("continue.................\n" ); system("killall -18 mplayer" ); spflag = 0 ; } } if (ts.x>285 && ts.x<338 ) { printf ("go 10s.........................\n" ); write(fd_fifo,"seek 10\n" , strlen ("seek 10\n" )); } if (ts.x>338 && ts.x<403 ) { printf ("volume-10.........................\n" ); write(fd_fifo,"volume -10\n" ,strlen ("volume -10\n" )); } if (ts.x>403 && ts.x<480 ) { printf ("volume+10.........................\n" ); write(fd_fifo,"volume 10\n" ,strlen ("volume 10\n" )); } if (ts.x>480 && ts.x<560 ) { if (muteflag ==0 ) { printf ("volume off.........................\n" ); write(fd_fifo,"mute 1\n" , strlen ("mute 1\n" )); muteflag = 1 ; } else if (muteflag == 1 ) { printf ("volume on.........................\n" ); write(fd_fifo,"mute 0\n" , strlen ("mute 0\n" )); muteflag = 0 ; } } if (ts.x>554 && ts.x<626 || videopreflag==1 ) { videopreflag=0 ; system("killall -9 mplayer" ); vflag--; if (vflag < 0 ) { vflag=0 ; printf ("First video!.........................\n" ); } system(strCat1[vflag]); } if (ts.x>626 && ts.x<700 || videonextflag==1 ) { videonextflag=0 ; system("killall -9 mplayer" ); vflag++; if (vflag > 2 ) { vflag=2 ; printf ("Last video!.........................\n" ); } system(strCat1[vflag]); } if (ts.x>700 && ts.x<800 || mode == MAIN) { printf ("back!\n" ); write(fd_fifo,"quit\n" , strlen ("quit\n" )); system("killall -9 mplayer" ); playingflag=0 ; break ; } ts.x=0 ;ts.y=0 ; } } }
video.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 #ifndef __VIDEO_h__ #define __VIDEO_h__ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <stdbool.h> #include "dir.h" #include "touch.h" extern struct xy ts ;int video_ts_show (void ) ;char videospflag;extern int mode; extern char videopreflag;extern char videonextflag;#endif
Makefile文件(基本是通用万能的语句,但不推荐长期使用 ):
1 2 3 4 all: arm-linux-gcc *.c -o main -I ./ -L ./ -l font -lpthread -lm clean: rm *.o main