5439|14

9716

帖子

24

TA的资源

版主

楼主
 

vl53l0x测距程序,BlueNRG-1发送,手机显示 [复制链接]

 
 

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

  20. /** @} */
  21. /** \cond DOXYGEN_SHOULD_SKIP_THIS
  22. */

  23. /* Includes ------------------------------------------------------------------*/
  24. #include <stdio.h>
  25. #include <string.h>
  26. #include "BlueNRG1_it.h"
  27. #include "BlueNRG1_conf.h"
  28. #include "ble_const.h"
  29. #include "bluenrg1_stack.h"
  30. #include "sleep.h"
  31. #include "SDK_EVAL_Config.h"
  32. #include "Beacon_config.h"
  33. #include "OTA_btl.h"
  34. #include "BlueNRG-1_prox.h"

  35. /* Private typedef -----------------------------------------------------------*/
  36. /* Private define ------------------------------------------------------------*/
  37. #define BLE_BEACON_VERSION_STRING "1.1.0"

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

  41. #define H16(x)  (((int) (x)) >> 8)
  42. #define L16(x)  (((int) (x)))

  43. void *VL53L0X_0_handler = NULL;
  44. volatile uint8_t no_VL53L0X = 0;
  45. uint16_t range;
  46. /* Private macro -------------------------------------------------------------*/
  47. /* Private variables ---------------------------------------------------------*/
  48. /* Private function prototypes -----------------------------------------------*/
  49. /* Private functions ---------------------------------------------------------*/

  50. void Device_Init(void)
  51. {
  52.   uint8_t ret;
  53.   uint16_t service_handle;
  54.   uint16_t dev_name_char_handle;
  55.   uint16_t appearance_char_handle;
  56.   
  57.   /* Set the TX Power to -2 dBm */
  58.   ret = aci_hal_set_tx_power_level(1,4);
  59.   if(ret != 0) {
  60.     printf ("Error in aci_hal_set_tx_power_level() 0x%04xr\n", ret);
  61.     while(1);
  62.   }

  63.   /* Init the GATT */
  64.   ret = aci_gatt_init();
  65.   if (ret != 0)
  66.     printf ("Error in aci_gatt_init() 0x%04xr\n", ret);
  67.   else
  68.     printf ("aci_gatt_init() --> SUCCESS\r\n");
  69.   
  70.   /* Init the GAP */
  71.   ret = aci_gap_init(0x01, 0x00, 0x08, &service_handle,
  72.                      &dev_name_char_handle, &appearance_char_handle);
  73.   if (ret != 0)
  74.     printf ("Error in aci_gap_init() 0x%04x\r\n", ret);
  75.   else
  76.     printf ("aci_gap_init() --> SUCCESS\r\n");
  77. }


  78. /**
  79. * [url=home.php?mod=space&uid=159083]@brief[/url]  Start beaconing
  80. * @param  None
  81. * @retval None
  82. */
  83. static void Start_Beaconing(void)
  84. {  
  85.   uint8_t ret = BLE_STATUS_SUCCESS;

  86. #if ENABLE_FLAGS_AD_TYPE_AT_BEGINNING
  87.   /* Set AD Type Flags at beginning on Advertising packet  */
  88.   uint8_t adv_data[] = {
  89.       /* Advertising data: Flags AD Type */
  90.       0x02,
  91.       0x01,
  92.       0x06,
  93.       /* Advertising data: manufacturer specific data */
  94.       26, //len
  95.       AD_TYPE_MANUFACTURER_SPECIFIC_DATA,  //manufacturer type
  96.       0x30, 0x00, //Company identifier code (Default is 0x0030 - STMicroelectronics: To be customized for specific identifier)
  97.       0x02,       // ID
  98.       0x15,       //Length of the remaining payload
  99.       0xE2, 0x0A, 0x39, 0xF4, 0x73, 0xF5, 0x4B, 0xC4, //Location UUID
  100.       0xA1, 0x2F, 0x17, 0xD1, 0xAD, 0x07, 0xA9, 0x61,
  101.       0x00, 0x00, // Major number
  102.       0x00, 0x00, // Minor number
  103.       0xC8        //2's complement of the Tx power (-56dB)};      
  104.    };
  105. #else
  106.    uint8_t manuf_data[] = {
  107.       26, //len
  108.       AD_TYPE_MANUFACTURER_SPECIFIC_DATA, //manufacturer type
  109.       0x30, 0x00, //Company identifier code (Default is 0x0030 - STMicroelectronics: To be customized for specific identifier)
  110.       0x02,       // ID
  111.       0x15,       //Length of the remaining payload
  112.       0xE2, 0x0A, 0x39, 0xF4, 0x73, 0xF5, 0x4B, 0xC4, //Location UUID
  113.       0xA1, 0x2F, 0x17, 0xD1, 0xAD, 0x07, 0xA9, 0x61,
  114.       0x00, 0x00, // Major number
  115.       0x00, 0x00, // Minor number
  116.       0xC8        //2's complement of the Tx power (-56dB)};      
  117.    };
  118. #endif
  119.    
  120.   /* disable scan response */
  121.   ret = hci_le_set_scan_response_data(0,NULL);
  122.   if (ret != BLE_STATUS_SUCCESS)
  123.   {
  124.     printf ("Error in hci_le_set_scan_resp_data() 0x%04x\r\n", ret);
  125.     return;
  126.   }
  127.   else
  128.     printf ("hci_le_set_scan_resp_data() --> SUCCESS\r\n");

  129.   /* put device in non connectable mode */
  130.   ret = aci_gap_set_discoverable(ADV_NONCONN_IND, 160, 160, PUBLIC_ADDR, NO_WHITE_LIST_USE,
  131.                                  0, NULL, 0, NULL, 0, 0);
  132.   if (ret != BLE_STATUS_SUCCESS)
  133.   {
  134.     printf ("Error in aci_gap_set_discoverable() 0x%04x\r\n", ret);
  135.     return;
  136.   }
  137.   else
  138.     printf ("aci_gap_set_discoverable() --> SUCCESS\r\n");

  139. #if ENABLE_FLAGS_AD_TYPE_AT_BEGINNING
  140.   /* Set the  ADV data with the Flags AD Type at beginning of the
  141.      advertsing packet,  followed by the beacon manufacturer specific data */
  142.   ret = hci_le_set_advertising_data (sizeof(adv_data), adv_data);
  143.   if (ret != BLE_STATUS_SUCCESS)
  144.   {
  145.     printf ("Error in hci_le_set_advertising_data() 0x%04x\r\n", ret);
  146.     return;
  147.   }
  148.   else
  149.     printf ("hci_le_set_advertising_data() --> SUCCESS\r\n");
  150. #else
  151.   /* Delete the TX power level information */
  152.   ret = aci_gap_delete_ad_type(AD_TYPE_TX_POWER_LEVEL);
  153.   if (ret != BLE_STATUS_SUCCESS)
  154.   {
  155.     printf ("Error in aci_gap_delete_ad_type() 0x%04x\r\n", ret);
  156.     return;
  157.   }
  158.   else
  159.     printf ("aci_gap_delete_ad_type() --> SUCCESS\r\n");

  160.   /* Update the ADV data with the BEACON manufacturing data */
  161.   ret = aci_gap_update_adv_data(27, manuf_data);  
  162.   if (ret != BLE_STATUS_SUCCESS)
  163.   {
  164.     printf ("Error in aci_gap_update_adv_data() 0x%04x\r\n", ret);
  165.     return;
  166.   }
  167.   else
  168.     printf ("aci_gap_update_adv_data() --> SUCCESS\r\n");
  169. #endif
  170. }
  171. void PROX_Measurement(void)
  172. {
  173.   uint8_t proxStatus, pDataready;
  174.   BSP_PROX_IsInitialized( VL53L0X_0_handler, &proxStatus );
  175.   if(proxStatus == 1)
  176.   {
  177.     BSP_PROX_Start_Measurement(VL53L0X_0_handler);
  178.     do
  179.     {
  180.       BSP_PROX_Get_Measurement_DataReady( VL53L0X_0_handler, &pDataready);
  181.     }
  182.     while(!pDataready);
  183.     BSP_PROX_Get_Range(VL53L0X_0_handler, &range);
  184.   }
  185. }
  186. static void Update_Beaconing(void)
  187. {
  188.   /* Set AD Type Flags at beginning on Advertising packet  */
  189.   uint8_t adv_data[] = {
  190.       /* Advertising data: Flags AD Type */
  191.       0x02,
  192.       0x01,
  193.       0x06,
  194.       2,
  195.       H16(range),
  196.       L16(range),
  197.   };
  198.   /* Update the ADV data with the BEACON manufacturing data */
  199.   hci_le_set_advertising_data (sizeof(adv_data), adv_data);
  200. }
  201. int main(void)
  202. {
  203.   uint8_t ret;
  204.   
  205.   /* System Init */
  206.   SystemInit();
  207.   
  208.   /* Identify BlueNRG-1 platform */
  209.   SdkEvalIdentification();

  210.   /* Init the UART peripheral */
  211.   SdkEvalComUartInit(UART_BAUDRATE);
  212.   
  213.   ret = SysTick_Config(SYST_CLOCK/2);

  214.   /* BlueNRG-1 stack init */
  215.   ret = BlueNRG_Stack_Initialization(&BlueNRG_Stack_Init_params);
  216.   if (ret != BLE_STATUS_SUCCESS) {
  217.     printf("Error in BlueNRG_Stack_Initialization() 0x%02x\r\n", ret);
  218.     while(1);
  219.   }
  220.   
  221.   /* Init the BlueNRG-1 device */
  222.   Device_Init();

  223. #if ST_USE_OTA_SERVICE_MANAGER_APPLICATION
  224.   /* Initialize the button */
  225.   SdkEvalPushButtonInit(BUTTON_1);
  226. #endif /* ST_USE_OTA_SERVICE_MANAGER_APPLICATION */
  227.   
  228.   /* Start Beacon Non Connectable Mode*/
  229.   Start_Beaconing();
  230.   
  231.   printf("BlueNRG-1 BLE Beacon Application (version: %s)\r\n", BLE_BEACON_VERSION_STRING);
  232.   if (BSP_PROX_Init( VL53L0X_0, &VL53L0X_0_handler) == COMPONENT_ERROR)
  233.   {
  234.     no_VL53L0X=1;
  235.   }
  236.   while(1)
  237.   {
  238.     /* BlueNRG-1 stack tick */
  239.     BTLE_StackTick();
  240.     PROX_Measurement();
  241.     Update_Beaconing();
  242.     /* Enable Power Save according the Advertising Interval */
  243.     BlueNRG_Sleep(SLEEPMODE_NOTIMER, 0, 0);
  244.    
  245. #if ST_USE_OTA_SERVICE_MANAGER_APPLICATION
  246.     if (SdkEvalPushButtonGetState(BUTTON_1) == RESET)
  247.     {
  248.       OTA_Jump_To_Service_Manager_Application();
  249.     }
  250. #endif /* ST_USE_OTA_SERVICE_MANAGER_APPLICATION */
  251.   }
  252. }

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

  254. SleepModes App_SleepMode_Check(SleepModes sleepMode)
  255. {
  256.   if(SdkEvalComIOTxFifoNotEmpty())
  257.     return SLEEPMODE_CPU_HALT;
  258.   
  259.   return SLEEPMODE_NOTIMER;
  260. }

  261. /***************************************************************************************/

  262. #ifdef  USE_FULL_ASSERT

  263. /**
  264. * @brief  Reports the name of the source file and the source line number
  265. *         where the assert_param error has occurred.
  266. * @param  file: pointer to the source file name
  267. * @param  line: assert_param error line source number
  268. */
  269. void assert_failed(uint8_t* file, uint32_t line)
  270. {
  271.   /* User can add his own implementation to report the file name and line number,
  272.   ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */
  273.   
  274.   /* Infinite loop */
  275.   while (1)
  276.   {
  277.   }
  278. }

  279. #endif

  280. /******************* (C) COPYRIGHT 2015 STMicroelectronics *****END OF FILE****/
  281. /** \endcond
  282. */
