EasyVR3_LED_Library
EasyVR.cpp@0:8ec860bd579a, 2015-10-22 (annotated)
- Committer:
- Xiaofei
- Date:
- Thu Oct 22 19:35:17 2015 +0000
- Revision:
- 0:8ec860bd579a
- Child:
- 2:d772f65f65ab
EasyVR3_LED
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Xiaofei | 0:8ec860bd579a | 1 | #pragma once |
Xiaofei | 0:8ec860bd579a | 2 | #include "EasyVR.h" |
Xiaofei | 0:8ec860bd579a | 3 | |
Xiaofei | 0:8ec860bd579a | 4 | EasyVR::EasyVR(PinName tx,PinName rx):_easyVR(tx,rx) |
Xiaofei | 0:8ec860bd579a | 5 | { |
Xiaofei | 0:8ec860bd579a | 6 | } |
Xiaofei | 0:8ec860bd579a | 7 | |
Xiaofei | 0:8ec860bd579a | 8 | EasyVR::~EasyVR() |
Xiaofei | 0:8ec860bd579a | 9 | { |
Xiaofei | 0:8ec860bd579a | 10 | } |
Xiaofei | 0:8ec860bd579a | 11 | |
Xiaofei | 0:8ec860bd579a | 12 | void EasyVR::sendCmd(uint8_t c) |
Xiaofei | 0:8ec860bd579a | 13 | { |
Xiaofei | 0:8ec860bd579a | 14 | _easyVR.putc(c); |
Xiaofei | 0:8ec860bd579a | 15 | wait(0.001); |
Xiaofei | 0:8ec860bd579a | 16 | } |
Xiaofei | 0:8ec860bd579a | 17 | |
Xiaofei | 0:8ec860bd579a | 18 | void EasyVR::sendArg(int8_t c) |
Xiaofei | 0:8ec860bd579a | 19 | { |
Xiaofei | 0:8ec860bd579a | 20 | _easyVR.putc(c + ARG_ZERO); |
Xiaofei | 0:8ec860bd579a | 21 | wait(0.001); |
Xiaofei | 0:8ec860bd579a | 22 | } |
Xiaofei | 0:8ec860bd579a | 23 | |
Xiaofei | 0:8ec860bd579a | 24 | int8_t EasyVR::recv(int8_t time) |
Xiaofei | 0:8ec860bd579a | 25 | { |
Xiaofei | 0:8ec860bd579a | 26 | while(!_easyVR.readable() && time != 0) |
Xiaofei | 0:8ec860bd579a | 27 | { |
Xiaofei | 0:8ec860bd579a | 28 | if(time>0) |
Xiaofei | 0:8ec860bd579a | 29 | time--; |
Xiaofei | 0:8ec860bd579a | 30 | wait(0.001); |
Xiaofei | 0:8ec860bd579a | 31 | } |
Xiaofei | 0:8ec860bd579a | 32 | return _easyVR.getc(); |
Xiaofei | 0:8ec860bd579a | 33 | } |
Xiaofei | 0:8ec860bd579a | 34 | |
Xiaofei | 0:8ec860bd579a | 35 | void EasyVR::decrypt(char* arg) |
Xiaofei | 0:8ec860bd579a | 36 | { |
Xiaofei | 0:8ec860bd579a | 37 | *arg = *arg - ARG_ZERO; |
Xiaofei | 0:8ec860bd579a | 38 | } |
Xiaofei | 0:8ec860bd579a | 39 | |
Xiaofei | 0:8ec860bd579a | 40 | bool EasyVR::awake(int timeOut) |
Xiaofei | 0:8ec860bd579a | 41 | { |
Xiaofei | 0:8ec860bd579a | 42 | bool isAwake=0; |
Xiaofei | 0:8ec860bd579a | 43 | |
Xiaofei | 0:8ec860bd579a | 44 | while (timeOut>0) |
Xiaofei | 0:8ec860bd579a | 45 | { |
Xiaofei | 0:8ec860bd579a | 46 | _easyVR.putc(CMD_BREAK); |
Xiaofei | 0:8ec860bd579a | 47 | if(_easyVR.getc()==CMD_TIMEOUT) |
Xiaofei | 0:8ec860bd579a | 48 | { |
Xiaofei | 0:8ec860bd579a | 49 | isAwake = 1; |
Xiaofei | 0:8ec860bd579a | 50 | } |
Xiaofei | 0:8ec860bd579a | 51 | |
Xiaofei | 0:8ec860bd579a | 52 | if(timeOut>0) |
Xiaofei | 0:8ec860bd579a | 53 | { |
Xiaofei | 0:8ec860bd579a | 54 | timeOut--; |
Xiaofei | 0:8ec860bd579a | 55 | } |
Xiaofei | 0:8ec860bd579a | 56 | wait(0.001); |
Xiaofei | 0:8ec860bd579a | 57 | } |
Xiaofei | 0:8ec860bd579a | 58 | return isAwake; |
Xiaofei | 0:8ec860bd579a | 59 | } |