@@ -65,14 +65,14 @@ bool drvQmc5883p::begin() {
65
65
66
66
/* ******************************************************************************/
67
67
/* !
68
- @brief Gets the QMC5883P's magnetometer sensor event.
69
- @param magEvent
68
+ @brief Gets the QMC5883P's magnetometer sensor event as raw magnitude .
69
+ @param rawEvent
70
70
Pointer to the magnetometer sensor event.
71
71
@returns True if the sensor event was obtained successfully, False
72
72
otherwise.
73
73
*/
74
74
/* ******************************************************************************/
75
- bool drvQmc5883p::getEventRaw (sensors_event_t *magEvent ) {
75
+ bool drvQmc5883p::getEventRaw (sensors_event_t *rawEvent ) {
76
76
// Check if data is ready before reading
77
77
if (!_qmc->isDataReady ()) {
78
78
return false ;
@@ -90,20 +90,7 @@ bool drvQmc5883p::getEventRaw(sensors_event_t *magEvent) {
90
90
// Get Gauss field data
91
91
if (!_qmc->getGaussField (&gx, &gy, &gz)) {
92
92
WS_DEBUG_PRINTLN (" Failed to read Gauss field data" );
93
- WS_DEBUG_PRINT (" Raw X: " );
94
- WS_DEBUG_PRINTLN (x);
95
- WS_DEBUG_PRINT (" Raw Y: " );
96
- WS_DEBUG_PRINTLN (y);
97
- WS_DEBUG_PRINT (" Raw Z: " );
98
- WS_DEBUG_PRINTLN (z);
99
93
return false ;
100
- } else {
101
- WS_DEBUG_PRINT (" Gauss X: " );
102
- WS_DEBUG_PRINTLN (gx);
103
- WS_DEBUG_PRINT (" Gauss Y: " );
104
- WS_DEBUG_PRINTLN (gy);
105
- WS_DEBUG_PRINT (" Gauss Z: " );
106
- WS_DEBUG_PRINTLN (gz);
107
94
}
108
95
109
96
// Check for overflow
@@ -114,12 +101,56 @@ bool drvQmc5883p::getEventRaw(sensors_event_t *magEvent) {
114
101
115
102
// Calculate magnitude in Gauss
116
103
float magnitude_G = sqrtf (gx * gx + gy * gy + gz * gz);
117
- magEvent->data [0 ] = magnitude_G;
104
+ rawEvent->data [0 ] = magnitude_G;
105
+ return true ;
106
+ }
107
+
108
+ /* ******************************************************************************/
109
+ /* !
110
+ @brief Gets the QMC5883P's magnetic field vector.
111
+ @param magneticEvent
112
+ Pointer to the magnetic field sensor event.
113
+ @returns True if the sensor event was obtained successfully, False
114
+ otherwise.
115
+ */
116
+ /* ******************************************************************************/
117
+ bool drvQmc5883p::getEventMagneticField (sensors_event_t *magneticEvent) {
118
+ // Check if data is ready before reading
119
+ if (!_qmc->isDataReady ()) {
120
+ return false ;
121
+ }
122
+
123
+ int16_t x, y, z;
124
+ float gx, gy, gz;
125
+
126
+ // Get raw magnetic data
127
+ if (!_qmc->getRawMagnetic (&x, &y, &z)) {
128
+ WS_DEBUG_PRINTLN (" Failed to read raw magnetic data" );
129
+ return false ;
130
+ }
131
+
132
+ // Get Gauss field data
133
+ if (!_qmc->getGaussField (&gx, &gy, &gz)) {
134
+ WS_DEBUG_PRINTLN (" Failed to read Gauss field data" );
135
+ return false ;
136
+ }
137
+
138
+ // Check for overflow
139
+ if (_qmc->isOverflow ()) {
140
+ WS_DEBUG_PRINTLN (" QMC5883P data overflow - skipping reading" );
141
+ return false ;
142
+ }
143
+
144
+ // Convert from Gauss to microTesla (1 Gauss = 100 microTesla)
145
+ magneticEvent->magnetic .x = gx * 100 .0f ;
146
+ magneticEvent->magnetic .y = gy * 100 .0f ;
147
+ magneticEvent->magnetic .z = gz * 100 .0f ;
148
+
118
149
return true ;
119
150
}
120
151
121
152
void drvQmc5883p::ConfigureDefaultSensorTypes () {
122
153
_default_sensor_types_count = 1 ;
123
154
_default_sensor_types[0 ] =
124
- wippersnapper_sensor_SensorType_SENSOR_TYPE_RAW ;
155
+ wippersnapper_sensor_SensorType_SENSOR_TYPE_MAGNETIC_FIELD ;
125
156
}
0 commit comments