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:
- 10:b50e4bb40571
- Parent:
- 9:ec1ee4a6b6a4
- Child:
- 11:d60fb729eacf
--- a/TRP105F_Spline.cpp Mon Jun 06 15:38:23 2016 +0000 +++ b/TRP105F_Spline.cpp Mon Jun 06 15:41:44 2016 +0000 @@ -70,6 +70,25 @@ TRP105FS::TRP105FS( unsigned int arg_num, + PinName pin +) + :_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)); + + for(int i = 0; i < _Sample_Num; i++) { + _Sample_Set[i].x = _Sample_Set[i].y = 0; + _u_spline[i] = 0.0; + } +} + +TRP105FS::TRP105FS( + unsigned int arg_num, UseType arg_type, PinName pin ) @@ -647,7 +666,7 @@ sprintf(filepath, "/local/%s", filename); fp = fopen(filepath, "rb"); - + for(int i = 0; i < _ENUM; i++) { fread(&_Set[i].x, sizeof(unsigned short), 1, fp); @@ -704,7 +723,7 @@ sprintf(filepath, "/local/%s", filename); fp = fopen(filepath, "w"); //fp = fopen("/local/log.txt", "w"); // open file in writing mode - + fprintf(fp, "x, y,(threshold)\n"); for(int i = 0; i < _ENUM; i++) { fprintf(fp, "%d,%d,(%d)\n", _Set[i].x, _Set[i].y, _Threshold[i]); @@ -713,7 +732,7 @@ for(int i = 0; i < _Sample_Num; i++) { fprintf(fp, "%d,%d\n", _Sample_Set[i].x, _Sample_Set[i].y); } - + free(filepath); fclose(fp);