teste de publish

Dependencies:   DS1820 HighSpeedAnalogIn devices mbed

Committer:
brunofgc
Date:
Fri Jun 08 22:14:21 2018 +0000
Revision:
38:07d3907b74e5
Parent:
37:0e95c85f0160
teste de publish para compilar no mbed-cli

Who changed what in which revision?

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