Bruno Cavalcanti / Mbed 2 deprecated brunoDrome

Dependencies:   DS1820 HighSpeedAnalogIn devices mbed

Committer:
brunofgc
Date:
Wed May 10 12:57:13 2017 +0000
Revision:
2:55b7b466e742
Parent:
0:1c0a769988ee
Child:
37:0e95c85f0160
Ainda com bug em configRede.htm

Who changed what in which revision?

UserRevisionLine numberNew contents of line
brunofgc 0:1c0a769988ee 1 #include "CircularBuffer.h"
brunofgc 0:1c0a769988ee 2 CircularBuffer::CircularBuffer(uint16_t tamanho) {
brunofgc 2:55b7b466e742 3 this->tam = tamanho+1;
brunofgc 2:55b7b466e742 4 this->bufIn = (char*) malloc(sizeof(char)*(this->tam)); //Cuidado extremo com uso de malloc!!!
brunofgc 0:1c0a769988ee 5 //printf("Alocados %lu caracteres para bufIn dentro do construtor CircularBuffer.\r\n",tam+1);
brunofgc 2:55b7b466e742 6 this->index = 0;
brunofgc 2:55b7b466e742 7 this->estouro = 0;
brunofgc 0:1c0a769988ee 8 }
brunofgc 0:1c0a769988ee 9
brunofgc 0:1c0a769988ee 10 void CircularBuffer::del(){
brunofgc 0:1c0a769988ee 11 uint16_t i;
brunofgc 0:1c0a769988ee 12 this->index = 0;
brunofgc 0:1c0a769988ee 13 this->estouro = 0;
brunofgc 2:55b7b466e742 14 for(i=0;i<this->tam;i++){
brunofgc 0:1c0a769988ee 15 this->bufIn[i]=0;
brunofgc 0:1c0a769988ee 16 }
brunofgc 0:1c0a769988ee 17 }
brunofgc 0:1c0a769988ee 18
brunofgc 0:1c0a769988ee 19 void CircularBuffer::putc(char entrada){
brunofgc 0:1c0a769988ee 20 //uint16_t i;
brunofgc 2:55b7b466e742 21 this->bufIn[index] = entrada;
brunofgc 2:55b7b466e742 22 this->index++;
brunofgc 2:55b7b466e742 23 if(this->index>(this->tam-2)){
brunofgc 2:55b7b466e742 24 this->index=0;
brunofgc 2:55b7b466e742 25 this->estouro=true;
brunofgc 0:1c0a769988ee 26 }
brunofgc 0:1c0a769988ee 27 }
brunofgc 0:1c0a769988ee 28
brunofgc 0:1c0a769988ee 29 char* CircularBuffer::get(){
brunofgc 0:1c0a769988ee 30 uint16_t nOperacoes;
brunofgc 0:1c0a769988ee 31 uint16_t i;
brunofgc 0:1c0a769988ee 32 //unsigned int x;
brunofgc 0:1c0a769988ee 33 char aux;
brunofgc 0:1c0a769988ee 34
brunofgc 2:55b7b466e742 35 if(this->estouro){
brunofgc 0:1c0a769988ee 36 for(nOperacoes=0;nOperacoes<index;nOperacoes++){
brunofgc 2:55b7b466e742 37 aux=this->bufIn[0];
brunofgc 2:55b7b466e742 38 for(i=0;i<this->tam;i++){
brunofgc 2:55b7b466e742 39 this->bufIn[i]=this->bufIn[i+1];
brunofgc 0:1c0a769988ee 40 }
brunofgc 2:55b7b466e742 41 this->bufIn[this->tam-2]=aux;
brunofgc 0:1c0a769988ee 42 }
brunofgc 2:55b7b466e742 43 this->bufIn[this->tam-1]=0;
brunofgc 2:55b7b466e742 44 this->estouro=false;
brunofgc 0:1c0a769988ee 45 }else{
brunofgc 2:55b7b466e742 46 this->bufIn[this->index]=0;
brunofgc 0:1c0a769988ee 47 }
brunofgc 2:55b7b466e742 48 this->index = 0;
brunofgc 2:55b7b466e742 49 return this->bufIn;
brunofgc 0:1c0a769988ee 50 }
brunofgc 0:1c0a769988ee 51
brunofgc 0:1c0a769988ee 52 uint16_t CircularBuffer::getLength(){
brunofgc 2:55b7b466e742 53 return this->index;
brunofgc 0:1c0a769988ee 54 }
brunofgc 0:1c0a769988ee 55
brunofgc 0:1c0a769988ee 56 char* CircularBuffer::getRowBuffer(){
brunofgc 2:55b7b466e742 57 return this->bufIn;
brunofgc 0:1c0a769988ee 58 }
brunofgc 0:1c0a769988ee 59
brunofgc 0:1c0a769988ee 60 uint16_t CircularBuffer::fill(char *buf,uint16_t cont){
brunofgc 0:1c0a769988ee 61 uint16_t i;
brunofgc 0:1c0a769988ee 62 for(i=0;i<cont;i++){
brunofgc 0:1c0a769988ee 63 this->putc(buf[i]);
brunofgc 0:1c0a769988ee 64 }
brunofgc 0:1c0a769988ee 65 return index;
brunofgc 0:1c0a769988ee 66 }