-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
63e98f7
commit 6005bf9
Showing
7 changed files
with
98 additions
and
135 deletions.
There are no files selected for viewing
This file contains 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 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 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 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 |
---|---|---|
@@ -1,36 +1,27 @@ | ||
#include "sensors.h" | ||
#include <Adafruit_LIS3MDL.h> | ||
|
||
#include "sensors.h" | ||
#include "hal.h" | ||
|
||
Adafruit_LIS3MDL LIS3MDL; // global static instance of the sensor | ||
|
||
/** | ||
* @brief Initializes the magnetometer sensor | ||
* | ||
* @return Error Code | ||
*/ | ||
ErrorCode MagnetometerSensor::init() { | ||
if (!LIS3MDL.begin_SPI(LIS3MDL_CS)) { //Checks if sensor is connected | ||
if (!LIS3MDL.begin_SPI(LIS3MDL_CS)) { // Checks if sensor is connected | ||
return ErrorCode::MagnetometerCouldNotBeInitialized; | ||
} | ||
LIS3MDL.setOperationMode(LIS3MDL_CONTINUOUSMODE);//reading continously | ||
LIS3MDL.setDataRate(LIS3MDL_DATARATE_155_HZ);//sets datarate to 155hz | ||
LIS3MDL.setRange(LIS3MDL_RANGE_4_GAUSS);//earth is 1/2 gauss, can detect high current | ||
LIS3MDL.setOperationMode(LIS3MDL_CONTINUOUSMODE); // Reading continuously, instead of single-shot or off | ||
LIS3MDL.setDataRate(LIS3MDL_DATARATE_155_HZ); | ||
LIS3MDL.setRange(LIS3MDL_RANGE_4_GAUSS); // Earth's magnetic field is 1/2 gauss, can detect high current | ||
return ErrorCode::NoError; | ||
} | ||
|
||
/** | ||
* @brief Reads and returns the data from the sensor | ||
* | ||
* @return a magnetometer packet with current flux in all three axes | ||
*/ | ||
Magnetometer MagnetometerSensor::read() { | ||
// read from aforementioned global instance of sensor | ||
LIS3MDL.read(); | ||
|
||
float mx = LIS3MDL.x_gauss; | ||
float my = LIS3MDL.y_gauss; | ||
float mz = LIS3MDL.z_gauss; | ||
Magnetometer reading {mx, my, mz}; | ||
Magnetometer reading{mx, my, mz}; | ||
return reading; | ||
} |
This file contains 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 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
Oops, something went wrong.