-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from openppg/dev/lps22hb
Barometer support (LPS22HB)
- Loading branch information
Showing
9 changed files
with
198 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
/* | ||
* baro_proc.h | ||
* | ||
* Created on: Oct 23, 2019 | ||
*/ | ||
|
||
#ifndef BARO_PROC_H_ | ||
#define BARO_PROC_H_ | ||
|
||
void baroAvgInit(); | ||
void baroSample(); | ||
uint32_t baroGetAvg(); | ||
int16_t baroGetTempAvg(); | ||
|
||
#endif /* BARO_PROC_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
#include "main.h" | ||
#include "baro_LPS22HB.h" | ||
|
||
#define BARO_AVG_COUNT 4 | ||
|
||
static uint32_t baro_value[BARO_AVG_COUNT]; | ||
static uint32_t baro_temp_value[BARO_AVG_COUNT]; | ||
static int32_t baro_value_idx; | ||
|
||
/** | ||
* @brief Initialize baro (LPS22HB) | ||
* @retval None | ||
*/ | ||
void baroAvgInit() | ||
{ | ||
int16_t init_temp_value; | ||
uint32_t init_value= baroReadPressTemp(&init_temp_value); | ||
|
||
// set all buf to the inital value | ||
for(int i=0;i<BARO_AVG_COUNT;i++) | ||
{ | ||
baro_value[i]=init_value; | ||
baro_temp_value[i]=init_temp_value; | ||
} | ||
|
||
baro_value_idx=0; | ||
} | ||
|
||
void baroSample() | ||
{ | ||
int16_t baro_temp_reading; | ||
uint32_t baro_reading= baroReadPressTemp(&baro_temp_reading); | ||
|
||
if(baro_reading!=0xffffffff) | ||
{// save the value if it is valid | ||
baro_value[baro_value_idx]=baro_reading; | ||
baro_temp_value[baro_value_idx]=baro_temp_reading; | ||
baro_value_idx++; | ||
|
||
if(baro_value_idx>=BARO_AVG_COUNT) | ||
{ | ||
baro_value_idx=0; | ||
} | ||
} | ||
|
||
} | ||
|
||
uint32_t baroGetAvg() | ||
{ | ||
uint32_t total=0; | ||
|
||
for(int i=0;i<BARO_AVG_COUNT;i++) | ||
{ | ||
total+=baro_value[i]; | ||
} | ||
|
||
return total/BARO_AVG_COUNT; | ||
} | ||
|
||
int16_t baroGetTempAvg() | ||
{ | ||
int32_t total=0; | ||
|
||
for(int i=0;i<BARO_AVG_COUNT;i++) | ||
{ | ||
total+=baro_temp_value[i]; | ||
} | ||
|
||
return total/BARO_AVG_COUNT; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters