I am trying to find a way to connect and disconnect a BLE HID keyboard. I would like to connect to an iOS device as a keyboard to send characters, then, when certain activity on the SensorTag occurs, disconnect-and later reconnect.
I have moved the HID profile from the key fob to the SensorTag. That works great.
I have been able to disconnect the keyboard using a call to GAPRole_TerminateKeyboard. Unfortunately, the SensorTag aggressively reconnected, causing the iOS software keyboard to vanish. Based on a suggestion from Zahid, I have been able to keep the keyboard disconnected by bypassing the call to oral_set_event(gapRole_TaskID, START_ADVERTISING_EVT); in the gapRole_ProcessGAPMesg function.
What I still lack is a way to reestablish the connection when the KeyFob is ready to send more characters. I've tried many permutations; the most recent is this function in peripheral.c:
void restartConnection () { gapRole_AdvEnabled = TRUE; VOID osal_set_event(gapRole_TaskID, START_ADVERTISING_EVT); if (pGapRoles_AppCGs && pGapRoles_AppGSs->pfnStateChange) { pGapRoles_AppCGs->pfnStateChange( gapRole_state ); } }
I have checked the variables in peripheral.c pretty carefully, and the state is the same when I make this call as it is when the original code was doing the same thing to reestablish the connection. Nothing seems to reestablish the connection.
1. What is the proper way to reestablish the connection once it is broken with GAPRole_TerminateKeyboard?
2. Is this the wrong approach? Is there a better way to enable/disable the BLE HID keyboard from the SensorTag?