littleshrimp 发表于 2018-4-30 19:08

vl53l0x测距程序,BlueNRG-1发送,手机显示



/******************** (C) COPYRIGHT 2016 STMicroelectronics ********************
* File Name          : BLE_Beacon_main.c
* Author             : AMS - VMA RF Application Team
* Version            : V1.1.0
* Date               : 20-May-2016
* Description      : BlueNRG-1 main file for beacon device
********************************************************************************
* THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS
* WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE TIME.
* AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY DIRECT,
* INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING FROM THE
* CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE CODING
* INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.
*******************************************************************************/
/** @addtogroup BlueNRG1_demonstrations_applications
*BlueNRG-1 Beacon demo \see BLE_Beacon_main.c for documentation.
*
*@{
*/

/** @} */
/** \cond DOXYGEN_SHOULD_SKIP_THIS
*/

/* Includes ------------------------------------------------------------------*/
#include <stdio.h>
#include <string.h>
#include "BlueNRG1_it.h"
#include "BlueNRG1_conf.h"
#include "ble_const.h"
#include "bluenrg1_stack.h"
#include "sleep.h"
#include "SDK_EVAL_Config.h"
#include "Beacon_config.h"
#include "OTA_btl.h"
#include "BlueNRG-1_prox.h"

/* Private typedef -----------------------------------------------------------*/
/* Private define ------------------------------------------------------------*/
#define BLE_BEACON_VERSION_STRING "1.1.0"

/* Set to 1 for enabling Flags AD Type position at the beginning
   of the advertising packet */
#define ENABLE_FLAGS_AD_TYPE_AT_BEGINNING 1

#define H16(x)(((int) (x)) >> 8)
#define L16(x)(((int) (x)))

void *VL53L0X_0_handler = NULL;
volatile uint8_t no_VL53L0X = 0;
uint16_t range;
/* Private macro -------------------------------------------------------------*/
/* Private variables ---------------------------------------------------------*/
/* Private function prototypes -----------------------------------------------*/
/* Private functions ---------------------------------------------------------*/

void Device_Init(void)
{
uint8_t ret;
uint16_t service_handle;
uint16_t dev_name_char_handle;
uint16_t appearance_char_handle;

/* Set the TX Power to -2 dBm */
ret = aci_hal_set_tx_power_level(1,4);
if(ret != 0) {
    printf ("Error in aci_hal_set_tx_power_level() 0x%04xr\n", ret);
    while(1);
}

/* Init the GATT */
ret = aci_gatt_init();
if (ret != 0)
    printf ("Error in aci_gatt_init() 0x%04xr\n", ret);
else
    printf ("aci_gatt_init() --> SUCCESS\r\n");

/* Init the GAP */
ret = aci_gap_init(0x01, 0x00, 0x08, &service_handle,
                     &dev_name_char_handle, &appearance_char_handle);
if (ret != 0)
    printf ("Error in aci_gap_init() 0x%04x\r\n", ret);
else
    printf ("aci_gap_init() --> SUCCESS\r\n");
}


/**
* @briefStart beaconing
* @paramNone
* @retval None
*/
static void Start_Beaconing(void)
{
uint8_t ret = BLE_STATUS_SUCCESS;

#if ENABLE_FLAGS_AD_TYPE_AT_BEGINNING
/* Set AD Type Flags at beginning on Advertising packet*/
uint8_t adv_data[] = {
      /* Advertising data: Flags AD Type */
      0x02,
      0x01,
      0x06,
      /* Advertising data: manufacturer specific data */
      26, //len
      AD_TYPE_MANUFACTURER_SPECIFIC_DATA,//manufacturer type
      0x30, 0x00, //Company identifier code (Default is 0x0030 - STMicroelectronics: To be customized for specific identifier)
      0x02,       // ID
      0x15,       //Length of the remaining payload
      0xE2, 0x0A, 0x39, 0xF4, 0x73, 0xF5, 0x4B, 0xC4, //Location UUID
      0xA1, 0x2F, 0x17, 0xD1, 0xAD, 0x07, 0xA9, 0x61,
      0x00, 0x00, // Major number
      0x00, 0x00, // Minor number
      0xC8      //2's complement of the Tx power (-56dB)};      
   };
#else
   uint8_t manuf_data[] = {
      26, //len
      AD_TYPE_MANUFACTURER_SPECIFIC_DATA, //manufacturer type
      0x30, 0x00, //Company identifier code (Default is 0x0030 - STMicroelectronics: To be customized for specific identifier)
      0x02,       // ID
      0x15,       //Length of the remaining payload
      0xE2, 0x0A, 0x39, 0xF4, 0x73, 0xF5, 0x4B, 0xC4, //Location UUID
      0xA1, 0x2F, 0x17, 0xD1, 0xAD, 0x07, 0xA9, 0x61,
      0x00, 0x00, // Major number
      0x00, 0x00, // Minor number
      0xC8      //2's complement of the Tx power (-56dB)};      
   };
#endif
   
/* disable scan response */
ret = hci_le_set_scan_response_data(0,NULL);
if (ret != BLE_STATUS_SUCCESS)
{
    printf ("Error in hci_le_set_scan_resp_data() 0x%04x\r\n", ret);
    return;
}
else
    printf ("hci_le_set_scan_resp_data() --> SUCCESS\r\n");

/* put device in non connectable mode */
ret = aci_gap_set_discoverable(ADV_NONCONN_IND, 160, 160, PUBLIC_ADDR, NO_WHITE_LIST_USE,
                                 0, NULL, 0, NULL, 0, 0);
if (ret != BLE_STATUS_SUCCESS)
{
    printf ("Error in aci_gap_set_discoverable() 0x%04x\r\n", ret);
    return;
}
else
    printf ("aci_gap_set_discoverable() --> SUCCESS\r\n");

#if ENABLE_FLAGS_AD_TYPE_AT_BEGINNING
/* Set theADV data with the Flags AD Type at beginning of the
   advertsing packet,followed by the beacon manufacturer specific data */
ret = hci_le_set_advertising_data (sizeof(adv_data), adv_data);
if (ret != BLE_STATUS_SUCCESS)
{
    printf ("Error in hci_le_set_advertising_data() 0x%04x\r\n", ret);
    return;
}
else
    printf ("hci_le_set_advertising_data() --> SUCCESS\r\n");
#else
/* Delete the TX power level information */
ret = aci_gap_delete_ad_type(AD_TYPE_TX_POWER_LEVEL);
if (ret != BLE_STATUS_SUCCESS)
{
    printf ("Error in aci_gap_delete_ad_type() 0x%04x\r\n", ret);
    return;
}
else
    printf ("aci_gap_delete_ad_type() --> SUCCESS\r\n");

/* Update the ADV data with the BEACON manufacturing data */
ret = aci_gap_update_adv_data(27, manuf_data);
if (ret != BLE_STATUS_SUCCESS)
{
    printf ("Error in aci_gap_update_adv_data() 0x%04x\r\n", ret);
    return;
}
else
    printf ("aci_gap_update_adv_data() --> SUCCESS\r\n");
#endif
}
void PROX_Measurement(void)
{
uint8_t proxStatus, pDataready;
BSP_PROX_IsInitialized( VL53L0X_0_handler, &proxStatus );
if(proxStatus == 1)
{
    BSP_PROX_Start_Measurement(VL53L0X_0_handler);
    do
    {
      BSP_PROX_Get_Measurement_DataReady( VL53L0X_0_handler, &pDataready);
    }
    while(!pDataready);
    BSP_PROX_Get_Range(VL53L0X_0_handler, &range);
}
}
static void Update_Beaconing(void)
{
/* Set AD Type Flags at beginning on Advertising packet*/
uint8_t adv_data[] = {
      /* Advertising data: Flags AD Type */
      0x02,
      0x01,
      0x06,
      2,
      H16(range),
      L16(range),
};
/* Update the ADV data with the BEACON manufacturing data */
hci_le_set_advertising_data (sizeof(adv_data), adv_data);
}
int main(void)
{
uint8_t ret;

/* System Init */
SystemInit();

/* Identify BlueNRG-1 platform */
SdkEvalIdentification();

/* Init the UART peripheral */
SdkEvalComUartInit(UART_BAUDRATE);

ret = SysTick_Config(SYST_CLOCK/2);

/* BlueNRG-1 stack init */
ret = BlueNRG_Stack_Initialization(&BlueNRG_Stack_Init_params);
if (ret != BLE_STATUS_SUCCESS) {
    printf("Error in BlueNRG_Stack_Initialization() 0x%02x\r\n", ret);
    while(1);
}

/* Init the BlueNRG-1 device */
Device_Init();

#if ST_USE_OTA_SERVICE_MANAGER_APPLICATION
/* Initialize the button */
SdkEvalPushButtonInit(BUTTON_1);
#endif /* ST_USE_OTA_SERVICE_MANAGER_APPLICATION */

/* Start Beacon Non Connectable Mode*/
Start_Beaconing();

printf("BlueNRG-1 BLE Beacon Application (version: %s)\r\n", BLE_BEACON_VERSION_STRING);
if (BSP_PROX_Init( VL53L0X_0, &VL53L0X_0_handler) == COMPONENT_ERROR)
{
    no_VL53L0X=1;
}
while(1)
{
    /* BlueNRG-1 stack tick */
    BTLE_StackTick();
    PROX_Measurement();
    Update_Beaconing();
    /* Enable Power Save according the Advertising Interval */
    BlueNRG_Sleep(SLEEPMODE_NOTIMER, 0, 0);
   
#if ST_USE_OTA_SERVICE_MANAGER_APPLICATION
    if (SdkEvalPushButtonGetState(BUTTON_1) == RESET)
    {
      OTA_Jump_To_Service_Manager_Application();
    }
#endif /* ST_USE_OTA_SERVICE_MANAGER_APPLICATION */
}
}

