Welcome to mirror list, hosted at ThFree Co, Russian Federation.

sensors.c « Src « BSP « Examples « STM32WB5MM-DK « Projects - github.com/Flipper-Zero/STM32CubeWB.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 9989fc4d347382ead35697d26927a630c7bbee3c (plain)
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
/**
******************************************************************************
* @file    sensors.c 
* @author  MCD Application Team
* @brief   This example code shows how to use the sensors supported by the 
*          STM32WB55MM-DK board
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
*                        opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/

/* Includes ------------------------------------------------------------------*/
#include "main.h"

/** @addtogroup STM32WLxx_HAL_Examples
* @{
*/

/** @addtogroup BSP
* @{
*/ 

/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
#define CELSIUS_ASCII_CODE 248

/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/

/**
  * @brief  Test of STTS22H and LPS22HB temperature sensors.
  */
void Temperature_Test(void)
{
  char temp[64];
  float temperature;
  temperature = 0;
  BSP_LCD_Clear(0,SSD1315_COLOR_BLACK);
  BSP_LCD_Refresh(0);
  UTIL_LCD_DisplayStringAt(0, 0, (uint8_t *)"Temperature", CENTER_MODE);
  UTIL_LCD_DisplayStringAt(0, 12, (uint8_t *)"Measure", CENTER_MODE);
  UTIL_LCD_DrawRect(0, 0, 127 , 23, SSD1315_COLOR_WHITE);
  BSP_LCD_Refresh(0);
  
  (void)BSP_ENV_SENSOR_Init(ENV_SENSOR_STTS22H_0, ENV_TEMPERATURE);
  (void)BSP_ENV_SENSOR_Enable(ENV_SENSOR_STTS22H_0, ENV_TEMPERATURE);
  while (1)
  {
    (void)BSP_ENV_SENSOR_GetValue(ENV_SENSOR_STTS22H_0, ENV_TEMPERATURE, &temperature);
    sprintf(temp,"Temp=%f", temperature);
    UTIL_LCD_DisplayStringAt(0, 37, (uint8_t *)temp, CENTER_MODE);
    BSP_LCD_Refresh(0);

    if(CheckForUserInput() > 0)
    {
      ButtonState = 0;
      (void)BSP_ENV_SENSOR_Disable(ENV_SENSOR_STTS22H_0, ENV_TEMPERATURE);
      (void)BSP_ENV_SENSOR_DeInit(ENV_SENSOR_STTS22H_0);
      return;
    }
  }
}

/**
  * @brief  Test of LSM6DSL accelerometer sensor.
  */
void Accelero_Test(void)
{
  char acc_x[64];
  char acc_y[64];
  char acc_z[64];
  MOTION_SENSOR_Axes_t acceleration;

  (void)BSP_MOTION_SENSOR_Init(MOTION_SENSOR_ISM330DHCX_0, MOTION_ACCELERO);
  (void)BSP_MOTION_SENSOR_Enable(MOTION_SENSOR_ISM330DHCX_0, MOTION_ACCELERO);

  while (1)
  {
    BSP_LCD_Clear(0,SSD1315_COLOR_BLACK);
    BSP_LCD_Refresh(0);
    UTIL_LCD_DisplayStringAt(0, 0, (uint8_t *)"Accelerometer", CENTER_MODE);
    UTIL_LCD_DisplayStringAt(0, 12, (uint8_t *)"Measure ", CENTER_MODE);
    UTIL_LCD_DrawRect(0, 0, 127 , 23, SSD1315_COLOR_WHITE);
    BSP_LCD_Refresh(0);
    memset(&acceleration, 0, sizeof(MOTION_SENSOR_Axes_t));
    (void)BSP_MOTION_SENSOR_GetAxes(MOTION_SENSOR_ISM330DHCX_0, MOTION_ACCELERO, &acceleration);
    sprintf(acc_x," ACC_X = %d", acceleration.x);
    sprintf(acc_y," ACC_Y = %d", acceleration.y);
    sprintf(acc_z," ACC_Z = %d", acceleration.z);
    UTIL_LCD_DisplayStringAt(0, 25, (uint8_t *)acc_x, LEFT_MODE);
    UTIL_LCD_DisplayStringAt(0, 37, (uint8_t *)acc_y, LEFT_MODE);
    UTIL_LCD_DisplayStringAt(0, 49, (uint8_t *)acc_z, LEFT_MODE);
    BSP_LCD_Refresh(0);
    HAL_Delay(1000);

    if(CheckForUserInput() > 0)
    {
      ButtonState = 0;
      (void)BSP_MOTION_SENSOR_Disable(MOTION_SENSOR_ISM330DHCX_0, MOTION_ACCELERO);
      (void)BSP_MOTION_SENSOR_DeInit(MOTION_SENSOR_ISM330DHCX_0);
      return;
    }
  }
}

/**
  * @brief  Test of ISM330DHCX gyroscope sensor.
  */
void Gyro_Test(void)
{
  char gyr_x[64];
  char gyr_y[64];
  char gyr_z[64];
  MOTION_SENSOR_Axes_t angular_velocity;
  
  (void)BSP_MOTION_SENSOR_Init(MOTION_SENSOR_ISM330DHCX_0, MOTION_GYRO);
  (void)BSP_MOTION_SENSOR_Enable(MOTION_SENSOR_ISM330DHCX_0, MOTION_GYRO);
  
  while (1)
  {
    BSP_LCD_Clear(0,SSD1315_COLOR_BLACK);
    BSP_LCD_Refresh(0);
    UTIL_LCD_DisplayStringAt(0, 0, (uint8_t *)"Gyroscope Measure ", CENTER_MODE);
    UTIL_LCD_DrawRect(0, 0, 127 , 11, SSD1315_COLOR_WHITE);
    BSP_LCD_Refresh(0);
    memset(&angular_velocity, 0, sizeof(MOTION_SENSOR_Axes_t));
    (void)BSP_MOTION_SENSOR_GetAxes(MOTION_SENSOR_ISM330DHCX_0, MOTION_GYRO, &angular_velocity);
    sprintf(gyr_x," GYRO_X = %d", angular_velocity.x);
    sprintf(gyr_y," GYRO_Y = %d", angular_velocity.y);
    sprintf(gyr_z," GYRO_Z = %d", angular_velocity.z);
    UTIL_LCD_DisplayStringAt(0, 25, (uint8_t *)gyr_x, LEFT_MODE);
    UTIL_LCD_DisplayStringAt(0, 37, (uint8_t *)gyr_y, LEFT_MODE);
    UTIL_LCD_DisplayStringAt(0, 49, (uint8_t *)gyr_z, LEFT_MODE);
    BSP_LCD_Refresh(0);
    HAL_Delay(1000);
    
    if(CheckForUserInput() > 0)
    {
      ButtonState = 0;
      (void)BSP_MOTION_SENSOR_Disable(MOTION_SENSOR_ISM330DHCX_0, MOTION_GYRO);
      (void)BSP_MOTION_SENSOR_DeInit(MOTION_SENSOR_ISM330DHCX_0);
      return;
    }
  }
}

/**
  * @}
  */ 

/**
  * @}
  */
 
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/