产品做优化好还是超级网站好,ui页面设计规范,装修公司前十强,设计网站pc版文章目录 所需器材装备操作SU-03T语音模块配置代码#xff08;没有用wiring库#xff0c;自己实现串口通信#xff09;结束 所需器材
可以百度了解以下器材
orangepi-zero2全志开发板
su-03T语音识别模块
USB-TTL模块
一个安卓手机
一根可以传输的数据线
装备操作
安… 文章目录 所需器材装备操作SU-03T语音模块配置代码没有用wiring库自己实现串口通信结束 所需器材
可以百度了解以下器材
orangepi-zero2全志开发板
su-03T语音识别模块
USB-TTL模块
一个安卓手机
一根可以传输的数据线
装备操作
安卓手机开启开发者模式并开启USB调试功能。 插入开发板跳出什么就点允许就行否则可能没有权限开发板无权访问手机系统
SU-03T语音模块配置
进入网站http://www.smartpi.cn/ 这个模块其实进入网站点点点就可以完成非常方便但是没有什么技术含量
配置SU-03T模块 设置串口通信 设置唤醒词 设置命令触发 设置触发之后发送的命令 到此点击身材sdk安静等待就可以了搞好之后需要将sdk上传至语音模块
将USB-TTL模块插入电脑并将TXRX与模块的TXRX交叉相接。 将下载的sdk文件打开上传即可图就不放了较简单
可以使用串口工具测试一下~
测试没问题将语音模块RX和TX接入开发板的RXTX端口
代码没有用wiring库自己实现串口通信
由于没有用wiring库所以多出俩个工具文件。当然也是用source insight分析源码cv编写没写注释将就看吧这俩个文件比较难啃都是和linux内核打交道struct termios options;
uartTools.c
#include stdio.h
#include stdlib.h
#include stdint.h
#include stdarg.h
#include string.h
#include termios.h
#include unistd.h
#include fcntl.h
#include sys/ioctl.h
#include sys/types.h
#include sys/stat.hint myserialOpen (const char *device, const int baud)
{speed_t myBaud ;int status, fd ; struct termios options;switch (baud){case 9600: myBaud B9600 ; break ;case 115200: myBaud B115200 ; break ;}if ((fd open (device, O_RDWR | O_NOCTTY | O_NDELAY | O_NONBLOCK)) -1)return -1 ;fcntl (fd, F_SETFL, O_RDWR) ;// Get and modify current options:tcgetattr (fd, options) ;cfmakeraw (options) ;cfsetispeed (options, myBaud) ;cfsetospeed (options, myBaud) ;options.c_cflag | (CLOCAL | CREAD) ;options.c_cflag ~PARENB ;options.c_cflag ~CSTOPB ;options.c_cflag ~CSIZE ; options.c_cflag | CS8 ; //数据位8个options.c_lflag ~(ICANON | ECHO | ECHOE | ISIG) ;options.c_oflag ~OPOST ;options.c_cc [VMIN] 0 ;options.c_cc [VTIME] 100 ; // Ten seconds (100 deciseconds)tcsetattr (fd, TCSANOW, options) ;ioctl (fd, TIOCMGET, status);status | TIOCM_DTR ;status | TIOCM_RTS ;ioctl (fd, TIOCMSET, status);usleep (10000) ; // 10mSreturn fd ;
}void myserialPutchar (const int fd, const unsigned char c)
{int ret;ret write (fd, c, 1) ;if (ret 0)printf(Serial Putchar Error\n);
}void mySerialSendString(const int fd,const unsigned char *str)
{if(write(fd,str,strlen(str)) 0){printf(Serial sendString Error\n);}
}int mySerialGetchar(const int fd, unsigned char *c)
{if(read(fd,c,1) !1){return -1 ;}}int mySerialGetString(const int fd, unsigned char *str)
{if(read(fd,str,32) ! 32){return -1;}
}
uartTools.h
#ifndef _UART_TOOLS_H_
#define _UART_TOOLS_H_
int myserialOpen (const char *device, const int baud);
void myserialPutchar (const int fd, const unsigned char c);
void mySerialSendString(const int fd,const unsigned char *str);
int mySerialGetchar(const int fd, unsigned char *c);
int mySerialGetString(const int fd, unsigned char *str);#endifuart.c 到这里就是简单的处理语音模块发来的命令了
#include stdio.h
#include stdlib.h
#include stdint.h
#include stdarg.h
#include string.h
#include termios.h
#include unistd.h
#include fcntl.h
#include sys/ioctl.h
#include sys/types.h
#include sys/stat.h
#include pthread.h#include uartTools.hint fd;void *recvHandler()
{char *recvBuf;recvBuf (char *)malloc(sizeof(char)*32);if(recvBuf NULL){printf(recvHandler malloc fail\n);}while(1){memset(recvBuf,\0,strlen(recvBuf));mySerialGetchar(fd,recvBuf);switch(*recvBuf){case N:printf(next\n);system(adb shell input swipe 540 1300 540 500 100); //adb 命令模拟手机滑动屏幕break;case P:printf(pre\n);system(adb shell input swipe 540 500 540 1300 100);break;case Z:system(adb shell \seq 2 | while read i;do input tap 350 1050 input tap 350 1050 sleep 0.2;done;\);printf(zan\n);break;case Q:printf(quit\n);system(adb shell input keyevent 26);break;}}}int main(char argc, char **argv)
{char filename[32] {\0};pthread_t recvPthread;if(argc 2){printf(uage:%s /dev/ttyS?\n,argv[0]);return -1;}strcpy(filename,argv[1]);if((fd myserialOpen(filename,115200)) -1){printf(open %s error\n,filename);return -1;}pthread_create(recvPthread,NULL,recvHandler,NULL);while(1){sleep(10);}return 0;
}
结束
如有问题欢迎提出共同进步