一.硬件准备
香橙派zero2 SU03-T语音模块
二.项目原理图
三.语音模块配置
四.编程实现语音和开发板通信
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <pthread.h>
#include "uartTool.h"
int fd;
void* readSerial()
{
char cmd;
while(1){
cmd = myserialGetchar(fd);
switch(cmd){
case 'N':
printf("next\n");
break;
case 'P':
printf("pre\n");
break;
case 'Z':
printf("zan\n");
break;
case 'Q':
printf("qu\n");
break;
}
}
}
int main(int argc, char **argv)
{
char deviceName[32] = {'\0'};
pthread_t readt;
if(argc < 2){
printf("uage:%s /dev/ttyS?\n",argv[0]);
return -1;
}
strcpy(deviceName, argv[1]);
if( (fd = myserialOpen(deviceName, 115200)) == -1){
printf("open %s error\n",deviceName);
return -1;
}
pthread_create(&readt, NULL, readSerial,NULL);
while(1){sleep(10);}
return 0;
}
五.手机接入Linux热拔插相关
- 把手机接入开发板
- 安装adb工具,在终端输入adb安装指令: sudo apt-get install adb
- dmeg能查看到手机接入的信息,但是输入adb devices会出现提醒 dinsufficient permissions for device: user in plugdev group; are your udev rules wrong?
- 配置文件,以支持USB设备的热拔插,支持UDEV的机制 在/etc/udev/rules.d 文件夹下创建规则文件 cd /etc/udev/rules.d/ sudo vim 51-android.rules 在文件中添加内容 SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", MODE="0666"
- 在手机开发者选项中,打开USB调试,重新拔插手机 f. 手机弹出调试提醒,点确认手机调试模式
六.用shell指令来操作手机屏幕,模拟手动滑屏幕
adb shell input swipe 540 1300 540 500 100 向下滑动540是水平的,1300是竖直方向,下 是
500
adb shell input swipe 540 500 540 1300 100 向上滑动
adb shell "seq 3 | while read i;do input tap 350 1050 & input tap 350 1050 &
sleep 0.01;done;" 点赞
adb shell input keyevent 26 锁屏
七.最终程序
#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 <unistd.h>
#include <pthread.h>
#include "uartTool.h"
int fd;
void* readSerial()
{
char cmd;
while(1){
cmd = myserialGetchar(fd);
switch(cmd){
case 'N':
printf("next\n");
system("adb shell input swipe 540 1300 540 500 100");
break;
case 'P':
printf("pre\n");
system("adb shell input swipe 540 500 540 1300 100");
break;
case 'Z':
printf("zan\n");
system("adb shell \"seq 3 | while read i;do input tap 350 1050 &
input tap 350 1050 & sleep 0.01;done;\"");
break;
case 'Q':
printf("qu\n");
system("adb shell input keyevent 26");
break;
}
}
}
int main(int argc, char **argv)
{
char deviceName[32] = {'\0'};
pthread_t readt;
if(argc < 2){
printf("uage:%s /dev/ttyS?\n",argv[0]);
return -1;
}
strcpy(deviceName, argv[1]);
if( (fd = myserialOpen(deviceName, 115200)) == -1){
printf("open %s error\n",deviceName);
return -1;
}
pthread_create(&readt, NULL, readSerial,NULL);
while(1){sleep(10);}
return 0;
}