libpropeller
Making PropellerGCC Easier
 All Classes Files Functions Variables Enumerations Enumerator Macros Pages
lsm303dlhc.test.h
Go to the documentation of this file.
1 #include <propeller.h>
2 #include "unity.h"
5 
6 const int kSDAPin = 1;
7 const int kSCLPin = 2;
8 
9 
10 I2C * bus;
12 
13 class UnityTests {
14 public:
15 
16  static void setUp(void) {
17  bus = new I2C();
18  bus->Init(kSCLPin, kSDAPin);
19  acclMagn.Init(bus);
20  }
21 
22  static void tearDown(void) {
23  delete bus;
24  }
25 
26  // -----------------------------------------------------------------------------
27 
28  static void test_Init(void) {
29  TEST_ASSERT_EQUAL_INT(0b00111000, bus->GetPutStack());
30  TEST_ASSERT_EQUAL_INT(0b10010111, bus->GetPutStack());
31  TEST_ASSERT_EQUAL_INT(0b00000000, bus->GetPutStack());
32  TEST_ASSERT_EQUAL_INT(0b00100000, bus->GetPutStack());
33  TEST_ASSERT_EQUAL_INT(0b10011100, bus->GetPutStack());
34  TEST_ASSERT_EQUAL_INT(-1, bus->GetPutStack());
35  }
36 
37  static void test_ReadAcclPositiveNumbers(void) {
38  //All 16 bits are returned from the LSM303DLHC
39  char indata[] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06};
40  bus->SetXYZ(indata, 6);
41  int x, y, z;
42  TEST_ASSERT_TRUE(acclMagn.ReadAccl(x, y, z));
43 
44  TEST_ASSERT_EQUAL_HEX32(0x0201, x);
45  TEST_ASSERT_EQUAL_HEX32(0x0403, y);
46  TEST_ASSERT_EQUAL_HEX32(0x0605, z);
47  }
48 
49  static void test_ReadAcclNegativeNumbers(void) {
50  //All 16 bits are returned from the LSM303DLHC
51  char indata[] = {0x01, 0xF2, 0x03, 0xF4, 0x05, 0xF6};
52  bus->SetXYZ(indata, 6);
53  int x, y, z;
54  TEST_ASSERT_TRUE(acclMagn.ReadAccl(x, y, z));
55 
56  TEST_ASSERT_EQUAL_HEX32(0xFFFFFF201, x);
57  TEST_ASSERT_EQUAL_HEX32(0xFFFFFF403, y);
58  TEST_ASSERT_EQUAL_HEX32(0xFFFFFF605, z);
59  }
60 
61  static void test_ReadMagnPositiveNumbers(void) {
62  //Notice how the lower 4 bits are removed: LSM303DLHC returns 12 bit numbers!
63  char indata[] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06};
64  bus->SetXYZ(indata, 6);
65  int x, y, z;
66  TEST_ASSERT_TRUE(acclMagn.ReadMagn(x, y, z));
67 
68  TEST_ASSERT_EQUAL_HEX32(0x010, x);
69  TEST_ASSERT_EQUAL_HEX32(0x030, y);
70  TEST_ASSERT_EQUAL_HEX32(0x050, z);
71  }
72 
73  static void test_ReadMagnNegativeNumbers(void) {
74  //Notice how the lower 4 bits are removed: LSM303DLHC returns 12 bit numbers!
75  char indata[] = {0xF1, 0xA2, 0xF3, 0xA4, 0xF5, 0xA6};
76  bus->SetXYZ(indata, 6);
77  int x, y, z;
78  TEST_ASSERT_TRUE(acclMagn.ReadMagn(x, y, z));
79 
80  TEST_ASSERT_EQUAL_HEX32(0xFFFFFF1A, x);
81  TEST_ASSERT_EQUAL_HEX32(0xFFFFFF3A, y);
82  TEST_ASSERT_EQUAL_HEX32(0xFFFFFF5A, z);
83  }
84 
85  //TODO(SRLM): Add tests for the ReadAccl/ReadMagn bus->Get == bus->kNak case
86  //Add tests for status being bus->kNak
87 
88 };