学习日志(十六)
基于Linux串口的语音控制刷抖音(详版)
很细很细。。。
总体框架
设备连接:
语音模块时B7是Tx
orangepi用的是sttyS5 串口5
语音模块
如何配置
创建产品:
随便选产品:
模块型号:SU-03
配置GPIO_B6 B7:
添加唤醒词:
添加语音指令:
添加控制:
其他设置按需求选就可以了。
生成固件。
如何烧录固件
解压出来,看到此文件:
再:
再:
再:
打开软件选择固件:
固件的位置跟软件再一个目录下,看上面操作:
D:\uni_hb_m_solution\image_demo\Hummingbird-M-Update-Tool
选择好固件点击烧录:
此时需要冷启动
等待完成:
Orangepi配置
用Type-c连接手机和orangepi zero2
输入指令查看usb设备:
dmesg
此时能看到usb设备号 (SerialNumber)和名称(HUAWEI),
这时只是单纯的识别了 这个 usb设备,但没有什么办法调试这个手机。
所以借用adb指令与android系统连接并进行调试:
输入指令:
adb devices
发现没安装adb:
安装adb:
sudo apt-get install adb
再次调用adb:
原因:
这是因为手机还没打开开发者模式,adb无法与android系统连接。
那么。。。。
下面打开开发者模式后:
再次输入adb devices 指令查看与adb连接的设备出现以下问题(没有访问权限,也就是没有生成文件柄,应用层无法操作接入的硬件设备):
此时:需要配置文件,以支持USB设备的热拔插,支持UDEV的机制
linux下一切皆文件:
udev机制:说白了就是为插入或者拔掉的设备,添加文件柄删除文件柄。
在/etc/udev/rules.d文件夹下创建规则文件
sudo vim 51-android.rules
在文件中添加内容
SUBSYSTEM==“usb”,ENV{DEVTYPE}==“usb_device”,MODE=“0666”
输入指令:
sudo vim /etc/udev/rules.d/51-android.rules
写入:
然后重新拔插一下手机(别忘记开开发者模式):
再次输入adb devices
就会弹出来usb调试确认界面,需要手动点击确认(有时候弹不出来,拔插多试试)
到此adb 和Android连接成功,此时adb可以调试Android,通过shell指令控制手机。
再输入:
adb shell
进入手机成功:
退出:
用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 4 | while read i;do input tap 350 1050 & input tap 350 1050 &sleep 0.01;done;” 点赞
adb shell input keyevent 26 锁屏
最后代码:
1 #include "uartTool.h"
2 #include "pthread.h"
3 #include "string.h"
4 #include "unistd.h"
5 #include "stdlib.h"
6 #include "stdio.h"
7
8 int fd;
9
10 void* readSerial()
11 {
12 char cmd;
13 while(1){
14 cmd = myserialGetchar(fd);
15 switch(cmd){
16 case 'N':
17 system("adb shell input swipe 540 1300 540 500 100");
18 printf("next\n");
19 break;
20 case 'P':
21 system("adb shell input swipe 540 500 540 1300 100");
22 printf("preview\n");
23 break;
24 case 'Z':
25 system("adb shell \"seq 4 | while read i;do input tap 350 1050 & input tap 350 1050 & sleep 0.01;done;\"");
26 printf("dian zan\n");
27 break;
28 case 'Q':
29 system("adb shell input keyevent 26");
30 printf("quit\n");
31 break;
32 }
33 }
34 }
35 int main(int argc,char **argv)
36 {
37 char deviceName[32];
38 pthread_t readt;
39
40 if(argc<2){
41 printf("uage:%s /dev/ttyS?\n",argv[0]);
42 return -1;
43 }
44
45 strcpy(deviceName,argv[1]);
46 if((fd = serialOpen(deviceName,115200)) == -1){
47 printf("open %s error \n",deviceName);
48 return -1;
49 }
50
51 pthread_create(&readt,NULL,readSerial,NULL);
52 while(1){sleep(10);}
53
54 return 0;
55 }
测试现象略。。。。