libpropeller
Making PropellerGCC Easier
 All Classes Files Functions Variables Enumerations Enumerator Macros Pages
ms5611.test.h
Go to the documentation of this file.
1 #include <propeller.h>
2 
3 #include "unity.h"
4 
6 #include "c++-alloc.h"
7 
8 //TODO(SRLM): Get rid of the hardcoded pins.
9 const int kPIN_I2C_SCL = 0;
10 const int kPIN_I2C_SDA = 1;
11 
12 I2C * bus = NULL; //nullptr;
13 MS5611 * sut = NULL; //nullptr;
14 
15 
16 class UnityTests {
17 public:
18 
19  static void setUp(void) {
20  bus = new I2C;
22  sut = new MS5611();
23  sut->Init(bus, MS5611::LSB_1);
24  }
25 
26  static void tearDown(void) {
27  sut->Reset();
28 
29  delete sut;
30  // sut = nullptr;
31  delete bus;
32  // bus = nullptr;
33  }
34 
35  static void test_GetStatus(void) {
36  TEST_ASSERT_TRUE(sut->GetStatus());
37  }
38 
39  static void test_GetPressureTemperatureBasic(void) {
40  //This test method is mostly for testing the timing of the functions
41 
42  int pressure = 0;
43  int temperature = 0;
44 
45  // int startCNT = CNT;
46  // int endCNT = CNT;
47  // int nothingDelta = endCNT-startCNT;
48 
49  // while(true){
50  //Touch 1
51  waitcnt(CLKFREQ / 100 + CNT);
52  // startCNT = CNT;
53  TEST_ASSERT_FALSE(sut->Touch()); //Pressure
54  // endCNT = CNT;
55 
56  // UnityPrint("Touch1 deltaCNT: ");
57  // UnityPrintNumber(endCNT - startCNT - nothingDelta);
58  // UNITY_OUTPUT_CHAR('\n');
59 
60 
61  //Touch 2
62  waitcnt(CLKFREQ / 100 + CNT);
63  // startCNT = CNT;
64  TEST_ASSERT_TRUE(sut->Touch()); //Temperature
65  // endCNT = CNT;
66 
67  // UnityPrint("Touch2 deltaCNT: ");
68  // UnityPrintNumber(endCNT - startCNT - nothingDelta);
69  // UNITY_OUTPUT_CHAR('\n');
70 
71 
72  //Conversion
73  // startCNT = CNT;
74  sut->Get(pressure, temperature);
75  // endCNT = CNT;
76 
77  // UnityPrint("Get deltaCNT: ");
78  // UnityPrintNumber(endCNT - startCNT - nothingDelta);
79  // UNITY_OUTPUT_CHAR('\n');
80 
81 
82  TEST_ASSERT_TRUE(pressure != 0);
83  TEST_ASSERT_TRUE(temperature != 0);
84 
85  // UnityPrint("Temperature: ");
86  // UnityPrintNumber(temperature);
87  // UNITY_OUTPUT_CHAR('\t');
88  // UnityPrint("Pressure: ");
89  // UnityPrintNumber(pressure);
90  // UNITY_OUTPUT_CHAR('\n');
91  // }
92  }
93 
94  static void test_CalculateHighTemperature(void) {
95  sut->SetC(40127,
96  36924,
97  23317,
98  23282,
99  33464,
100  28312);
101 
102  sut->TEST_SetD(9085466, 8569150);
103 
104  int pressure, temperature;
105  sut->Get(pressure, temperature);
106  TEST_ASSERT_EQUAL_INT(2007, temperature);
107  TEST_ASSERT_EQUAL_INT(100009, pressure);
108 
109  }
110 
111  static void test_SetGetC(void) {
112  int C[] = {40127,
113  36924,
114  23317,
115  23282,
116  33464,
117  28312};
118  int rC[6];
119 
120 
121  sut->SetC(C[0], C[1], C[2], C[3], C[4], C[5]);
122  sut->GetC(rC[0], rC[1], rC[2], rC[3], rC[4], rC[5]);
123 
124  TEST_ASSERT_EQUAL_INT_ARRAY(C, rC, 6);
125  }
126 
127  static void test_GetRaw(void) {
128 
129  int D1 = 52352;
130  int D2 = 87950;
131  sut->TEST_SetD(D1, D2);
132 
133  int p, t;
134  sut->Get(p, t, false);
135 
136  TEST_ASSERT_EQUAL_INT(D1, p);
137  TEST_ASSERT_EQUAL_INT(D2, t);
138  }
139 
140  static void test_GetProccessedIsNotRaw(void) {
141 
142  int D1 = 52352;
143  int D2 = 87950;
144  sut->TEST_SetD(D1, D2);
145 
146  int p, t;
147  sut->Get(p, t); // default of true
148 
149  TEST_ASSERT_FALSE(D1 == p);
150  TEST_ASSERT_FALSE(D2 == t);
151  }
152 
153  static void test_TouchTimeoutEffectWhenCalledQuickly(void) {
154  for (int i = 0; i < 25; i++) {
155  for (int j = 0; j < 17; j++) {
156  waitcnt(CLKFREQ / 1000 + CNT);
157  TEST_ASSERT_FALSE(sut->Touch());
158  }
159  waitcnt(CLKFREQ / 1000 + CNT);
160  TEST_ASSERT_TRUE(sut->Touch());
161  TEST_ASSERT_FALSE(sut->Touch());
162  }
163  }
164 
165  static void test_TouchTimeoutHasNoEffectWhenCalledSlowly(void) {
166  for (int i = 0; i < 100; i++) {
167  waitcnt(CLKFREQ / 100 + CNT);
168  TEST_ASSERT_FALSE(sut->Touch());
169  waitcnt(CLKFREQ / 100 + CNT);
170  TEST_ASSERT_TRUE(sut->Touch());
171  }
172  }
173 
174  static void test_GetStatusIsFalseForNoBus(void) {
175  MS5611 dummy;
176  TEST_ASSERT_FALSE(dummy.GetStatus());
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