static void controlBLECentral_HandleKeys( uint8 shift, uint8 keys ) { (void)shift; // Intentionally unreferenced parameter uint8 adc; if(keys & KEY_FUN1) { app_write_string("\r\ngot the KEY_FUN1 V:"); adc=halGetVoltageMonitorInput(); app_write_string( uint8_to_string(adc)); HalLedSet( HAL_LED_1 , HAL_LED_MODE_FLASH ); } if(keys & KEY_FUN2) { app_write_string("\r\ngot the KEY_FUN2"); HalLedSet(HAL_LED_2, HAL_LED_MODE_BLINK); } if ( keys & HAL_KEY_UP ) { // Start or stop discovery if ( simpleBLEState != BLE_STATE_CONNECTED ) { if ( !simpleBLEScanning ) { simpleBLEScanning = TRUE; simpleBLEScanRes = 0; LCD_WRITE_STRING( "Discovering...", HAL_LCD_LINE_1 ); LCD_WRITE_STRING( "", HAL_LCD_LINE_2 ); GAPCentralRole_StartDiscovery( DEFAULT_DISCOVERY_MODE, DEFAULT_DISCOVERY_ACTIVE_SCAN, DEFAULT_DISCOVERY_WHITE_LIST ); } else { GAPCentralRole_CancelDiscovery(); } } else if ( simpleBLEState == BLE_STATE_CONNECTED && simpleBLECharHdl != 0 && simpleBLEProcedureInProgress == FALSE ) { uint8 status; // Do a read or write as long as no other read or write is in progress if ( simpleBLEDoWrite ) { // Do a write attWriteReq_t req; req.handle = simpleBLECharHdl; req.len = 1; req.value[0] = simpleBLECharVal; req.sig = 0; req.cmd = 0; status = GATT_WriteCharValue( simpleBLEConnHandle, &req, simpleBLETaskId ); } else { // Do a read attReadReq_t req; req.handle = simpleBLECharHdl; status = GATT_ReadCharValue( simpleBLEConnHandle, &req, simpleBLETaskId ); } if ( status == SUCCESS ) { simpleBLEProcedureInProgress = TRUE; simpleBLEDoWrite = !simpleBLEDoWrite; } } } if ( keys & HAL_KEY_LEFT ) { // Display discovery results if ( !simpleBLEScanning && simpleBLEScanRes > 0 ) { // Increment index of current result (with wraparound) simpleBLEScanIdx++; if ( simpleBLEScanIdx >= simpleBLEScanRes ) { simpleBLEScanIdx = 0; } LCD_WRITE_STRING_VALUE( "Device", simpleBLEScanIdx + 1, 10, HAL_LCD_LINE_1 ); LCD_WRITE_STRING( bdAddr2Str( simpleBLEDevList[simpleBLEScanIdx].addr ), HAL_LCD_LINE_2 ); } } if ( keys & HAL_KEY_RIGHT ) { // Connection update if ( simpleBLEState == BLE_STATE_CONNECTED ) { GAPCentralRole_UpdateLink( simpleBLEConnHandle, DEFAULT_UPDATE_MIN_CONN_INTERVAL, DEFAULT_UPDATE_MAX_CONN_INTERVAL, DEFAULT_UPDATE_SLAVE_LATENCY, DEFAULT_UPDATE_CONN_TIMEOUT ); } } if ( keys & HAL_KEY_CENTER ) { uint8 addrType; uint8 *peerAddr; // Connect or disconnect if ( simpleBLEState == BLE_STATE_IDLE ) { // if there is a scan result if ( simpleBLEScanRes > 0 ) { // connect to current device in scan result peerAddr = simpleBLEDevList[simpleBLEScanIdx].addr; addrType = simpleBLEDevList[simpleBLEScanIdx].addrType; simpleBLEState = BLE_STATE_CONNECTING; GAPCentralRole_EstablishLink( DEFAULT_LINK_HIGH_DUTY_CYCLE, DEFAULT_LINK_WHITE_LIST, addrType, peerAddr ); LCD_WRITE_STRING( "Connecting", HAL_LCD_LINE_1 ); LCD_WRITE_STRING( bdAddr2Str( peerAddr ), HAL_LCD_LINE_2 ); } } else if ( simpleBLEState == BLE_STATE_CONNECTING || simpleBLEState == BLE_STATE_CONNECTED ) { // disconnect simpleBLEState = BLE_STATE_DISCONNECTING; gStatus = GAPCentralRole_TerminateLink( simpleBLEConnHandle ); LCD_WRITE_STRING( "Disconnecting", HAL_LCD_LINE_1 ); } } if ( keys & HAL_KEY_DOWN ) { // Start or cancel RSSI polling if ( simpleBLEState == BLE_STATE_CONNECTED ) { if ( !simpleBLERssi ) { simpleBLERssi = TRUE; GAPCentralRole_StartRssi( simpleBLEConnHandle, DEFAULT_RSSI_PERIOD ); } else { simpleBLERssi = FALSE; GAPCentralRole_CancelRssi( simpleBLEConnHandle ); LCD_WRITE_STRING( "RSSI Cancelled", HAL_LCD_LINE_1 ); } } } }
/********************************************************************* * @fn OADManager_ProcessEvent * * @brief OAD Manager Application Task event processor. This function * is called to process all events for the task. Events * include timers, messages and any other user defined events. * * @param task_id - The OSAL assigned task ID. * @param events - events to process. This is a bit map and can * contain more than one event. * * @return events not processed */ uint16 OADManager_ProcessEvent( uint8 task_id, uint16 events ) { if ( events & SYS_EVENT_MSG ) { uint8 *pMsg; if ( (pMsg = osal_msg_receive( task_id )) != NULL ) { oadManager_ProcessOSALMsg( (osal_event_hdr_t *)pMsg ); VOID osal_msg_deallocate( pMsg ); } return (events ^ SYS_EVENT_MSG); } if ( events & DEV_DISCOVERY_EVT ) { oadManagerDevDiscovery(); return ( events ^ DEV_DISCOVERY_EVT ); } if ( events & SVC_DISCOVERY_EVT ) { oadManagerSvcDiscovery(); return ( events ^ SVC_DISCOVERY_EVT ); } if ( events & CCC_DISCOVERY_EVT ) { oadManagerCCCDiscovery(); return ( events ^ CCC_DISCOVERY_EVT ); } if ( events & CHAR_DISCOVERY_EVT ) { oadManagerCharDiscovery(); return ( events ^ CHAR_DISCOVERY_EVT ); } if ( events & CONN_INTERVAL_EVT ) { (void)osal_set_event(oadManagerTaskId, SVC_DISCOVERY_EVT); GAPCentralRole_UpdateLink( oadManagerConnHandle, DEFAULT_OAD_MIN_CONN_INTERVAL, DEFAULT_OAD_MAX_CONN_INTERVAL, DEFAULT_OAD_SLAVE_LATENCY, DEFAULT_OAD_CONN_TIMEOUT ); return ( events ^ CONN_INTERVAL_EVT ); } if ( events & START_DEVICE_EVT ) { VOID GAPCentralRole_StartDevice( (gapCentralRoleCB_t *) &oadManagerRoleCB ); oadManagerDevDiscovery(); return ( events ^ START_DEVICE_EVT ); } if ( events & OAD_DOWNLOAD_EVT ) { #if (defined HAL_LCD) && (HAL_LCD == TRUE) if ( (oadBlkNum + 1) >= oadBlkTot ) { LCD_WRITE_STRING("OAD Completed!", HAL_LCD_LINE_3); } else { LCD_WRITE_STRING("OAD Failed!", HAL_LCD_LINE_3); } #endif return ( events ^ OAD_DOWNLOAD_EVT ); } return 0; }