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/>.
23 #include "drivers/barometer/barometer.h"
24 #include "drivers/bus.h"
26 void bmp085Calculate(int32_t *pressure
, int32_t *temperature
);
27 extern uint32_t bmp085_up
;
28 extern uint16_t bmp085_ut
;
42 } bmp085_smd500_calibration_param_t
;
45 bmp085_smd500_calibration_param_t cal_param
;
47 uint8_t chip_id
, ml_version
, al_version
;
50 int16_t oversampling_setting
;
58 #include "unittest_macros.h"
59 #include "gtest/gtest.h"
62 TEST(baroBmp085Test
, TestBmp085CalculateOss0
)
66 int32_t pressure
, temperature
;
67 bmp085_up
= 23843; // Digital pressure value
68 bmp085_ut
= 27898; // Digital temperature value
71 bmp085
.cal_param
.ac1
= 408;
72 bmp085
.cal_param
.ac2
= -72;
73 bmp085
.cal_param
.ac3
= -14383;
74 bmp085
.cal_param
.ac4
= 32741;
75 bmp085
.cal_param
.ac5
= 32757;
76 bmp085
.cal_param
.ac6
= 23153;
77 bmp085
.cal_param
.b1
= 6190;
78 bmp085
.cal_param
.b2
= 4;
79 bmp085
.cal_param
.mb
= -32767;
80 bmp085
.cal_param
.mc
= -8711;
81 bmp085
.cal_param
.md
= 2868;
82 bmp085
.oversampling_setting
= 0;
85 bmp085Calculate(&pressure
, &temperature
);
88 EXPECT_EQ(69964, pressure
); // Datasheet says 69965
89 EXPECT_EQ(1500, temperature
);
93 TEST(baroBmp085Test
, TestBmp085CalculateOss3
)
97 int32_t pressure
, temperature
;
98 bmp085_up
= 271097; // Digital pressure value
99 bmp085_ut
= 27898; // Digital temperature value
102 bmp085
.cal_param
.ac1
= 408;
103 bmp085
.cal_param
.ac2
= -72;
104 bmp085
.cal_param
.ac3
= -14383;
105 bmp085
.cal_param
.ac4
= 32741;
106 bmp085
.cal_param
.ac5
= 32757;
107 bmp085
.cal_param
.ac6
= 23153;
108 bmp085
.cal_param
.b1
= 6190;
109 bmp085
.cal_param
.b2
= 4;
110 bmp085
.cal_param
.mb
= -32767;
111 bmp085
.cal_param
.mc
= -8711;
112 bmp085
.cal_param
.md
= 2868;
113 bmp085
.oversampling_setting
= 3;
116 bmp085Calculate(&pressure
, &temperature
);
119 EXPECT_EQ(99998, pressure
);
120 EXPECT_EQ(1500, temperature
);
124 TEST(baroBmp085Test
, TestBmp085CalculateOss3Cold
)
128 int32_t pressure
, temperature
;
129 bmp085_up
= 271097; // Digital pressure value
130 bmp085_ut
= 24342; // Digital temperature value 24342 = -20degC 27898 = 15degC
133 bmp085
.cal_param
.ac1
= 408;
134 bmp085
.cal_param
.ac2
= -72;
135 bmp085
.cal_param
.ac3
= -14383;
136 bmp085
.cal_param
.ac4
= 32741;
137 bmp085
.cal_param
.ac5
= 32757;
138 bmp085
.cal_param
.ac6
= 23153;
139 bmp085
.cal_param
.b1
= 6190;
140 bmp085
.cal_param
.b2
= 4;
141 bmp085
.cal_param
.mb
= -32767;
142 bmp085
.cal_param
.mc
= -8711;
143 bmp085
.cal_param
.md
= 2868;
144 bmp085
.oversampling_setting
= 3;
147 bmp085Calculate(&pressure
, &temperature
);
150 EXPECT_EQ(92251, pressure
);
151 EXPECT_EQ(-2006, temperature
); // -20.06 degC
155 TEST(baroBmp085Test
, TestBmp085CalculateOss3Hot
)
159 int32_t pressure
, temperature
;
160 bmp085_up
= 271097; // Digital pressure value
161 bmp085_ut
= 33315; // Digital temperature value
164 bmp085
.cal_param
.ac1
= 408;
165 bmp085
.cal_param
.ac2
= -72;
166 bmp085
.cal_param
.ac3
= -14383;
167 bmp085
.cal_param
.ac4
= 32741;
168 bmp085
.cal_param
.ac5
= 32757;
169 bmp085
.cal_param
.ac6
= 23153;
170 bmp085
.cal_param
.b1
= 6190;
171 bmp085
.cal_param
.b2
= 4;
172 bmp085
.cal_param
.mb
= -32767;
173 bmp085
.cal_param
.mc
= -8711;
174 bmp085
.cal_param
.md
= 2868;
175 bmp085
.oversampling_setting
= 3;
178 bmp085Calculate(&pressure
, &temperature
);
181 EXPECT_EQ(108922, pressure
);
182 EXPECT_EQ(5493, temperature
); // 54.93 degC
191 void RCC_APB2PeriphClockCmd() {}
192 void delay(uint32_t) {}
193 void delayMicroseconds(uint32_t) {}
194 bool busReadRegisterBuffer(const extDevice_t
*, uint8_t, uint8_t*, uint8_t) {return true;}
195 bool busWriteRegister(const extDevice_t
*, uint8_t, uint8_t) {return true;}
196 void IOConfigGPIO() {}
201 bool busBusy(const extDevice_t
*, bool*) {return false;}
202 void busDeviceRegister(const extDevice_t
*) {}
203 bool busReadRegisterBufferStart(const extDevice_t
*, uint8_t, uint8_t*, uint8_t) {return true;}
204 bool busWriteRegisterStart(const extDevice_t
*, uint8_t, uint8_t) {return true;}