基于全志h616的语音刷抖音小项目

一.硬件准备

香橙派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热拔插相关

  1. 把手机接入开发板
  2. 安装adb工具,在终端输入adb安装指令: sudo apt-get install adb
  3. dmeg能查看到手机接入的信息,但是输入adb devices会出现提醒 dinsufficient permissions for device: user in plugdev group; are your udev rules wrong?
  4. 配置文件,以支持USB设备的热拔插,支持UDEV的机制 在/etc/udev/rules.d 文件夹下创建规则文件 cd /etc/udev/rules.d/ sudo vim 51-android.rules 在文件中添加内容 SUBSYSTEM=="usb", ENV{DEVTYPE}=="usb_device", MODE="0666"
  5. 在手机开发者选项中,打开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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值