Repository navigation
Expand file tree
/
Copy pathLSM303DLHC.cpp
More file actions
2149 lines (1925 loc) · 69.7 KB
/
Copy pathLSM303DLHC.cpp
File metadata and controls
2149 lines (1925 loc) · 69.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// I2Cdev library collection - LSM303DLHC I2C device class
// Based on ST LSM303DLHC datasheet, REV 2, 11/2013
// [current release date] by Nate Costello <natecostello at gmail dot com>
// Updates should (hopefully) always be available at https://github.com/jrowberg/i2cdevlib
//
// Changelog:
// 2015-03-10 - initial release
/* ============================================
I2Cdev device library code is placed under the MIT license
Copyright (c) 2011 [Author Name], Jeff Rowberg
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
===============================================
*/
#include "LSM303DLHC.h"
/** Default constructor, uses default I2C address.
* @see LSM303DLHC_DEFAULT_ADDRESS_A
* @see LSM303DLHC_DEFAULT_ADDRESS_M
*/
LSM303DLHC::LSM303DLHC() {
devAddrA = LSM303DLHC_DEFAULT_ADDRESS_A;
devAddrM = LSM303DLHC_DEFAULT_ADDRESS_M;
endianMode = 0;
}
/** Specific address constructor.
@param addressA I2C accelerometer address
@param addressM I2C magnetometer address
@see LSM303DLHC_DEFAULT_ADDRESS_A
@see LSM303DLHC_DEFAULT_ADDRESS_M
@see LSM303DLHC_ADDRESS_A
@see LSM303DLHC_ADDRESS_M
*/
LSM303DLHC::LSM303DLHC(uint8_t addressA, uint8_t addressM) {
devAddrA = addressA;
devAddrM = addressM;
endianMode = 0;
}
/** Power on and prepare for general usage.
All values are defaults except for the data rates for the accelerometer and
magnetometer data rates (200hz and 220hz respectively).
@see LSM303DLHC_RA_CTRL_REG1_A
@see LSM303DLHC_RA_CRA_REG_M
*/
void LSM303DLHC::initialize() {
I2Cdev::writeByte(devAddrA, LSM303DLHC_RA_CTRL_REG1_A, 0b01100111);
I2Cdev::writeByte(devAddrM, LSM303DLHC_RA_CRA_REG_M, 0b00011100);
// ----------------------------------------------------------------------------
// STUB TODO:
// Perform any important initialization here. Maybe nothing is required, but
// the method should exist anyway.
// ----------------------------------------------------------------------------
}
/** Verify the I2C connection.
Make sure the device is connected and responds as expected. This device has no
device ID or WHO_AM_I register. To test the connection, bits are written to control
register, checked, and then the original contents are written back.
* @return True if connection is valid, false otherwise
*/
bool LSM303DLHC::testConnection() {
I2Cdev::readByte(devAddrA, LSM303DLHC_RA_CTRL_REG1_A, buffer);
uint8_t origValA = buffer[0];
I2Cdev::readByte(devAddrM, LSM303DLHC_RA_CRA_REG_M, buffer);
uint8_t origValM = buffer[0];
uint8_t zeros = 0b00000000;
I2Cdev::writeByte(devAddrA, LSM303DLHC_RA_CTRL_REG1_A, zeros);
I2Cdev::writeByte(devAddrM, LSM303DLHC_RA_CRA_REG_M, zeros);
I2Cdev::readByte(devAddrA, LSM303DLHC_RA_CTRL_REG1_A, buffer);
uint8_t newValA = buffer[0];
I2Cdev::readByte(devAddrM, LSM303DLHC_RA_CRA_REG_M, buffer);
uint8_t newValM = buffer[0];
I2Cdev::writeByte(devAddrA, LSM303DLHC_RA_CTRL_REG1_A, origValA);
I2Cdev::writeByte(devAddrM, LSM303DLHC_RA_CRA_REG_M, origValM);
if ((newValM == zeros) and (newValA == zeros)) {
return true;
}
return false;
}
// ----------------------------------------------------------------------------
// STUB TODO:
// Define methods to fully cover all available functionality provided by the
// device, according to the datasheet and/or register map. Unless there is very
// clear reason not to, try to follow the get/set naming convention for all
// values, for instance:
// - uint8_t getThreshold()
// - void setThreshold(uint8_t threshold)
// - uint8_t getRate()
// - void setRate(uint8_t rate)
//
// Some methods may be named differently if it makes sense. As long as all
// functionality is covered, that's the important part. The methods here are
// only examples and should not be kept for your real device.
// ----------------------------------------------------------------------------
//CTRL_REG1_A, r/w
/** Set the output data rate
* @param rate The new data output rate (can be 1, 10, 25, 50, 100, 200, 400, 1620, 1344, or 5376)
* @see LSM303DLHC_RA_CTRL_REG1_A
* @see LSM303DLHC_ODR_BIT
* @see LSM303DLHC_ODR_LENGTH
* @see LSM303DLHC_RATE_1
* @see LSM303DLHC_RATE_10
* @see LSM303DLHC_RATE_25
* @see LSM303DLHC_RATE_50
* @see LSM303DLHC_RATE_100
* @see LSM303DLHC_RATE_200
* @see LSM303DLHC_RATE_400
* @see LSM303DLHC_RATE_1620_LP
* @see LSM303DLHC_RATE_1344_N_5376_LP
*/
void LSM303DLHC::setAccelOutputDataRate(uint16_t rate) {
uint8_t writeVal;
if (rate == 0) {
writeVal = LSM303DLHC_ODR_RATE_POWERDOWN;
} else if (rate == 1) {
writeVal = LSM303DLHC_ODR_RATE_1;
} else if (rate == 10) {
writeVal = LSM303DLHC_ODR_RATE_10;
} else if (rate == 25) {
writeVal = LSM303DLHC_ODR_RATE_25;
} else if (rate == 50) {
writeVal = LSM303DLHC_ODR_RATE_50;
} else if (rate == 100) {
writeVal = LSM303DLHC_ODR_RATE_100;
} else if (rate == 200) {
writeVal = LSM303DLHC_ODR_RATE_200;
} else if (rate == 400) {
writeVal = LSM303DLHC_ODR_RATE_400;
} else if (rate == 1620) {
writeVal = LSM303DLHC_ODR_RATE_1620_LP;
} else if (rate == 1344) {
writeVal = LSM303DLHC_ODR_RATE_1344_N_5376_LP;
} else if (rate == 5376) {
writeVal = LSM303DLHC_ODR_RATE_1344_N_5376_LP;
}
I2Cdev::writeBits(devAddrA, LSM303DLHC_RA_CTRL_REG1_A, LSM303DLHC_ODR_BIT,
LSM303DLHC_ODR_LENGTH, writeVal);
}
/** Get the output data rate
* @return The current data output rate (can be 1, 10, 25, 50, 100, 200, 400, 1620, or 1344 (implies 5376))
* @see LSM303DLHC_RA_CTRL_REG1_A
* @see LSM303DLHC_ODR_BIT
* @see LSM303DLHC_ODR_LENGTH
* @see LSM303DLHC_RATE_1
* @see LSM303DLHC_RATE_10
* @see LSM303DLHC_RATE_25
* @see LSM303DLHC_RATE_50
* @see LSM303DLHC_RATE_100
* @see LSM303DLHC_RATE_200
* @see LSM303DLHC_RATE_400
* @see LSM303DLHC_RATE_1620_LP
* @see LSM303DLHC_RATE_1344_N_5376_LP
*/
uint16_t LSM303DLHC::getAccelOutputDataRate() {
I2Cdev::readBits(devAddrA, LSM303DLHC_RA_CTRL_REG1_A, LSM303DLHC_ODR_BIT,
LSM303DLHC_ODR_LENGTH, buffer);
uint8_t rate = buffer[0];
if (rate == LSM303DLHC_ODR_RATE_POWERDOWN) {
return 0;
} else if (rate == LSM303DLHC_ODR_RATE_1) {
return 1;
} else if (rate == LSM303DLHC_ODR_RATE_10) {
return 10;
} else if (rate == LSM303DLHC_ODR_RATE_25) {
return 25;
} else if (rate == LSM303DLHC_ODR_RATE_50) {
return 50;
} else if (rate == LSM303DLHC_ODR_RATE_100) {
return 100;
} else if (rate == LSM303DLHC_ODR_RATE_200) {
return 200;
} else if (rate == LSM303DLHC_ODR_RATE_400) {
return 400;
} else if (rate == LSM303DLHC_ODR_RATE_1620_LP) {
return 1620;
} else if (rate == LSM303DLHC_ODR_RATE_1344_N_5376_LP) {
return 1344;
} else if (rate == LSM303DLHC_ODR_RATE_1344_N_5376_LP) {
return 5376;
}
}
/*Enables or disables the accelerometer low power mode
@param enabled The new enabled state of the low power mode
@see LSM303DLHC_RA_CTRL_REG1_A
@see LSM303DLHC_LPEN_BIT
*/
void LSM303DLHC::setAccelLowPowerEnabled(bool enabled){
I2Cdev::writeBit(devAddrA, LSM303DLHC_RA_CTRL_REG1_A, LSM303DLHC_LPEN_BIT, enabled);
}
/*Get whether the accelerometer low power mode is enabled
@return True if the acceleromer low power mode is enabled
@see LSM303DLHC_RA_CTRL_REG1_A
@see LSM303DLHC_LPEN_BIT
*/
bool LSM303DLHC::getAccelLowPowerEnabled(){
I2Cdev::readBit(devAddrA, LSM303DLHC_RA_CTRL_REG1_A, LSM303DLHC_LPEN_BIT, buffer);
return buffer[0];
}
/** Enables or disables the ability to get Z data
* @param enabled The new enabled state of the Z axis
* @see LSM303DLHC_RA_CTRL_REG1_A
* @see LSM303DLHC_ZEN_BIT
*/
void LSM303DLHC::setAccelZEnabled(bool enabled) {
I2Cdev::writeBit(devAddrA, LSM303DLHC_RA_CTRL_REG1_A, LSM303DLHC_ZEN_BIT, enabled);
}
/** Get whether Z axis data is enabled
* @return True if the Z axis is enabled, false otherwise
* @see LSM303DLHC_RA_CTRL_REG1_A
* @see LSM303DLHC_ZEN_BIT
*/
bool LSM303DLHC::getAccelZEnabled() {
I2Cdev::readBit(devAddrA, LSM303DLHC_RA_CTRL_REG1_A, LSM303DLHC_ZEN_BIT, buffer);
return buffer[0];
}
/** Enables or disables the ability to get Y data
* @param enabled The new enabled state of the Y axis
* @see LSM303DLHC_RA_CTRL_REG1_A
* @see LSM303DLHC_YEN_BIT
*/
void LSM303DLHC::setAccelYEnabled(bool enabled) {
I2Cdev::writeBit(devAddrA, LSM303DLHC_RA_CTRL_REG1_A, LSM303DLHC_YEN_BIT, enabled);
}
/** Get whether Y axis data is enabled
* @return True if the Y axis is enabled, false otherwise
* @see LSM303DLHC_RA_CTRL_REG1_A
* @see LSM303DLHC_YEN_BIT
*/
bool LSM303DLHC::getAccelYEnabled() {
I2Cdev::readBit(devAddrA, LSM303DLHC_RA_CTRL_REG1_A, LSM303DLHC_YEN_BIT, buffer);
return buffer[0];
}
/** Enables or disables the ability to get X data
* @param enabled The new enabled state of the X axis
* @see LSM303DLHC_RA_CTRL_REG1_A
* @see LSM303DLHC_XEN_BIT
*/
void LSM303DLHC::setAccelXEnabled(bool enabled) {
I2Cdev::writeBit(devAddrA, LSM303DLHC_RA_CTRL_REG1_A, LSM303DLHC_XEN_BIT, enabled);
}
/** Get whether X axis data is enabled
* @return True if the X axis is enabled, false otherwise
* @see LSM303DLHC_RA_CTRL_REG1_A
* @see LSM303DLHC_XEN_BIT
*/
bool LSM303DLHC::getAccelXEnabled() {
I2Cdev::readBit(devAddrA, LSM303DLHC_RA_CTRL_REG1_A, LSM303DLHC_XEN_BIT, buffer);
return buffer[0];
}
//CTRL_REG2_A r/w
/** Set the high pass mode
* @param mode The new high pass mode
* @see LSM303DLHC_RA_CTRL_REG2
* @see LSM303DLHC_HPM_BIT
* @see LSM303DLHC_HPM_LENGTH
* @see LSM303DLHC_HPM_HRF
* @see LSM303DLHC_HPM_REFERENCE
* @see LSM303DLHC_HPM_NORMAL
* @see LSM303DLHC_HPM_AUTORESET
*/
void LSM303DLHC::setAccelHighPassMode(uint8_t mode) {
I2Cdev::writeBits(devAddrA, LSM303DLHC_RA_CTRL_REG2_A, LSM303DLHC_HPM_BIT,
LSM303DLHC_HPM_LENGTH, mode);
}
/** Get the high pass mode
* @return High pass mode
* @see LSM303DLHC_RA_CTRL_REG2_A
* @see LSM303DLHC_HPM_BIT
* @see LSM303DLHC_HPM_LENGTH
* @see LSM303DLHC_HPM_HRF
* @see LSM303DLHC_HPM_REFERENCE
* @see LSM303DLHC_HPM_NORMAL
* @see LSM303DLHC_HPM_AUTORESET
*/
uint8_t LSM303DLHC::getAccelHighPassMode() {
I2Cdev::readBits(devAddrA, LSM303DLHC_RA_CTRL_REG2_A, LSM303DLHC_HPM_BIT,
LSM303DLHC_HPM_LENGTH, buffer);
return buffer[0];
}
/** Set the high pass filter cut off frequency level (1 - 10)
* @param level The new level for the hpcf, using one of the defined levels
* @see LSM303DLHC_RA_CTRL_REG2_A
* @see LSM303DLHC_HPCF_BIT
* @see LSM303DLHC_HPCF_LENGTH
* @see LSM303DLHC_HPCF1
* @see LSM303DLHC_HPCF2
* @see LSM303DLHC_HPCF3
* @see LSM303DLHC_HPCF4
*/
void LSM303DLHC::setAccelHighPassFilterCutOffFrequencyLevel(uint8_t level) {
I2Cdev::writeBits(devAddrA, LSM303DLHC_RA_CTRL_REG2_A, LSM303DLHC_HPCF_BIT,
LSM303DLHC_HPCF_LENGTH, level);
}
/** Get the high pass filter cut off frequency level (1 - 10)
* @return High pass filter cut off frequency level
* @see LSM303DLHC_RA_CTRL_REG2_A
* @see LSM303DLHC_HPCF_BIT
* @see LSM303DLHC_HPCF_LENGTH
* @see LSM303DLHC_HPCF1
* @see LSM303DLHC_HPCF2
* @see LSM303DLHC_HPCF3
* @see LSM303DLHC_HPCF4
*/
uint8_t LSM303DLHC::getAccelHighPassFilterCutOffFrequencyLevel() {
I2Cdev::readBits(devAddrA, LSM303DLHC_RA_CTRL_REG2_A, LSM303DLHC_HPCF_BIT,
LSM303DLHC_HPCF_LENGTH, buffer);
return buffer[0];
}
//CTRL_REG3_A r/w
/*Enable the Click interrupt routed to the INT1 pin.
@param enabled The new enabled state of the Click interrupt routed to the INT1 pin
@see LSM303DLHC_RA_CTRL_REG3_A
@see LSM303DLHC_I1_CLICK_BIT
*/
void LSM303DLHC::setAccelINT1ClickEnabled(bool enabled){
I2Cdev::writeBit(devAddrA, LSM303DLHC_RA_CTRL_REG3_A, LSM303DLHC_I1_CLICK_BIT, enabled);
}
/*Get whether the Click interrupt is routed to the INT1 pin.
@return True if the Click interrupt is routed to the INT1 pin
@see LSM303DLHC_RA_CTRL_REG3_A
@see LSM303DLHC_I1_CLICK_BIT
*/
bool LSM303DLHC::getAccelINT1ClickEnabled(){
I2Cdev::readBit(devAddrA, LSM303DLHC_RA_CTRL_REG3_A, LSM303DLHC_I1_CLICK_BIT, buffer);
return buffer[0];
}
/*Enable the AOR1 interrupt routed to the INT1 pin.
@param enabled The new enabled state of the AOR1 interrupt routed to the INT1 pin
@see LSM303DLHC_RA_CTRL_REG3_A
@see LSM303DLHC_I1_AOI1_BIT
*/
void LSM303DLHC::setAccelINT1AOI1Enabled(bool enabled){
I2Cdev::writeBit(devAddrA, LSM303DLHC_RA_CTRL_REG3_A, LSM303DLHC_I1_AOI1_BIT, enabled);
}
/*Get whether the AOR1 interrupt is routed to the INT1 pin.
@return True if the AOR1 interrupt is routed to the INT1 pin
@see LSM303DLHC_RA_CTRL_REG3_A
@see LSM303DLHC_I1_AOI1_BIT
*/
bool LSM303DLHC::getAccelINT1AOI1Enabled(){
I2Cdev::readBit(devAddrA, LSM303DLHC_RA_CTRL_REG3_A, LSM303DLHC_I1_AOI1_BIT, buffer);
return buffer[0];
}
/*Enable the AOR2 interrupt routed to the INT1 pin.
@param enabled The new enabled state of the AOR2 interrupt routed to the INT1 pin
@see LSM303DLHC_RA_CTRL_REG3_A
@see LSM303DLHC_I1_AOI2_BIT
*/
void LSM303DLHC::setAccelINT1AOI2Enabled(bool enabled){
I2Cdev::writeBit(devAddrA, LSM303DLHC_RA_CTRL_REG3_A, LSM303DLHC_I1_AOI2_BIT, enabled);
}
/*Get whether the AOR2 interrupt is routed to the INT1 pin.
@return True if the AOR2 interrupt is routed to the INT1 pin
@see LSM303DLHC_RA_CTRL_REG3_A
@see LSM303DLHC_I1_AOI2_BIT
*/
bool LSM303DLHC::getAccelINT1AOI2Enabled(){
I2Cdev::readBit(devAddrA, LSM303DLHC_RA_CTRL_REG3_A, LSM303DLHC_I1_AOI2_BIT, buffer);
return buffer[0];
}
/*Enable the Data Ready 1 interrupt routed to the INT1 pin.
@param enabled The new enabled state of the Data Ready 1 interrupt routed to the INT1 pin
@see LSM303DLHC_RA_CTRL_REG3_A
@see LSM303DLHC_I1_DRDY1_BIT
*/
void LSM303DLHC::setAccelINT1DataReady1Enabled(bool enabled){
I2Cdev::writeBit(devAddrA, LSM303DLHC_RA_CTRL_REG3_A, LSM303DLHC_I1_DRDY1_BIT, enabled);
}
/*Get whether the Data Ready 1 interrupt is routed to the INT1 pin.
@return True if the Data Ready 1 interrupt is routed to the INT1 pin
@see LSM303DLHC_RA_CTRL_REG3_A
@see LSM303DLHC_I1_DRDY1_BIT
*/
bool LSM303DLHC::getAccelINT1DataReady1Enabled(){
I2Cdev::readBit(devAddrA, LSM303DLHC_RA_CTRL_REG3_A, LSM303DLHC_I1_DRDY1_BIT, buffer);
return buffer[0];
}
/*Enable the Data Ready 2 interrupt routed to the INT1 pin.
@param enabled The new enabled state of the Data Ready 2 interrupt routed to the INT1 pin
@see LSM303DLHC_RA_CTRL_REG3_A
@see LSM303DLHC_I1_DRDY2_BIT
*/
void LSM303DLHC::setAccelINT1DataReady2Enabled(bool enabled){
I2Cdev::writeBit(devAddrA, LSM303DLHC_RA_CTRL_REG3_A, LSM303DLHC_I1_DRDY2_BIT, enabled);
}
/*Get whether the Data Ready 2 interrupt is routed to the INT1 pin.
@return True if the Data Ready 2 interrupt is routed to the INT1 pin
@see LSM303DLHC_RA_CTRL_REG3_A
@see LSM303DLHC_I1_DRDY2_BIT
*/
bool LSM303DLHC::getAccelINT1DataReady2Enabled(){
I2Cdev::readBit(devAddrA, LSM303DLHC_RA_CTRL_REG3_A, LSM303DLHC_I1_DRDY2_BIT, buffer);
return buffer[0];
}
/*Enable the FIFO watermark interrupt routed to the INT1 pin.
@param enabled The new enabled state of the FIFO watermark interrupt routed to the INT1 pin
@see LSM303DLHC_RA_CTRL_REG3_A
@see LSM303DLHC_I1_WTM_BIT
*/
void LSM303DLHC::setAccelINT1FIFOWatermarkEnabled(bool enabled){
I2Cdev::writeBit(devAddrA, LSM303DLHC_RA_CTRL_REG3_A, LSM303DLHC_I1_WTM_BIT, enabled);
}
/*Get whether the FIFO watermark interrupt is routed to the INT1 pin.
@return True if the FIFO watermark interrupt is routed to the INT1 pin
@see LSM303DLHC_RA_CTRL_REG3_A
@see LSM303DLHC_I1_WTM_BIT
*/
bool LSM303DLHC::getAccelINT1FIFOWatermarkEnabled(){
I2Cdev::readBit(devAddrA, LSM303DLHC_RA_CTRL_REG3_A, LSM303DLHC_I1_WTM_BIT, buffer);
return buffer[0];
}
/*Enable the FIFO overrun interrupt routed to the INT1 pin.
@param enabled The new enabled state of the FIFO overrun interrupt routed to the INT1 pin
@see LSM303DLHC_RA_CTRL_REG3_A
@see LSM303DLHC_I1_OVERRUN_BIT
*/
void LSM303DLHC::setAccelINT1FIFOOverunEnabled(bool enabled){
I2Cdev::writeBit(devAddrA, LSM303DLHC_RA_CTRL_REG3_A, LSM303DLHC_I1_OVERRUN_BIT, enabled);
}
/*Get whether the FIFO overrun interrupt is routed to the INT1 pin.
@return True if the FIFO overrun interrupt is routed to the INT1 pin
@see LSM303DLHC_RA_CTRL_REG3_A
@see LSM303DLHC_I1_OVERRUN_BIT
*/
bool LSM303DLHC::getAccelINT1FIFOOverunEnabled(){
I2Cdev::readBit(devAddrA, LSM303DLHC_RA_CTRL_REG3_A, LSM303DLHC_I1_OVERRUN_BIT, buffer);
return buffer[0];
}
//CTRL_REG4_A r/w
/** Set the Block Data Update (BDU) enabled state
* @param enabled New BDU enabled state
* @see LSM303DLHC_RA_CTRL_REG4_A
* @see LSM303DLHC_BDU_BIT
*/
void LSM303DLHC::setAccelBlockDataUpdateEnabled(bool enabled) {
I2Cdev::writeBit(devAddrA, LSM303DLHC_RA_CTRL_REG4_A, LSM303DLHC_BDU_BIT, enabled);
}
/** Get the BDU enabled state
* @return True if Block Data Update is enabled, false otherwise
* @see LSM303DLHC_RA_CTRL_REG4_A
* @see LSM303DLHC_BDU_BIT
*/
bool LSM303DLHC::getAccelBlockDataUpdateEnabled() {
I2Cdev::readBit(devAddrA, LSM303DLHC_RA_CTRL_REG4_A, LSM303DLHC_BDU_BIT, buffer);
return buffer[0];
}
/** Set the data endian modes
* In Big Endian mode, the Most Significat Byte (MSB) is on the lower address,
* and the Least Significant Byte (LSB) is on the higher address. Little Endian
* mode reverses this order. Little Endian is the default mode.
* @param endianness New endian mode
* @see LSM303DLHC_RA_CTRL_REG4_A
* @see LSM303DLHC_BLE_BIT
* @see LSM303DLHC_BIG_ENDIAN
* @see LSM303DLHC_LITTLE_ENDIAN
*/
void LSM303DLHC::setAccelEndianMode(bool endianness) {
I2Cdev::writeBit(devAddrA, LSM303DLHC_RA_CTRL_REG4_A, LSM303DLHC_BLE_BIT,
endianness);
endianMode = getAccelEndianMode();
}
/** Get the data endian mode
* @return Current endian mode
* @see LSM303DLHC_RA_CTRL_REG4_A
* @see LSM303DLHC_BLE_BIT
* @see LSM303DLHC_BIG_ENDIAN
* @see LSM303DLHC_LITTLE_ENDIAN
*/
bool LSM303DLHC::getAccelEndianMode() {
return endianMode;
I2Cdev::readBit(devAddrA, LSM303DLHC_RA_CTRL_REG4_A, LSM303DLHC_BLE_BIT,
buffer);
return buffer[0];
}
/** Set the full scale of the data output (in dps)
* @param scale The new scale of the data output (250, 500, 2000)
* @see LSM303DLHC_RA_CTRL_REG4_A
* @see LSM303DLHC_FS_BIT
* @see LSM303DLHC_FS_LENGTH
* @see LSM303DLHC_FS_2
* @see LSM303DLHC_FS_4
* @see LSM303DLHC_FS_8
* @see LSM303DLHC_FS_16
*/
void LSM303DLHC::setAccelFullScale(uint8_t scale) {
uint8_t writeBits;
if (scale == 2) {
writeBits = LSM303DLHC_FS_2;
} else if (scale == 4) {
writeBits = LSM303DLHC_FS_4;
} else if (scale == 8) {
writeBits = LSM303DLHC_FS_8;
} else {
writeBits = LSM303DLHC_FS_16;
}
I2Cdev::writeBits(devAddrA, LSM303DLHC_RA_CTRL_REG4_A, LSM303DLHC_FS_BIT,
LSM303DLHC_FS_LENGTH, writeBits);
}
/** Get the current full scale of the output data (in dps)
* @return Current scale of the output data
* @see LSM303DLHC_RA_CTRL_REG4_A
* @see LSM303DLHC_FS_BIT
* @see LSM303DLHC_FS_LENGTH
* @see LSM303DLHC_FS_2
* @see LSM303DLHC_FS_4
* @see LSM303DLHC_FS_8
* @see LSM303DLHC_FS_16
*/
uint8_t LSM303DLHC::getAccelFullScale() {
I2Cdev::readBits(devAddrA, LSM303DLHC_RA_CTRL_REG4_A,
LSM303DLHC_FS_BIT, LSM303DLHC_FS_LENGTH, buffer);
uint8_t readBits = buffer[0];
if (readBits == LSM303DLHC_FS_2) {
return 2;
} else if (readBits == LSM303DLHC_FS_4) {
return 4;
} else if (readBits == LSM303DLHC_FS_8) {
return 8;
} else {
return 16;
}
}
/*Enables or disables high resolution output.
@param enabled New enabled state of high resolution output
@see LSM303DLHC_RA_CTRL_REG4_A
@see LSM303DLHC_HR_BIT
*/
void LSM303DLHC::setAccelHighResOutputEnabled(bool enabled){
I2Cdev::writeBit(devAddrA, LSM303DLHC_RA_CTRL_REG4_A, LSM303DLHC_HR_BIT,
enabled);
}
/*Gets whether high resolution output is enabled.
@return True if high resolution output is enabled
@see LSM303DLHC_RA_CTRL_REG4_A
@see LSM303DLHC_HR_BIT
*/
bool LSM303DLHC::getAccelHighResOutputEnabled(){
I2Cdev::readBit(devAddrA, LSM303DLHC_RA_CTRL_REG4_A, LSM303DLHC_HR_BIT,
buffer);
return buffer[0];
}
/** Set the SPI mode
* @param mode New SPI mode
* @see LSM303DLHC_RA_CTRL_REG4_A
* @see LSM303DLHC_SIM_BIT
* @see LSM303DLHC_SIM_4W
* @see LSM303DLHC_SIM_3W
*/
void LSM303DLHC::setAccelSPIMode(bool mode) {
I2Cdev::writeBit(devAddrA, LSM303DLHC_RA_CTRL_REG4_A, LSM303DLHC_SIM_BIT, mode);
}
/** Get the SPI mode
* @return Current SPI mode
* @see LSM303DLHC_RA_CTRL_REG4_A
* @see LSM303DLHC_SIM_BIT
* @see LSM303DLHC_SIM_4W
* @see LSM303DLHC_SIM_3W
*/
bool LSM303DLHC::getAccelSPIMode() {
I2Cdev::readBit(devAddrA, LSM303DLHC_RA_CTRL_REG4_A, LSM303DLHC_SIM_BIT,
buffer);
return buffer[0];
}
//CTRL_REG5_A r/w
/** Reboots the FIFO memory content
* @see LSM303DLHC_RA_CTRL_REG5_A
* @see LSM303DLHC_BOOT_BIT
*/
void LSM303DLHC::rebootAccelMemoryContent() {
I2Cdev::writeBit(devAddrA, LSM303DLHC_RA_CTRL_REG5_A, LSM303DLHC_BOOT_BIT, true);
}
/** Set whether the FIFO buffer is enabled
* @param enabled New enabled state of the FIFO buffer
* @see LSM303DLHC_RA_CTRL_REG5_A
* @see LSM303DLHC_FIFO_EN_BIT
*/
void LSM303DLHC::setAccelFIFOEnabled(bool enabled) {
I2Cdev::writeBit(devAddrA, LSM303DLHC_RA_CTRL_REG5_A, LSM303DLHC_FIFO_EN_BIT,
enabled);
}
/** Get whether the FIFO buffer is enabled
* @return True if the FIFO buffer is enabled, false otherwise
* @see LSM303DLHC_RA_CTRL_REG5_A
* @see LSM303DLHC_FIFO_EN_BIT
*/
bool LSM303DLHC::getAccelFIFOEnabled() {
I2Cdev::readBit(devAddrA, LSM303DLHC_RA_CTRL_REG5_A, LSM303DLHC_FIFO_EN_BIT,
buffer);
return buffer[0];
}
/*Enable latching of interrupt requrest 1
@param latched New enabled state of latching interrupt request 1
@see LSM303DLHC_RA_CTRL_REG5_A
@see LSM303DLHC_LIR_INT1_BIT
*/
void LSM303DLHC::setAccelInterrupt1RequestLatched(bool latched){
I2Cdev::writeBit(devAddrA, LSM303DLHC_RA_CTRL_REG5_A, LSM303DLHC_LIR_INT1_BIT,
latched);
}
/*Get whether latching of interrupt request 1 is enabled.
@return True if latching of interrupt request 1 is enabled
@see LSM303DLHC_RA_CTRL_REG5_A
@see LSM303DLHC_LIR_INT1_BIT
*/
bool LSM303DLHC::getAccelInterrupt1RequestLatched(){
I2Cdev::readBit(devAddrA, LSM303DLHC_RA_CTRL_REG5_A, LSM303DLHC_LIR_INT1_BIT,
buffer);
return buffer[0];
}
/*Enable latching of interrupt requrest 2
@param latched New enabled state of latching interrupt request 2
@see LSM303DLHC_RA_CTRL_REG5_A
@see LSM303DLHC_LIR_INT2_BIT
*/
void LSM303DLHC::setAccelInterrupt2RequestLatched(bool latched){
I2Cdev::writeBit(devAddrA, LSM303DLHC_RA_CTRL_REG5_A, LSM303DLHC_LIR_INT2_BIT,
latched);
}
/*Get whether latching of interrupt request 2 is enabled.
@return True if latching of interrupt request 2 is enabled
@see LSM303DLHC_RA_CTRL_REG5_A
@see LSM303DLHC_LIR_INT2_BIT
*/
bool LSM303DLHC::getAccelInterrupt2RequestLatched(){
I2Cdev::readBit(devAddrA, LSM303DLHC_RA_CTRL_REG5_A, LSM303DLHC_LIR_INT2_BIT,
buffer);
return buffer[0];
}
/*Enable 4D dectection interrupt 1
@param enabled New enabled state of the 4D detection interrupt 1
@see LSM303DLHC_RA_CTRL_REG5_A
@see LSM303DLHC_D4D_INT1_BIT
*/
void LSM303DLHC::setAccelDetect4DInterrupt1Enabled(bool enabled){
I2Cdev::writeBit(devAddrA, LSM303DLHC_RA_CTRL_REG5_A, LSM303DLHC_D4D_INT1_BIT,
enabled);
}
/*Get whether 4D detection interrupt 1 is enabled.
@return True if 4D detection interrupt 1 is enabled
@see LSM303DLHC_RA_CTRL_REG5_A
@see LSM303DLHC_D4D_INT1_BIT
*/
bool LSM303DLHC::getAccelDetect4DInterrupt1Enabled(){
I2Cdev::readBit(devAddrA, LSM303DLHC_RA_CTRL_REG5_A, LSM303DLHC_D4D_INT1_BIT,
buffer);
return buffer[0];
}
/*Enable 4D dectection interrupt 2
@param enabled New enabled state of the 4D detection interrupt 2
@see LSM303DLHC_RA_CTRL_REG5_A
@see LSM303DLHC_D4D_INT2_BIT
*/
void LSM303DLHC::setAccelDetect4DInterrupt2Enabled(bool enabled){
I2Cdev::writeBit(devAddrA, LSM303DLHC_RA_CTRL_REG5_A, LSM303DLHC_D4D_INT2_BIT,
enabled);
}
/*Get whether 4D detection interrupt 2 is enabled.
@return True if 4D detection interrupt 2 is enabled
@see LSM303DLHC_RA_CTRL_REG5_A
@see LSM303DLHC_D4D_INT2_BIT
*/
bool LSM303DLHC::getAccelDetect4DInterrupt2Enabled(){
I2Cdev::readBit(devAddrA, LSM303DLHC_RA_CTRL_REG5_A, LSM303DLHC_D4D_INT2_BIT,
buffer);
return buffer[0];
}
//CTRL_REG6_A r/w
//TODO:
/*Enable the Click interrupt routed to the INT2 pin.
@param enabled The new enabled state of the Click interrupt routed to the INT2 pin
@see LSM303DLHC_RA_CTRL_REG6_A
@see LSM303DLHC_I2_CLICK_BIT
*/
void LSM303DLHC::setAccelINT2ClickEnabled(bool enabled){
I2Cdev::writeBit(devAddrA, LSM303DLHC_RA_CTRL_REG6_A, LSM303DLHC_I2_CLICK_BIT, enabled);
}
/*Get whether the Click interrupt is routed to the INT2 pin.
@return True if the Click interrupt is routed to the INT2 pin
@see LSM303DLHC_RA_CTRL_REG6_A
@see LSM303DLHC_I2_CLICK_BIT
*/
bool LSM303DLHC::getAccelINT2ClickEnabled(){
I2Cdev::readBit(devAddrA, LSM303DLHC_RA_CTRL_REG6_A, LSM303DLHC_I2_CLICK_BIT, buffer);
return buffer[0];
}
/*Enable interrupt 1 routed to the INT2 pin.
@param enabled The new enabled state of whether interrupt 1 routed to the INT2 pin
@see LSM303DLHC_RA_CTRL_REG6_A
@see LSM303DLHC_I2_INT1_BIT
*/
void LSM303DLHC::setAccelINT2Interrupt1Enabled(bool enabled){
I2Cdev::writeBit(devAddrA, LSM303DLHC_RA_CTRL_REG6_A, LSM303DLHC_I2_INT1_BIT, enabled);
}
/*Get whether interrupt 1 is routed to the INT2 pin.
@return True if interrupt 1 is routed to the INT2 pin
@see LSM303DLHC_RA_CTRL_REG6_A
@see LSM303DLHC_I2_INT1_BIT
*/
bool LSM303DLHC::getAccelINT2Interrupt1Enabled(){
I2Cdev::readBit(devAddrA, LSM303DLHC_RA_CTRL_REG6_A, LSM303DLHC_I2_INT1_BIT, buffer);
return buffer[0];
}
/*Enable interrupt 2 routed to the INT2 pin.
@param enabled The new enabled state of whether interrupt 2 routed to the INT2 pin
@see LSM303DLHC_RA_CTRL_REG6_A
@see LSM303DLHC_I2_INT2_BIT
*/
void LSM303DLHC::setAccelINT2Interrupt2Enabled(bool enabled){
I2Cdev::writeBit(devAddrA, LSM303DLHC_RA_CTRL_REG6_A, LSM303DLHC_I2_INT2_BIT, enabled);
}
/*Get whether interrupt 2 is routed to the INT2 pin.
@return True if interrupt 2 is routed to the INT2 pin
@see LSM303DLHC_RA_CTRL_REG6_A
@see LSM303DLHC_I2_INT2_BIT
*/
bool LSM303DLHC::getAccelINT2Interrupt2Enabled(){
I2Cdev::readBit(devAddrA, LSM303DLHC_RA_CTRL_REG6_A, LSM303DLHC_I2_INT2_BIT, buffer);
return buffer[0];
}
/*Enable memory content reboot via INT2 pin
@param enabled The new state of whether memory content is rebooted via INT2 pin
@see LSM303DLHC_RA_CTRL_REG6_A
@see LSM303DLHC_BOOT_I1_BIT
*/
void LSM303DLHC::setAccelRebootMemoryContentINT2Enabled(bool enabled){
I2Cdev::writeBit(devAddrA, LSM303DLHC_RA_CTRL_REG6_A, LSM303DLHC_BOOT_I1_BIT, enabled);
}
/*Get whether memory content reboot is enabled via INT2 pin
@return True if memory content reboot is via INT2 pin is enabled
@see LSM303DLHC_RA_CTRL_REG6_A
@see LSM303DLHC_BOOT_I1_BIT
*/
bool LSM303DLHC::getAccelRebootMemoryContentINT2Enabled(){
I2Cdev::readBit(devAddrA, LSM303DLHC_RA_CTRL_REG6_A, LSM303DLHC_BOOT_I1_BIT, buffer);
return buffer[0];
}
// // TODO Documentation
// void setAccelActiveFunctionStatusINT2Enabled(bool enabled);
// // TODO Documentation
// bool getAccelActiveFunctionStatusINT2Enabled();
/*Enable active low interrupts.
@param enable The new state of whether active low interrupts are enabled
@see LSM303DLHC_RA_CTRL_REG6_A
@see LSM303DLHC_H_ACTIVE_BIT
*/
void LSM303DLHC::setAccelInterruptActiveLowEnabled(bool enabled){
I2Cdev::writeBit(devAddrA, LSM303DLHC_RA_CTRL_REG6_A, LSM303DLHC_H_ACTIVE_BIT, enabled);
}
/*Get whether active low interrupts are enabled.
@return True if active low interrupts are enabled.
@see LSM303DLHC_RA_CTRL_REG6_A
@see LSM303DLHC_H_ACTIVE_BIT
*/
bool LSM303DLHC::getAccelInterruptActiveLowEnabled(){
I2Cdev::readBit(devAddrA, LSM303DLHC_RA_CTRL_REG6_A, LSM303DLHC_H_ACTIVE_BIT, buffer);
return buffer[0];
}
//REFERENCE_A, r/w
/** Set the reference value for interrupt generation
* @param reference New reference value for interrupt generation
* @see LSM303DLHC_RA_REFERENCE_A
*/
void LSM303DLHC::setAccelInterruptReference(uint8_t reference) {
I2Cdev::writeByte(devAddrA, LSM303DLHC_RA_REFERENCE_A, reference);
}
/** Get the 8-bit reference value for interrupt generation
* @return 8-bit reference value for interrupt generation
* @see LSM303DLHC_RA_REFERENCE
*/
uint8_t LSM303DLHC::getAccelInterruptReference() {
I2Cdev::readByte(devAddrA, LSM303DLHC_RA_REFERENCE_A, buffer);
return buffer[0];
}
//STATUS_REG_A r
/** Get whether new data overwrote the last set of data before it was read
* @return True if the last set of data was overwritten before being read, false
* otherwise
* @see LSM303DLHC_RA_STATUS_REG_A
* @see LSM303DLHC_ZYXOR_BIT
*/
bool LSM303DLHC::getAccelXYZOverrun() {
I2Cdev::readBit(devAddrA, LSM303DLHC_RA_STATUS_REG_A, LSM303DLHC_ZYXOR_BIT,
buffer);
return buffer[0];
}
/** Get whether new Z data overwrote the last set of data before it was read
* @return True if the last set of Z data was overwritten before being read,
* false otherwise
* @see LSM303DLHC_RA_STATUS_REG_A
* @see LSM303DLHC_ZOR_BIT
*/
bool LSM303DLHC::getAccelZOverrun() {
I2Cdev::readBit(devAddrA, LSM303DLHC_RA_STATUS_REG_A, LSM303DLHC_ZOR_BIT,
buffer);
return buffer[0];
}
/** Get whether new Y data overwrote the last set of data before it was read
* @return True if the last set of Y data was overwritten before being read,
* false otherwise
* @see LSM303DLHC_RA_STATUS_REG_A
* @see LSM303DLHC_YOR_BIT
*/
bool LSM303DLHC::getAccelYOverrun() {
I2Cdev::readBit(devAddrA, LSM303DLHC_RA_STATUS_REG_A, LSM303DLHC_YOR_BIT,
buffer);
return buffer[0];
}
/** Get whether new X data overwrote the last set of data before it was read
* @return True if the last set of X data was overwritten before being read,
* false otherwise
* @see LSM303DLHC_RA_STATUS_REG_A
* @see LSM303DLHC_XOR_BIT
*/
bool LSM303DLHC::getAccelXOverrun() {
I2Cdev::readBit(devAddrA, LSM303DLHC_RA_STATUS_REG_A, LSM303DLHC_XOR_BIT,
buffer);
return buffer[0];
}
/** Get whether there is new data avaialable
* @return True if there is new data available, false otherwise
* @see LSM303DLHC_RA_STATUS_REG_A
* @see LSM303DLHC_ZYXDA_BIT
*/
bool LSM303DLHC::getAccelXYZDataAvailable() {
I2Cdev::readBit(devAddrA, LSM303DLHC_RA_STATUS_REG_A, LSM303DLHC_ZYXDA_BIT,
buffer);
return buffer[0];
}
/** Get whether there is new Z data avaialable
* @return True if there is new Z data available, false otherwise
* @see LSM303DLHC_RA_STATUS_REG_A
* @see LSM303DLHC_ZDA_BIT
*/
bool LSM303DLHC::getAccelZDataAvailable() {
I2Cdev::readBit(devAddrA, LSM303DLHC_RA_STATUS_REG_A, LSM303DLHC_ZDA_BIT,
buffer);
return buffer[0];
}
/** Get whether there is new Y data avaialable
* @return True if there is new Y data available, false otherwise
* @see LSM303DLHC_RA_STATUS_REG_A
* @see LSM303DLHC_YDA_BIT
*/
bool LSM303DLHC::getAccelYDataAvailable() {
I2Cdev::readBit(devAddrA, LSM303DLHC_RA_STATUS_REG_A, LSM303DLHC_YDA_BIT,
buffer);
return buffer[0];
}
/** Get whether there is new X data avaialable
* @return True if there is new X data available, false otherwise
* @see LSM303DLHC_RA_STATUS_REG_A
* @see LSM303DLHC_XDA_BIT
*/
bool LSM303DLHC::getAccelXDataAvailable() {
I2Cdev::readBit(devAddrA, LSM303DLHC_RA_STATUS_REG_A, LSM303DLHC_XDA_BIT,
buffer);
return buffer[0];
}
//OUT_*_A, r
//TODO:
//Fix getAccerlation to read all 6 regs, and fix endian internal state
/** Get the acceleration for all 3 axes
* Due to the fact that this device supports two difference Endian modes, both
* must be accounted for when reading data. In Little Endian mode, the first
* byte (lowest address) is the least significant and in Big Endian mode the
* first byte is the most significant.
* @param x 16-bit integer container for the X-axis acceleration
* @param y 16-bit integer container for the Y-axis acceleration
* @param z 16-bit integer container for the Z-axis acceleration
*/
void LSM303DLHC::getAcceleration(int16_t* x, int16_t* y, int16_t* z) {
I2Cdev::readBytes(devAddrA, LSM303DLHC_RA_OUT_X_L_A | 0x80, 6, buffer);
if (endianMode == LSM303DLHC_LITTLE_ENDIAN) {
*x = (((int16_t)buffer[1]) << 8) | buffer[0];
*y = (((int16_t)buffer[3]) << 8) | buffer[2];
*z = (((int16_t)buffer[5]) << 8) | buffer[4];
} else {
*x = (((int16_t)buffer[0]) << 8) | buffer[1];
*y = (((int16_t)buffer[2]) << 8) | buffer[3];
*z = (((int16_t)buffer[4]) << 8) | buffer[5];
}
}
/** Get the acceleration along the X-axis
* @return acceleration along the X-axis
* @see LSM303DLHC_RA_OUT_X_L_A
* @see LSM303DLHC_RA_OUT_X_H_A