libpropeller
Making PropellerGCC Easier
 All Classes Files Functions Variables Enumerations Enumerator Macros Pages
l3gd20.test.h
Go to the documentation of this file.
1 // Copyright 2013 SRLM and Red9
2 #include <propeller.h>
3 #include "unity.h"
4 #include "c++-alloc.h"
7 
8 
9 //TODO(SRLM): Get rid of the hardcoded pins.
10 const int kSDAPin = 1;
11 const int kSCLPin = 2;
12 
13 
14 I2C * bus;
16 
17 class UnityTests {
18 public:
19 
20  static void setUp(void) {
21  bus = new I2C();
22  bus->Init(kSCLPin, kSDAPin);
23  gyro.Init(bus, L3GD20::LSB_1);
24  }
25 
26  static void tearDown(void) {
27  delete bus;
28  bus = NULL;
29  }
30 
31  // -----------------------------------------------------------------------------
32 
33  static void test_Init(void) {
34  TEST_ASSERT_EQUAL_INT(0b00110000, bus->GetPutStack());
35  TEST_ASSERT_EQUAL_INT(0b11111111, bus->GetPutStack());
36  TEST_ASSERT_EQUAL_INT(-1, bus->GetPutStack());
37  }
38 
39  static void test_ReadGyroPositiveNumbers(void) {
40  char indata[] = {0x01, 0x02, 0x03, 0x04, 0x05, 0x06};
41  bus->SetXYZ(indata, 6);
42  int x, y, z;
43  TEST_ASSERT_TRUE(gyro.ReadGyro(x, y, z));
44 
45  TEST_ASSERT_EQUAL_HEX32(0x0201, x);
46  TEST_ASSERT_EQUAL_HEX32(0x0403, y);
47  TEST_ASSERT_EQUAL_HEX32(0x0605, z);
48  }
49 
50  static void test_ReadGyroNegativeNumbers(void) {
51  char indata[] = {0x01, 0xF2, 0x03, 0xF4, 0x05, 0xF6};
52  bus->SetXYZ(indata, 6);
53  int x, y, z;
54  TEST_ASSERT_TRUE(gyro.ReadGyro(x, y, z));
55 
56  TEST_ASSERT_EQUAL_HEX32(0xFFFFF201, x);
57  TEST_ASSERT_EQUAL_HEX32(0xFFFFF403, y);
58  TEST_ASSERT_EQUAL_HEX32(0xFFFFF605, z);
59  }
60 
61 };