2 * This file is part of Cleanflight.
4 * Cleanflight is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * Cleanflight is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with Cleanflight. If not, see <http://www.gnu.org/licenses/>.
21 void bmp085_calculate(int32_t *pressure, int32_t *temperature);
22 extern uint32_t bmp085_up;
23 extern uint16_t bmp085_ut;
37 } bmp085_smd500_calibration_param_t;
40 bmp085_smd500_calibration_param_t cal_param;
42 uint8_t chip_id, ml_version, al_version;
45 int16_t oversampling_setting;
53 #include "unittest_macros.h"
54 #include "gtest/gtest.h"
57 TEST(baroBmp085Test, TestBmp085CalculateOss0)
61 int32_t pressure, temperature;
62 bmp085_up = 23843; // Digital pressure value
63 bmp085_ut = 27898; // Digital temperature value
66 bmp085.cal_param.ac1 = 408;
67 bmp085.cal_param.ac2 = -72;
68 bmp085.cal_param.ac3 = -14383;
69 bmp085.cal_param.ac4 = 32741;
70 bmp085.cal_param.ac5 = 32757;
71 bmp085.cal_param.ac6 = 23153;
72 bmp085.cal_param.b1 = 6190;
73 bmp085.cal_param.b2 = 4;
74 bmp085.cal_param.mb = -32767;
75 bmp085.cal_param.mc = -8711;
76 bmp085.cal_param.md = 2868;
77 bmp085.oversampling_setting = 0;
80 bmp085_calculate(&pressure, &temperature);
83 EXPECT_EQ(69964, pressure); // Datasheet says 69965
84 EXPECT_EQ(1500, temperature);
88 TEST(baroBmp085Test, TestBmp085CalculateOss3)
92 int32_t pressure, temperature;
93 bmp085_up = 271097; // Digital pressure value
94 bmp085_ut = 27898; // Digital temperature value
97 bmp085.cal_param.ac1 = 408;
98 bmp085.cal_param.ac2 = -72;
99 bmp085.cal_param.ac3 = -14383;
100 bmp085.cal_param.ac4 = 32741;
101 bmp085.cal_param.ac5 = 32757;
102 bmp085.cal_param.ac6 = 23153;
103 bmp085.cal_param.b1 = 6190;
104 bmp085.cal_param.b2 = 4;
105 bmp085.cal_param.mb = -32767;
106 bmp085.cal_param.mc = -8711;
107 bmp085.cal_param.md = 2868;
108 bmp085.oversampling_setting = 3;
111 bmp085_calculate(&pressure, &temperature);
114 EXPECT_EQ(99998, pressure);
115 EXPECT_EQ(1500, temperature);
119 TEST(baroBmp085Test, TestBmp085CalculateOss3Cold)
123 int32_t pressure, temperature;
124 bmp085_up = 271097; // Digital pressure value
125 bmp085_ut = 24342; // Digital temperature value 24342 = -20degC 27898 = 15degC
128 bmp085.cal_param.ac1 = 408;
129 bmp085.cal_param.ac2 = -72;
130 bmp085.cal_param.ac3 = -14383;
131 bmp085.cal_param.ac4 = 32741;
132 bmp085.cal_param.ac5 = 32757;
133 bmp085.cal_param.ac6 = 23153;
134 bmp085.cal_param.b1 = 6190;
135 bmp085.cal_param.b2 = 4;
136 bmp085.cal_param.mb = -32767;
137 bmp085.cal_param.mc = -8711;
138 bmp085.cal_param.md = 2868;
139 bmp085.oversampling_setting = 3;
142 bmp085_calculate(&pressure, &temperature);
145 EXPECT_EQ(92251, pressure);
146 EXPECT_EQ(-2006, temperature); // -20.06 degC
150 TEST(baroBmp085Test, TestBmp085CalculateOss3Hot)
154 int32_t pressure, temperature;
155 bmp085_up = 271097; // Digital pressure value
156 bmp085_ut = 33315; // Digital temperature value
159 bmp085.cal_param.ac1 = 408;
160 bmp085.cal_param.ac2 = -72;
161 bmp085.cal_param.ac3 = -14383;
162 bmp085.cal_param.ac4 = 32741;
163 bmp085.cal_param.ac5 = 32757;
164 bmp085.cal_param.ac6 = 23153;
165 bmp085.cal_param.b1 = 6190;
166 bmp085.cal_param.b2 = 4;
167 bmp085.cal_param.mb = -32767;
168 bmp085.cal_param.mc = -8711;
169 bmp085.cal_param.md = 2868;
170 bmp085.oversampling_setting = 3;
173 bmp085_calculate(&pressure, &temperature);
176 EXPECT_EQ(108922, pressure);
177 EXPECT_EQ(5493, temperature); // 54.93 degC
185 void RCC_APB2PeriphClockCmd() {}
186 void delay(uint32_t) {}
187 void delayMicroseconds(uint32_t) {}
188 bool i2cWrite(uint8_t, uint8_t, uint8_t) {
191 bool i2cRead(uint8_t, uint8_t, uint8_t, uint8_t) {