目录
一、手机连接Linux步骤
1、把手机接入开发板
2、安装
adb
工具,在终端输入
adb
安装指令:
sudo apt-get install adb
3、dmesg
能查看到手机接入的信息
4、
在手机开发者选项中,打开USB调试,重新拔插手机,点击信任此设备
5、输入
adb devices
6、输入
adb shell
二、adb控制指令
用
shell
指令来操作手机屏幕,模拟手动滑屏幕
1、向下滑动。从坐标点(540,1300)用100ms滑动到坐标点(540,500)
adb shell input swipe 540 1300 540 500 100
2、 向下滑动。从坐标点(540,500)用100ms滑动到坐标点(540,1300)
adb shell input swipe 540 500 540 1300 100
3、双击。点击坐标点(540,1050)两次,间隔0.1s
adb shell "seq 2 | while read i;do input tap 540 1050 & input tap 540 1050 &
sleep 0.1;done;"
4、锁屏。
adb shell input keyevent 26
三、基于Linux串口实现语音刷抖音
1、语音模块控制详情
2、代码实现
uartTest.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 <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 'L':
printf("last\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 540 1050 & input tap 540 1050 & sleep 0.1;done;\"");
break;
case 'Q':
printf("quit\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);}
}
uartTool.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 "wiringSerial.h"
char myserialGetchar (const int fd)
{
char x ;
if (read(fd , &x, 1) != 1)
return -1 ;
return x ;
}
int myserialOpen (const char *device, const int baud)
{
struct termios options ;
speed_t myBaud ;
int status, fd ;
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 ; //1位停止位
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) ; // 10mS
return fd ;
}
void serialSendstring (const int fd, const char *s)
{
int ret;
ret = write (fd, s, strlen (s));
if (ret < 0)
printf("Serial Sendstring Error\n");
}
int serialGetstring (const int fd, char *buffer)
{
int n_read;
n_read = read(fd, buffer,32);
return n_read;
}
uartTool.h
char myserialGetchar (const int fd);
int myserialOpen (const char *device, const int baud);
void serialSendstring (const int fd, const char *s);
int serialGetstring (const int fd, char *buffer);