sample_handler

Files at this revision

API Documentation at this revision

Comitter:
faverosantos
Date:
Tue Jan 16 19:43:53 2018 +0000
Commit message:
R04b

Changed in this revision

sample_handler.cpp Show annotated file Show diff for this revision Revisions of this file
sample_handler.h Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 508e2f3c5f46 sample_handler.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sample_handler.cpp	Tue Jan 16 19:43:53 2018 +0000
@@ -0,0 +1,42 @@
+#include "mylibs/globais.h"
+#include "sample_handler.h"
+
+// TODO: Deixar o construtor genérico para vários ADCs
+SampleHandler::SampleHandler(PinName adc_pin):this_adc(adc_pin){
+    // Aqui o certo é criar o objeto e depois passar a referência para o objeto da classe
+    
+    AnalogIn ain(adc_pin);
+    this_adc = ain;   
+    is_buffer_filled = false;
+    sp_rdy = false;
+    tr_rdy = false;
+    start_transfer = false;
+    one_sample_readout = 0.0;
+    is_sampled = false;
+    position = 0;
+    
+    uint16_t local_counter = 0;
+    for (local_counter = 0; local_counter < BUFFER_SIZE; local_counter = local_counter + 1) {
+        sampling_buffer[local_counter] = 0;
+    }
+}
+
+void SampleHandler::get_sample(void){
+    is_sampled = false;
+    one_sample_readout = float(ADC_VREF)*this_adc.read(); // sem a multiplicação por ADC_VREF, chega-se a picos de 62500 Hz
+    is_sampled = true;
+}
+
+
+void SampleHandler::get_buffer(void){
+    static uint16_t static_local_counter = 0;
+    sampling_buffer[static_local_counter] = one_sample_readout;
+    static_local_counter = static_local_counter + 1;
+    
+    if (static_local_counter == BUFFER_SIZE - 1){
+        static_local_counter = 0;
+        //return true;    
+    }else{
+        //return false;    
+    }
+}
diff -r 000000000000 -r 508e2f3c5f46 sample_handler.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sample_handler.h	Tue Jan 16 19:43:53 2018 +0000
@@ -0,0 +1,35 @@
+/*  Autor: Fávero Santos
+    Localização: Curitiba, Paraná
+    Data: 11/01/2018
+    Informações:
+*/
+
+#ifndef SAMPLE_HANDLER_H
+#define SAMPLE_HANDLER_H
+
+#include "mylibs/globais.h"
+
+
+class SampleHandler{
+    private:
+        AnalogIn this_adc;
+        bool sp_rdy;
+        bool tr_rdy;
+        bool start_transfer;
+        bool is_sampled;
+        uint16_t position;
+               
+    public:
+        float one_sample_readout;
+        float sampling_buffer[BUFFER_SIZE];
+        bool is_buffer_filled;
+        
+        SampleHandler(PinName adc_pin);
+        AnalogIn get_sampler(void);
+        
+        void start_buffering(void);
+        void get_sample(void);
+        void get_buffer(void);
+};
+
+#endif
\ No newline at end of file