Browse Source

some code refactoring

software_develop
Elmar van Rijnswou 7 years ago
parent
commit
cb29bc0c4f
  1. 76
      software/app/ads101x.h
  2. 3
      software/app/ads_converter.cpp
  3. 31
      software/app/ads_converter.h
  4. 14
      software/app/application.cpp
  5. 72
      software/app/dac101c085.h
  6. 36
      software/app/dummy_adc.cpp
  7. 30
      software/app/dummy_adc.h
  8. 2
      software/app/excitation_light.cpp
  9. 64
      software/app/excitation_light.h
  10. 2
      software/app/sensor_hub.h
  11. 3
      software/app/signal_process.cpp
  12. 4
      software/app/signal_process.h
  13. 28
      software/app/temperature.h
  14. 1
      software/app/web_interface.cpp
  15. 130
      software/app/web_interface.h
  16. 0
      software/include/defines.h
  17. 2
      software/include/rijnfel_core/adc.h
  18. 0
      software/include/rijnfel_core/data_provider.h
  19. 0
      software/include/rijnfel_core/data_receiver.h
  20. 0
      software/include/rijnfel_core/data_sink.h
  21. 1
      software/include/rijnfel_core/double_buffer.h
  22. 0
      software/include/rijnfel_core/helper_structs.h
  23. 21
      software/include/rijnfel_core/rijnfel_core.h
  24. 0
      software/include/rijnfel_core/sensor.h
  25. 2
      software/include/rijnfel_core/sensor_settings.h

76
software/app/ads101x.h

@ -1,76 +0,0 @@
/*
* ADS101x.h
*
* Created on: Jul 20, 2017
* Author: Elmar
*/
#ifndef APP_ADS101X_H_
#define APP_ADS101X_H_
#include <stdint.h>
#include "hardware.h"
#include "adc.h"
namespace rijnfel {
namespace ads {
//Voltage in uV
typedef int32_t ads_voltage_t;
enum eInputMux {
AIN_0_1, AIN_0_3, AIN_1_3, AIN_2_3, AIN_0, AIN_1, AIN_2, AIN_3
};
enum eGainAmplifier {
FSR_6_144, FSR_4_096, FSR_2_048, FSR_1_024, FSR_0_512, FSR_0_256
};
enum eSampleSpeed {
SPS_128, SPS_250, SPS_490, SPS_920, SPS_1600, SPS_2400, SPS_3300
};
struct ads_sample_t {
uint16_t rawSample;
enum eInputMux mux;
enum eGainAmplifier gain;
};
class cADS101x: public cADC<ads_sample_t, ads_voltage_t> {
public:
cADS101x(uint8_t i_address = 0x48);
cADS101x(uint8_t i_readyPin, uint8_t i_address = 0x48);
void SetOneShot(bool i_oneShot = true);
void SetGain(enum eGainAmplifier i_gain);
void SetMux(enum eInputMux i_mux);
void SetSampleSpeed(enum eSampleSpeed i_speed);
virtual void WaitSample(void);
virtual bool IsReady(void);
uint16_t GetSettings(void);
virtual ads_sample_t RawSample(void);
virtual ads_voltage_t ConvertSample(ads_sample_t & sample);
virtual ~cADS101x() {
}
private:
uint16_t CreateSettings(uint8_t i_startSample);
uint16_t ReadRegister(uint8_t i_register);
void WriteSettings(uint16_t i_settings);
void SetDefaults(void);
void OneShot(void);
private:
uint8_t m_address, m_readyPin;
bool m_oneShot;
enum eInputMux m_mux;
enum eGainAmplifier m_gain;
enum eSampleSpeed m_sampleSpeed;
private:
#ifdef DUMMY_ADC
uint16_t m_counter;
#endif
};
}
}
#endif /* APP_ADS101X_H_ */

3
software/app/ads_converter.cpp

