#include "fun.h"
#include "pic_ch/tg_bmp_display.h"
#include "pic_ch/tg_lcd.h"
char a = 0;
int cmp_flg = 0;
//24*35
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
}
};
//多个进程好像都用到了啊
//多进程程好像用到的不是同一个xc哦???去验证
//这里应该用进程间通信去传递xc号吧???
/*
1.创建并打开共享内存
*/
char* ckddr4()
{
key_t key;
//step1:申请一个system V IPC的键值
key = ftok(PATHNAME,PRO_ID);
if(key == -1)
{
perror("ftok error:");
return NULL;
}
//step2:创建一个共享内存
int shm_id = shmget(key,4096,IPC_CREAT|0666); //创建
shm_id = shmget(key,4096,0); //打开
if(shm_id==-1)
{
perror("shmget error:");
}
//step3:映射
char*p = shmat(shm_id,NULL,0);
if(p == NULL)
{
perror("shmat error:");
return NULL;
}
return p;
}
/*
2.串口初始化函数
*/
int init_serial(const char *file, int baudrate)
{
// printf("-----%d-----\n",__LINE__);
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);
// printf("-----%d-----\n",__LINE__);
return fd;
}
/*
3.字符串对应相应的指令
*/
void duiying(char* s,pthread_t* p_xc,char* p)
{
if(strcmp(s,"deng")==0) //开灯
{
//开灯
kz_led(1);
}
else if(strcmp(s,"nodeng")==0) //关灯
{
//关灯
kz_led(0);
}
else if(strcmp(s,"lian")==0) //开帘子
{
//帘子
kz_dj(1);
}
else if(strcmp(s,"nolian")==0) //关帘子
{
//NO帘子
kz_dj(2);
}
else if(strcmp(s,"kong")==0) //开空调
{
//开空调
kz_dj(3);
}
else if(strcmp(s,"nokong")==0) //关空调
{
//关空调
kz_dj(0);
}
else if(strcmp(s,"yuyin")==0) //开语音
{
//语音
kz_jdq(1);
kz_jdq(1);
kz_jdq(1);
system("mplayer mp34_mulu/yuyin.mp3");
}
else if(strcmp(s,"noyuyin")==0) //关语音
{
//语音关
kz_jdq(0);
kz_jdq(0);
kz_jdq(0);
system("mplayer mp34_mulu/noyuyin.mp3");
}
else if(strcmp(s,"1mp3")==0)
{
a = 9;
*(p+1) = 1; //分界面
//1mp3
system("killall -9 mplayer"); //结束音乐
//显示音乐图片
bmp_display("pic_mulu/3.bmp",0,0);
pthread_create(p_xc, NULL,player,(void*)&a); //音乐1
}
else if(strcmp(s,"2mp3")==0)
{
a = 10;
*(p+1) = 1; //分界面
//2mp3
system("killall -9 mplayer"); //结束音乐
//显示音乐图片
bmp_display("pic_mulu/4.bmp",0,0);
pthread_create(p_xc, NULL,player,(void*)&a); //音乐2
}
else if(strcmp(s,"1tg")==0)
{
a = 15;
*(p+1) = 1; //分界面
//11mp3
system("killall -9 mplayer"); //结束音乐
//显示音乐图片
bmp_display("pic_mulu/11.bmp",0,0);
pthread_create(p_xc, NULL,player,(void*)&a); //音乐11
}
else if(strcmp(s,"bkx")==0)
{
a = 15;
//*(p+1) = 1; //分界面
//11mp3
system("killall -9 mplayer"); //结束音乐
system("mplayer mp34_mulu/bng.mp3");
//显示音乐图片
//bmp_display("pic_mulu/11.bmp",0,0);
pthread_create(p_xc, NULL,player,(void*)&a); //音乐11
}
else if(strcmp(s,"1mp4")==0)
{
a = 11;
*(p+1) = 1; //分界面
//1mp4
system("killall -9 mplayer"); //结束视频
pthread_create(p_xc, NULL,player,(void*)&a); //视频1
}
else if(strcmp(s,"2mp4")==0)
{
a = 12;
*(p+1) = 1; //分界面
//2mp4
system("killall -9 mplayer"); //结束视频
pthread_create(p_xc, NULL,player,(void*)&a); //视频2
}
else if(strcmp(s,"stop")==0)
{
//stop
system("killall -9 mplayer"); //结束音乐
pthread_cancel(*p_xc); //线程退出
pthread_join(*p_xc, NULL); //线程收尸
//显示主界面图片
bmp_display("pic_mulu/1.bmp",0,0);
*(p+1) = 0; //主界面
}
else if(strcmp(s,"red1