From e42a471a33ca04f78cf5352b1a845323882ef9e6 Mon Sep 17 00:00:00 2001 From: Hans Haupt Date: Fri, 3 May 2024 09:29:53 +0200 Subject: [PATCH] wip:reading acceleration --- src/Dezibot.cpp | 1 + src/motionDetection/MotionDetection.cpp | 14 ++++++++------ 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/src/Dezibot.cpp b/src/Dezibot.cpp index cf2084e..273a5a2 100644 --- a/src/Dezibot.cpp +++ b/src/Dezibot.cpp @@ -17,4 +17,5 @@ Dezibot::Dezibot():multiColorLight(),motionDetection(){ }; void Dezibot::begin(void) { multiColorLight.begin(); + motionDetection.begin(); }; diff --git a/src/motionDetection/MotionDetection.cpp b/src/motionDetection/MotionDetection.cpp index e2c2ca3..5e648ec 100644 --- a/src/motionDetection/MotionDetection.cpp +++ b/src/motionDetection/MotionDetection.cpp @@ -8,9 +8,8 @@ void MotionDetection::begin(void){ pinMode(34,OUTPUT); digitalWrite(34,HIGH); handler->begin(36,37,35,34); - - //handler->beginTransaction(SPISettings(frequency,SPI_MSBFIRST,SPI_MODE0)); + handler->beginTransaction(SPISettings(frequency,SPI_MSBFIRST,SPI_MODE0)); digitalWrite(34,LOW); // set Accel and Gyroscop to Low Noise @@ -20,7 +19,7 @@ void MotionDetection::begin(void){ delayMicroseconds(200); digitalWrite(34,HIGH); - //handler->endTransaction();*/ + handler->endTransaction(); }; void MotionDetection::end(void){ handler->beginTransaction(SPISettings(frequency,SPI_MSBFIRST,SPI_MODE0)); @@ -35,9 +34,12 @@ IMUResult MotionDetection::getAcceleration(){ IMUResult result; handler->beginTransaction(SPISettings(frequency,SPI_MSBFIRST,SPI_MODE0)); digitalWrite(34,LOW); - result.x = handler->transfer16(cmdRead(ACCEL_DATA_X_HIGH,ACCEL_DATA_X_LOW)); - result.y = handler->transfer16(cmdRead(ACCEL_DATA_Y_HIGH,ACCEL_DATA_Y_LOW)); - result.z = handler->transfer16(cmdRead(ACCEL_DATA_Z_HIGH,ACCEL_DATA_Z_LOW)); + result.x = readRegister(ACCEL_DATA_X_HIGH)<<8; + result.x |= readRegister(ACCEL_DATA_X_LOW); + result.y = readRegister(ACCEL_DATA_Y_HIGH)<<8; + result.y |= readRegister(ACCEL_DATA_Y_LOW); + result.z = readRegister(ACCEL_DATA_Z_HIGH)<<8; + result.z |= readRegister(ACCEL_DATA_Z_LOW); digitalWrite(34,HIGH); handler->endTransaction(); return result;