#include "InputCommand.h"
#include <wiringPi.h>
#include <wiringSerial.h>
#include <stdio.h>
#include <unistd.h>
int voiceInit(struct InputCommander *voicer,char *ipAdress,char *port)
{
int fd;
if(fd = serialOpen(voicer->commandName,9600) == -1)
{
exit(-1);
}
voicer->fd = fd;
return fd;
}
int voiceGetCommand(struct InputCommander *voicer)
{
int nread = 0;
nread = read(voicer->fd,voicer->command,sizeof(voicer->command));
if(nread == 0)
{
printf("usart for voice over time\n");
}else
{
return nread;
}
}
struct InputCommander voiceContrl = {
.commandName = "voice",
.command = {'\0'},
.deviceName = "dev/ttyAMA0",
.Init = voiceInit,
.getCommand = voiceGetCommand,
.log = {'\0'},
.next = NULL
};
struct InputCommander *addvoiceContrlToCommandLink(struct InputCommander *phead)
{
if(phead == NULL)
{
return &voiceContrl;
}else
{
voiceContrl.next = phead;
phead = &voiceContrl;
return phead;
}
}
树莓派开发实战项目 智能家居--简单工厂模式(添加声音识别模块的串口读取功能)
最新推荐文章于 2025-04-25 15:45:14 发布