/* NAME open a file or device SYNOPSIS #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> 参数列表,参数列表中的每一个参数叫做形参 int open(const char *pathname, int flags); 参数: pathname:要打开的文件的路径或者文件名 flags: 打开的标志 只读:O_RDONLY 只写:O_WRONLY 可读可写:O_RDWR 返回值:file descriptor文件描述符 成功: 返回打开的文件的文件描述符 失败:返回-1 NAME write - write to a file descriptor SYNOPSIS #include <unistd.h> ssize_t write(int fd, const void *buf, size_t count); 参数: fd:要写入的文件的文件描述符,open的返回值 buf: 一个容器,用来装需要写入文件中的内容的(一个指针,指向需要写入文件的内容) count:需要写入文件的内容的字节数!!! NAME mmap, munmap - map or unmap files or devices into memory SYNOPSIS #include <sys/mman.h> void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset); addr: 表示您要映射到进程哪个地址上去。一般为NULL,让操作系统 自动分配一个地址。 length:要映射文件或设备多少字节,映射长度。会自动向上取PAGE_SIZE(4k) 的整数倍。 prot: 映射区域的权限,应与打开文件时设定的权限一致,因为操作该映射区域 实际就是操作文件 PROT_READ:映射区域为只读 PROT_WRITE:映射区域为读写 PROT_EXCE: 映射区域可执行 PROT_NONE: 映射区域没有访问权限 flags: 映射标志 MAP_SHARED: 共享的。对映射区域的操作直接操作在文件上。 MAP_PRIVATE:私有的。对映射区域开了一个私有的缓冲,对映射区域的操作不直接操作在文件上。 fd: 文件描述符,表示您要映射哪个文件或设备 offset: 偏移量,表示从文件哪个位置开始映射。这个地方必须为PAGE_SIZE(4096)的整数倍。 返回值: 成功返回映射区域的首地址 失败返回MAP_FAILED ,同时errno被设置。 munmap解映射 int munmap(void *addr, size_t length); read用来从fd指定的文件中,读取count个字节到buf指向的内存 ssize_t read(int fd, void *buf, ssize_t count); 返回值: > 0: 表示实际读到的字节数 =0: 文件读到末尾 <0: 出错,同时errno被设置。 */ #include <stdio.h> #include <stdlib.h> #include <string.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <unistd.h> #include <sys/mman.h> #include <sys/stat.h> #include <fcntl.h> #include <errno.h> #include <termios.h> #include <sys/ioctl.h> #include <linux/input.h> #include <pthread.h> //枚举 用来标识 手指触摸在哪个功能区域 enum en_area { MUSIC_PLAY, //播放音乐 MUSIC_PAUSE, //暂停音乐 MUSIC_NEXT, //下一曲 MUSIC_LAST, //上一曲 VOICE_ADD, //音量增加 VOICE_MINUS, //音量减少 LIGHT_ON, //开灯 LIGHT_OFF, //关灯 }; #define SERIAL1 "/dev/s3c2410_serial1" #define SERIAL2 "/dev/s3c2410_serial2" #define SERIAL3 "/dev/s3c2410_serial3" //灯的状态 int light_state = 0; //音乐播放状态 int music_state = 0; //beep 状态 int beep_state = 0; int led_fd; //控制led int beep_fd; //控制beep int *plcd = NULL; //定义一个指针用来指向映射的地址 //数字 0~9 char digit[][58] = {{ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xC0,0x1E,0xF0, 0x3C,0x78,0x38,0x38,0x78,0x3C,0x78,0x3C,0x70,0x1C,0x70,0x1C,0x70,0x1C,0x70,0x1C, 0x70,0x1C,0x70,0x1C,0x70,0x3C,0x78,0x3C,0x78,0x38,0x38,0x38,0x3C,0x70,0x1E,0xF0, 0x07,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x01,0x80,0x03,0x80, 0x1F,0x80,0x03,0x80,0x03,0x80,0x03,0x80,0x03,0x80,0x03,0x80,0x03,0x80,0x03,0x80, 0x03,0x80,0x03,0x80,0x03,0x80,0x03,0x80,0x03,0x80,0x03,0x80,0x03,0x80,0x03,0xC0, 0x1F,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xE0,0x1C,0x70, 0x38,0x38,0x78,0x3C,0x78,0x3C,0x78,0x3C,0x38,0x38,0x00,0x78,0x00,0x70,0x00,0xE0, 0x01,0xC0,0x03,0x80,0x07,0x00,0x0E,0x00,0x1C,0x0C,0x38,0x1C,0x70,0x3C,0x7F,0xF8, 0x7F,0xF8,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xC0,0x38,0xF0, 0x38,0x78,0x78,0x78,0x38,0x78,0x00,0x78,0x00,0x70,0x00,0xE0,0x07,0xC0,0x00,0xF0, 0x00,0x78,0x00,0x38,0x00,0x3C,0x00,0x3C,0x78,0x3C,0x78,0x38,0x78,0x38,0x38,0xF0, 0x0F,0xC0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0xE0,0x00,0xE0,0x01,0xE0, 0x03,0xE0,0x03,0xE0,0x07,0xE0,0x0E,0xE0,0x0C,0xE0,0x1C,0xE0,0x18,0xE0,0x30,0xE0, 0x70,0xE0,0x60,0xE0,0xFF,0xFC,0x00,0xE0,0x00,0xE0,0x00,0xE0,0x00,0xE0,0x01,0xF0, 0x07,0xFC,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0xF8,0x3F,0xF8, 0x38,0x00,0x38,0x00,0x38,0x00,0x38,0x00,0x30,0x00,0x37,0xE0,0x3C,0x70,0x38,0x38, 0x10,0x3C,0x00,0x3C,0x00,0x3C,0x78,0x3C,0x78,0x3C,0x78,0x38,0x38,0x78,0x38,0xF0, 0x0F,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x07,0xF0,0x0E,0x78, 0x1C,0x78,0x38,0x78,0x38,0x00,0x78,0x00,0x70,0x00,0x77,0xE0,0x7E,0x78,0x78,0x38, 0x78,0x3C,0x70,0x3C,0x70,0x1C,0x70,0x1C,0x78,0x3C,0x38,0x3C,0x3C,0x38,0x1E,0x70, 0x0F,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x3F,0xFC,0x3F,0xF8, 0x78,0x38,0x70,0x30,0x60,0x60,0x00,0x60,0x00,0xC0,0x01,0xC0,0x01,0xC0,0x03,0x80, 0x03,0x80,0x03,0x80,0x07,0x80,0x07,0x00,0x07,0x00,0x07,0x00,0x0F,0x00,0x0F,0x00, 0x07,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xE0,0x3C,0x70, 0x38,0x38,0x70,0x3C,0x70,0x1C,0x70,0x1C,0x38,0x38,0x3E,0x70,0x0F,0xE0,0x1F,0xE0, 0x38,0xF0,0x70,0x78,0x70,0x3C,0x70,0x1C,0x70,0x1C,0x70,0x1C,0x70,0x38,0x3C,0x70, 0x0F,0xE0,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0F,0xC0,0x3C,0x70, 0x38,0x38,0x78,0x38,0x70,0x3C,0x70,0x3C,0x70,0x1C,0x70,0x3C,0x70,0x3C,0x78,0x7C, 0x3C,0xFC,0x1F,0xFC,0x00,0x3C,0x00,0x38,0x00,0x38,0x38,0x70,0x38,0x70,0x3D,0xE0, 0x1F,0x80,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 } }; //title:智能家居控制系统 char title[8][288] = {{ 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x20,0x00,0x00,0x00,0x00,0x00,0x38,0x00,0x00, 0x00,0x00,0x00,0x7E,0x00,0x00,0x00,0x00,0x00,0x78,0x00,0x00,0x00,0x00,0x00,0x78, 0x07,0x00,0x00,0xC0,0x00,0xF0,0x0F,0x8E,0x01,0xE0,0x00,0xFF,0xFF,0xCF,0xFF,0xF0, 0x00,0xE3,0xE0,0xCF,0x01,0xE0,0x01,0xE3,0xC0,0x0F,0x01,0xE0,0x01,0xC3,0xC0,0x0F, 0x01,0xE0,0x03,0x83,0xC0,0x0F,0x01,0xE0,0x07,0x03,0xC0,0x0F,0x01,0xE0,0x06,0x03, 0xC3,0x8F,0x01,0xE0,0x00,0x03,0xC7,0xCF,0x01,0xE0,0x3F,0xFF,0xFF,0xEF,0x01,0xE0, 0x0C,0x03,0xC0,0x3F,0x01,0xE0,0x00,0x07,0x80,0x0F,0x01,0xE0,0x00,0x07,0xE0,0x0F, 0x01,0xE0,0x00,0x0F,0xFC,0x0F,0x01,0xE0,0x00,0x0F,0x3F,0x0F,0xFF,0xE0,0x00,0x1E, 0x1F,0x8F,0x01,0xE0,0x00,0x1E,0x0F,0xCF,0x01,0xE0,0x00,0x3C,0x07,0xCF,0x01,0xC0, 0x00,0x78,0x03,0xCC,0x00,0x00,0x00,0xFC,0x01,0x80,0x18,0x00,0x03,0xCF,0x00,0x00, 0x3C,0x00,0x07,0x0F,0xFF,0xFF,0xFE,0x00,0x1C,0x0F,0x80,0x00,0x3C,0x00,0x10,0x0F, 0x80,0x00,0x3C,0x00,0x00,0x07,0x80,0x00,0x3C,0x00,0x00,0x07,0x80,0x00,0x3C,0x00, 0x00,0x07,0x80,0x00,0x3C,0x00,0x00,0x07,0x80,0x00,0x3C,0x00,0x00,0x07,0xFF,0xFF, 0xFC,0x00,0x00,0x07,0x80,0x00,0x3C,0x00,0x00,0x07,0x80,0x00,0x3C,0x00,0x00,0x07, 0x80,0x00,0x3C,0x00,0x00,0x07,0x80,0x00,0x3C,0x00,0x00,0x07,0x80,0x00,0x3C,0x00, 0x00,0x07,0x80,0x00,0x3C,0x00,0x00,0x0F,0xFF,0xFF,0xFC,0x00,0x00,0x0F,0x80,0x00, 0x3C,0x00,0x00,0x0F,0x80,0x00,0x3C,0x00,0x00,0x0F,0x00,0x00,0x38,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x0E,0x00,0x00, 0x00,0x00,0x00,0x0F,0x00,0x1C,0x00,0x00,0x00,0x1F,0x80,0x1F,0x00,0x00,0x00,0x1E, 0x00,0x1F,0x00,0x00,0x00,0x3C,0x00,0x1E,0x03,0x00,0x00,0x78,0x60,0x1E,0x07,0x80, 0x00,0xF0,0x78,0x1E,0x0F,0xC0,0x00,0xE0,0x3C,0x1E,0x3F,0xC0,0x01,0xC0,0x1E,0x1E, 0x7C,0x00,0x03,0x80,0x1F,0x1E,0xF0,0x00,0x0F,0x00,0x0F,0x9F,0xC0,0x60,0x1F,0xFF, 0xFF,0x9E,0x00,0x60,0x0F,0xFC,0x07,0x9E,0x00,0x60,0x0F,0x00,0x07,0x9E,0x00,0x60, 0x00,0x00,0x03,0x1E,0x00,0x70,0x00,0x00,0x18,0x1E,0x00,0x70,0x07,0x00,0x3C,0x1E, 0x00,0xF8,0x03,0xFF,0xFE,0x1F,0xFF,0xFC,0x03,0xC0,0x3E,0x0F,0xFF,0xF0,0x03,0xC0, 0x3C,0x00,0x00,0x00,0x03,0xC0,0x3C,0x00,0x00,0x00,0x03,0xC0,0x3C,0x00,0x00,0x00, 0x03,0xC0,0x3C,0x38,0x00,0x00,0x03,0xFF,0xFC,0x3E,0x03,0x00,0x03,0xC0,0x3C,0x3F, 0x03,0x80,0x03,0xC0,0x3C,0x3C,0x07,0xC0,0x03,0xC0,0x3C,0x3C,0x0F,0xE0,0x03,0xC0, 0x3C,0x3C,0x3F,0x00,0x03,0xC0,0x3C,0x3C,0x7C,0x00,0x03,0xC0,0x3C,0x3C,0xF0,0x00, 0x03,0xFF,0xFC,0x3F,0xC0,0x00,0x03,0xC0,0x3C,0x3F,0x00,0x00,0x03,0xC0,0x3C,0x3C, 0x00,0x70,0x03,0xC0,0x3C,0x3C,0x00,0x70,0x03,0xC0,0x3C,0x3C,0x00,0x70,0x03,0xC0, 0x3C,0x3C,0x00,0x70,0x03,0xC0,0x3C,0x3C,0x00,0x70,0x03,0xC0,0x3C,0x3C,0x00,0x70, 0x03,0xC0,0x3C,0x3E,0x00,0x78,0x03,0xCF,0xFC,0x1F,0x00,0xFC,0x03,0xC3,0xFC,0x1F, 0xFF,0xF8,0x03,0xC0,0xF8,0x0F,0xFF,0xF0,0x07,0x80,0x70,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1F,0x00, 0x00,0x00,0x00,0x00,0x0F,0xC0,0x00,0x00,0x00,0x00,0x07,0xE0,0x00,0x00,0x00,0x00, 0x03,0xE0,0x00,0x00,0x01,0xC0,0x01,0xE0,0x00,0x00,0x01,0xC0,0x01,0xC0,0x00,0xE0, 0x01,0xC0,0x00,0x00,0x01,0xF0,0x03,0xFF,0xFF,0xFF,0xFF,0xF8,0x03,0xC0,0x00,0x00, 0x01,0xFC,0x07,0xC0,0x00,0x00,0x03,0xC0,0x0F,0x80,0x00,0x00,0x03,0x80,0x0F,0x80, 0x00,0x00,0x77,0x00,0x00,0x00,0x00,0x00,0xF8,0x00,0x00,0x7F,0xFF,0xFF,0xFC,0x00, 0x00,0x00,0x1F,0x00,0x0C,0x00,0x00,0x00,0x3E,0x00,0x00,0x00,0x00,0x00,0x7C,0x00, 0x18,0x00,0x00,0x00,0xFC,0x00,0x3C,0x00,0x00,0x01,0xFF,0x00,0x7E,0x00,0x00,0x03, 0xC7,0x80,0xFF,0x00,0x00,0x0F,0x83,0xC1,0xF0,0x00,0x00,0x3E,0x07,0xC7,0x80,0x00, 0x00,0xF8,0x0F,0xEF,0x00,0x00,0x03,0xC0,0x1E,0xFB,0x80,0x00,0x0F,0x00,0x7C,0xF3, 0x80,0x00,0x18,0x00,0xF8,0x7B,0x80,0x00,0x00,0x01,0xE0,0xF9,0xC0,0x00,0x00,0x07, 0xC1,0xF9,0xC0,0x00,0x00,0x0F,0x03,0xF9,0xE0,0x00,0x00,0x3E,0x07,0xFC,0xE0,0x00, 0x00,0xF0,0x0F,0xBC,0xF0,0x00,0x03,0xC0,0x1F,0x3C,0x78,0x00,0x0E,0x00,0x3E,0x3C, 0x3C,0x00,0x18,0x00,0xF8,0x3C,0x3F,0x00,0x00,0x01,0xF0,0x3C,0x1F,0x80,0x00,0x07, 0xC0,0x3C,0x0F,0xF0,0x00,0x0F,0x00,0x7C,0x07,0xFC,0x00,0x3C,0x00,0x7C,0x01,0xE0, 0x00,0xF0,0x00,0x78,0x00,0xC0,0x07,0xC0,0xFC,0xF8,0x00,0x00,0x1E,0x00,0x1F,0xF8, 0x00,0x00,0x30,0x00,0x07,0xF0,0x00,0x00,0x00,0x00,0x03,0xC0,0x00,0x00,0x00,0x00, 0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0xE0,0x00,0x00,0x03,0x80,0x00,0xF0,0x00,0x00,0x07,0xC0,0x00,0xFF, 0xFF,0xFF,0xFF,0xE0,0x00,0xF0,0x00,0x00,0x07,0x80,0x00,0xF0,0x00,0x00,0x07,0x80, 0x00,0xF0,0x00,0x00,0x07,0x80,0x00,0xF0,0x00,0x00,0x07,0x80,0x00,0xF0,0x00,0x00, 0x07,0x80,0x00,0xF0,0x00,0x00,0x07,0x80,0x00,0xFF,0xFF,0xFF,0xFF,0x80,0x00,0xF0, 0x00,0x00,0x07,0x80,0x00,0xF0,0x00,0x70,0x07,0x80,0x00,0xF0,0x00,0x7C,0x00,0x00, 0x00,0xF0,0x00,0x78,0x00,0x00,0x00,0xF0,0x00,0x78,0x00,0x00,0x00,0xF0,0x00,0x78, 0x00,0x00,0x00,0xF0,0x00,0x78,0x00,0x60,0x00,0xF0,0x00,0x78,0x00,0xF0,0x00,0xFF, 0xFF,0xFF,0xFF,0xF8,0x00,0xFF,0xFF,0xFF,0xFF,0xFC,0x00,0xF0,0x00,0x78,0x00,0x00, 0x00,0xF0,0x00,0x78,0x00,0x00,0x00,0xF0,0x00,0x78,0x00,0x00,0x00,0xF0,0x00,0x78, 0x00,0x00,0x00,0xF0,0x00,0x78,0x00,0x00,0x00,0xE0,0x00,0x78,0x0C,0x00,0x01,0xE3, 0x80,0x78,0x1E,0x00,0x01,0xE3,0xFF,0xFF,0xFF,0x80,0x01,0xE3,0xE0,0x00,0x1F,0x00, 0x01,0xE3,0xE0,0x00,0x1E,0x00,0x01,0xC3,0xE0,0x00,0x1E,0x00,0x03,0xC3,0xE0,0x00, 0x1E,0x00,0x03,0xC3,0xE0,0x00,0x1E,0x00,0x03,0x83,0xE0,0x00,0x1E,0x00,0x07,0x83, 0xE0,0x00,0x1E,0x00,0x07,0x03,0xE0,0x00,0x1E,0x00,0x07,0x03,0xE0,0x00,0x1E,0x00, 0x0E,0x03,0xE0,0x00,0x1E,0x00,0x0E,0x03,0xFF,0xFF,0xFE,0x00,0x1C,0x03,0xE0,0x00, 0x1E,0x00,0x38,0x03,0xE0,0x00,0x1F,0x00,0x30,0x03,0xE0,0x00,0x18,0x00,0x20,0x03, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x70,0x00,0x00, 0x00,0x00,0x00,0x7C,0x00,0x38,0x00,0x00,0x00,0x7E,0x00,0x1E,0x00,0x00,0x00,0x78, 0x00,0x0F,0x80,0x00,0x00,0x78,0x00,0x0F,0xC0,0x00,0x00,0x78,0x00,0x07,0xC0,0x00, 0x00,0x78,0x00,0x03,0xC0,0x00,0x00,0x78,0x0E,0x03,0x80,0x70,0x00,0x79,0x8E,0x00, 0x00,0xF8,0x00,0x7B,0xCF,0xFF,0xFF,0xFC,0x7F,0xFF,0xFE,0x00,0x00,0xFC,0x18,0x78, 0x7E,0x00,0x00,0xE0,0x00,0x78,0x3E,0x30,0x01,0xC0,0x00,0x78,0x7C,0x78,0x01,0x80, 0x00,0x78,0x00,0x7C,0xF1,0x80,0x00,0x78,0x00,0xFE,0x3C,0x00,0x00,0x78,0x01,0xF0, 0x1F,0x00,0x00,0x78,0x01,0xE0,0x0F,0xC0,0x00,0x78,0x63,0xC0,0x07,0xE0,0x00,0x79, 0xC7,0x80,0x03,0xE0,0x00,0x7F,0x8F,0x00,0x03,0xF0,0x00,0x7E,0x1C,0x00,0x01,0xE0, 0x01,0xF8,0x78,0x00,0x00,0xE0,0x07,0xF8,0xE0,0x00,0x07,0x00,0x3F,0xF8,0x00,0x00, 0x0F,0x80,0x7F,0x78,0x1F,0xFF,0xFF,0xC0,0x3C,0x78,0x00,0x0F,0x00,0x40,0x18,0x78, 0x00,0x0F,0x00,0x00,0x00,0x78,0x00,0x0F,0x00,0x00,0x00,0x78,0x00,0x0F,0x00,0x00, 0x00,0x78,0x00,0x0F,0x00,0x00,0x00,0x78,0x00,0x0F,0x00,0x00,0x00,0x78,0x00,0x0F, 0x00,0x00,0x00,0x78,0x00,0x0F,0x00,0x00,0x00,0x78,0x00,0x0F,0x00,0x00,0x00,0x78, 0x00,0x0F,0x00,0x00,0x00,0x78,0x00,0x0F,0x00,0x60,0x00,0x78,0x00,0x0F,0x00,0xF0, 0x00,0x78,0x00,0x0F,0x01,0xF8,0x3E,0xF9,0xFF,0xFF,0xFF,0xFC,0x0F,0xF8,0x00,0x00, 0x00,0x06,0x03,0xF0,0x00,0x00,0x00,0x00,0x00,0xE0,0x00,0x00,0x00,0x00,0x00,0xC0, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x00, 0x01,0xC0,0x00,0x03,0xE0,0x00,0x01,0xF0,0x00,0x03,0xE0,0x00,0x01,0xF0,0x00,0x03, 0x80,0x00,0x01,0xE0,0x03,0x83,0x80,0x00,0x01,0xE0,0x03,0xE3,0x80,0x00,0x01,0xE0, 0x03,0xE3,0x80,0x00,0x01,0xE0,0x03,0xC3,0x80,0x01,0x81,0xE0,0x03,0x83,0x87,0x81, 0xF1,0xE0,0x07,0x83,0x8F,0xC1,0xF1,0xE0,0x07,0xFF,0xFF,0xE1,0xE1,0xE0,0x07,0x03, 0x80,0x61,0xE1,0xE0,0x0E,0x03,0x80,0x01,0xE1,0xE0,0x0E,0x03,0x80,0x01,0xE1,0xE0, 0x1C,0x03,0x80,0x61,0xE1,0xE0,0x18,0x03,0x80,0xF1,0xE1,0xE0,0x7F,0xFF,0xFF,0xF9, 0xE1,0xE0,0x3F,0xFF,0xFF,0xFD,0xE1,0xE0,0x00,0x03,0x80,0x01,0xE1,0xE0,0x00,0x03, 0x80,0x01,0xE1,0xE0,0x00,0x03,0x80,0x01,0xE1,0xE0,0x06,0x03,0x81,0xC1,0xE1,0xE0, 0x07,0x03,0x83,0xE1,0xE1,0xE0,0x07,0xFF,0xFF,0xF1,0xE1,0xE0,0x07,0x83,0x83,0xC1, 0xE1,0xE0,0x07,0x83,0x83,0xC1,0xE1,0xE0,0x07,0x83,0x83,0xC1,0xE1,0xE0,0x07,0x83, 0x83,0xC1,0xE1,0xE0,0x07,0x83,0x83,0xC1,0xE1,0xE0,0x07,0x83,0x83,0xC1,0xE1,0xE0, 0x07,0x83,0x83,0xC1,0xE1,0xE0,0x07,0x83,0x83,0xC1,0xC1,0xE0,0x07,0x83,0x83,0xC1, 0x01,0xE0,0x07,0x83,0x83,0xC0,0x01,0xE0,0x07,0x83,0xFF,0xC0,0x01,0xE0,0x07,0x83, 0x9F,0xC0,0x01,0xE0,0x07,0x83,0x87,0x80,0x01,0xE0,0x07,0x03,0x87,0x00,0x01,0xE0, 0x00,0x03,0x80,0x00,0x01,0xE0,0x00,0x03,0x80,0x00,0xFF,0xE0,0x00,0x03,0xC0,0x00, 0x1F,0xE0,0x00,0x03,0xC0,0x00,0x07,0xC0,0x00,0x03,0x80,0x00,0x03,0xC0,0x00,0x02, 0x00,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00, 0x1F,0x00,0x00,0x00,0x00,0x01,0xFF,0x00,0x00,0x00,0x00,0x1F,0xFF,0x80,0x00,0x00, 0x0F,0xFF,0xE0,0x80,0x00,0x1F,0xFF,0xC0,0x00,0x00,0x01,0xF8,0x03,0xC0,0x00,0x00, 0x00,0x00,0x07,0xF0,0x00,0x00,0x00,0x00,0x0F,0xC0,0x00,0x00,0x00,0x00,0x1F,0x00, 0x00,0x00,0x00,0x00,0x3E,0x00,0x30,0x00,0x00,0x00,0x78,0x00,0x78,0x00,0x00,0x00, 0xF0,0x00,0xFC,0x00,0x00,0x03,0xE0,0x01,0xFE,0x00,0x00,0x07,0x80,0x07,0xE0,0x00, 0x00,0x3E,0x7F,0xFF,0x80,0x00,0x00,0x3F,0xFF,0xBF,0x00,0x00,0x00,0x1F,0xC0,0x7C, 0x00,0x00,0x00,0x1E,0x01,0xF0,0x00,0x00,0x00,0x00,0x07,0xC0,0x00,0x00,0x00,0x00, 0x0F,0x81,0xE0,0x00,0x00,0x00,0x3E,0x00,0x78,0x00,0x00,0x00,0xF8,0x00,0x3E,0x00, 0x00,0x03,0xE0,0x00,0x1F,0x80,0x00,0x1F,0x80,0x00,0x1F,0xC0,0x00,0xFF,0xFF,0xFF, 0xF7,0xE0,0x00,0x7F,0xFF,0xF0,0x07,0xE0,0x00,0x7F,0x80,0xF0,0x03,0xE0,0x00,0x38, 0x00,0xF0,0x01,0xC0,0x00,0x00,0x00,0xF0,0x00,0xC0,0x00,0x01,0xE0,0xF6,0x00,0x00, 0x00,0x01,0xF0,0xF3,0xC0,0x00,0x00,0x03,0xF8,0xF1,0xF0,0x00,0x00,0x07,0xF8,0xF0, 0xFC,0x00,0x00,0x0F,0xC0,0xF0,0x3F,0x00,0x00,0x1F,0x00,0xF0,0x1F,0xC0,0x00,0x3E, 0x00,0xF0,0x0F,0xE0,0x00,0x7C,0x00,0xF0,0x07,0xF0,0x00,0xF0,0x00,0xF0,0x03,0xF0, 0x03,0xC0,0xF1,0xF0,0x01,0xF0,0x07,0x80,0x3F,0xF0,0x01,0xF0,0x1E,0x00,0x0F,0xE0, 0x00,0xF0,0x38,0x00,0x07,0xE0,0x00,0x00,0x00,0x00,0x03,0x80,0x00,0x00,0x00,0x00, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 }, { 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x1C,0x00,0x1C, 0x00,0x00,0x00,0x1F,0x00,0x0F,0x00,0x00,0x00,0x1F,0x80,0x0F,0x80,0x00,0x00,0x3E, 0x00,0x07,0xC0,0x00,0x00,0x3C,0x00,0x07,0xC0,0x00,0x00,0x7C,0x00,0x03,0xC0,0xE0, 0x00,0x78,0x00,0x03,0x81,0xF0,0x00,0xF0,0x3F,0xFF,0xFF,0xF8,0x00,0xF0,0x1F,0xFF, 0xFF,0xFC,0x01,0xE0,0xE0,0x0F,0x00,0x00,0x01,0xC0,0xF0,0x0F,0x80,0x00,0x03,0x81, 0xF8,0x1F,0xC0,0x00,0x07,0x81,0xF0,0x1E,0x00,0x00,0x0F,0x03,0xE0,0x3C,0x00,0x00, 0x1E,0x3F,0xC0,0x78,0x78,0x00,0x3F,0xFF,0x80,0xF0,0x3E,0x00,0x1F,0x8F,0x00,0xE0, 0x1F,0x00,0x0C,0x1E,0x01,0xC0,0x0F,0xC0,0x00,0x3C,0x03,0x80,0x07,0xE0,0x00,0x3C, 0x07,0x00,0x3F,0xF0,0x00,0x78,0x1F,0xFF,0xFD,0xF0,0x00,0xF0,0x0F,0xFC,0x78,0xF0, 0x01,0xE0,0x0F,0xFC,0x78,0xF0,0x03,0xC0,0x06,0x7C,0x78,0x00,0x07,0x83,0xF8,0x7C, 0x78,0x00,0x1F,0xFF,0x80,0x7C,0x78,0x00,0x0F,0xF8,0x00,0x7C,0x78,0x00,0x0F,0xC0, 0x00,0x78,0x78,0x00,0x07,0x00,0x00,0x78,0x78,0x00,0x00,0x00,0x00,0x78,0x78,0x00, 0x00,0x00,0x00,0x78,0x78,0x00,0x00,0x00,0x00,0x78,0x78,0x00,0x00,0x00,0xF8,0xF8, 0x78,0x00,0x00,0x0F,0xC0,0xF0,0x78,0x30,0x01,0xFE,0x00,0xF0,0x78,0x30,0x1F,0xF0, 0x01,0xF0,0x78,0x38,0x1F,0xC0,0x01,0xE0,0x78,0x38,0x0F,0x00,0x03,0xC0,0x78,0x38, 0x0E,0x00,0x07,0x80,0x78,0x38,0x00,0x00,0x1F,0x00,0x78,0x7C,0x00,0x00,0x3E,0x00, 0x7F,0xFC,0x00,0x00,0xF8,0x00,0x3F,0xF8,0x00,0x01,0xC0,0x00,0x00,0x00,0x00,0x03, 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00 } }; void ctrl_beep(unsigned char state) { unsigned char cmd = state; write(beep_fd, &cmd, 1); } //num:要控制哪一个led灯 0-3 4:控制所有的 //state: 0 灯亮 1 灯灭 void ctrl_led(int num, unsigned char state) { unsigned char cmd[2]; cmd[0] = num; cmd[1] = state; write(led_fd, cmd, 2); } //初始化串口 int init_serial(const char *file, int baudrate) { int fd; fd = open(file, O_RDWR); if (fd == -1) { perror("open device error:"); return -1; } struct termios myserial; //清空结构体 memset(&myserial, 0, sizeof (myserial)); //O_RDWR myserial.c_cflag |= (CLOCAL | CREAD); //设置控制模式状态,本地连接,接受使能 //设置 数据位 myserial.c_cflag &= ~CSIZE; //清空数据位 myserial.c_cflag &= ~CRTSCTS; //无硬件流控制 myserial.c_cflag |= CS8; //数据位:8 myserial.c_cflag &= ~CSTOPB;// //1位停止位 myserial.c_cflag &= ~PARENB; //不要校验 //myserial.c_iflag |= IGNPAR; //不要校验 //myserial.c_oflag = 0; //输入模式 //myserial.c_lflag = 0; //不激活终端模式 switch (baudrate) { case 9600: cfsetospeed(&myserial, B9600); //设置波特率 cfsetispeed(&myserial, B9600); break; case 115200: cfsetospeed(&myserial, B115200); //设置波特率 cfsetispeed(&myserial, B115200); break; case 19200: cfsetospeed(&myserial, B19200); //设置波特率 cfsetispeed(&myserial, B19200); break; } /* 刷新输出队列,清楚正接受的数据 */ tcflush(fd, TCIFLUSH); /* 改变配置 */ tcsetattr(fd, TCSANOW, &myserial); return fd; } /* @brief 在坐标为(x,y)的位置画一个颜色为color的像素点 @param x 横坐标 @param y 纵坐标 @param color 像素点的颜色 @return void */ void lcd_draw_point(int x, int y, int color) { *(plcd + y*800 + x) = color; } /* @brief 在坐标为(x0,y0)的位置画一个颜色为color矩形 @param x0 横坐标 @param y0 纵坐标 @param w 矩形的宽度 @param h 矩形的高度 @param color 矩形的颜色 @return void */ void lcd_draw_rect(int x0, int y0, int w, int h, int color) { int x, y; for (y = y0; y < y0+h; y++) { for (x = x0; x < x0+w; x++) lcd_draw_point(x, y, color); } } /* @brief 将lcd清除成某种颜色 @param color 显示的颜色 @return void */ void lcd_clear_screen(int color) { int x, y; for (y = 0; y < 480; y++) { for (x = 0; x < 800; x++) lcd_draw_point(x, y, color); } } /* @brief 在坐标为(x0, y0)的位置开始显示一个文字 @param x0 横坐标 @param y0 纵坐标 @param len 字模数组的长度 @param w 文字的宽度 @param color 文字的颜色 @return void */ void lcd_draw_word(int x0,int y0,char ch[], int len, int w, int color) { int i, j; int flag; flag = w/8; //遍历整个字模数组 for (i = 0; i < len; i++) { //求每一个字节中的每一位 for (j = 7; j >= 0; j--) { if ((ch[i] >> j) & 1) { //画一个点 lcd_draw_point(7-j + 8*(i%flag) + x0,i/flag + y0,color); } } } } /* @brief 在坐标为(x0,y0)的位置显示一个数字(0~9) @param x0 横坐标 @param y0 纵坐标 @param w 数字的高度 @param color 数字的颜色 @return void */ void lcd_draw_digit(int num, int x0, int y0, int color, int w) { lcd_draw_word(x0, y0, digit[num], sizeof(digit[num]), w, color); } /* @brief 在坐标为(x0, y0)的位置开始显示一张bmp图片 @param x0 横坐标 @param y0 纵坐标 @param w 图片的宽度 @param h 图片的高度 @return void */ void lcd_draw_bmp(char *file, int x0, int y0, int w, int h) { // 打开bmp图片 int fd; fd = open(file, O_RDWR); if (-1 == fd) { printf("open file :%s error !\n", file); return ; } int len = w*h*3+54; char bit[len]; read(fd, bit, len); close(fd); //遍历整个数组 int i = 0, x, y; for (y = 0; y < h; y++) { for (x = 0; x < w; x++) { char b, g, r; int color; b = bit[54+i]; g = bit[54+i+1]; r = bit[54+i+2]; i += 3; color = (r<<16) | (g<<8) | b; //显示颜色 lcd_draw_point(x + x0,h-y+y0,color); } } } void show_start_screen() { //展示音乐播放界面 lcd_draw_bmp("music.bmp", 10, 190, 240, 240); //显示播放按钮 lcd_draw_bmp("play.bmp", 92, 270, 80, 78); //显示关灯按钮 lcd_draw_bmp("light_off.bmp", 350, 190, 144, 240); lcd_draw_bmp("tem.bmp", 614, 150, 44, 96); lcd_draw_bmp("hum.bmp", 596, 270, 80, 80); lcd_draw_bmp("atmos.bmp", 586, 380, 100, 80); } int get_touch_area() { //打开触摸屏 int fd; fd = open("/dev/event0", O_RDWR); if (-1 == fd) { printf("open touch error !\n"); return ; } struct input_event ev; int x, y; while (1) { read(fd, &ev, sizeof(ev)); //判断是否为触摸事件 if ((ev.type == EV_ABS) && (ev.code == ABS_X)) { x = ev.value; } else if ((ev.type == EV_ABS) && (ev.code == ABS_Y)) { y = ev.value; } //手指弹起 if ((ev.type == EV_ABS) && (ev.code == ABS_PRESSURE) && (ev.value == 0)) break; } close(fd); // printf("x: %d, y: %d\n",x, y); //音乐播放或者暂停界面 if ((x >= 92) && (x <= 160) && (y >= 270) && (y <= 340)) { if (music_state == 0) { music_state = 1; return MUSIC_PLAY; } else { music_state = 0; return MUSIC_PAUSE; } } //音量+ else if ((x >= 70) && (x <= 180) && (y >= 210) && (y <= 255)) { return VOICE_ADD; } //音量- else if ((x >= 70) && (x <= 180) && (y >= 360) && (y <= 410)) { return VOICE_MINUS; } //下一首 else if ((x >= 180) && (x <= 240) && (y >= 270) && (y <= 345)) { printf("music next ...\n"); return MUSIC_NEXT; } //上一首 else if ((x >= 10) && (x <= 75) && (y >= 270) && (y <= 345)) { printf("music last ...\n"); return MUSIC_LAST; } //控制灯的关或者灭 else if ((x >= 350) && (x <= 494) && (y >= 190) && (y <= 430)) { if (light_state == 0) { light_state = 1; return LIGHT_ON; } else { light_state = 0; return LIGHT_OFF; } } } /* @brief 在坐标为(x0,y0)的位置显示一个4位数以内的整数 @param x0 横坐标 @param y0 纵坐标 @param num 要显示的整数 @return void */ void lcd_show_digit(int num, int x, int y) { int a, b, c, d; if ((num / 1000) == 0) { if ((num / 100) == 0) { if ((num / 10) == 0) { lcd_draw_digit(num, x+16+16+16, y, 0x00ff0000, 16); } else { c = num / 10; lcd_draw_digit(c, x+16+16, y, 0x00ff0000, 16); d = num % 10; lcd_draw_digit(d, x+16+16+16, y, 0x00ff0000, 16); } } else { //百位 b = num/100; lcd_draw_digit(b, x+16, y, 0x00ff0000, 16); c = num % 100 / 10; lcd_draw_digit(c, x+16+16, y, 0x00ff0000, 16); d = num % 10; lcd_draw_digit(d, x+16+16+16, y, 0x00ff0000, 16); } } else { //千位 a = num/1000; //void lcd_draw_digit(int num, int x0, //int y0, int color, int w) lcd_draw_digit(a, x, y, 0x00ff0000, 16); //百位 b = num%1000/100; lcd_draw_digit(b, x+16, y, 0x00ff0000, 16); c = num % 100 / 10; lcd_draw_digit(c, x+16+16, y, 0x00ff0000, 16); d = num % 10; lcd_draw_digit(d, x+16+16+16, y, 0x00ff0000, 16); } } //监测 烟雾传感器 void *monitor_smoke(void *arg) { int fd = init_serial(SERIAL2, 9600); char cmd[] = {0xff,0x01,0x86,0x00,0x00,0x00,0x00,0x00,0x79}; int total_read; int res; int value; while (1) { write(fd, cmd, sizeof(cmd)); char ack[10]; memset(ack, 0, sizeof(ack)); res = read(fd, ack, 9); if (res == 9) { int i; printf("*** smoke ***\n"); for (i = 0; i < 9; i++) printf("%x ",ack[i]); printf("\n"); if ((ack[0] == 0xFF) && (ack[1] == 0x86)) { value = (ack[2] << 8) | ack[3]; } if ((value >= 0x0100) && (beep_state == 0)) { //打开beep beep_state = 1; } else { if (beep_state == 1) { //关闭beep beep_state = 0; } } } usleep(200000); } } //监测 气象传感器 void *monitor_wed(void *arg) { char cmd[3] = {0xa5, 0x82, 0x27}; char ack[15]; int i; int fd = init_serial(SERIAL1, 9600); while (1) { write(fd, cmd, 3); read(fd, ack, 15); printf("***wed***\n"); for(i = 0; i < 15; i++) printf("%x ", ack[i]); printf("\n"); if ((ack[0] == 0x5a) && (ack[1] == 0x5a)) { int web; int shidu; int qiya; int haiba; web = ((ack[4]<<8) | ack[5])/100; printf("wendu: %d\n", web); lcd_draw_rect(680,190, 100, 20,0xffffffff); lcd_show_digit(web, 680, 190); //lcd_draw_bmp("atmos.bmp", 586, 380, 100, 80); qiya = ((ack[6]<<14)|(ack[7]<<16)|(ack[8]<<8)|ack[9])/10000; printf("qiya: %d\n", qiya); lcd_draw_rect(700,410, 100, 20,0xffffffff); lcd_show_digit(qiya, 700, 410); shidu = ((ack[10]<<8)|ack[11])/100; printf("shidu: %d\n", shidu); lcd_draw_rect(680,290, 100, 20,0xffffffff); lcd_show_digit(shidu, 680, 290); } sleep(1); } } int main(int argc, char *argv[]) { //把lcd给打开 //定义一个变量接收open的返回值 int fd; fd = open("/dev/fb0", O_RDWR); //if (fd == -1) if (-1 == fd) { printf("open lcd error !\n"); return 0; } //把整个LCD全部显示成红色 0x00ff0000 //lcd的分辨率:800*480 //个像素点,每一个像素点占4byte int buf[800*480]; int i; for(i = 0; i < 800*480; i++) buf[i] = 0x00ff0000; //write(fd, buf, 800*480*4); //内存映射 //800*480*4 :操作系统的内存管理 //以页(page)为单位: 1page = 4096byte = 4k plcd = mmap(NULL, 800*480*4, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); //plcd就指向了映射的内存的首地址=>plcd指向了lcd//中的第一个像素点 //操作plcd就相当于操作 lcd设备了 //如果要将第10个像素点显示成红色,该如何操作 //plcd //指针如何访问指针所指向的地址的内容: * //把指针当做数组:plcd[下标] //*(plcd + n) = 0x00ff0000; //如何将坐标为(x, y)的像素点显示成红色? //*(plcd + y*800 + x) = 0x00ff0000; //通过调用lcd_draw_point函数实现将整个lcd显示成//蓝色 #if 0 int x, y; for (y = 0; y < 480; y++) { for (x = 0; x < 800; x++) lcd_draw_point(x, y, 0x000000ff); } #endif //lcd_draw_rect(0, 0, 800, 480, 0xffffffff); //显示开始界面 lcd_clear_screen(0xffffffff); //lcd_draw_rect(int x0, int y0, int w, int h, //int color) //lcd_draw_rect(50, 50, 200, 200, 0x000000ff); //void lcd_draw_word(int x0,int y0,char ch[], //int len, int w, int color) //显示标题的汉字 for (i = 0; i < 8; i++) { lcd_draw_word(170+i*(10+48), 50, title[i], sizeof(title[i]), 48, 0x0000ff00); } //显示开始界面 show_start_screen(); //监测烟雾传感器 //monitor_smoke(NULL); //监测温度、湿度大气压力传感器 //monitor_wed(NULL); led_fd = open("/dev/led", O_RDWR); beep_fd = open("/dev/beep", O_RDWR); //ctrl_beep(atoi(argv[1])); //ctrl_led(atoi(argv[2]), atoi(argv[3])); int music_fd; music_fd = init_serial(SERIAL3, 9600); while (1) { int ret; ret = get_touch_area(); if (ret == MUSIC_PLAY) { //播放音乐 char cmd[] = {0x7e, 0x03, 0x01, 0x02, 0xEF}; write(music_fd, cmd, 5); //显示暂停按钮 lcd_draw_bmp("pause1.bmp", 92, 270, 80, 78); } else if (ret == MUSIC_PAUSE) { //暂停音乐 char cmd[] = {0x7e, 0x03, 0x02, 0x01, 0xEF}; write(music_fd, cmd, 5); lcd_draw_bmp("play.bmp", 92, 270, 80, 78); } else if (ret == MUSIC_NEXT) { //下一曲 char cmd[] = {0x7e, 0x03, 0x03, 0x00, 0xEF}; write(music_fd, cmd, 5); } else if (ret == MUSIC_LAST) { //上一曲 char cmd[] = {0x7e, 0x03, 0x04, 0x07, 0xEF}; write(music_fd, cmd, 5); } else if (ret == VOICE_ADD) { //音量增 char cmd[] = {0x7e, 0x03, 0x05, 0x06, 0xEF}; write(music_fd, cmd, 5); } else if (ret == VOICE_MINUS) { //音量减 char cmd[] = {0x7e, 0x03, 0x06, 0x05, 0xEF}; write(music_fd, cmd, 5); } else if (ret == LIGHT_OFF) { printf("**** light off ****\n"); ctrl_led(4, 1); lcd_draw_bmp("light_off.bmp", 350, 190, 144, 240); // pthread_cancel(pid3); } else if (ret == LIGHT_ON) { printf("**** light on ****\n"); ctrl_led(4, 0); lcd_draw_bmp("light_on.bmp", 350, 190, 144, 240); //pthread_t pid3; //pthread_create(&pid3, NULL, show_led, NULL); } } return 0; }
时间: 2024-11-08 05:20:35