思路:
- 配置语言模块硬件库(说什么话之类的)
- 刷固件到语言模块上(USB转TTL)
- 连接安卓手机,使其能处于USB调试状态
- 测试shell指令(abd shell指令)
- 编写并封装串口收发函数(下一篇)
- 编写主函数
- 实现功能
配置语言模块硬件库(说什么话之类的)
用的是智能公元的SU-03T
![](https://i-blog.csdnimg.cn/blog_migrate/993cbb433f3cbc297f5c66650db9a142.png)
设置好名字和语言以后设置输出模式,设置完B6,B7自动设置完成
![](https://i-blog.csdnimg.cn/blog_migrate/da2b3d89e5ed10bf97506ef6a16874bc.png)
设置这三个地方
![](https://i-blog.csdnimg.cn/blog_migrate/fc4f4e4f0f4dc0d3eca8816a6dd121b7.png)
设置完成添加控制
![](https://i-blog.csdnimg.cn/blog_migrate/2289e045298bed95c1301b4cda30b2c7.png)
后面的配置根据个人来配
生成固件库,等待下载
刷固件到语言模块上(USB转TTL)
连线,类似于串口模块和单片机连接,T-R;R-T
刷机(找商家要教程)
连接安卓手机,使其能处于USB调试状态
先用dmesg指令查看内核相关信息
插入手机(记得在开发者选项中选择USB可调试状态),华为手机会提示充电还是传输文件还是传输照片,我们选择传输文件,因为Linux之上皆文件
插入之后重新dmesg,滑倒最下面会有这些关于你手机的信息
![](https://i-blog.csdnimg.cn/blog_migrate/167078ed57f556732031a4691754c7eb.png)
sudo apt-get install adb :与安卓手机交互
adb devices :查看手机设备信息
![](https://i-blog.csdnimg.cn/blog_migrate/8eaa060e7195ef10a2372e0fff5ec2b6.png)
正常情况下,敲打两次指令后是这样的
接下来就可以测试指令了
测试shell指令(abd 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 锁屏
编写并封装串口收发函数(下一篇)
编写主函数
主函数:
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <stdint.h>
4 #include <stdarg.h>
5 #include <string.h>
6 #include <termios.h>
7 #include <unistd.h>
8 #include <fcntl.h>
9 #include <sys/ioctl.h>
10 #include <sys/types.h>
11 #include <sys/stat.h>
12 #include <pthread.h>
13 #include "wiringSerial.h"
14 #include <unistd.h>
15 #include "uartTool.h"
16
17 int fd;//定义一个进程标识符
18 void* readserial()//指针函数,返回值是一个指针
19 {
20
21 char cmd;
22 while(1){
23
24 cmd = myserialGetchar(fd);//参考uartTool.c中的myserialGetchar(获取一个字符)
25
26 switch(cmd){//这里获取的字符是由语言模块硬件配置SDK生成得到的
27
28 case'N':
29 printf("next\n");
30 system("adb shell input swipe 540 1300 540 500 100");//通过adb shell指令来控制安卓手机的操作手势,这是上滑
//其中540是x轴,1300和500是y轴,100是动作时间
31 break;
32 case'P':
33 printf("pre\n");
34 system("adb shell input swipe 540 500 540 1300 100");//向下滑动的动作
35 break;
36 case'Z':
37 printf("zan\n");
38 system("adb shell \"seq 6 | while read i;do input tap 350 1050 & input tap 350 1050 &sleep 0.001;done;\"");//6代表6次,0.001是间隔时间
39 break;
40 case'Q':
41 printf("quit\n");
42 system("adb shell input keyevent 26");//息屏动作
43 break;
44
45
46
47 }
48
49 }
50
51 }
52
53
54 int main(int argc,char** argv)//主函数,以输入的形式运行argv[0]是'./';argv[1]是'a.out';argv[2]是串口硬件所在'/dev/ttyS?',我这里是5
55 {
56 char deviceName[32] = {'\0'};//定义一个32字符,并且初始化位0
57
58 pthread_t readt;//设置一个进程
59
60 if(argc < 2){
61 printf("uage:%s /dev/ttyS?\n",argv[0]);
62 return -1;//不成功返回-1
63 }
64
65 strcpy(deviceName,argv[1]);//字符串操作函数,把后面的值赋予前面
66
67 if((fd = MyserialOpen(deviceName,115200)) == -1){//打开串口
68
69 printf("open %s error\n",deviceName);
70 return -1;//不成功返回-1
63 }
71
72 }
73
74 pthread_create(&readt,NULL,readserial,NULL);//创建进程
75
76 while(1){//不让函数退出
77
78
79 sleep(10);
80
81
82 }
实现功能:
./uartTool.c douy.c -lpthread
./a.out /adv/ttyS5
//即可运行成功