This lib is supposed to be used as a sensor's calibration or control program. This makes Cubic Spline Model from some sample plots(sets of (value, voltage)), and then discretize the model (dividing the range of voltage into some steps) in order to use the calibrated model data without getting the INVERSE function.
Diff: TRP105F_Spline.cpp
- Revision:
- 9:ec1ee4a6b6a4
- Parent:
- 6:d2363b50aeaf
- Child:
- 10:b50e4bb40571
--- a/TRP105F_Spline.cpp Mon Jun 06 14:44:15 2016 +0000 +++ b/TRP105F_Spline.cpp Mon Jun 06 15:38:23 2016 +0000 @@ -3,7 +3,7 @@ #include "TRP105F_Spline.h" // To get ytage of TRP105F -AnalogIn* g_Sensor_Voltage; +//AnalogIn* g_Sensor_Voltage; // To get sample distance via seral com Serial g_Serial_Signal(USBTX, USBRX); @@ -19,11 +19,11 @@ // Constructor TRP105FS::TRP105FS() :_useType(AsMODULE) + ,_ai(AnalogIn(DEFALT_AI_PIN)) { _Sample_Num = 5; _Sample_Set = (VDset *)malloc(_Sample_Num * sizeof(VDset)); _u_spline = (double*)malloc(_Sample_Num * sizeof(double)); - g_Sensor_Voltage = new AnalogIn(p16); for(int i = 0; i < _Sample_Num; i++) { _Sample_Set[i].x = _Sample_Set[i].y = 0; @@ -35,13 +35,13 @@ unsigned int arg_num ) :_useType(AsMODULE) + ,_ai(AnalogIn(DEFALT_AI_PIN)) { if(arg_num > _ENUM) _Sample_Num = _ENUM; else _Sample_Num = arg_num; _Sample_Set = (VDset *)malloc(_Sample_Num * sizeof(VDset)); _u_spline = (double*)malloc(_Sample_Num * sizeof(double)); - g_Sensor_Voltage = new AnalogIn(p16); for(int i = 0; i < _Sample_Num; i++) { _Sample_Set[i].x = _Sample_Set[i].y = 0; @@ -54,13 +54,13 @@ UseType arg_type ) :_useType(arg_type) + ,_ai(AnalogIn(DEFALT_AI_PIN)) { if(arg_num > _ENUM) _Sample_Num = _ENUM; else _Sample_Num = arg_num; _Sample_Set = (VDset *)malloc(_Sample_Num * sizeof(VDset)); _u_spline = (double*)malloc(_Sample_Num * sizeof(double)); - g_Sensor_Voltage = new AnalogIn(p16); for(int i = 0; i < _Sample_Num; i++) { _Sample_Set[i].x = _Sample_Set[i].y = 0; @@ -74,13 +74,13 @@ PinName pin ) :_useType(arg_type) + ,_ai(AnalogIn(pin)) { if(arg_num > _ENUM) _Sample_Num = _ENUM; else _Sample_Num = arg_num; _Sample_Set = (VDset *)malloc(_Sample_Num * sizeof(VDset)); _u_spline = (double*)malloc(_Sample_Num * sizeof(double)); - g_Sensor_Voltage = new AnalogIn(pin); for(int i = 0; i < _Sample_Num; i++) { _Sample_Set[i].x = _Sample_Set[i].y = 0; @@ -93,7 +93,7 @@ { free(_Sample_Set); free(_u_spline); - delete g_Sensor_Voltage; + //delete g_Sensor_Voltage; } @@ -119,7 +119,7 @@ unsigned short TRP105FS::getDistance() { - return getX(g_Sensor_Voltage->read_u16()); + return getX(_ai.read_u16()); } /* @@ -290,7 +290,7 @@ for(int j = 0; j < 10; j++) { //unsigned short 's range [0 , 65535] //the Number of significant figures of read ytage is 3 or 4. - tmp_y = g_Sensor_Voltage->read_u16(); + tmp_y = _ai.read_u16(); #ifdef DEBUG g_Serial_Signal.printf("%d,",tmp_y);