BLE设置广播时间
#define TGAP_LIM_ADV_TIMEOUT 1 //!< Maximum time to remain advertising, when in Limited Discoverable mode.Default 180 seconds. (n * 1 seconds)
比如设置60s广播时间
GAP_SetParamValue(TGAP_LIM_ADV_TIMEOUT,60);
运行效果
重新开启广播是因为,广播关闭以后会进,重新开启了广播(如果想停,关闭广播即可)
static void hidEmuStateCB(gapRole_States_t newState, gapRoleEvent_t *pEvent) { switch(newState) { case GAPROLE_WAITING: if(pEvent->gap.opcode == GAP_END_DISCOVERABLE_DONE_EVENT) { PRINT("Waiting for advertising..\n"); } else if(pEvent->gap.opcode == GAP_LINK_TERMINATED_EVENT) { PRINT("Disconnected.. Reason:%x\n", pEvent->linkTerminate.reason); } else if(pEvent->gap.opcode == GAP_LINK_ESTABLISHED_EVENT) { PRINT("Advertising timeout..\n"); } // Enable advertising { uint8_t initial_advertising_enable = TRUE; // Set the GAP Role Parameters GAPRole_SetParameter(GAPROLE_ADVERT_ENABLED, sizeof(uint8_t), &initial_advertising_enable); } break; } }