@ -6,8 +6,7 @@
*/
#include "ads_converter.h"
#include "double_buffer.h"
#include "helper_structs.h"
namespace rijnfel {
cAdsConverter::cAdsConverter(cADC<ads::ads_sample_t, int32_t> & i_adc) :

31
software/app/ads_converter.h

@ -1,31 +0,0 @@
/*
* ads_converter.h
*
* Created on: Aug 22, 2017
* Author: Elmar
*/
#ifndef APP_ADS_CONVERTER_H_
#define APP_ADS_CONVERTER_H_
#include "data_receiver.h"
#include "data_provider.h"
#include "ads101x.h"
namespace rijnfel {
class cAdsConverter: public cDataSink {
public:
cAdsConverter(cADC<ads::ads_sample_t, int32_t> & i_adc);
virtual void ReceiveCallback(void * i_data, cDataReceiver * i_provider);
// Every channel has its own provider, after this we can not distinguish anymore
cDataProvider m_convertedSamples[4];
cDataReceiver m_rawSamples;
virtual ~cAdsConverter();
private:
cADC<ads::ads_sample_t, int32_t> & m_adc;
};
} /* namespace rijnfel */
#endif /* APP_ADS_CONVERTER_H_ */

14
software/app/application.cpp

@ -1,17 +1,17 @@
#include <user_config.h>
#include <hardware.h>
#include <SmingCore/SmingCore.h>
#include <SmingCore/HardwareSerial.h>
#include "excitation_light.h"
#include "sensor_settings.h"
#include "double_buffer.h"
#include "web_interface.h"
#include <application.h>
#include <stdint.h>
#include <rijnfel_core/rijnfel_core.h>
#include "excitation_light.h"
#include "ads101x.h"
#include "ads_converter.h"
#include "web_interface.h"
#include "signal_process.h"
#include <application.h>
#include <hardware.h>
#include "sensor_hub.h"
#include "ads101x.h"
using namespace rijnfel;

72
software/app/dac101c085.h

@ -1,72 +0,0 @@
//----------------------------------------------------------------------------------------------------------------------------
// Project: Uppsense
// Name: dac101c085.h
// Author: Maximilian Stiefel
// Date: 08.08.2017
//
// Description: Small simple driver for the TI DAC101C085.
//
//----------------------------------------------------------------------------------------------------------------------------
#ifndef APP_DAC101C085_H_
#define APP_DAC101C085_H_
//-------------------------------------Libraries------------------------------------------------------------------------------
#include <stdint.h>
#include "defines.h"
//-------------------------------------Defines--------------------------------------------------------------------------------
#define PD_BITS_POS 13 // Position of power down bits
#define D_BITS_POS 2 // Position of data bits
//-------------------------------------Namespaces-----------------------------------------------------------------------------
namespace rijnfel {
namespace dac {
//-------------------------------------Enums----------------------------------------------------------------------------------
/** Represents the operational mode of the DAC.
*/
enum eOpMode {NORMAL, PULL_DOWN_2K5, PULL_DOWN_100K, HIGH_IMPEDANCE};
//-------------------------------------cDAC101085-----------------------------------------------------------------------------
/** Small simple driver for the TI DAC101C085.
*/
class cDAC101C085
{
public:
/** @brief Instantiate DAC, assign a number and an address.
* @param i_dac_number Number of the DAC.
* @param i_address I2C address of this DAC.
*/
cDAC101C085(uint8_t i_dac_number, uint8_t i_address); // Constructor
/** @brief Free DAC, is currently doing nothing.
*/
~cDAC101C085(); // Destructor
/** @brief Check if the device is answering on the bus.
* @retval uint8_t Returns 1 on success, 0 when failing.
*/
uint8_t CheckDev(); // Check if device is available and alive
/** @brief Read out 16 bit register of the DAC.
* @retval uint16_t 16 bit read from the DAC.
*/
uint16_t ReadSettings(void);
/** @brief Write new setting to DAC register.
* @retval uint8_t Returns 1 on success, 0 when failing.
*/
uint8_t ChangeSettings(enum eOpMode mode, uint16_t val);
private:
uint8_t m_dac_number; // Which of the dacs is it?
uint8_t m_address;
uint8_t WriteSettings(uint16_t settings);
uint8_t I2CError(uint8_t error);
};
}
}
#endif /* APP_DAC101C085_H_ */

36
software/app/dummy_adc.cpp

@ -1,36 +0,0 @@
/*
* dummy_adc.cpp
*
* Created on: Aug 15, 2017
* Author: Elmar
*/
#include "dummy_adc.h"
namespace rijnfel {
cDymmyAdc::cDymmyAdc() {
m_sampleCounter = 0;
}
void cDymmyAdc::WaitSample(void) {
}
bool cDymmyAdc::IsReady(void) {
return true;
}
uint32_t cDymmyAdc::RawSample(void) {
m_sampleCounter++;
return m_sampleCounter;
}
uint32_t cDymmyAdc::ConvertSample(uint32_t& sample) {
return sample - 1;
}
cDymmyAdc::~cDymmyAdc() {
// TODO Auto-generated destructor stub
}
} /* namespace rijnfel */

30
software/app/dummy_adc.h

@ -1,30 +0,0 @@
/*
* dummy_adc.h
*
* Created on: Aug 15, 2017
* Author: Elmar
*/
#ifndef APP_DUMMY_ADC_H_
#define APP_DUMMY_ADC_H_
#include "adc.h"
#include <stdint.h>
namespace rijnfel {
class cDymmyAdc: public cADC<uint32_t, uint32_t> {
public:
cDymmyAdc();
virtual void WaitSample(void);
virtual bool IsReady(void);
virtual uint32_t RawSample(void);
virtual uint32_t ConvertSample(uint32_t & sample);
virtual ~cDymmyAdc();
private:
uint32_t m_sampleCounter;
};
} /* namespace rijnfel */
#endif /* APP_DUMMY_ADC_H_ */

2
software/app/excitation_light.cpp

@ -10,7 +10,7 @@
//-------------------------------------Libraries------------------------------------------------------------------------------
#include "excitation_light.h"
#include "defines.h"
#include <defines.h>
#include <SmingCore/SmingCore.h>
//-------------------------------------Namespaces-----------------------------------------------------------------------------

64
software/app/excitation_light.h

@ -1,64 +0,0 @@
//----------------------------------------------------------------------------------------------------------------------------
// Project: Uppsense
// Name: excitation_light.h
// Author: Maximilian Stiefel
// Date: 09.08.2017
//
// Description: Class to use the excitation light in an advanced way with the help of a DAC.
//
//----------------------------------------------------------------------------------------------------------------------------
#ifndef APP_EXCITATION_LIGHT_H_
#define APP_EXCITATION_LIGHT_H_
//-------------------------------------Libraries------------------------------------------------------------------------------
#include <stdint.h>
#include "dac101c085.h"
#include "hardware.h"
//-------------------------------------Defines--------------------------------------------------------------------------------
//-------------------------------------Namespaces-----------------------------------------------------------------------------
namespace rijnfel {
namespace light {
//-------------------------------------Enums----------------------------------------------------------------------------------
//-------------------------------------cExcitationLight-----------------------------------------------------------------------
/** Class to use the excitation light in an advanced way with the help of a DAC.
*/
class cExcitationLight
{
public:
/** Construct object, allocate space for DAC.
*/
cExcitationLight(); // Constructor
/** Destruct object, free space for DAC.
*/
~cExcitationLight(); // Destructor
/** Set the desired current through excitation light.
* @param microamp Current in uA.
* @retval uint8_t Returns 1 on success, 0 when failing.
*/
uint8_t SetCurrent(uint16_t microamp);
/** Function to be hooked up to a timer to generate rectangular signal.
* @retval uint8_t Returns 1 on success, 0 when failing.
*/
uint8_t RectangleUpdate();
/** Use 2K5 pull-down resistor to turn LED completely off.
* @retval uint8_t Returns 1 on success, 0 when failing.
*/
uint8_t DeactivateLED();
private:
dac::cDAC101C085 *m_DAC;
uint8_t m_rectangleStatus;
uint16_t m_DACRectHigh;
};
}
}
#endif /* APP_EXCITATION_LIGHT_H_ */

2
software/app/sensor_hub.h

@ -8,8 +8,8 @@
#ifndef APP_SENSOR_HUB_H_
#define APP_SENSOR_HUB_H_
#include <rijnfel_core/sensor_settings.h>
#include "ads101x.h"
#include "sensor_settings.h"
namespace rijnfel {

3
software/app/signal_process.cpp

@ -6,8 +6,9 @@
*/
#include "signal_process.h"
#include "helper_structs.h"
#include <stddef.h>
#include "../include/rijnfel_core/helper_structs.h"
//TODO remove this
namespace rijnfel {

4
software/app/signal_process.h

@ -7,8 +7,8 @@
#ifndef APP_SIGNAL_PROCESS_H_
#define APP_SIGNAL_PROCESS_H_
#include "data_receiver.h"
#include "data_provider.h"
#include "../include/rijnfel_core/data_provider.h"
#include "../include/rijnfel_core/data_receiver.h"
namespace rijnfel {

28
software/app/temperature.h

@ -1,28 +0,0 @@
/*
* temperature.h
*
* Created on: Aug 1, 2017
* Author: Elmar
*/
#ifndef APP_TEMPERATURE_H_
#define APP_TEMPERATURE_H_
#include "sensor.h"
namespace rijnfel {
template<typename Sample, typename Temperature>
class cTemperatureSensor: cSensor<Sample> {
public:
cTemperatureSensor() {
}
virtual Temperature ConvertSample(Sample sample) = 0;
virtual ~cTemperatureSensor() {
}
};
}
#endif /* APP_TEMPERATURE_H_ */

1
software/app/web_interface.cpp

@ -6,7 +6,6 @@
*/
#include "web_interface.h"
#include "helper_structs.h"
#include <application.h>
#include <SmingCore/SmingCore.h>
#include <SmingCore/Network/WebConstants.h>

130
software/app/web_interface.h

@ -1,130 +0,0 @@
/*
* web_interface.h
*
* Created on: Aug 6, 2017
* Author: Elmar
*/
#ifndef APP_WEB_INTERFACE_H_
#define APP_WEB_INTERFACE_H_
#include "adc.h"
//TODO remove this
#include "ads101x.h"
#include "dummy_adc.h"
#include "double_buffer.h"
#include <SmingCore/SmingCore.h>
#include "data_receiver.h"
namespace rijnfel {
#define RAW_CHANNEL 1
#define RAW_SAMPLES 1000
class cWebInterface: public cDataSink {
public:
/**
* Returns the global cWebInterface instance.
* Only one webserver should ever be running
* @return global cWebInterface instance
*/
static cWebInterface *GetInstance() {
if (cWebInterface::s_instance == NULL)
cWebInterface::s_instance = new cWebInterface();
return cWebInterface::s_instance;
}
/// Singleton instance
static cWebInterface *s_instance;
public:
/**
* Should not be used because it's a singleton
* @param delete
*/
cWebInterface(cWebInterface const&) = delete;
/**
* Should not be used because it's a singleton
* @param delete
* @return delete
*/
cWebInterface& operator=(cWebInterface const&) = delete;
/**
* Registers the paths and starts the server
*/
void StartServer();
/**
* Stops the server
*/
void StopServer();
/**
* This is a debug function that prints out the average values
* @todo remove this
*/
void PrintValues();
/**
* Destructor
*/
virtual ~cWebInterface();
// This is what the future will look like
// cDataReceiver m_sensorVal[2];
// cDataReceiver m_battery;
// cDataReceiver m_ledLife;
// cDataReceiver m_temp;
// But for now...
cDataReceiver m_adc_0;
cDataReceiver m_adc_1;
cDataReceiver m_adc_2;
cDataReceiver m_adc_3;
virtual void ReceiveCallback(void * i_data, cDataReceiver * i_receiver);
public:
/**
*
* @param i_request
* @param i_response Response to the client, index.html
*/
void OnIndex(HttpRequest & i_request, HttpResponse & i_response);
/**
* Function gets called from the mobile to refresh the average values
* @param i_request Request from the client
* @param i_response Response to the client, contains JSON with averages
*/
void OnRefresh(HttpRequest & i_request, HttpResponse & i_response);
/**
*
* @param i_request
* @param i_response
*/
void OnRawUpdate(HttpRequest& i_request, HttpResponse& i_response);
void OnConfiguration_json(HttpRequest &request, HttpResponse &response);
void OnConfiguration(HttpRequest &request, HttpResponse &response);
//TODO migrate this
WebSocketConnection * m_connectedUser;
bool m_sendWebsocket;
protected:
/**
* Initializes the variables
*/
cWebInterface();
private:
void ResetRawValues();
/// Whether the server has started or not
bool m_serverStarted;
/// Holds the average for all the channels
int32_t m_adc_value_average[4];
/// Server instance
HttpServer m_server;
};
} /* namespace rijnfel */
#endif /* APP_WEB_INTERFACE_H_ */

0
software/app/defines.h → software/include/defines.h

2
software/app/adc.h → software/include/rijnfel_core/adc.h

@ -8,7 +8,7 @@
#ifndef APP_ADC_H_
#define APP_ADC_H_
#include "sensor.h"
#include "../rijnfel_core/sensor.h"
namespace rijnfel {

0
software/app/data_provider.h → software/include/rijnfel_core/data_provider.h

0
software/app/data_receiver.h → software/include/rijnfel_core/data_receiver.h

0
software/app/data_sink.h → software/include/rijnfel_core/data_sink.h

1
software/app/double_buffer.h → software/include/rijnfel_core/double_buffer.h

@ -9,7 +9,6 @@
#define APP_DOUBLE_BUFFER_H_
#include <stdint.h>
#include <SmingCore/SmingCore.h>
namespace rijnfel {

0
software/app/helper_structs.h → software/include/rijnfel_core/helper_structs.h

21
software/include/rijnfel_core/rijnfel_core.h

@ -0,0 +1,21 @@
/*
* core.h
*
* Created on: Aug 23, 2017
* Author: Elmar
*/
#ifndef APP_CORE_CORE_H_
#define APP_CORE_CORE_H_
#include "adc.h"
#include "data_provider.h"
#include "data_receiver.h"
#include "data_sink.h"
#include "double_buffer.h"
#include "helper_structs.h"
#include "sensor_settings.h"
#endif /* APP_CORE_CORE_H_ */

0
software/app/sensor.h → software/include/rijnfel_core/sensor.h

2
software/app/sensor_settings.h → software/include/rijnfel_core/sensor_settings.h

@ -8,8 +8,8 @@
#ifndef APP_SENSOR_SETTINGS_H_
#define APP_SENSOR_SETTINGS_H_
#include "double_buffer.h"
#include "data_provider.h"
#include "double_buffer.h"
namespace rijnfel {
//timebase, in miliseconds.
Loading…
Cancel
Save