Repository navigation
Expand file tree
/
Copy pathsensor_driver_test.c
More file actions
108 lines (90 loc) · 3.59 KB
/
Copy pathsensor_driver_test.c
File metadata and controls
108 lines (90 loc) · 3.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
/*! @mainpage
*
****************************************************************************
* Copyright (C) 2016 GlobalMEMS, Inc. <www.globalmems.com>
* All rights reserved.
*
* File : sensor_driver_test.c
*
* Usage: GMP102 Sensor Driver Test
*
****************************************************************************
* @section License
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
**************************************************************************/
/*! @file sensor_driver_test.c
* @brief GMP102 Sensor Driver Test Main Program
* @author Joseph FC Tseng
*/
#include <stdio.h>
#include "gmp102.h"
#include "pSensor_util.h"
#define DELAY_MS(ms) //..... /* Add your time delay function here */
/*---------------------------------------------------------------------------------------------------------*/
/* Main Function */
/*---------------------------------------------------------------------------------------------------------*/
int main(void)
{
s8 s8Res;
bus_support_t gmp102_bus;
float fCalibParam[GMP102_CALIBRATION_PARAMETER_COUNT], fT_Celsius, fP_Pa, fAlt_m;
s16 s16Value[GMP102_CALIBRATION_PARAMETER_COUNT];
u8 u8Power[GMP102_CALIBRATION_PARAMETER_COUNT];
s16 s16T;
s32 s32P, s32P64_Pa, s32P32_Pa, s32T_Celsius;
/* Add your HW initialization code here
...
...
...
...
*/
/* GMP102 I2C bus setup */
bus_init_I2C(&gmp102_bus, GMP102_7BIT_I2C_ADDR); //Initialize I2C bus
gmp102_bus_init(&gmp102_bus); //Initailze GMP102 bus to I2C
/* GMP102 soft reset */
s8Res = gmp102_soft_reset();
/* Wait 100ms for reset complete */
DELAY_MS(100);
/* GMP102 get the pressure calibration parameters */
s8Res = gmp102_get_calibration_param(fCalibParam);
s8Res = gmp102_get_calibration_param_fixed_point(s16Value, u8Power);
/* GMP102 initialization setup */
s8Res = gmp102_initialization();
/* set sea level reference pressure */
//If not set, use default 101325 Pa for pressure altitude calculation
set_sea_level_pressure_base(102100.f);
for(;;)
{
/* Measure P */
s8Res = gmp102_measure_P(&s32P);
printf("P(code)=%d\r", s32P);
/* Mesaure T */
s8Res = gmp102_measure_T(&s16T);
printf("T(code)=%d\r", s16T);
/* Compensation, choose one of the three below in actual implementation*/
gmp102_compensation(s16T, s32P, fCalibParam, &fT_Celsius, &fP_Pa);
gmp102_compensation_fixed_point_s64(s16T, s32P, s16Value, u8Power, &s32T_Celsius, &s32P64_Pa);
gmp102_compensation_fixed_point_s32(s16T, s32P, s16Value, u8Power, &s32T_Celsius, &s32P32_Pa);
printf("P(Pa)=%f, %d, %d\r", fP_Pa, s32P64_Pa, s32P32_Pa);
printf("T(C)=%f, %f\r", fT_Celsius, s32T_Celsius/256.0);
/* Pressure Altitude */
fAlt_m = pressure2Alt(fP_Pa);
printf("Alt(m)=%f\r", fAlt_m);
/* Delay 1 sec */
DELAY_MS(1000);
}
}