| BlueNRG-1 DK: BLE examples

- Main Page
- Modules
- Files

- File List

SensorDemo_main.c
Go to the documentation of this file.
1
2 /******************** (C) COPYRIGHT 2016 STMicroelectronics ********************
3 * File Name : SensorDemo_main.c
4 * Author : VMA DIVISION
5 * Version : 1.1.0
6 * Date : 15-January-2016
7 * Description : Code demostrating a proprietary Bluetooth Low Energy profile: the sensor profile.
8 ********************************************************************************
9 * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
10 * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
11 * AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
12 * INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
13 * CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
14 * INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
15 *******************************************************************************/
16
196 /* Includes ------------------------------------------------------------------*/
197 #include <stdio.h>
198 #include "BlueNRG1_it.h"
199 #include "BlueNRG1_conf.h"
200 #include "ble_const.h"
201 #include "bluenrg1_stack.h"
202 #include "SDK_EVAL_Config.h"
203 #include "sleep.h"
204 #include "sensor.h"
205 #include "SensorDemo_config.h"
206 #include "OTA_btl.h"
207
208 /* Private typedef -----------------------------------------------------------*/
209 /* Private define ------------------------------------------------------------*/
210 #ifndef DEBUG
211 #define DEBUG 0
212 #endif
213
214 #if DEBUG
215 #include <stdio.h>
216 #define PRINTF(...) printf(__VA_ARGS__)
217 #else
218 #define PRINTF(...)
219 #endif
220
221 #define BLE_SENSOR_VERSION_STRING "1.0.0"
222
223 /* Private macro -------------------------------------------------------------*/
224 /* Private variables ---------------------------------------------------------*/
225 /* Private function prototypes -----------------------------------------------*/
226 /* Private functions ---------------------------------------------------------*/
227
228 int main(void)
229 {
230 uint8_t ret;
231
232 /* System Init */
233 SystemInit();
234
235 /* Identify BlueNRG1 platform */
236 SdkEvalIdentification();
237
238 /* Configure I/O communication channel */
239 SdkEvalComUartInit(UART_BAUDRATE);
240
241 /* BlueNRG-1 stack init */
242 ret = BlueNRG_Stack_Initialization(&BlueNRG_Stack_Init_params);
243 if (ret != BLE_STATUS_SUCCESS) {
244 printf("Error in BlueNRG_Stack_Initialization() 0x%02x\r\n", ret);
245 while(1);
246 }
247
248 /* Application demo Led Init */
249 SdkEvalLedInit(LED1); //Activity led
250 SdkEvalLedInit(LED3); //Error led
251 SdkEvalLedOn(LED1);
252 SdkEvalLedOff(LED3);
253
254 PRINTF("BlueNRG-1 BLE Sensor Demo Application (version: %s)\r\n", BLE_SENSOR_VERSION_STRING);
255
256 /* Sensor Device Init */
257 ret = Sensor_DeviceInit();
258 if (ret != BLE_STATUS_SUCCESS) {
259 SdkEvalLedOn(LED3);
260 while(1);
261 }
262
263 #if ST_USE_OTA_SERVICE_MANAGER_APPLICATION
264 /* Initialize the button */
265 SdkEvalPushButtonInit(BUTTON_1);
266 #endif /* ST_USE_OTA_SERVICE_MANAGER_APPLICATION */
267
268 while(1)
269 {
270 /* BLE Stack Tick */
271 BTLE_StackTick();
272
273 /* Application Tick */
274 APP_Tick();
275
276 /* Power Save management */
277 BlueNRG_Sleep(SLEEPMODE_WAKETIMER, 0, 0, 0);
278
279 #if ST_OTA_FIRMWARE_UPGRADE_SUPPORT
280 /* Check if the OTA firmware upgrade session has been completed */
281 if (OTA_Tick() == 1)
282 {
283 /* Jump to the new application */
284 OTA_Jump_To_New_Application();
285 }
286 #endif /* ST_OTA_FIRMWARE_UPGRADE_SUPPORT */
287
288 #if ST_USE_OTA_SERVICE_MANAGER_APPLICATION
289 if (SdkEvalPushButtonGetState(BUTTON_1) == RESET)
290 {
291 OTA_Jump_To_Service_Manager_Application();
292 }
293 #endif /* ST_USE_OTA_SERVICE_MANAGER_APPLICATION */
294 }/* while (1) */
295 }
296
297 #ifdef USE_FULL_ASSERT
298 /*******************************************************************************
299 * Function Name : assert_failed
300 * Description : Reports the name of the source file and the source line number
301 * where the assert_param error has occurred.
302 * Input : - file: pointer to the source file name
303 * - line: assert_param error line source number
304 * Output : None
305 * Return : None
306 *******************************************************************************/
307 void assert_failed(uint8_t* file, uint32_t line)
308 {
309 /* User can add his own implementation to report the file name and line number,
310 ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
311
312 /* Infinite loop */
313 while (1)
314 {}
315 }
316 #endif
317
318 /******************* (C) COPYRIGHT 2015 STMicroelectronics *****END OF FILE****/