18
18
19
19
#include " Adafruit_MLX90395.h"
20
20
21
- Adafruit_MLX90395::Adafruit_MLX90395 (void ) {
22
- }
21
+ Adafruit_MLX90395::Adafruit_MLX90395 (void ) {}
23
22
24
23
/* !
25
24
* @brief Sets up the hardware and initializes I2C
@@ -63,16 +62,14 @@ bool Adafruit_MLX90395::_init(void) {
63
62
64
63
_resolution = getResolution ();
65
64
66
- if (! readRegister (0x26 , &uniqueID[0 ]) ||
67
- ! readRegister (0x27 , &uniqueID[1 ]) ||
68
- ! readRegister (0x28 , &uniqueID[2 ])) {
65
+ if (!readRegister (0x26 , &uniqueID[0 ]) || !readRegister (0x27 , &uniqueID[1 ]) ||
66
+ !readRegister (0x28 , &uniqueID[2 ])) {
69
67
return false ;
70
68
}
71
69
72
70
return true ;
73
71
}
74
72
75
-
76
73
/* *
77
74
* Performs a single X/Y/Z conversion and returns the results.
78
75
*
@@ -85,13 +82,12 @@ bool Adafruit_MLX90395::_init(void) {
85
82
bool Adafruit_MLX90395::readData (float *x, float *y, float *z) {
86
83
if (!startSingleMeasurement ())
87
84
return false ;
88
- while (! readMeasurement (x, y, z))
85
+ while (!readMeasurement (x, y, z))
89
86
delay (1 );
90
87
91
88
return true ;
92
89
}
93
90
94
-
95
91
/* *
96
92
* Reads data from data register & returns the results.
97
93
*
@@ -103,7 +99,7 @@ bool Adafruit_MLX90395::readData(float *x, float *y, float *z) {
103
99
*/
104
100
bool Adafruit_MLX90395::readMeasurement (float *x, float *y, float *z) {
105
101
uint8_t tx[1 ] = {0x80 }; // Read memory command
106
- uint8_t rx[12 ] = {0 }; // status, crc, X16, Y16, Z16, T16, V16
102
+ uint8_t rx[12 ] = {0 }; // status, crc, X16, Y16, Z16, T16, V16
107
103
108
104
/* Perform the transaction. */
109
105
if (i2c_dev) {
@@ -113,7 +109,7 @@ bool Adafruit_MLX90395::readMeasurement(float *x, float *y, float *z) {
113
109
}
114
110
115
111
// check status
116
- Serial.print (" Status: " ); Serial.println (rx[0 ], HEX);
112
+ // Serial.print("Status: "); Serial.println(rx[0], HEX);
117
113
if (rx[0 ] != MLX90395_STATUS_DRDY) {
118
114
return false ;
119
115
}
@@ -137,8 +133,6 @@ bool Adafruit_MLX90395::readMeasurement(float *x, float *y, float *z) {
137
133
return true ;
138
134
}
139
135
140
-
141
-
142
136
/* *
143
137
* Perform a soft reset
144
138
* @return True if the operation succeeded, otherwise false.
@@ -158,7 +152,6 @@ bool Adafruit_MLX90395::exitMode(void) {
158
152
return command (MLX90395_REG_EX) == 0 ;
159
153
}
160
154
161
-
162
155
/* *
163
156
* Begin a single measurement on all axes
164
157
*
@@ -168,59 +161,86 @@ bool Adafruit_MLX90395::startSingleMeasurement(void) {
168
161
return (command (MLX90395_REG_SM | 0x0F ) == MLX90395_STATUS_SMMODE);
169
162
}
170
163
171
-
164
+ /* *
165
+ * Get the current oversampling setting
166
+ * @return MLX90395_OSR_1, MLX90395_OSR_2, MLX90395_OSR_4, or MLX90395_OSR_8
167
+ */
172
168
mlx90393_osr_t Adafruit_MLX90395::getOSR (void ) {
173
169
Adafruit_BusIO_Register reg2 =
174
- Adafruit_BusIO_Register (i2c_dev, MLX90395_REG_2, 2 , MSBFIRST);
170
+ Adafruit_BusIO_Register (i2c_dev, MLX90395_REG_2, 2 , MSBFIRST);
175
171
Adafruit_BusIO_RegisterBits osr_bits =
176
172
Adafruit_BusIO_RegisterBits (®2, 2 , 0 );
177
173
return (mlx90393_osr_t )osr_bits.read ();
178
174
}
179
175
176
+ /* *
177
+ * Set the current oversampling setting
178
+ * @param osrval MLX90395_OSR_1, MLX90395_OSR_2, MLX90395_OSR_4,
179
+ * or MLX90395_OSR_8
180
+ * @return True on command success
181
+ */
180
182
bool Adafruit_MLX90395::setOSR (mlx90393_osr_t osrval) {
181
183
Adafruit_BusIO_Register reg2 =
182
- Adafruit_BusIO_Register (i2c_dev, MLX90395_REG_2, 2 , MSBFIRST);
184
+ Adafruit_BusIO_Register (i2c_dev, MLX90395_REG_2, 2 , MSBFIRST);
183
185
Adafruit_BusIO_RegisterBits osr_bits =
184
186
Adafruit_BusIO_RegisterBits (®2, 2 , 0 );
185
187
return osr_bits.write (osrval);
186
188
}
187
189
188
-
189
-
190
+ /* *
191
+ * Get the current gainsel value, see DS 18.6. Sensitivity for values
192
+ * @return 0-15 gain selection offset
193
+ */
190
194
uint8_t Adafruit_MLX90395::getGain (void ) {
191
195
Adafruit_BusIO_Register reg0 =
192
- Adafruit_BusIO_Register (i2c_dev, MLX90395_REG_0, 2 , MSBFIRST);
196
+ Adafruit_BusIO_Register (i2c_dev, MLX90395_REG_0, 2 , MSBFIRST);
193
197
Adafruit_BusIO_RegisterBits gain_bits =
194
- Adafruit_BusIO_RegisterBits (®0, 4 , 4 );
198
+ Adafruit_BusIO_RegisterBits (®0, 4 , 4 );
195
199
return gain_bits.read ();
196
200
}
197
201
202
+ /* *
203
+ * Get the current gainsel value, see DS 18.6. Sensitivity for values
204
+ * @param gainval 0-15 gain selection offset
205
+ * @return True on command success
206
+ */
198
207
bool Adafruit_MLX90395::setGain (uint8_t gainval) {
199
208
gainval &= 0xF ;
200
209
_gain = gainval; // cache it
201
210
202
211
Adafruit_BusIO_Register reg0 =
203
- Adafruit_BusIO_Register (i2c_dev, MLX90395_REG_0, 2 , MSBFIRST);
212
+ Adafruit_BusIO_Register (i2c_dev, MLX90395_REG_0, 2 , MSBFIRST);
204
213
Adafruit_BusIO_RegisterBits gain_bits =
205
- Adafruit_BusIO_RegisterBits (®0, 4 , 4 );
214
+ Adafruit_BusIO_RegisterBits (®0, 4 , 4 );
206
215
return gain_bits.write (gainval);
207
216
}
208
217
209
-
210
-
218
+ /* *
219
+ * Get the resolution, note that its till 16 bits just offset within the 19
220
+ * bit ADC output.
221
+ * @return MLX90395_RES_16, MLX90395_RES_17, MLX90395_RES_18 or
222
+ * MLX90395_RES_19
223
+ */
211
224
mlx90393_res_t Adafruit_MLX90395::getResolution (void ) {
212
225
Adafruit_BusIO_Register reg2 =
213
- Adafruit_BusIO_Register (i2c_dev, MLX90395_REG_2, 2 , MSBFIRST);
226
+ Adafruit_BusIO_Register (i2c_dev, MLX90395_REG_2, 2 , MSBFIRST);
214
227
Adafruit_BusIO_RegisterBits resX_bits =
215
228
Adafruit_BusIO_RegisterBits (®2, 2 , 5 );
216
229
return (mlx90393_res_t )resX_bits.read ();
217
230
}
218
231
232
+ /* *
233
+ * Set the resolution, note that its till 16 bits just offset within the 19
234
+ * bit ADC output.
235
+ * @param resval MLX90395_RES_16, MLX90395_RES_17, MLX90395_RES_18 or
236
+ * MLX90395_RES_19
237
+ * @return True on command success
238
+ */
219
239
bool Adafruit_MLX90395::setResolution (mlx90393_res_t resval) {
220
240
_resolution = resval; // cache it
221
241
222
242
Adafruit_BusIO_Register reg2 =
223
- Adafruit_BusIO_Register (i2c_dev, MLX90395_REG_2, 2 , MSBFIRST);
243
+ Adafruit_BusIO_Register (i2c_dev, MLX90395_REG_2, 2 , MSBFIRST);
224
244
Adafruit_BusIO_RegisterBits resX_bits =
225
245
Adafruit_BusIO_RegisterBits (®2, 2 , 5 );
226
246
resX_bits.write (resval);
@@ -234,15 +254,14 @@ bool Adafruit_MLX90395::setResolution(mlx90393_res_t resval) {
234
254
235
255
/* ***************************************************************/
236
256
237
-
238
257
uint8_t Adafruit_MLX90395::command (uint8_t cmd) {
239
258
uint8_t tx[2 ] = {0x80 , cmd};
240
259
uint8_t status = 0xFF ;
241
260
242
261
/* Perform the transaction. */
243
262
if (i2c_dev) {
244
263
if (!i2c_dev->write_then_read (tx, 2 , &status, 1 )) {
245
- Serial.println (" Failed command" );
264
+ // Serial.println("Failed command");
246
265
return 0xFF ;
247
266
}
248
267
}
@@ -253,15 +272,13 @@ bool Adafruit_MLX90395::readRegister(uint8_t reg, uint16_t *data) {
253
272
/* Perform the transaction. */
254
273
if (i2c_dev) {
255
274
Adafruit_BusIO_Register regis =
256
- Adafruit_BusIO_Register (i2c_dev, reg << 1 , 2 );
275
+ Adafruit_BusIO_Register (i2c_dev, reg << 1 , 2 );
257
276
*data = regis.read ();
258
277
}
259
278
260
279
return true ;
261
280
}
262
281
263
-
264
-
265
282
/* *************************************************************************/
266
283
/* !
267
284
@brief Gets the sensor_t device data, Adafruit Unified Sensor format
@@ -282,11 +299,9 @@ void Adafruit_MLX90395::getSensor(sensor_t *sensor) {
282
299
sensor->min_delay = 0 ;
283
300
sensor->min_value = -120000 ; // -120 gauss in uTesla
284
301
sensor->max_value = 120000 ; // +120 gauss in uTesla
285
- sensor->resolution = _uTLSB; // 240/16-bit uTesla per LSB
302
+ sensor->resolution = _uTLSB; // 240/16-bit uTesla per LSB
286
303
}
287
304
288
-
289
-
290
305
/* *************************************************************************/
291
306
/* !
292
307
@brief Gets the most recent sensor event, Adafruit Unified Sensor format
0 commit comments