@@ -265,6 +265,64 @@ bool QwDevKX13X::enableTiltEngine(bool enable)
265
265
return true ;
266
266
}
267
267
268
+
269
+ // ////////////////////////////////////////////////
270
+ // enableWakeEngine()
271
+ //
272
+ // Enables the wake detection feature.
273
+ //
274
+ // Parameter:
275
+ // enable - enables/disables the wake detection feature
276
+ //
277
+ bool QwDevKX13X::enableWakeEngine (bool enable)
278
+ {
279
+ int retVal;
280
+ uint8_t tempVal;
281
+
282
+ retVal = readRegisterRegion (SFE_KX13X_CNTL4, &tempVal, 1 );
283
+
284
+ if ( retVal != 0 )
285
+ return false ;
286
+
287
+ tempVal = tempVal | (enable << 5 );
288
+
289
+ retVal = writeRegisterByte (SFE_KX13X_CNTL4, tempVal);
290
+
291
+ if ( retVal != 0 )
292
+ return false ;
293
+
294
+ return true ;
295
+ }
296
+
297
+ // ////////////////////////////////////////////////
298
+ // enableSleepEngine()
299
+ //
300
+ // Enables the sleep feature.
301
+ //
302
+ // Parameter:
303
+ // enable - enables/disables the sleep feature
304
+ //
305
+ bool QwDevKX13X::enableSleepEngine (bool enable)
306
+ {
307
+ int retVal;
308
+ uint8_t tempVal;
309
+
310
+ retVal = readRegisterRegion (SFE_KX13X_CNTL4, &tempVal, 1 );
311
+
312
+ if ( retVal != 0 )
313
+ return false ;
314
+
315
+ tempVal = tempVal | (enable << 4 );
316
+
317
+ retVal = writeRegisterByte (SFE_KX13X_CNTL4, tempVal);
318
+
319
+ if ( retVal != 0 )
320
+ return false ;
321
+
322
+ return true ;
323
+ }
324
+
325
+
268
326
// ////////////////////////////////////////////////
269
327
// setOutputDataRate()
270
328
//
@@ -329,6 +387,71 @@ bool QwDevKX13X::setTapDataRate(uint8_t rate)
329
387
return true ;
330
388
}
331
389
390
+
391
+ // ////////////////////////////////////////////////
392
+ // setTiltDataRate()
393
+ //
394
+ // Changes the rate at which the tilt position is polled.
395
+ //
396
+ // Parameter:
397
+ // rate - determines the rate to be applied.
398
+ //
399
+ bool QwDevKX13X::setTiltDataRate (uint8_t rate)
400
+ {
401
+
402
+ if ( rate > 3 )
403
+ return false ;
404
+
405
+ uint8_t tempVal;
406
+ int retVal;
407
+
408
+ retVal = readRegisterRegion (SFE_KX13X_CNTL3, &tempVal, 1 );
409
+
410
+ if ( retVal != 0 )
411
+ return false ;
412
+
413
+ tempVal = tempVal | (rate << 6 );
414
+
415
+ retVal = writeRegisterByte (SFE_KX13X_CNTL3, tempVal);
416
+
417
+ if ( retVal != 0 )
418
+ return false ;
419
+
420
+ return true ;
421
+ }
422
+
423
+
424
+ // ////////////////////////////////////////////////
425
+ // setWakeDataRate()
426
+ //
427
+ // Changes the rate at which the wake function is performed.
428
+ //
429
+ // Parameter:
430
+ // rate - determines the rate to be applied.
431
+ //
432
+ bool QwDevKX13X::setWakeDataRate (uint8_t rate)
433
+ {
434
+
435
+ if ( rate > 7 )
436
+ return false ;
437
+
438
+ uint8_t tempVal;
439
+ int retVal;
440
+
441
+ retVal = readRegisterRegion (SFE_KX13X_CNTL3, &tempVal, 1 );
442
+
443
+ if ( retVal != 0 )
444
+ return false ;
445
+
446
+ tempVal = tempVal | rate;
447
+
448
+ retVal = writeRegisterByte (SFE_KX13X_CNTL3, tempVal);
449
+
450
+ if ( retVal != 0 )
451
+ return false ;
452
+
453
+ return true ;
454
+ }
332
455
// ////////////////////////////////////////////////
333
456
// getOutputDataRate()
334
457
//
@@ -519,7 +642,7 @@ bool QwDevKX13X::setPulseWidth(uint8_t width, uint8_t pin)
519
642
int retVal;
520
643
uint8_t tempVal;
521
644
522
- if ( width > 4 | pin > 2 )
645
+ if ( ( width > 4 ) | ( pin > 2 ) )
523
646
return false ;
524
647
525
648
if ( pin == 1 )
@@ -1173,6 +1296,57 @@ bool QwDevKX13X::getRawAccelData(rawOutputData *rawAccelData){
1173
1296
return true ;
1174
1297
}
1175
1298
1299
+ // ////////////////////////////////////////////////
1300
+ // forceSleep()
1301
+ //
1302
+ // Forces the accelerometer into a sleep state.
1303
+ //
1304
+ bool QwDevKX13X::forceSleep ()
1305
+ {
1306
+ int retVal;
1307
+ uint8_t tempVal;
1308
+ uint8_t forceSleep = 0x01 ;
1309
+
1310
+ retVal = readRegisterRegion (SFE_KX13X_CNTL5, &tempVal, 1 );
1311
+
1312
+ if ( retVal != 0 )
1313
+ return false ;
1314
+
1315
+ tempVal |= forceSleep;
1316
+
1317
+ retVal = writeRegisterByte (SFE_KX13X_CNTL5, tempVal);
1318
+
1319
+ if ( retVal != 0 )
1320
+ return false ;
1321
+
1322
+ return true ;
1323
+ }
1324
+
1325
+ // ////////////////////////////////////////////////
1326
+ // forceWake()
1327
+ //
1328
+ // Forces the accelerometer into a sleep state.
1329
+ //
1330
+ bool QwDevKX13X::forceWake ()
1331
+ {
1332
+ int retVal;
1333
+ uint8_t tempVal;
1334
+ uint8_t forceWake = 0x02 ;
1335
+
1336
+ retVal = readRegisterRegion (SFE_KX13X_CNTL5, &tempVal, 1 );
1337
+
1338
+ if ( retVal != 0 )
1339
+ return false ;
1340
+
1341
+ tempVal |= forceWake;
1342
+
1343
+ retVal = writeRegisterByte (SFE_KX13X_CNTL5, tempVal);
1344
+
1345
+ if ( retVal != 0 )
1346
+ return false ;
1347
+
1348
+ return true ;
1349
+ }
1176
1350
1177
1351
// ////////////////////////////////////////////////////////////////////////////////
1178
1352
// readRegisterRegion()
@@ -1223,10 +1397,7 @@ int QwDevKX13X::writeRegisterByte(uint8_t reg, uint8_t data)
1223
1397
}
1224
1398
1225
1399
1226
- // ***************************************** KX132 ******************************************
1227
- // ******************************************************************************************
1228
- // ******************************************************************************************
1229
- // ******************************************************************************************
1400
+ // ***************************************** KX132 *********************************************************
1230
1401
1231
1402
1232
1403
// ////////////////////////////////////////////////////////////////////////////////
@@ -1323,11 +1494,7 @@ bool QwDevKX132::convAccelData(outputData *userAccel, rawOutputData *rawAccelDat
1323
1494
return true ;
1324
1495
}
1325
1496
1326
- // ***************************************** KX134 ******************************************
1327
- // ******************************************************************************************
1328
- // ******************************************************************************************
1329
- // ******************************************************************************************
1330
-
1497
+ // ***************************************** KX134 ******************************************************
1331
1498
1332
1499
// ////////////////////////////////////////////////////////////////////////////////
1333
1500
// init()
0 commit comments