树莓派开发——语音控制adb刷抖音
1.综述
利用语音模块,adb 控制刷抖音小项目,增长了相关方面认知(无什么实际作用)
2.语音模块
这里使用的语音模块为 YS-LDV7语音识别模块
通过阅读官方代码,修改所需识别的词条:
(1)增加所需识别的词条
(2)宏定义识别词条
(3)修改识别成功后通过串口发送的内容
3.语音模块与树莓派串口连接
树莓派串口编程可参考之前写的相关文章树莓派串口开发
这里进行简单修改:
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <pthread.h>
#include "mySerial.h"
#include <unistd.h>
#include <stdlib.h>
int fd;void *receiveHandler()
{char receBuf[8];char cmd;while(1){memset(receBuf,'\0',9);mySerialGetString(fd,receBuf);cmd = receBuf[0];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 2 | while read i;do input tap 350 1050 &input tap 350 1050 & sleep 0.005;done\"");break;case'Q':printf("quit\n");system("adb shell input keyevent 26");break;}}
}int main(int argc,char **argv)
{pthread_t SendFunID;pthread_t ReceiveFunID;char pathBuf[32] = {'\0'};if(argc < 2){printf("Please input the path of usart for example:/dev/ttyAMA0\n");return -1;}strcpy(pathBuf,argv[1]);fd = mySerialOpen(pathBuf,9600);pthread_create(&ReceiveFunID,NULL,receiveHandler,NULL);while(1);return 0 ;
}
4.树莓派adb连接安卓手机
(1)将手机用数据线与树莓派相连
(2)安装adb 工具:
sudo apt-get install adb
(3)可利用dmeg查看手机接入信息
(4)输入adb devices 会出现no permissions (verify udev rules) 因此需要进行以下操作:
sudo vi/etc/udev/rules.d/51-android.rules
并输入以下内容:
SUBSYSTEM=="usb", ATTR{idVendor}=="05c6", MODE="0666", GROUP="plugdev"
(5)之后便可通过adb shell 连接手机对手机进行操作
5.用shell指令操作手机屏幕,模拟手动滑屏、点赞、息屏等操作:
(1)向下滑动屏幕 :
adb shell input swipe 540 1300 540 500 100
(2)向上滑动屏幕:
adb shell input swipe 540 500 540 1300 100
(4)双击点赞:
adb shell "seq 2 | while read i;do input tap 350 1050 &input tap 350 1050 & sleep 0.005;done"
(5)息屏:
adb shell input keyevent 26
树莓派开发——语音控制adb刷抖音
1.综述
利用语音模块,adb 控制刷抖音小项目,增长了相关方面认知(无什么实际作用)
2.语音模块
这里使用的语音模块为 YS-LDV7语音识别模块
通过阅读官方代码,修改所需识别的词条:
(1)增加所需识别的词条
(2)宏定义识别词条
(3)修改识别成功后通过串口发送的内容
3.语音模块与树莓派串口连接
树莓派串口编程可参考之前写的相关文章树莓派串口开发
这里进行简单修改:
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <pthread.h>
#include "mySerial.h"
#include <unistd.h>
#include <stdlib.h>
int fd;void *receiveHandler()
{char receBuf[8];char cmd;while(1){memset(receBuf,'\0',9);mySerialGetString(fd,receBuf);cmd = receBuf[0];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 2 | while read i;do input tap 350 1050 &input tap 350 1050 & sleep 0.005;done\"");break;case'Q':printf("quit\n");system("adb shell input keyevent 26");break;}}
}int main(int argc,char **argv)
{pthread_t SendFunID;pthread_t ReceiveFunID;char pathBuf[32] = {'\0'};if(argc < 2){printf("Please input the path of usart for example:/dev/ttyAMA0\n");return -1;}strcpy(pathBuf,argv[1]);fd = mySerialOpen(pathBuf,9600);pthread_create(&ReceiveFunID,NULL,receiveHandler,NULL);while(1);return 0 ;
}
4.树莓派adb连接安卓手机
(1)将手机用数据线与树莓派相连
(2)安装adb 工具:
sudo apt-get install adb
(3)可利用dmeg查看手机接入信息
(4)输入adb devices 会出现no permissions (verify udev rules) 因此需要进行以下操作:
sudo vi/etc/udev/rules.d/51-android.rules
并输入以下内容:
SUBSYSTEM=="usb", ATTR{idVendor}=="05c6", MODE="0666", GROUP="plugdev"
(5)之后便可通过adb shell 连接手机对手机进行操作
5.用shell指令操作手机屏幕,模拟手动滑屏、点赞、息屏等操作:
(1)向下滑动屏幕 :
adb shell input swipe 540 1300 540 500 100
(2)向上滑动屏幕:
adb shell input swipe 540 500 540 1300 100
(4)双击点赞:
adb shell "seq 2 | while read i;do input tap 350 1050 &input tap 350 1050 & sleep 0.005;done"
(5)息屏:
adb shell input keyevent 26