/****************** BlueNRG-1 Sleep Management Callback ********************************/

SleepModes App_SleepMode_Check(SleepModes sleepMode)
{
if(SdkEvalComIOTxFifoNotEmpty())
    return SLEEPMODE_CPU_HALT;

return SLEEPMODE_NOTIMER;
}

/***************************************************************************************/

#ifdefUSE_FULL_ASSERT

/**
* @briefReports the name of the source file and the source line number
*         where the assert_param error has occurred.
* @paramfile: pointer to the source file name
* @paramline: assert_param error line source number
*/
void assert_failed(uint8_t* file, uint32_t line)
{
/* User can add his own implementation to report the file name and line number,
ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */

/* Infinite loop */
while (1)
{
}
}

#endif

/******************* (C) COPYRIGHT 2015 STMicroelectronics *****END OF FILE****/
/** \endcond
*/



工程文件
**** Hidden Message *****

vctest 发表于 2018-5-9 22:32

啥情况。。

LYJ002 发表于 2018-8-31 15:44

目前正在寻找着方面的资料

kingmingcn 发表于 2018-9-25 17:23

学习了

JimmyKudo 发表于 2018-10-31 21:51

虾总,基于L1测距作为入口的人流统计有好的思路或者资料吗?

littleshrimp 发表于 2018-10-31 21:58

JimmyKudo 发表于 2018-10-31 21:51
虾总,基于L1测距作为入口的人流统计有好的思路或者资料吗?

单个传感器不一定能满足精准人流检测,可以试试传感器阵列,我觉得应该能实现
具体和你的实际环境和安装位置有关

zuoxf 发表于 2018-12-4 15:55

VL53L1X 新版本出来了,已经买了样品,焊接搞坏了一个。好脆弱

littleshrimp 发表于 2018-12-4 16:54

zuoxf 发表于 2018-12-4 15:55
VL53L1X 新版本出来了,已经买了样品,焊接搞坏了一个。好脆弱

确实不是很好焊

wky2013 发表于 2019-1-2 11:15

学习了!

j23456 发表于 2019-3-17 14:30

如果您要查看本帖隐藏内容请回复

verify 发表于 2019-3-23 14:28

{:1_138:}

herowav18665969 发表于 2019-4-25 16:05


谢谢楼主分享

1234568765 发表于 2023-11-6 10:11

好东西

lanhua 发表于 2023-11-25 14:30

<p>vl53l0x测距程序,BlueNRG-1发送,手机显示</p>

<p>好元件。好资料</p>

<p>。</p>

hjl2832 发表于 2024-2-26 13:59

<p>我现在要用VL53L3,参考一下这个</p>
页: [1]
查看完整版本: vl53l0x测距程序,BlueNRG-1发送,手机显示