复制代码



工程文件
游客,如果您要查看本帖隐藏内容请回复


最新回复

我现在要用VL53L3,参考一下这个   详情 回复 发表于 2024-2-26 13:59
点赞 关注(1)
个人签名虾扯蛋,蛋扯虾,虾扯蛋扯虾
 
 

回复
举报

2

帖子

0

TA的资源

一粒金砂(初级)

沙发
 
啥情况。。
 
 
 

回复

2

帖子

0

TA的资源

一粒金砂(初级)

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

回复

3

帖子

0

TA的资源

一粒金砂(初级)

4
 
 
 
 

回复

8

帖子

0

TA的资源

一粒金砂(中级)

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

点评

单个传感器不一定能满足精准人流检测,可以试试传感器阵列,我觉得应该能实现 具体和你的实际环境和安装位置有关  详情 回复 发表于 2018-10-31 21:58
 
 
 

回复

9716

帖子

24

TA的资源

版主

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

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

回复

16

帖子

0

TA的资源

一粒金砂(中级)

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

点评

确实不是很好焊  详情 回复 发表于 2018-12-4 16:54
 
 
 

回复

9716

帖子

24

TA的资源

版主

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

确实不是很好焊
个人签名虾扯蛋,蛋扯虾,虾扯蛋扯虾
 
 
 

