我觉得这个区别来源于FIRMWARE中间sensor_service.c中的LED蓝牙属性的添加、LED_UPDATE()函数回报LED状态以及LedOnTargetPlatform()/LedOffTargetPlatform()来控制SensorTile小灯的点亮和关闭。
- ///line 847-852
- COPY_LED_W2ST_CHAR_UUID(uuid);
- ret = aci_gatt_add_char(HWServW2STHandle, UUID_TYPE_128, uuid, 2+1,
- CHAR_PROP_NOTIFY | CHAR_PROP_READ,
- ATTR_PERMISSION_NONE,
- GATT_NOTIFY_READ_REQ_AND_WAIT_FOR_APPL_RESP,
- 16, 0, &LedCharHandle);
- ///这段代码先把LED的CHAR_UUID通过aci_gatt_add_char添加到蓝牙服务中。这个特性是NOTIFY和READ。这样就可以把LED状态NOTIFY给上位机同时也能通过READ读取上位机的LED的指令。
- ///line 991-2012
- tBleStatus LED_Update(uint8_t LedStatus)
- {
- tBleStatus ret;
- uint8_t buff[2+1];
- STORE_LE_16(buff ,(HAL_GetTick()>>3));
- buff[2] = LedStatus;
- ret = aci_gatt_update_char_value(HWServW2STHandle, LedCharHandle, 0, 2+1,buff);
- if (ret != BLE_STATUS_SUCCESS){
- if(W2ST_CHECK_CONNECTION(W2ST_CONNECT_STD_ERR)){
- BytesToWrite = sprintf((char *)BufferToWrite, "Error Updating LED Char\r\n");
- Stderr_Update(BufferToWrite,BytesToWrite);
- } else {
- OSX_BMS_PRINTF("Error Updating Temp Char\r\n");
- }
- return BLE_STATUS_ERROR;
- }
- return BLE_STATUS_SUCCESS;
- }
- ///这个LED_UPDATE()函数将LED的状态通过aci_gatt_char_value返回给上位机。
- ///line2310-2334
- case FEATURE_MASK_LED:
- /* Led events */
- #ifdef OSX_BMS_DEBUG_CONNECTION
- if(W2ST_CHECK_CONNECTION(W2ST_CONNECT_STD_TERM)) {
- BytesToWrite = sprintf((char *)BufferToWrite,"Conf Sig F=%lx C=%2x\n\r",FeatureMask,Command);
- Term_Update(BufferToWrite,BytesToWrite);
- } else {
- OSX_BMS_PRINTF("Conf Sig F=%lx C=%2x\r\n",FeatureMask,Command);
- }
- #endif /* OSX_BMS_DEBUG_CONNECTION */
- switch(Command) {
- case 1:
- LedOnTargetPlatform();
- Config_Notify(FEATURE_MASK_LED,Command,Data);
- break;
- case 0:
- LedOffTargetPlatform();
- Config_Notify(FEATURE_MASK_LED,Command,Data);
- break;
- }
- /* Update the LED feature */
- if(W2ST_CHECK_CONNECTION(W2ST_CONNECT_LED)) {
- LED_Update(TargetBoardFeatures.LedStatus);
- }
- break;
- ///这里是通过LedOffTargetPlatform()和LedOnTargetPlatform()来关闭或者点亮SensorTile上的LED的。
如果你希望在BlueMicrosystem2的基础上加入LED控制的部分,可以尝试添加上面的蓝牙属性/LED_Update函数来实现LED控制和状态的汇报。
供您参考。