-
Notifications
You must be signed in to change notification settings - Fork 54
Add qmc5883p #802
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add qmc5883p #802
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
a1b412c
fix(partitions): 4MB NoOTA in platformIO.ini
tyeth 1ef9d16
add(qmc5883p): initial vectorless result
tyeth 2a2c2cf
fix(qmc5883p): use continuous mode instead of normal
tyeth e900680
fix(huzzah): platformIO ram .text1 section size (iram1_0_seg)
tyeth 2723c39
fix(qmc883p): set range to 30G and log xyz until vector supported
tyeth b8900be
Merge branch 'upstream-main' into add-qmc5883p-vectorless
tyeth 9520701
chore(qmc5883p): clang format
tyeth 284263a
chore(qmc5883p): doxygen
tyeth aa4ef3c
chore(qmc5883p): clang format
tyeth 6532bc4
Merge branch 'main' into add-qmc5883p-vectorless
tyeth b338a56
refactor(includes): move math.h to WipperSnapper.h
tyeth File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,6 +19,8 @@ | |
#define WIPPERSNAPPER_H | ||
|
||
// Cpp STD | ||
#include <math.h> | ||
|
||
#include <vector> | ||
|
||
// Nanopb dependencies | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
106 changes: 106 additions & 0 deletions
106
src/components/i2c/drivers/WipperSnapper_I2C_Driver_QMC5883P.cpp
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
/*! | ||
* @file WipperSnapper_I2C_Driver_QMC5883P.cpp | ||
* | ||
* Implementation for the Adafruit QMC5883P magnetometer wrapper. | ||
*/ | ||
|
||
#include "WipperSnapper_I2C_Driver_QMC5883P.h" | ||
|
||
#include <Adafruit_QMC5883P.h> | ||
|
||
/*! | ||
* @brief Constructor for a QMC5883P sensor. | ||
* @param i2c | ||
* The I2C interface. | ||
* @param sensorAddress | ||
* The 7-bit I2C address of the sensor. | ||
*/ | ||
WipperSnapper_I2C_Driver_QMC5883P::WipperSnapper_I2C_Driver_QMC5883P( | ||
TwoWire *i2c, uint16_t sensorAddress) | ||
: WipperSnapper_I2C_Driver(i2c, sensorAddress) {} | ||
|
||
/*! | ||
* @brief Destructor for a QMC5883P sensor. | ||
*/ | ||
WipperSnapper_I2C_Driver_QMC5883P::~WipperSnapper_I2C_Driver_QMC5883P() { | ||
if (_qmc) { | ||
delete _qmc; | ||
} | ||
} | ||
|
||
/*! | ||
* @brief Initializes the QMC5883P sensor and begins I2C. | ||
* @return True if initialized successfully, False otherwise. | ||
*/ | ||
bool WipperSnapper_I2C_Driver_QMC5883P::begin() { | ||
_qmc = new Adafruit_QMC5883P(); | ||
if (!_qmc->begin(_sensorAddress, _i2c)) { | ||
return false; | ||
} | ||
|
||
// Set to continuous mode | ||
_qmc->setMode(QMC5883P_MODE_CONTINUOUS); | ||
// Set ODR (Output Data Rate) to 50Hz | ||
_qmc->setODR(QMC5883P_ODR_50HZ); | ||
// Set OSR (Over Sample Ratio) to 4 | ||
_qmc->setOSR(QMC5883P_OSR_4); | ||
// Set DSR (Downsample Ratio) to 2 | ||
_qmc->setDSR(QMC5883P_DSR_2); | ||
// Set Range to 30G | ||
_qmc->setRange(QMC5883P_RANGE_30G); | ||
// Set SetReset mode to On | ||
_qmc->setSetResetMode(QMC5883P_SETRESET_ON); | ||
|
||
return true; | ||
} | ||
|
||
/*! | ||
* @brief Get the magnetometer's sensor event. | ||
* @param magEvent | ||
* Pointer to the magnetometer sensor event. | ||
* @return True if the event was obtained successfully, False otherwise. | ||
*/ | ||
bool WipperSnapper_I2C_Driver_QMC5883P::getEventRaw(sensors_event_t *magEvent) { | ||
if (!_qmc->isDataReady()) { | ||
return false; | ||
} | ||
|
||
int16_t x, y, z; | ||
float gx, gy, gz; | ||
|
||
// Get raw magnetic data | ||
if (!_qmc->getRawMagnetic(&x, &y, &z)) { | ||
WS_DEBUG_PRINTLN("Failed to read raw magnetic data"); | ||
return false; | ||
} | ||
|
||
// Get Gauss field data | ||
if (!_qmc->getGaussField(&gx, &gy, &gz)) { | ||
WS_DEBUG_PRINTLN("Failed to read Gauss field data"); | ||
WS_DEBUG_PRINT("Raw X: "); | ||
WS_DEBUG_PRINTLN(x); | ||
WS_DEBUG_PRINT("Raw Y: "); | ||
WS_DEBUG_PRINTLN(y); | ||
WS_DEBUG_PRINT("Raw Z: "); | ||
WS_DEBUG_PRINTLN(z); | ||
return false; | ||
} else { | ||
WS_DEBUG_PRINT("Gauss X: "); | ||
WS_DEBUG_PRINTLN(gx); | ||
WS_DEBUG_PRINT("Gauss Y: "); | ||
WS_DEBUG_PRINTLN(gy); | ||
WS_DEBUG_PRINT("Gauss Z: "); | ||
WS_DEBUG_PRINTLN(gz); | ||
} | ||
|
||
// Check for overflow | ||
if (_qmc->isOverflow()) { | ||
WS_DEBUG_PRINTLN("QMC5883P data overflow - skipping reading"); | ||
return false; | ||
} | ||
|
||
// Calculate magnitude in Gauss | ||
tyeth marked this conversation as resolved.
Show resolved
Hide resolved
|
||
float magnitude_G = sqrtf(gx * gx + gy * gy + gz * gz); | ||
magEvent->data[0] = magnitude_G; | ||
return true; | ||
} |
33 changes: 33 additions & 0 deletions
33
src/components/i2c/drivers/WipperSnapper_I2C_Driver_QMC5883P.h
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/*! | ||
* @file WipperSnapper_I2C_Driver_QMC5883P.h | ||
* | ||
* Driver wrapper for the Adafruit QMC5883P 3-axis magnetometer. | ||
* | ||
* Publishes magnetic field magnitude in Gauss as SENSOR_TYPE_MAGNETIC_FIELD. | ||
*/ | ||
#ifndef WipperSnapper_I2C_Driver_QMC5883P_H | ||
#define WipperSnapper_I2C_Driver_QMC5883P_H | ||
|
||
#include "WipperSnapper_I2C_Driver.h" | ||
#include "Wippersnapper.h" | ||
|
||
class Adafruit_QMC5883P; // forward | ||
|
||
/**************************************************************************/ | ||
/*! | ||
@brief Class that provides a driver interface for a QMC5883P sensor. | ||
*/ | ||
/**************************************************************************/ | ||
class WipperSnapper_I2C_Driver_QMC5883P : public WipperSnapper_I2C_Driver { | ||
public: | ||
WipperSnapper_I2C_Driver_QMC5883P(TwoWire *i2c, uint16_t sensorAddress); | ||
~WipperSnapper_I2C_Driver_QMC5883P(); | ||
|
||
bool begin(); | ||
bool getEventRaw(sensors_event_t *magEvent); | ||
|
||
private: | ||
Adafruit_QMC5883P *_qmc = nullptr; ///< Pointer to the QMC5883P sensor object | ||
}; | ||
|
||
#endif // WipperSnapper_I2C_Driver_QMC5883P_H |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.