1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
// driver_5525DSO.h

#ifndef _DRIVER_5525DSO_h
#define _DRIVER_5525DSO_h

#if defined(ARDUINO) && ARDUINO >= 100
	#include "arduino.h"
#else
	#include "WProgram.h"
#endif
#include "DriverContext.h"

typedef struct
{
	int32_t C[6];
	int32_t Q[6];
	float ZERO;
} t_5525DSO_calibration_table;

//#define PBUFFER_SIZE 32
typedef enum { DS_01, GS_05 } t_ps_sensor;
typedef enum { OVS_256, OVS_512, OVS_1024, OVS_2048, OVS_4096 } t_ps_resolution;

/**
 * \brief	The class provide support for TE 5525DSO Pressure sensor
 * 
 * The class support both blocking and non blocking reading
 * 
 * Blocking Reading:     The driver start conversion on the sensor and wait
    *					 for the result. It require the full conversion time
 * 
 * Non Blocking reading: The readout process is spitted in two part
 *						  1) the measure is started on the device by asyncMeasure function
 *						  2) the result is get from the device by asyncGetResult function
 *						 there is no delay and dead time
 * 
 * The class download calibration from the device to convert raw data to P/T
 * automatically
 * 
 *						 
 */
	class Sensor5525DSO
	{
		public:

			
			bool Init(t_i2cdevices device, t_ps_sensor model, t_ps_resolution ps_resolution, void* hw_handle);
			bool doMeasure(float* P, float* T);

			bool asyncMeasure();
			bool asyncGetResult(float *P, float *T);

			void setZero(float value);
			float doZero();
			void correctZero(float value);
			float GetConversionDelay();

		private:



			t_5525DSO_calibration_table sensorCT;
			t_i2cdevices i2c_device;
			t_ps_sensor sensor_model;
			t_ps_resolution sensor_resolution;
			
			void CalibrateDate_5525DSO(int32_t raw_temp, int32_t raw_pressure, float* T, float* P);
			bool Reset_5525DSO();
			uint8_t GetResolutionByteCodeTemp();
			uint8_t GetResolutionByteCodePressure();
			uint32_t GetResolutionDelay();


			HW* hwi;
			DebugIfaceClass* dbg;

			uint32_t __chache_P;
			uint32_t __chache_T;
			int __TDiv;
			bool __last_is_T;
			bool __pending_meas;
			uint64_t __last_millis;
			//float PBuffer[PBUFFER_SIZE];
			int startup_counter;
			bool data_valid;

			bool _initialized = false;
	};

#endif



//                  #     # ### 
//                  ##    #  #  
//                  # #   #  #  
//                  #  #  #  #  
//                  #   # #  #  
//                  #    ##  #  
//                  #     # ### 
//
// Nuclear Instruments 2020 - All rights reserved
// Any commercial use of this code is forbidden
// Contact info@nuclearinstruments.eu