/** * @file MotionDetection.h * @author Hans Haupt * @brief This component controls the IMU (Accelerometer & Gyroscope) ICM-42670-P * @version 0.1 * @date 2023-12-15 * * @copyright Copyright (c) 2023 * */ #ifndef MotionDetection_h #define MotionDetection_h #include #include #include "IMU_CMDs.h" struct IMUResult{ int16_t x; int16_t y; int16_t z; }; class MotionDetection{ protected: enum registerBank{MREG1,MREG2,MREG3}; static const uint frequency = 10000000; uint8_t readFromRegisterBank(registerBank bank,uint8_t reg); void writeToRegisterBank(registerBank bank, uint8_t reg, uint8_t value); void resetRegisterBankAccess(); uint16_t cmdRead(uint8_t regHigh,uint8_t regLow); uint16_t cmdWrite(uint8_t regHigh,uint8_t regLow); uint8_t cmdRead(uint8_t reg); uint8_t cmdWrite(uint8_t reg); uint8_t readRegister(uint8_t reg); int16_t readDoubleRegister(uint8_t lowerReg); void writeRegister(uint8_t reg, uint8_t value); void initFIFO(); SPIClass * handler = NULL; public: MotionDetection(); /** * @brief initialized the IMU Component. * Wakes the IMU from Standby * Set configuration * */ void begin(void); /** * @brief stops the component * Sets the IMU to Low-Power-Mode * */ void end(void); /** * @brief Triggers a new Reading of the accelerationvalues and reads them from the IMU * * @return IMUResult that contains the new read values */ IMUResult getAcceleration(); /** * @brief Triggers a new reading of the gyroscope and reads the values from the imu * * @return IMUResult */ IMUResult getRotation(); /** * @brief Reads the current On Chip temperature of the IMU * * @return normalized temperature in degree Centigrade */ float getTemperature(); /** * @brief Returns the value of reading the whoAmI register * When IMU working correctly, value should be 0x67 * * @return the value of the whoami register of the ICM-42670 */ int8_t getWhoAmI(); void testFIFO(); }; #endif //MotionDetection