回复

3

帖子

0

TA的资源

一粒金砂(初级)

9
 
学习了!
 
 
 

回复

5

帖子

0

TA的资源

一粒金砂(初级)

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

回复

2

帖子

0

TA的资源

一粒金砂(初级)

11
 
 
 

回复

8

帖子

0

TA的资源

一粒金砂(初级)

12
 

谢谢楼主分享
 
 
 

回复

1

帖子

0

TA的资源

一粒金砂(初级)

13
 
 
 
 

回复

719

帖子

0

TA的资源

纯净的硅(高级)

14
 

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

好元件。好资料

 
 
 

回复

351

帖子

3

TA的资源

纯净的硅(初级)

15
 

我现在要用VL53L3,参考一下这个

 
 
 

回复
您需要登录后才可以回帖 登录 | 注册

随便看看
查找数据手册?

EEWorld Datasheet 技术支持

相关文章 更多>>
关闭
站长推荐上一条 1/10 下一条

 
EEWorld订阅号

 
EEWorld服务号

 
汽车开发圈

About Us 关于我们 客户服务 联系方式 器件索引 网站地图 最新更新 手机版

站点相关: 国产芯 安防电子 汽车电子 手机便携 工业控制 家用电子 医疗电子 测试测量 网络通信 物联网

北京市海淀区中关村大街18号B座15层1530室 电话:(010)82350740 邮编:100190

电子工程世界版权所有 京B2-20211791 京ICP备10001474号-1 电信业务审批[2006]字第258号函 京公网安备 11010802033920号 Copyright © 2005-2024 EEWORLD.com.cn, Inc. All rights reserved
快速回复 返回顶部 返回列表