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.
Dependents: NucleoMGC3130 i2c_master
SensorData.cpp
00001 #include "SensorData.h" 00002 00003 SensorData::SensorData() 00004 :GestICMsg(), touch(), gesture() 00005 {} 00006 00007 SensorData::SensorData(GestICMsg * msg) 00008 :GestICMsg(), touch(), gesture() 00009 { 00010 data = msg->gets(); 00011 process(); 00012 } 00013 00014 bool SensorData::convert(GestICMsg * msg) 00015 { 00016 if (msg == NULL) 00017 return false; 00018 00019 if (msg->getID() != Sensor_Data_Output) 00020 return false; 00021 00022 data = msg->gets(); 00023 process(); 00024 return true; 00025 } 00026 00027 void SensorData::process() 00028 { 00029 int temp = 8; 00030 if ((data[4] & 0x01) == 0x01) { 00031 _DSPStatus = temp; 00032 temp += 2; 00033 } else _DSPStatus =-1; 00034 00035 if ((data[4] & 0x02) == 0x02) { 00036 _GestureInfo = temp; 00037 temp += 4; 00038 } else _GestureInfo =-1; 00039 00040 if ((data[4] & 0x04) == 0x04) { 00041 _TouchInfo = temp; 00042 temp += 4; 00043 } else _TouchInfo =-1; 00044 00045 if ((data[4] & 0x08) == 0x08) { 00046 _AirWheelInfo = temp; 00047 temp += 2; 00048 } else _AirWheelInfo =-1; 00049 00050 if ((data[4] & 0x10) == 0x10) { 00051 _xyzPosition = temp; 00052 temp += 6; 00053 } else _xyzPosition =-1; 00054 00055 if ((data[4] & 0x20) == 0x20) { 00056 _NoisePower = temp; 00057 temp += 4; 00058 } else _NoisePower =-1; 00059 00060 if ((data[5] & 0x08) == 0x08) { 00061 _CICData = temp; 00062 temp += 20; 00063 } else _CICData =-1; 00064 00065 if ((data[5] & 0x10) == 0x10) { 00066 _SDData = temp; 00067 temp += 20; 00068 } else _SDData =-1; 00069 00070 } 00071 //////////////////////////////////////////////////////////////////////////////////// 00072 bool SensorData::isDSPStatus() 00073 { 00074 if (_DSPStatus < 0) 00075 return false; 00076 else return true; 00077 } 00078 00079 bool SensorData::isGestureInfo() 00080 { 00081 if (_GestureInfo < 0) 00082 return false; 00083 else return true; 00084 } 00085 00086 bool SensorData::isTouchInfo() 00087 { 00088 if (_TouchInfo < 0) 00089 return false; 00090 else return true; 00091 } 00092 00093 bool SensorData::isAirWheelInfo() 00094 { 00095 if (_AirWheelInfo < 0) 00096 return false; 00097 else return true; 00098 } 00099 00100 bool SensorData::isxyzPosition() 00101 { 00102 if (_xyzPosition < 0) 00103 return false; 00104 else return true; 00105 } 00106 00107 bool SensorData::isNoisePower() 00108 { 00109 if (_NoisePower < 0) 00110 return false; 00111 else return true; 00112 } 00113 00114 bool SensorData::isCICData() 00115 { 00116 if (_CICData < 0) 00117 return false; 00118 else return true; 00119 } 00120 00121 bool SensorData::isSDData() 00122 { 00123 if (_SDData < 0) 00124 return false; 00125 else return true; 00126 } 00127 00128 /////////////////////////////////////////////////////////////////////////// 00129 int SensorData::getTimeStamp() 00130 { 00131 return data[6]; 00132 } 00133 00134 //////////////////////////////////////////////////////////////////////// 00135 bool SensorData::isPositionValid() 00136 { 00137 if ((data[7] & 0x01) == 0x01) 00138 return true; 00139 else return false; 00140 } 00141 00142 bool SensorData::isAirWheelValid() 00143 { 00144 if ((data[7] & 0x02) == 0x02) 00145 return true; 00146 else return false; 00147 } 00148 00149 bool SensorData::isRawDataValid() 00150 { 00151 if ((data[7] & 0x04) == 0x04) 00152 return true; 00153 else return false; 00154 } 00155 00156 bool SensorData::isNoisePowerValid() 00157 { 00158 if ((data[7] & 0x08) == 0x08) 00159 return true; 00160 else return false; 00161 } 00162 00163 bool SensorData::isEnvironmentalNoise() 00164 { 00165 if ((data[7] & 0x10) == 0x10) 00166 return true; 00167 else return false; 00168 } 00169 00170 bool SensorData::isClipping() 00171 { 00172 if ((data[7] & 0x20) == 0x20) 00173 return true; 00174 else return false; 00175 } 00176 00177 bool SensorData::isDSPRunning() 00178 { 00179 if ((data[7] & 0x80) == 0x80) 00180 return true; 00181 else return false; 00182 } 00183 00184 00185 int * SensorData::getxyzPosition() 00186 { 00187 if (_xyzPosition < 0) 00188 return NULL; 00189 00190 if (!isPositionValid()) 00191 return NULL; 00192 00193 xyz[0] = (data[_xyzPosition + 1]<< 8) | data[_xyzPosition]; 00194 xyz[1] = (data[_xyzPosition + 3]<< 8) | data[_xyzPosition + 2]; 00195 xyz[2] = (data[_xyzPosition + 5]<< 8) | data[_xyzPosition + 4]; 00196 00197 return xyz; 00198 } 00199 00200 TouchInfo * SensorData::getTouchInfo() 00201 { 00202 if (_TouchInfo < 0) 00203 return NULL; 00204 00205 touch.set((data[_TouchInfo] << 8) | data[_TouchInfo + 1], data[_TouchInfo + 2]); 00206 00207 return &touch; 00208 } 00209 00210 int * SensorData::getAirWheelInfo() 00211 { 00212 if (_AirWheelInfo < 0) 00213 return NULL; 00214 00215 if (!isAirWheelValid()) 00216 return NULL; 00217 00218 xyz[0] = data[_AirWheelInfo] >> 3; 00219 xyz[1] = data[_AirWheelInfo] & 0x07; 00220 00221 return xyz; 00222 } 00223 00224 float SensorData::getNoisePower() 00225 { 00226 if (_NoisePower < 0) 00227 return 0; 00228 00229 if (!isNoisePowerValid()) 00230 return 0; 00231 00232 float noise = -3; 00233 memcpy(&noise, data + _NoisePower, 4); 00234 return noise; 00235 } 00236 00237 float * SensorData::getUncalibratedData() 00238 { 00239 if (_CICData < 0) 00240 return NULL; 00241 00242 if (!isRawDataValid()) 00243 return NULL; 00244 00245 memcpy(raw, data +_CICData , 20); 00246 00247 return raw; 00248 } 00249 00250 float * SensorData::getSignalDeviation() 00251 { 00252 if (_SDData < 0) 00253 return NULL; 00254 00255 if (!isRawDataValid()) 00256 return NULL; 00257 00258 memcpy(raw, data +_SDData , 20); 00259 00260 return raw; 00261 } 00262 00263 GestureInfo * SensorData::getGestureInfo() 00264 { 00265 if (_GestureInfo < 0) 00266 return NULL; 00267 00268 gesture.set(data + _GestureInfo); 00269 00270 return &gesture; 00271 }
Generated on Fri Jul 15 2022 02:54:57 by
