teste de publish
Dependencies: DS1820 HighSpeedAnalogIn devices mbed
mediaMovel.cpp@38:07d3907b74e5, 2018-06-08 (annotated)
- Committer:
- brunofgc
- Date:
- Fri Jun 08 22:14:21 2018 +0000
- Revision:
- 38:07d3907b74e5
- Parent:
- 0:1c0a769988ee
teste de publish para compilar no mbed-cli
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
brunofgc | 0:1c0a769988ee | 1 | #include "mediaMovel.h" |
brunofgc | 0:1c0a769988ee | 2 | |
brunofgc | 0:1c0a769988ee | 3 | MediaMovel::MediaMovel(uint16_t tamanho){ |
brunofgc | 0:1c0a769988ee | 4 | uint16_t i; |
brunofgc | 0:1c0a769988ee | 5 | p = (uint16_t *) malloc(tamanho*sizeof(uint16_t)); |
brunofgc | 0:1c0a769988ee | 6 | for(i=0;i<tamanho;i++){ |
brunofgc | 0:1c0a769988ee | 7 | p[i] = 0; |
brunofgc | 0:1c0a769988ee | 8 | } |
brunofgc | 0:1c0a769988ee | 9 | this->index = 0; |
brunofgc | 0:1c0a769988ee | 10 | this->tam = tamanho; |
brunofgc | 0:1c0a769988ee | 11 | } |
brunofgc | 0:1c0a769988ee | 12 | uint16_t MediaMovel::get(uint16_t val){ |
brunofgc | 0:1c0a769988ee | 13 | uint16_t i; |
brunofgc | 0:1c0a769988ee | 14 | double media; |
brunofgc | 0:1c0a769988ee | 15 | this->p[this->index] = val; |
brunofgc | 0:1c0a769988ee | 16 | this->index++; |
brunofgc | 0:1c0a769988ee | 17 | if(this->index >= this->tam){ |
brunofgc | 0:1c0a769988ee | 18 | this->index = 0; |
brunofgc | 0:1c0a769988ee | 19 | } |
brunofgc | 0:1c0a769988ee | 20 | media = 0; |
brunofgc | 0:1c0a769988ee | 21 | for(i=0;i < this->tam;i++){ |
brunofgc | 0:1c0a769988ee | 22 | media += this->p[i]; |
brunofgc | 0:1c0a769988ee | 23 | } |
brunofgc | 0:1c0a769988ee | 24 | media = media/this->tam; |
brunofgc | 0:1c0a769988ee | 25 | return (uint16_t) media; |
brunofgc | 0:1c0a769988ee | 26 | } |