3 changed files with 114 additions and 2 deletions
			
			
		@ -0,0 +1,44 @@ | 
				
			|||||
 | 
					//----------------------------------------------------------------------------------------------------------------------------
 | 
				
			||||
 | 
					// Project:     Uppsense
 | 
				
			||||
 | 
					// Name:        signal_processor.cpp
 | 
				
			||||
 | 
					// Author:      Maximilian Stiefel
 | 
				
			||||
 | 
					// Date:        22.08.2017
 | 
				
			||||
 | 
					//
 | 
				
			||||
 | 
					// Description:
 | 
				
			||||
 | 
					//
 | 
				
			||||
 | 
					//----------------------------------------------------------------------------------------------------------------------------
 | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					//-------------------------------------Libraries------------------------------------------------------------------------------
 | 
				
			||||
 | 
					#include "signal_processor.h" | 
				
			||||
 | 
					#include <SmingCore/SmingCore.h> | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					//-------------------------------------Namespaces-----------------------------------------------------------------------------
 | 
				
			||||
 | 
					namespace rijnfel { | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					cSignalProcessor* cSignalProcessor::s_instance = NULL; | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					//-------------------------------------GetInstance----------------------------------------------------------------------------
 | 
				
			||||
 | 
					cSignalProcessor* cSignalProcessor::GetInstance() | 
				
			||||
 | 
					{ | 
				
			||||
 | 
						if(s_instance == NULL) | 
				
			||||
 | 
							s_instance = new cSignalProcessor; | 
				
			||||
 | 
						return s_instance; | 
				
			||||
 | 
					} | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					//-------------------------------------receiveADCValues-----------------------------------------------------------------------
 | 
				
			||||
 | 
					void cSignalProcessor::receiveADCValues(cADC<ads::ads_sample_t, int32_t> & i_adc, cDoubleBuffer<ads::ads_sample_t>& i_adcBuffer) { | 
				
			||||
 | 
					        ads::ads_sample_t * buf = &i_adcBuffer.GetReadyBuffer()[0]; | 
				
			||||
 | 
					        if (buf != NULL) { | 
				
			||||
 | 
					                int pos = buf->mux - ads::eInputMux::AIN_0; | 
				
			||||
 | 
					                int64_t average = 0; | 
				
			||||
 | 
					                int size = i_adcBuffer.GetSize(); | 
				
			||||
 | 
					                for (int i = 0; i < size; i++) { | 
				
			||||
 | 
					                        average += i_adc.ConvertSample(buf[i]);                  | 
				
			||||
 | 
					                } | 
				
			||||
 | 
					                if (size != 0) { | 
				
			||||
 | 
					                        average /= size; | 
				
			||||
 | 
					                } | 
				
			||||
 | 
					       		Serial.printf("Average: %d/n/r", average);          | 
				
			||||
 | 
						} | 
				
			||||
 | 
					} | 
				
			||||
 | 
					} | 
				
			||||
@ -0,0 +1,66 @@ | 
				
			|||||
 | 
					//----------------------------------------------------------------------------------------------------------------------------
 | 
				
			||||
 | 
					// Project:    	Uppsense
 | 
				
			||||
 | 
					// Name:	signal_processor.h
 | 
				
			||||
 | 
					// Author:	Maximilian Stiefel
 | 
				
			||||
 | 
					// Date:	22.08.2017
 | 
				
			||||
 | 
					//
 | 
				
			||||
 | 
					// Description: 
 | 
				
			||||
 | 
					//
 | 
				
			||||
 | 
					//----------------------------------------------------------------------------------------------------------------------------
 | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					#ifndef APP_SIGNAL_PROCESSOR_H_ | 
				
			||||
 | 
					#define APP_SIGNAL_PROCESSOR_H_ | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					//-------------------------------------Libraries------------------------------------------------------------------------------
 | 
				
			||||
 | 
					#include <stdint.h> | 
				
			||||
 | 
					#include "defines.h" | 
				
			||||
 | 
					#include "double_buffer.h" | 
				
			||||
 | 
					#include "adc.h" | 
				
			||||
 | 
					#include "ads101x.h" | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					//-------------------------------------Defines--------------------------------------------------------------------------------
 | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					//-------------------------------------Namespaces-----------------------------------------------------------------------------
 | 
				
			||||
 | 
					namespace rijnfel { | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					//-------------------------------------Enums----------------------------------------------------------------------------------
 | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					//-------------------------------------cDAC101085-----------------------------------------------------------------------------
 | 
				
			||||
 | 
					/** Small simple driver for the TI DAC101C085.
 | 
				
			||||
 | 
					 */ | 
				
			||||
 | 
					class cSignalProcessor | 
				
			||||
 | 
					{ | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					public:	 | 
				
			||||
 | 
						/**
 | 
				
			||||
 | 
						  * 	@brief Returns the global cSignalProcessor instance. | 
				
			||||
 | 
						  *     Only one webserver should ever be running | 
				
			||||
 | 
						  *     @return global cSignalProcessor instance | 
				
			||||
 | 
						  *                                     */ | 
				
			||||
 | 
						static cSignalProcessor *GetInstance(); | 
				
			||||
 | 
					public:	 | 
				
			||||
 | 
						/**
 | 
				
			||||
 | 
						 * 	@brief Notifies object that new samples are available. | 
				
			||||
 | 
						 * 	@param i_adc Instance of the adc sensor. | 
				
			||||
 | 
						 * 	@param i_adcBuffer Buffer containing the raw adc values. | 
				
			||||
 | 
						 *                                     */ | 
				
			||||
 | 
					        void receiveADCValues(cADC<ads::ads_sample_t, int32_t> & i_adc, cDoubleBuffer<ads::ads_sample_t> & i_adcBuffer);	 | 
				
			||||
 | 
					
 | 
				
			||||
 | 
					private: | 
				
			||||
 | 
						// Singleton instance
 | 
				
			||||
 | 
						static cSignalProcessor *s_instance; | 
				
			||||
 | 
						/**
 | 
				
			||||
 | 
						 * @brief Constructor is private, so it can not be called. | 
				
			||||
 | 
						 */ | 
				
			||||
 | 
						cSignalProcessor(){}; | 
				
			||||
 | 
						/**
 | 
				
			||||
 | 
						 * @brief Copy constructor is private, so it can not be called. | 
				
			||||
 | 
						 */ | 
				
			||||
 | 
						cSignalProcessor(cSignalProcessor const&){}; | 
				
			||||
 | 
						/**
 | 
				
			||||
 | 
						 * @brief Assignment operator is private, so it can not be used. | 
				
			||||
 | 
						 */ | 
				
			||||
 | 
						cSignalProcessor& operator=(cSignalProcessor const&){}; | 
				
			||||
 | 
					}; | 
				
			||||
 | 
					} | 
				
			||||
 | 
					#endif /* APP_SIGNAL_PROCESSOR_H_ */ | 
				
			||||
					Loading…
					
					
				
		Reference in new issue