128 lines
4.0 KiB
C
128 lines
4.0 KiB
C
/* USER CODE BEGIN Header */
|
|
/**
|
|
******************************************************************************
|
|
* @file sys_sensors.c
|
|
* @author MCD Application Team
|
|
* @brief Manages the sensors on the application
|
|
******************************************************************************
|
|
* @attention
|
|
*
|
|
* Copyright (c) 2021 STMicroelectronics.
|
|
* All rights reserved.
|
|
*
|
|
* This software is licensed under terms that can be found in the LICENSE file
|
|
* in the root directory of this software component.
|
|
* If no LICENSE file comes with this software, it is provided AS-IS.
|
|
*
|
|
******************************************************************************
|
|
*/
|
|
/* USER CODE END Header */
|
|
|
|
/* Includes ------------------------------------------------------------------*/
|
|
#include "stdint.h"
|
|
#include "platform.h"
|
|
#include "sys_conf.h"
|
|
#include "sys_sensors.h"
|
|
#if defined (SENSOR_ENABLED) && (SENSOR_ENABLED == 0)
|
|
#include "adc_if.h"
|
|
#endif /* SENSOR_ENABLED */
|
|
|
|
/* USER CODE BEGIN Includes */
|
|
#if defined (SENSOR_ENABLED) && (SENSOR_ENABLED == 1)
|
|
#elif !defined (SENSOR_ENABLED)
|
|
#error SENSOR_ENABLED not defined
|
|
#endif /* SENSOR_ENABLED */
|
|
/* USER CODE END Includes */
|
|
|
|
/* External variables ---------------------------------------------------------*/
|
|
/* USER CODE BEGIN EV */
|
|
|
|
/* USER CODE END EV */
|
|
|
|
/* Private typedef -----------------------------------------------------------*/
|
|
/* USER CODE BEGIN PTD */
|
|
|
|
/* USER CODE END PTD */
|
|
|
|
/* Private define ------------------------------------------------------------*/
|
|
|
|
/* USER CODE BEGIN PD */
|
|
#define STSOP_LATTITUDE ((float) 43.618622 ) /*!< default latitude position */
|
|
#define STSOP_LONGITUDE ((float) 7.051415 ) /*!< default longitude position */
|
|
#define MAX_GPS_POS ((int32_t) 8388607 ) /*!< 2^23 - 1 */
|
|
#define HUMIDITY_DEFAULT_VAL 50.0f /*!< default humidity */
|
|
#define TEMPERATURE_DEFAULT_VAL 18.0f /*!< default temperature */
|
|
#define PRESSURE_DEFAULT_VAL 1000.0f /*!< default pressure */
|
|
/* USER CODE END PD */
|
|
|
|
/* Private macro -------------------------------------------------------------*/
|
|
/* USER CODE BEGIN PM */
|
|
|
|
/* USER CODE END PM */
|
|
|
|
/* Private variables ---------------------------------------------------------*/
|
|
|
|
/* USER CODE BEGIN PV */
|
|
#if defined (SENSOR_ENABLED) && (SENSOR_ENABLED == 1)
|
|
#elif !defined (SENSOR_ENABLED)
|
|
#error SENSOR_ENABLED not defined
|
|
#endif /* SENSOR_ENABLED */
|
|
/* USER CODE END PV */
|
|
|
|
/* Private function prototypes -----------------------------------------------*/
|
|
/* USER CODE BEGIN PFP */
|
|
|
|
/* USER CODE END PFP */
|
|
|
|
/* Exported functions --------------------------------------------------------*/
|
|
int32_t EnvSensors_Read(sensor_t *sensor_data)
|
|
{
|
|
/* USER CODE BEGIN EnvSensors_Read */
|
|
float HUMIDITY_Value = HUMIDITY_DEFAULT_VAL;
|
|
float TEMPERATURE_Value = TEMPERATURE_DEFAULT_VAL;
|
|
float PRESSURE_Value = PRESSURE_DEFAULT_VAL;
|
|
|
|
#if defined (SENSOR_ENABLED) && (SENSOR_ENABLED == 1)
|
|
#else
|
|
TEMPERATURE_Value = (SYS_GetTemperatureLevel() >> 8);
|
|
#endif /* SENSOR_ENABLED */
|
|
|
|
sensor_data->humidity = HUMIDITY_Value;
|
|
sensor_data->temperature = TEMPERATURE_Value;
|
|
sensor_data->pressure = PRESSURE_Value;
|
|
|
|
sensor_data->latitude = (int32_t)((STSOP_LATTITUDE * MAX_GPS_POS) / 90);
|
|
sensor_data->longitude = (int32_t)((STSOP_LONGITUDE * MAX_GPS_POS) / 180);
|
|
|
|
return 0;
|
|
/* USER CODE END EnvSensors_Read */
|
|
}
|
|
|
|
int32_t EnvSensors_Init(void)
|
|
{
|
|
int32_t ret = 0;
|
|
|
|
/* USER CODE BEGIN EnvSensors_Init */
|
|
#if defined (SENSOR_ENABLED) && (SENSOR_ENABLED == 1)
|
|
/* Init */
|
|
|
|
/* Enable */
|
|
|
|
/* Get capabilities */
|
|
|
|
#elif !defined (SENSOR_ENABLED)
|
|
#error SENSOR_ENABLED not defined
|
|
#endif /* SENSOR_ENABLED */
|
|
/* USER CODE END EnvSensors_Init */
|
|
return ret;
|
|
}
|
|
|
|
/* USER CODE BEGIN EF */
|
|
|
|
/* USER CODE END EF */
|
|
|
|
/* Private Functions Definition -----------------------------------------------*/
|
|
/* USER CODE BEGIN PrFD */
|
|
|
|
/* USER CODE END PrFD */
|