Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of TRP105F_Spline by
Revision 20:0453919a76b2, committed 2016-06-30
- Comitter:
- aktk
- Date:
- Thu Jun 30 16:45:30 2016 +0000
- Parent:
- 19:ee2558b13570
- Child:
- 21:cd20537290f9
- Commit message:
- snum the local static variable in _setSample(ns, ns) has come to be declared as _snum the TRP105FS class' member field. It's because it was not expected that local static variable is shared by the instances of the same class.
Changed in this revision
| TRP105F_Spline.cpp | Show annotated file Show diff for this revision Revisions of this file |
| TRP105F_Spline.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/TRP105F_Spline.cpp Thu Jun 30 15:23:41 2016 +0000
+++ b/TRP105F_Spline.cpp Thu Jun 30 16:45:30 2016 +0000
@@ -34,6 +34,7 @@
:_useType(AsMODULE)
,_ai(AnalogIn(DEFALT_AI_PIN))
{
+ _snum = 0;
_Sample_Num = 5;
_Sample_Set = (VDset *)malloc(_Sample_Num * sizeof(VDset));
_u_spline = (double*)malloc(_Sample_Num * sizeof(double));
@@ -50,6 +51,7 @@
:_useType(AsMODULE)
,_ai(AnalogIn(DEFALT_AI_PIN))
{
+ _snum = 0;
if(arg_num > _ENUM) _Sample_Num = _ENUM;
else _Sample_Num = arg_num;
@@ -69,6 +71,7 @@
:_useType(arg_type)
,_ai(AnalogIn(DEFALT_AI_PIN))
{
+ _snum = 0;
if(arg_num > _ENUM) _Sample_Num = _ENUM;
else _Sample_Num = arg_num;
@@ -89,6 +92,7 @@
:_ai(AnalogIn(pin))
{
+ _snum = 0;
if(arg_num > _ENUM) _Sample_Num = _ENUM;
else _Sample_Num = arg_num;
@@ -109,6 +113,7 @@
:_useType(arg_type)
,_ai(AnalogIn(pin))
{
+ _snum = 0;
if(arg_num > _ENUM) _Sample_Num = _ENUM;
else _Sample_Num = arg_num;
@@ -189,35 +194,34 @@
void TRP105FS::_setSample(unsigned short arg_x, unsigned short arg_y)
{
- static unsigned int snum = 0;
unsigned int num;
int tmp;
VDset tmp_set[_ENUM]; // for bucket sort
// Increment it if this function called.
- snum++;
+ _snum++;
#ifdef DEBUG
- g_Serial_Signal.printf("snum : %d\n", snum);
+ g_Serial_Signal.printf("_snum : %d\n", _snum);
g_Serial_Signal.printf("(%d,%d)\n",arg_x, arg_y);
#endif
// fit to smaller
- if (snum < _Sample_Num) {
- num = snum;
+ if (_snum < _Sample_Num) {
+ num = _snum;
} else {
- // To reclloc memories if snum is bigger than _Sample_Num.
- // When realloc is failed, snum is back to porevius.
- VDset* tmp_Set = (VDset *)realloc(_Sample_Set, snum * sizeof(VDset));
- double* tmp__u_ = (double*)realloc(_u_spline, snum * sizeof(double));
- if (tmp_set != NULL && tmp__u_ != NULL) {
+ // To reclloc memories if _snum is bigger than _Sample_Num.
+ // When realloc is failed, _snum is back to porevius.
+ VDset* tmp_Set = (VDset *)realloc(_Sample_Set, _snum * sizeof(VDset));
+ double* tmp__u_ = (double*)realloc(_u_spline, _snum * sizeof(double));
+ if (tmp_Set != NULL && tmp__u_ != NULL) {
_Sample_Set = tmp_Set;
_u_spline = tmp__u_;
- num = _Sample_Num = snum;
+ num = _Sample_Num = _snum;
} else {
- snum--;
- num = snum = _Sample_Num ;
+ _snum--;
+ num = _snum = _Sample_Num ;
#ifdef DEBUG
- g_Serial_Signal.printf("failed to realloc\n", snum);
+ g_Serial_Signal.printf("failed to realloc\n", _snum);
#endif
}
}
@@ -251,7 +255,7 @@
#endif
// substruct tmp from number of sample.
_Sample_Num -= tmp;
- snum -= tmp;
+ _snum -= tmp;
#ifdef DEBUG
g_Serial_Signal.printf("-----------------\n");
g_Serial_Signal.printf(" _Sample_num: %d\n", _Sample_Num );
--- a/TRP105F_Spline.h Thu Jun 30 15:23:41 2016 +0000
+++ b/TRP105F_Spline.h Thu Jun 30 16:45:30 2016 +0000
@@ -108,6 +108,7 @@
UseType _useType;
// For data sampling and making spline model
unsigned short _Sample_Num; // the number of samples for derive spline
+ unsigned short _snum; // for counting set sample data by _setSample(us,us);
VDset* _Sample_Set;
double* _u_spline;
// For comvert voltage -> physical quantity e.g. distance
