diff --git a/software/app/application.cpp b/software/app/application.cpp index 599ffc7..b031718 100644 --- a/software/app/application.cpp +++ b/software/app/application.cpp @@ -4,6 +4,7 @@ #include "ads101x.h" #include #include "excitation_light.h" +#include "signal_processor.h" #include "sensor_hub.h" #include "sensor_settings.h" #include "double_buffer.h" @@ -49,12 +50,13 @@ void updateSensorHub() { } void adcCallback(cDoubleBuffer & buffer) { - channel++; + channel = 0; if (channel > 3) { channel = 0; //cWebInterface::GetInstance()->PrintValues(); } - cWebInterface::GetInstance()->UpdateAdc(adc, buffer); + cSignalProcessor::GetInstance()->receiveADCValues(adc, buffer); + //cWebInterface::GetInstance()->UpdateAdc(adc, buffer); adc.SetMux(static_cast(ads::eInputMux::AIN_0 + channel)); } diff --git a/software/app/signal_processor.cpp b/software/app/signal_processor.cpp new file mode 100644 index 0000000..9321d79 --- /dev/null +++ b/software/app/signal_processor.cpp @@ -0,0 +1,44 @@ +//---------------------------------------------------------------------------------------------------------------------------- +// Project: Uppsense +// Name: signal_processor.cpp +// Author: Maximilian Stiefel +// Date: 22.08.2017 +// +// Description: +// +//---------------------------------------------------------------------------------------------------------------------------- + +//-------------------------------------Libraries------------------------------------------------------------------------------ +#include "signal_processor.h" +#include + +//-------------------------------------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 & i_adc, cDoubleBuffer& 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); + } +} +} diff --git a/software/app/signal_processor.h b/software/app/signal_processor.h new file mode 100644 index 0000000..a40111c --- /dev/null +++ b/software/app/signal_processor.h @@ -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 +#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 & i_adc, cDoubleBuffer & 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_ */