| 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 |
#include "Communication.h" |
| 45 |
#include "Command.h" |
| 46 |
#include "ADXL362.h" |
| 47 |
#include "Console.h" |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
|
| 52 |
|
| 53 |
|
| 54 |
const char* cmdList[] = { "help?", |
| 55 |
"id?", |
| 56 |
"measure=", |
| 57 |
"temperature?", |
| 58 |
"reset!", |
| 59 |
"acceleration?", |
| 60 |
"accelerationX?", |
| 61 |
"accelerationY?", |
| 62 |
"accelerationZ?", |
| 63 |
"activity?"}; |
| 64 |
const char* cmdDescription[] = { |
| 65 |
" - Displays all available commands.", |
| 66 |
" - Display device details.", |
| 67 |
" - Start/stop the measurement process of the device. Accepted values:\r\n\ |
| 68 |
\t0 - Stop measurement. \r\n\ |
| 69 |
\t1 - Start measurement.", |
| 70 |
" - Displays the temperature.", |
| 71 |
" - Resets the device.", |
| 72 |
" - Displays the accelerations on XYZ axes.", |
| 73 |
" - Displays the acceleration on X axis.", |
| 74 |
" - Displays the acceleration on Y axis.", |
| 75 |
" - Displays the acceleration on Z axis.", |
| 76 |
" - Displays the activity status of the device. It runs for 5 motion detections."}; |
| 77 |
const char* cmdExample[] = { |
| 78 |
"", |
| 79 |
"", |
| 80 |
"To turn on the measurement process, type: measure=1.", |
| 81 |
"", |
| 82 |
"", |
| 83 |
"", |
| 84 |
"", |
| 85 |
"", |
| 86 |
"", |
| 87 |
""}; |
| 88 |
|
| 89 |
const char cmdNo = (sizeof(cmdList) / sizeof(const char*)); |
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
|
| 94 |
cmdFunction cmdFunctions[10] = {GetHelp, GetId, SetMeasurement, GetTemperature, |
| 95 |
DoReset, GetAcceleration, GetAccelerationX, |
| 96 |
GetAccelerationY, GetAccelerationZ, GetActivity}; |
| 97 |
char measureSetting = 0; |
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
void GetHelp(double* param, char paramNo) |
| 109 |
{ |
| 110 |
char displayCmd; |
| 111 |
|
| 112 |
CONSOLE_Print("Available commands:\r\n"); |
| 113 |
for(displayCmd = 0; displayCmd < cmdNo; displayCmd++) |
| 114 |
{ |
| 115 |
CONSOLE_Print("%s%s\r\n", (char*)cmdList[displayCmd], |
| 116 |
(char*)cmdDescription[displayCmd]); |
| 117 |
} |
| 118 |
} |
| 119 |
|
| 120 |
|
| 121 |
|
| 122 |
|
| 123 |
|
| 124 |
|
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
char DoDeviceInit(void) |
| 130 |
{ |
| 131 |
|
| 132 |
if(ADXL362_Init() == 0) |
| 133 |
{ |
| 134 |
CONSOLE_Print("ADXL362 OK\r\n"); |
| 135 |
GetHelp(NULL, 0); |
| 136 |
return SUCCESS; |
| 137 |
} |
| 138 |
else |
| 139 |
{ |
| 140 |
CONSOLE_Print("ADXL362 Error\r\n"); |
| 141 |
|
| 142 |
return ERROR; |
| 143 |
} |
| 144 |
} |
| 145 |
|
| 146 |
|
| 147 |
|
| 148 |
|
| 149 |
|
| 150 |
|
| 151 |
void GetId(double* param, char paramNo) |
| 152 |
{ |
| 153 |
unsigned char regVal = 0; |
| 154 |
|
| 155 |
|
| 156 |
CONSOLE_Print("Analog Devices device ID: "); |
| 157 |
ADXL362_GetRegisterValue(®Val, ADXL362_REG_DEVID_AD, 1); |
| 158 |
CONSOLE_Print("%d\r\n",regVal); |
| 159 |
|
| 160 |
CONSOLE_Print("Analog Devices MEMS ID: "); |
| 161 |
ADXL362_GetRegisterValue(®Val, ADXL362_REG_DEVID_MST, 1); |
| 162 |
CONSOLE_Print("%d\r\n",regVal); |
| 163 |
|
| 164 |
CONSOLE_Print("Analog Devices PART ID: "); |
| 165 |
ADXL362_GetRegisterValue(®Val, ADXL362_REG_PARTID, 1); |
| 166 |
CONSOLE_Print("%d\r\n",regVal); |
| 167 |
|
| 168 |
CONSOLE_Print("Analog Devices REVISION ID: "); |
| 169 |
ADXL362_GetRegisterValue(®Val, ADXL362_REG_REVID, 1); |
| 170 |
CONSOLE_Print("%d\r\n",regVal); |
| 171 |
} |
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
|
| 176 |
|
| 177 |
|
| 178 |
void SetMeasurement(double* param, char paramNo) |
| 179 |
{ |
| 180 |
if(paramNo >= 1) |
| 181 |
{ |
| 182 |
if(param[0] < 0) |
| 183 |
{ |
| 184 |
param[0] = 0; |
| 185 |
} |
| 186 |
if(param[0] > 1) |
| 187 |
{ |
| 188 |
param[0] = 1; |
| 189 |
} |
| 190 |
|
| 191 |
measureSetting = param[0]; |
| 192 |
|
| 193 |
ADXL362_SetPowerMode(param[0]); |
| 194 |
|
| 195 |
CONSOLE_Print("%s%d\r\n",cmdList[2],(short)param[0]); |
| 196 |
} |
| 197 |
else |
| 198 |
{ |
| 199 |
|
| 200 |
CONSOLE_Print("Invalid parameter!\r\n"); |
| 201 |
CONSOLE_Print("%s%s\r\n", (char*)cmdList[2], (char*)cmdDescription[2]); |
| 202 |
CONSOLE_Print("Example: %s\r\n", (char*)cmdExample[2]); |
| 203 |
} |
| 204 |
} |
| 205 |
|
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
|
| 211 |
void GetTemperature(double* param, char paramNo) |
| 212 |
{ |
| 213 |
float temperature = 0; |
| 214 |
|
| 215 |
if(measureSetting) |
| 216 |
{ |
| 217 |
|
| 218 |
temperature = ADXL362_ReadTemperature(); |
| 219 |
|
| 220 |
CONSOLE_Print("temperature=%.2f [C]\r\n",temperature); |
| 221 |
} |
| 222 |
else |
| 223 |
{ |
| 224 |
CONSOLE_Print("Device is in Standby mode. Use the 'measure=1' command \ |
| 225 |
to enter Measurement mode.\r\n"); |
| 226 |
} |
| 227 |
} |
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
void DoReset(double* param, char paramNo) |
| 235 |
{ |
| 236 |
|
| 237 |
measureSetting = 0; |
| 238 |
ADXL362_SoftwareReset(); |
| 239 |
|
| 240 |
|
| 241 |
CONSOLE_Print("Device was reset.\r\n"); |
| 242 |
} |
| 243 |
|
| 244 |
|
| 245 |
|
| 246 |
|
| 247 |
|
| 248 |
|
| 249 |
void GetAcceleration(double* param, char paramNo) |
| 250 |
{ |
| 251 |
unsigned char samplesNumber = 0; |
| 252 |
float xAxisAcc = 0; |
| 253 |
float yAxisAcc = 0; |
| 254 |
float zAxisAcc = 0; |
| 255 |
|
| 256 |
if(measureSetting) |
| 257 |
{ |
| 258 |
|
| 259 |
samplesNumber = 30; |
| 260 |
while(samplesNumber) |
| 261 |
{ |
| 262 |
|
| 263 |
ADXL362_GetGxyz(&xAxisAcc, &yAxisAcc, &zAxisAcc); |
| 264 |
|
| 265 |
CONSOLE_Print("x axis:%.3f\r\n",xAxisAcc); |
| 266 |
CONSOLE_Print("y axis:%.3f\r\n",yAxisAcc); |
| 267 |
CONSOLE_Print("z axis:%.3f\r\n",zAxisAcc); |
| 268 |
|
| 269 |
TIME_DelayMs(200); |
| 270 |
samplesNumber--; |
| 271 |
} |
| 272 |
} |
| 273 |
else |
| 274 |
{ |
| 275 |
CONSOLE_Print("Device is in Standby mode. Use the 'measure=1' command \ |
| 276 |
to enter Measurement mode.\r\n"); |
| 277 |
} |
| 278 |
} |
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
|
| 284 |
|
| 285 |
void GetAccelerationX(double* param, char paramNo) |
| 286 |
{ |
| 287 |
unsigned char samplesNumber = 0; |
| 288 |
float xAxisAcc = 0; |
| 289 |
float yAxisAcc = 0; |
| 290 |
float zAxisAcc = 0; |
| 291 |
|
| 292 |
if(measureSetting) |
| 293 |
{ |
| 294 |
|
| 295 |
samplesNumber = 30; |
| 296 |
while(samplesNumber) |
| 297 |
{ |
| 298 |
|
| 299 |
ADXL362_GetGxyz(&xAxisAcc, &yAxisAcc, &zAxisAcc); |
| 300 |
|
| 301 |
CONSOLE_Print("x axis:%.3f\r\n",xAxisAcc); |
| 302 |
|
| 303 |
TIME_DelayMs(200); |
| 304 |
samplesNumber--; |
| 305 |
} |
| 306 |
} |
| 307 |
else |
| 308 |
{ |
| 309 |
CONSOLE_Print("Device is in Standby mode. Use the 'measure=1' command \ |
| 310 |
to enter Measurement mode.\r\n"); |
| 311 |
} |
| 312 |
} |
| 313 |
|
| 314 |
|
| 315 |
|
| 316 |
|
| 317 |
|
| 318 |
|
| 319 |
void GetAccelerationY(double* param, char paramNo) |
| 320 |
{ |
| 321 |
unsigned char samplesNumber = 0; |
| 322 |
float xAxisAcc = 0; |
| 323 |
float yAxisAcc = 0; |
| 324 |
float zAxisAcc = 0; |
| 325 |
|
| 326 |
if(measureSetting) |
| 327 |
{ |
| 328 |
|
| 329 |
samplesNumber = 30; |
| 330 |
while(samplesNumber) |
| 331 |
{ |
| 332 |
|
| 333 |
ADXL362_GetGxyz(&xAxisAcc, &yAxisAcc, &zAxisAcc); |
| 334 |
|
| 335 |
CONSOLE_Print("y axis:%.3f\r\n",yAxisAcc); |
| 336 |
|
| 337 |
TIME_DelayMs(200); |
| 338 |
samplesNumber--; |
| 339 |
} |
| 340 |
} |
| 341 |
else |
| 342 |
{ |
| 343 |
CONSOLE_Print("Device is in Standby mode. Use the 'measure=1' command \ |
| 344 |
to enter Measurement mode.\r\n"); |
| 345 |
} |
| 346 |
} |
| 347 |
|
| 348 |
|
| 349 |
|
| 350 |
|
| 351 |
|
| 352 |
|
| 353 |
void GetAccelerationZ(double* param, char paramNo) |
| 354 |
{ |
| 355 |
unsigned char samplesNumber = 0; |
| 356 |
float xAxisAcc = 0; |
| 357 |
float yAxisAcc = 0; |
| 358 |
float zAxisAcc = 0; |
| 359 |
|
| 360 |
if(measureSetting) |
| 361 |
{ |
| 362 |
|
| 363 |
samplesNumber = 30; |
| 364 |
while(samplesNumber) |
| 365 |
{ |
| 366 |
|
| 367 |
ADXL362_GetGxyz(&xAxisAcc, &yAxisAcc, &zAxisAcc); |
| 368 |
|
| 369 |
CONSOLE_Print("z axis:%.3f\r\n",zAxisAcc); |
| 370 |
|
| 371 |
TIME_DelayMs(200); |
| 372 |
samplesNumber--; |
| 373 |
} |
| 374 |
} |
| 375 |
else |
| 376 |
{ |
| 377 |
CONSOLE_Print("Device is in Standby mode. Use the 'measure=1' command \ |
| 378 |
to enter Measurement mode.\r\n"); |
| 379 |
} |
| 380 |
} |
| 381 |
|
| 382 |
|
| 383 |
|
| 384 |
|
| 385 |
|
| 386 |
|
| 387 |
void GetActivity(double* param, char paramNo) |
| 388 |
{ |
| 389 |
unsigned char detections = 0; |
| 390 |
unsigned char regVal = 0; |
| 391 |
|
| 392 |
if(measureSetting) |
| 393 |
{ |
| 394 |
|
| 395 |
CONSOLE_Print("Activity polling enabled.\r\n"); |
| 396 |
|
| 397 |
ADXL362_SetPowerMode(0); |
| 398 |
ADXL362_SetOutputRate(ADXL362_ODR_100_HZ); |
| 399 |
ADXL362_SetRegisterValue( |
| 400 |
ADXL362_ACT_INACT_CTL_LINKLOOP(ADXL362_MODE_LINK), |
| 401 |
ADXL362_REG_ACT_INACT_CTL, |
| 402 |
1); |
| 403 |
ADXL362_SetupActivityDetection(1, 60, 4); |
| 404 |
ADXL362_SetupInactivityDetection(1, 700, 250); |
| 405 |
ADXL362_SetPowerMode(1); |
| 406 |
|
| 407 |
ADXL362_GetRegisterValue(®Val, |
| 408 |
ADXL362_REG_STATUS, |
| 409 |
1); |
| 410 |
|
| 411 |
detections = 5; |
| 412 |
while(detections) |
| 413 |
{ |
| 414 |
do |
| 415 |
{ |
| 416 |
ADXL362_GetRegisterValue(®Val, |
| 417 |
ADXL362_REG_STATUS, |
| 418 |
1); |
| 419 |
}while(!(regVal & ADXL362_STATUS_ACT) && |
| 420 |
!(regVal & ADXL362_STATUS_INACT)); |
| 421 |
detections--; |
| 422 |
if(regVal & ADXL362_STATUS_ACT) |
| 423 |
{ |
| 424 |
CONSOLE_Print("Activity\r\n"); |
| 425 |
} |
| 426 |
if(regVal & ADXL362_STATUS_INACT) |
| 427 |
{ |
| 428 |
CONSOLE_Print("Inactivity\r\n"); |
| 429 |
} |
| 430 |
} |
| 431 |
CONSOLE_Print("Finished activity polling.\r\n"); |
| 432 |
} |
| 433 |
else |
| 434 |
{ |
| 435 |
CONSOLE_Print("Device is in Standby mode. Use the 'measure=1' command \ |
| 436 |
to enter Measurement mode.\r\n"); |
| 437 |
} |
| 438 |
} |