Xiaofei Qiu / EasyVR3_LED_Library
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers EasyVR.cpp Source File

EasyVR.cpp

00001 #pragma once
00002 #include "EasyVR.h"
00003 
00004 EasyVR::EasyVR(PinName tx,PinName rx):_easyVR(tx,rx)
00005 {
00006 }
00007 
00008 EasyVR::~EasyVR()
00009 {
00010 }
00011 
00012 void EasyVR::sendCmd(uint8_t c)
00013 {
00014     _easyVR.putc(c);
00015     wait(0.001);
00016 }
00017 
00018 void EasyVR::sendArg(int8_t c)
00019 {
00020     _easyVR.putc(c + ARG_ZERO);
00021     wait(0.001);
00022 }
00023 
00024 int8_t EasyVR::recv(int8_t time)
00025 {
00026     while(!_easyVR.readable() && time != 0)
00027     {
00028         if(time>0)
00029         time--;
00030         wait(0.001);
00031     }
00032     return _easyVR.getc();
00033 }
00034 
00035 void EasyVR::decrypt(char* arg)
00036 {
00037     *arg = *arg - ARG_ZERO;
00038 }
00039 
00040 bool EasyVR::awake(int timeOut)
00041 {
00042     bool isAwake=0;
00043 
00044     while (timeOut>0)
00045     {
00046         _easyVR.putc(CMD_BREAK);
00047         if(_easyVR.getc()==CMD_TIMEOUT)
00048         {
00049             isAwake = 1;
00050             break;
00051         }
00052 
00053         if(timeOut>0)
00054         {
00055             timeOut--;
00056         }
00057         wait(0.001);
00058     }
00059     return isAwake;
00060 }