소스 검색

lsm303: Modifying C++ example

Signed-off-by: Zion Orent <zorent@ics.com>
Signed-off-by: Jon Trulson <jtrulson@ics.com>
Signed-off-by: Sarah Knepper <sarah.knepper@intel.com>
Zion Orent 10 년 전
부모
커밋
9d48301402
1개의 변경된 파일11개의 추가작업 그리고 3개의 파일을 삭제
  1. 11
    3
      examples/lsm303.cxx

+ 11
- 3
examples/lsm303.cxx 파일 보기

@@ -30,25 +30,33 @@
30 30
 int
31 31
 main(int argc, char **argv)
32 32
 {
33
+	// Instantiate LSM303 compass on I2C
33 34
     upm::LSM303 *sensor = new upm::LSM303(0);
34 35
 
36
+    // Get the coordinate data
35 37
     sensor->getCoordinates();
36
-    int16_t* coor = sensor->getRawCoorData(); // in XZY order
38
+    int16_t* coor = sensor->getRawCoorData(); // in XYZ order. 
39
+    // The sensor returns XZY, but the driver compensates and makes it XYZ
40
+    
41
+    // Print out the X, Y, and Z coordinate data using two different methods
37 42
     std::cout << "coor: rX " << (int)coor[0]
38
-              << " - rY " << (int)coor[2]  // note: index is 2
39
-              << " - rZ " << (int)coor[1]  // note: index is 1
43
+              << " - rY " << (int)coor[1]
44
+              << " - rZ " << (int)coor[2]
40 45
               << std::endl;
41 46
     std::cout << "coor: gX " << sensor->getCoorX()
42 47
               << " - gY " << sensor->getCoorY()
43 48
               << " - gZ " << sensor->getCoorZ()
44 49
               << std::endl;
45 50
 
51
+    // Get and print out the heading
46 52
     std::cout << "heading: "
47 53
               << sensor->getHeading()
48 54
               << std::endl;
49 55
 
56
+    // Get the acceleration
50 57
     sensor->getAcceleration();
51 58
     int16_t* accel = sensor->getRawAccelData();
59
+    // Print out the X, Y, and Z acceleration data using two different methods
52 60
     std::cout << "acc: rX " << (int)accel[0]
53 61
               << " - rY " << (int)accel[1]
54 62
               << " - Z " << (int)accel[2]