/************************************************************* * Function : dictShow * Author : bulldozer.ma * Date : 2015-11-01 * Input : dict *pHeader * Output : N/A * Return : int * Other : N/A * Description : show all **************************************************************/ int dictShow(dict *pHeader) { int iRet = DICT_ERROR; if (NULL == pHeader) { return DICT_ERROR; } iRet = ShowValue(pHeader->ht[0]); if (dictIsRehashing(pHeader)) { iRet = ShowValue(pHeader->ht[1]); } return iRet; }
void ScaleObj::CreateScale(MotifUI *parent, char *title, int value, int numDecimalPoints, int max, int min, int scaleMultiple, ScaleType style, boolean showValue) { _style = style; _value = value; _numDecimalPoints = numDecimalPoints; _max = max; _min = min; _scaleMultiple = scaleMultiple; _style = style; _showValue = showValue; CheckValues(false); int orientation; short points = _numDecimalPoints; if (_style == VERTICAL_SCALE) orientation = XmVERTICAL; else orientation = XmHORIZONTAL; XmString xm_string = StringCreate(title); _w = XtVaCreateManagedWidget(title, xmFormWidgetClass, parent->InnerWidget(), NULL); _minLabel = XtVaCreateWidget(title, xmLabelWidgetClass, _w, XmNtopAttachment, XmATTACH_FORM, XmNbottomAttachment, XmATTACH_FORM, XmNleftAttachment, XmATTACH_FORM, NULL); _maxLabel = XtVaCreateWidget(title, xmLabelWidgetClass, _w, XmNtopAttachment, XmATTACH_FORM, XmNbottomAttachment, XmATTACH_FORM, XmNrightAttachment, XmATTACH_FORM, NULL); _scale = XtVaCreateManagedWidget(title, xmScaleWidgetClass, _w, XmNmaximum, _max, XmNminimum, _min, XmNvalue, _value, XmNscaleMultiple, _scaleMultiple, XmNdecimalPoints, points, XmNtitleString, xm_string, XmNshowValue, _showValue, XmNtopAttachment, XmATTACH_FORM, XmNbottomAttachment, XmATTACH_FORM, XmNorientation, orientation, NULL); StringFree(xm_string); SetString(_minLabel, _min); SetString(_maxLabel, _max); ShowValue(_showValue); }
/******************************************************************************* * Function Name: CpsCallBack() ******************************************************************************** * * Summary: * This is an event callback function to receive service specific events from * Cycling Power Service. * * Parameters: * event - the event code * *eventParam - the event parameters * * Return: * None. * *******************************************************************************/ void CpsCallback(uint32 event, void *eventParam) { CYBLE_API_RESULT_T apiResult = CYBLE_ERROR_OK; uint8 i; uint8 locCharIndex; locCharIndex = ((CYBLE_CPS_CHAR_VALUE_T *)eventParam)->charIndex; DBG_PRINTF("CPS event: %lx, ", event); switch(event) { /* CPS Server - Notifications for Cycling Power Service Characteristic was enabled. The parameter of this event is a structure of CYBLE_CPS_CHAR_VALUE_T type. */ case CYBLE_EVT_CPSS_NOTIFICATION_ENABLED: DBG_PRINTF("CYBLE_EVT_CPSS_NOTIFICATION_ENABLED: char: %x\r\n", locCharIndex); if(locCharIndex == CYBLE_CPS_POWER_MEASURE) { powerSimulation |= CPS_NOTIFICATION_MEASURE_ENABLE; } if(locCharIndex == CYBLE_CPS_POWER_VECTOR) { powerSimulation |= CPS_NOTIFICATION_VECTOR_ENABLE; } break; /* CPS Server - Notifications for Cycling Power Service Characteristic was disabled. The parameter of this event is a structure of CYBLE_CPS_CHAR_VALUE_T type */ case CYBLE_EVT_CPSS_NOTIFICATION_DISABLED: DBG_PRINTF("CYBLE_EVT_CPSS_NOTIFICATION_DISABLED: char: %x\r\n", locCharIndex); if(locCharIndex == CYBLE_CPS_POWER_MEASURE) { powerSimulation &= ~CPS_NOTIFICATION_MEASURE_ENABLE; } if(locCharIndex == CYBLE_CPS_POWER_VECTOR) { powerSimulation &= ~CPS_NOTIFICATION_VECTOR_ENABLE; } break; /* CPS Server - Indication for Cycling Power Service Characteristic was enabled. The parameter of this event is a structure of CYBLE_CPS_CHAR_VALUE_T type */ case CYBLE_EVT_CPSS_INDICATION_ENABLED: DBG_PRINTF("CYBLE_EVT_CPSS_INDICATION_ENABLED: char: %x\r\n", locCharIndex); powerSimulation |= CPS_INDICATION_ENABLE; break; /* CPS Server - Indication for Cycling Power Service Characteristic was disabled. The parameter of this event is a structure of CYBLE_CPS_CHAR_VALUE_T type */ case CYBLE_EVT_CPSS_INDICATION_DISABLED: DBG_PRINTF("CYBLE_EVT_CPSS_INDICATION_DISABLED: char: %x\r\n", locCharIndex); powerSimulation &= ~CPS_INDICATION_ENABLE; break; /* CPS Server - Cycling Power Service Characteristic Indication was confirmed. The parameter of this event is a structure of CYBLE_CPS_CHAR_VALUE_T type */ case CYBLE_EVT_CPSS_INDICATION_CONFIRMED: DBG_PRINTF("CYBLE_EVT_CPSS_INDICATION_CONFIRMED: char: %x\r\n", locCharIndex); break; /* CPS Server - Broadcast for Cycling Power Service Characteristic was enabled. The parameter of this event is a structure of CYBLE_CPS_CHAR_VALUE_T type */ case CYBLE_EVT_CPSS_BROADCAST_ENABLED: DBG_PRINTF("CYBLE_EVT_CPSS_BROADCAST_ENABLED: char: %x\r\n", locCharIndex); powerSimulation |= CPS_BROADCAST_ENABLE; break; /* CPS Server - Broadcast for Cycling Power Service Characteristic was disabled. The parameter of this event is a structure of CYBLE_CPS_CHAR_VALUE_T type */ case CYBLE_EVT_CPSS_BROADCAST_DISABLED: DBG_PRINTF("CYBLE_EVT_CPSS_BROADCAST_DISABLED: char: %x\r\n", locCharIndex); powerSimulation &= ~CPS_BROADCAST_ENABLE; CyBle_CpssStopBroadcast(); DBG_PRINTF("Stop Broadcast \r\n"); break; /* CPS Server - Write Request for Cycling Power Service Characteristic was received. The parameter of this event is a structure of CYBLE_CPS_CHAR_VALUE_T type. */ case CYBLE_EVT_CPSS_CHAR_WRITE: DBG_PRINTF("CYBLE_EVT_CPSS_CHAR_WRITE: %x ", locCharIndex); ShowValue(((CYBLE_CPS_CHAR_VALUE_T *)eventParam)->value); if(locCharIndex == CYBLE_CPS_POWER_CP) { uint8 cpOpCode; cpOpCode = ((CYBLE_CPS_CHAR_VALUE_T *)eventParam)->value->val[0]; /* Prepare general response */ powerCPResponse = 1u; powerCPData[CYBLE_CPS_CP_RESP_LENGTH] = 3u; /* Length of response */ powerCPData[CYBLE_CPS_CP_RESP_OP_CODES] = CYBLE_CPS_CP_OC_RC; powerCPData[CYBLE_CPS_CP_RESP_REQUEST_OP_CODE] = cpOpCode; powerCPData[CYBLE_CPS_CP_RESP_VALUE] = CYBLE_CPS_CP_RC_SUCCESS; DBG_PRINTF("CP Opcode %x: ", cpOpCode); switch(cpOpCode) { case CYBLE_CPS_CP_OC_SCV: DBG_PRINTF("Set Cumulative Value \r\n"); /* Initiate the procedure to set a cumulative value. The new value is sent as parameter following op code (parameter defined per service). The response to this control point is Op Code 0x20 followed by the appropriate Response Value. */ if(((CYBLE_CPS_CHAR_VALUE_T *)eventParam)->value->len == (sizeof(uint32) + 1u)) { powerMeasure.cumulativeWheelRevolutions = *(uint32 *)&((CYBLE_CPS_CHAR_VALUE_T *)eventParam)->value->val[1]; } else { powerCPData[CYBLE_CPS_CP_RESP_VALUE] = CYBLE_CPS_CP_RC_INVALID_PARAMETER; } break; case CYBLE_CPS_CP_OC_USL: DBG_PRINTF("Update Sensor Location \r\n"); /* Update to the location of the Sensor with the value sent as parameter to this op code. The response to this control point is Op Code 0x20 followed by the appropriate Response Value. */ if(((CYBLE_CPS_CHAR_VALUE_T *)eventParam)->value->val[1] < CYBLE_CPS_SL_COUNT) { apiResult = CyBle_CpssSetCharacteristicValue(CYBLE_CPS_SENSOR_LOCATION, sizeof(uint8), &((CYBLE_CPS_CHAR_VALUE_T *)eventParam)->value->val[1]); } else { powerCPData[CYBLE_CPS_CP_RESP_VALUE] = CYBLE_CPS_CP_RC_INVALID_PARAMETER; } (void)apiResult; DBG_PRINTF("CyBle_CpssSetCharacteristicValue SENSOR_LOCATION, API result: %x \r\n", apiResult); break; case CYBLE_CPS_CP_OC_RSSL: DBG_PRINTF("Request Supported Sensor Locations \r\n"); /* Request a list of supported locations where the Sensor can be attached. The response to this control point is Op Code 0x20 followed by the appropriate Response Value, including a list of supported Sensor locations in the Response Parameter. */ powerCPData[CYBLE_CPS_CP_RESP_LENGTH] += CYBLE_CPS_SL_COUNT; /* Length of response */ for(i = 0; i < CYBLE_CPS_SL_COUNT; i++) { powerCPData[CYBLE_CPS_CP_RESP_PARAMETER + i] = i; } break; case CYBLE_CPS_CP_OC_SCRL: DBG_PRINTF("Set Crank Length \r\n"); /* Initiate the procedure to set the crank length value to Sensor. The new value is sent as a parameter with preceding Op Code 0x04 operand. The response to this control point is Op Code 0x20 followed by the appropriate Response Value. */ if(((CYBLE_CPS_CHAR_VALUE_T *)eventParam)->value->len == (sizeof(uint16) + 1u)) { cyBle_cpssAdjustment.crankLength = *(uint16 *)&((CYBLE_CPS_CHAR_VALUE_T *)eventParam)->value->val[1]; } else { powerCPData[CYBLE_CPS_CP_RESP_VALUE] = CYBLE_CPS_CP_RC_INVALID_PARAMETER; } break; case CYBLE_CPS_CP_OC_RCRL: DBG_PRINTF(" Request Crank Length \r\n"); powerCPData[CYBLE_CPS_CP_RESP_LENGTH] += sizeof(cyBle_cpssAdjustment.crankLength); /* Length of response */ CyBle_Set16ByPtr(powerCPData + CYBLE_CPS_CP_RESP_PARAMETER, cyBle_cpssAdjustment.crankLength); break; case CYBLE_CPS_CP_OC_SCHL: DBG_PRINTF("Set Chain Length \r\n"); if(((CYBLE_CPS_CHAR_VALUE_T *)eventParam)->value->len == (sizeof(uint16) + 1u)) { cyBle_cpssAdjustment.chainLength = *(uint16 *)&((CYBLE_CPS_CHAR_VALUE_T *)eventParam)->value->val[1]; } else { powerCPData[CYBLE_CPS_CP_RESP_VALUE] = CYBLE_CPS_CP_RC_INVALID_PARAMETER; } break; case CYBLE_CPS_CP_OC_RCHL: DBG_PRINTF("Request Chain Length \r\n"); powerCPData[CYBLE_CPS_CP_RESP_LENGTH] += sizeof(cyBle_cpssAdjustment.chainLength); /* Length of response */ CyBle_Set16ByPtr(powerCPData + CYBLE_CPS_CP_RESP_PARAMETER, cyBle_cpssAdjustment.chainLength); break; case CYBLE_CPS_CP_OC_SCHW: DBG_PRINTF("Set Chain Weight \r\n"); if(((CYBLE_CPS_CHAR_VALUE_T *)eventParam)->value->len == (sizeof(uint16) + 1u)) { cyBle_cpssAdjustment.chainWeight = *(uint16 *)&((CYBLE_CPS_CHAR_VALUE_T *)eventParam)->value->val[1]; } else { powerCPData[CYBLE_CPS_CP_RESP_VALUE] = CYBLE_CPS_CP_RC_INVALID_PARAMETER; } break; case CYBLE_CPS_CP_OC_RCHW: DBG_PRINTF("Request Chain Weight \r\n"); powerCPData[CYBLE_CPS_CP_RESP_LENGTH] += sizeof(cyBle_cpssAdjustment.chainWeight); /* Length of response */ CyBle_Set16ByPtr(powerCPData + CYBLE_CPS_CP_RESP_PARAMETER, cyBle_cpssAdjustment.chainWeight); break; case CYBLE_CPS_CP_OC_SSL: DBG_PRINTF("Set Span Length \r\n"); if(((CYBLE_CPS_CHAR_VALUE_T *)eventParam)->value->len == (sizeof(uint16) + 1u)) { cyBle_cpssAdjustment.spanLength = *(uint16 *)&((CYBLE_CPS_CHAR_VALUE_T *)eventParam)->value->val[1]; } else { powerCPData[CYBLE_CPS_CP_RESP_VALUE] = CYBLE_CPS_CP_RC_INVALID_PARAMETER; } break; case CYBLE_CPS_CP_OC_RSL: DBG_PRINTF(" Request Span Length \r\n"); powerCPData[CYBLE_CPS_CP_RESP_LENGTH] += sizeof(cyBle_cpssAdjustment.spanLength); /* Length of response */ CyBle_Set16ByPtr(powerCPData + CYBLE_CPS_CP_RESP_PARAMETER, cyBle_cpssAdjustment.spanLength); break; case CYBLE_CPS_CP_OC_SOC: DBG_PRINTF("Start Offset Compensation \r\n"); powerCPData[CYBLE_CPS_CP_RESP_LENGTH] += sizeof(cyBle_cpssAdjustment.offsetCompensation); /* Length of response */ CyBle_Set16ByPtr(powerCPData + CYBLE_CPS_CP_RESP_PARAMETER, cyBle_cpssAdjustment.offsetCompensation); break; case CYBLE_CPS_CP_OC_MCPMCC: DBG_PRINTF("Mask Cycling Power Measurement Characteristic Content \r\n"); { uint16 mask = *(uint16 *)&((CYBLE_CPS_CHAR_VALUE_T *)eventParam)->value->val[1]; if((mask & CYBLE_CPS_CP_ENERGY_RESERVED) != 0u) { powerCPData[CYBLE_CPS_CP_RESP_VALUE] = CYBLE_CPS_CP_RC_INVALID_PARAMETER; } if((mask & CYBLE_CPS_CP_PEDAL_PRESENT_BIT) != 0u) { powerMeasure.flags &= ~CYBLE_CPS_CPM_PEDAL_PRESENT_BIT; } if((mask & CYBLE_CPS_CP_TORQUE_PRESENT_BIT) != 0u) { powerMeasure.flags &= ~CYBLE_CPS_CPM_TORQUE_PRESENT_BIT; } if((mask & CYBLE_CPS_CP_WHEEL_BIT) != 0u) { powerMeasure.flags &= ~CYBLE_CPS_CPM_WHEEL_BIT; } if((mask & CYBLE_CPS_CP_CRANK_BIT) != 0u) { powerMeasure.flags &= ~CYBLE_CPS_CPM_CRANK_BIT; } if((mask & CYBLE_CPS_CP_MAGNITUDES_BIT) != 0u) { powerMeasure.flags &= ~CYBLE_CPS_CPM_FORCE_MAGNITUDES_BIT; powerMeasure.flags &= ~CYBLE_CPS_CPM_TORQUE_MAGNITUDES_BIT; } if((mask & CYBLE_CPS_CP_ANGLES_BIT) != 0u) { powerMeasure.flags &= ~CYBLE_CPS_CPM_ANGLES_BIT; } if((mask & CYBLE_CPS_CP_TOP_DEAD_SPOT_BIT) != 0u) { powerMeasure.flags &= ~CYBLE_CPS_CPM_TOP_DEAD_SPOT_BIT; } if((mask & CYBLE_CPS_CP_BOTTOM_DEAD_SPOT_BIT) != 0u) { powerMeasure.flags &= ~CYBLE_CPS_CPM_BOTTOM_DEAD_SPOT_BIT; } if((mask & CYBLE_CPS_CP_ENERGY_BIT) != 0u) { powerMeasure.flags &= ~CYBLE_CPS_CPM_ENERGY_BIT; } } break; case CYBLE_CPS_CP_OC_RSR: DBG_PRINTF("Request Sampling Rate \r\n"); powerCPData[CYBLE_CPS_CP_RESP_LENGTH] += sizeof(cyBle_cpssAdjustment.samplingRate); /* Length of response */ powerCPData[CYBLE_CPS_CP_RESP_PARAMETER] = cyBle_cpssAdjustment.samplingRate; break; case CYBLE_CPS_CP_OC_RFCD: DBG_PRINTF("Request Factory Calibration Date \r\n"); powerCPData[CYBLE_CPS_CP_RESP_LENGTH] += sizeof(cyBle_cpssAdjustment.factoryCalibrationDate); /* Length of response */ memcpy(powerCPData + CYBLE_CPS_CP_RESP_PARAMETER, &cyBle_cpssAdjustment.factoryCalibrationDate, sizeof(cyBle_cpssAdjustment.factoryCalibrationDate)); break; case CYBLE_CPS_CP_OC_RC: DBG_PRINTF("Response Code \r\n"); break; default: DBG_PRINTF("Op Code Not supported \r\n"); powerCPData[CYBLE_CPS_CP_RESP_VALUE] = CYBLE_CPS_CP_RC_NOT_SUPPORTED; break; } } break; /* CPS Client - Cycling Power Service Characteristic Notification was received. The parameter of this event is a structure of CYBLE_CPS_CHAR_VALUE_T type */ case CYBLE_EVT_CPSC_NOTIFICATION: break; /* CPS Client - Cycling Power Service Characteristic Indication was received. The parameter of this event is a structure of CYBLE_CPS_CHAR_VALUE_T type */ case CYBLE_EVT_CPSC_INDICATION: break; /* CPS Client - Read Response for Read Request of Cycling Power Service Characteristic value. The parameter of this event is a structure of CYBLE_CPS_CHAR_VALUE_T type */ case CYBLE_EVT_CPSC_READ_CHAR_RESPONSE: break; /* CPS Client - Write Response for Write Request of Cycling Power Service Characteristic value. The parameter of this event is a structure of CYBLE_CPS_CHAR_VALUE_T type */ case CYBLE_EVT_CPSC_WRITE_CHAR_RESPONSE: break; /* CPS Client - Read Response for Read Request of Cycling Power Service Characteristic Descriptor Read request. The parameter of this event is a structure of CYBLE_CPS_DESCR_VALUE_T type */ case CYBLE_EVT_CPSC_READ_DESCR_RESPONSE: break; /* CPS Client - Write Response for Write Request of Cycling Power Service Characteristic Configuration Descriptor value. The parameter of this event is a structure of CYBLE_CPS_DESCR_VALUE_T type */ case CYBLE_EVT_CPSC_WRITE_DESCR_RESPONSE: break; /* CPS Client - This event is triggered every time a device receive non-connectable undirected advertising event. The parameter of this event is a structure of CYBLE_CPS_CHAR_VALUE_T type */ case CYBLE_EVT_CPSC_SCAN_PROGRESS_RESULT: break; default: DBG_PRINTF("Not supported event\r\n"); break; } }
/******************************************************************************* * Function Name: HidsCallBack() ******************************************************************************** * * Summary: * This is an event callback function to receive service specific events from * HID Service. * * Parameters: * event - the event code * *eventParam - the event parameters * * Return: * None. * ********************************************************************************/ void HidsCallBack(uint32 event, void *eventParam) { CYBLE_HIDS_CHAR_VALUE_T *locEventParam = (CYBLE_HIDS_CHAR_VALUE_T *)eventParam; DBG_PRINTF("HIDS event: %lx, ", event); switch(event) { case CYBLE_EVT_HIDSS_NOTIFICATION_ENABLED: DBG_PRINTF("CYBLE_EVT_HIDSS_NOTIFICATION_ENABLED: serv=%x, char=%x\r\n", locEventParam->serviceIndex, locEventParam->charIndex); if(CYBLE_HUMAN_INTERFACE_DEVICE_SERVICE_INDEX == locEventParam->serviceIndex) { keyboardSimulation = ENABLED; } break; case CYBLE_EVT_HIDSS_NOTIFICATION_DISABLED: DBG_PRINTF("CYBLE_EVT_HIDSS_NOTIFICATION_DISABLED: serv=%x, char=%x\r\n", locEventParam->serviceIndex, locEventParam->charIndex); if(CYBLE_HUMAN_INTERFACE_DEVICE_SERVICE_INDEX == locEventParam->serviceIndex) { keyboardSimulation = DISABLED; } break; case CYBLE_EVT_HIDSS_BOOT_MODE_ENTER: DBG_PRINTF("CYBLE_EVT_HIDSS_BOOT_MODE_ENTER \r\n"); protocol = CYBLE_HIDS_PROTOCOL_MODE_BOOT; break; case CYBLE_EVT_HIDSS_REPORT_MODE_ENTER: DBG_PRINTF("CYBLE_EVT_HIDSS_REPORT_MODE_ENTER \r\n"); protocol = CYBLE_HIDS_PROTOCOL_MODE_REPORT; break; case CYBLE_EVT_HIDSS_SUSPEND: DBG_PRINTF("CYBLE_EVT_HIDSS_SUSPEND \r\n"); suspend = CYBLE_HIDS_CP_SUSPEND; #if (DEBUG_UART_ENABLED == ENABLED) /* Reduce power consumption, power down logic that is not required to wake up the system */ UART_DEB_Stop(); #endif /* (DEBUG_UART_ENABLED == ENABLED) */ break; case CYBLE_EVT_HIDSS_EXIT_SUSPEND: #if (DEBUG_UART_ENABLED == ENABLED) /* Power up all circuitry previously shut down */ UART_DEB_Start(); #endif /* (DEBUG_UART_ENABLED == ENABLED) */ DBG_PRINTF("CYBLE_EVT_HIDSS_EXIT_SUSPEND \r\n"); suspend = CYBLE_HIDS_CP_EXIT_SUSPEND; break; case CYBLE_EVT_HIDSS_REPORT_CHAR_WRITE: if(CYBLE_HUMAN_INTERFACE_DEVICE_SERVICE_INDEX == locEventParam->serviceIndex) { /* Write request to Keyboard Output Report characteristic. * Handle Boot and Report protocol. */ if( ((CYBLE_HIDS_PROTOCOL_MODE_REPORT == protocol) && (CYBLE_HUMAN_INTERFACE_DEVICE_REPORT_OUT == locEventParam->charIndex)) || ((CYBLE_HIDS_PROTOCOL_MODE_BOOT == protocol) && (CYBLE_HIDS_BOOT_KYBRD_OUT_REP == locEventParam->charIndex)) ) { if( (CAPS_LOCK_LED & locEventParam->value->val[0u]) != 0u) { CapsLock_LED_Write(LED_ON); } else { CapsLock_LED_Write(LED_OFF); } } } DBG_PRINTF("CYBLE_EVT_HIDSS_REPORT_CHAR_WRITE: serv=%x, char=%x, value=", locEventParam->serviceIndex, locEventParam->charIndex); ShowValue(locEventParam->value); break; case CYBLE_EVT_HIDSC_NOTIFICATION: break; case CYBLE_EVT_HIDSC_READ_CHAR_RESPONSE: break; case CYBLE_EVT_HIDSC_WRITE_CHAR_RESPONSE: break; case CYBLE_EVT_HIDSC_READ_DESCR_RESPONSE: break; case CYBLE_EVT_HIDSC_WRITE_DESCR_RESPONSE: break; default: DBG_PRINTF("Not supported event\r\n"); break; } }
/******************************************************************************* * Function Name: AppCallBack() ******************************************************************************** * * Summary: * This is an event callback function to receive events from the BLE Component. * *******************************************************************************/ void AppCallBack(uint32 event, void* eventParam) { CYBLE_API_RESULT_T apiResult; CYBLE_GAP_BD_ADDR_T localAddr; CYBLE_GAP_AUTH_INFO_T *authInfo; uint8 i; switch (event) { /********************************************************** * General Events ***********************************************************/ case CYBLE_EVT_STACK_ON: /* This event is received when the component is Started */ /* Enter into discoverable mode so that remote can search it. */ apiResult = CyBle_GappStartAdvertisement(CYBLE_ADVERTISING_FAST); if(apiResult != CYBLE_ERROR_OK) { DBG_PRINTF("StartAdvertisement API Error: %d \r\n", apiResult); } DBG_PRINTF("Bluetooth On, StartAdvertisement with addr: "); localAddr.type = 0u; CyBle_GetDeviceAddress(&localAddr); for(i = CYBLE_GAP_BD_ADDR_SIZE; i > 0u; i--) { DBG_PRINTF("%2.2x", localAddr.bdAddr[i-1]); } DBG_PRINTF("\r\n"); break; case CYBLE_EVT_TIMEOUT: break; case CYBLE_EVT_HARDWARE_ERROR: /* This event indicates that some internal HW error has occurred. */ DBG_PRINTF("CYBLE_EVT_HARDWARE_ERROR \r\n"); break; /* This event will be triggered by host stack if BLE stack is busy or not busy. * Parameter corresponding to this event will be the state of BLE stack. * BLE stack busy = CYBLE_STACK_STATE_BUSY, * BLE stack not busy = CYBLE_STACK_STATE_FREE */ case CYBLE_EVT_STACK_BUSY_STATUS: DBG_PRINTF("CYBLE_EVT_STACK_BUSY_STATUS: %x\r\n", *(uint8 *)eventParam); break; case CYBLE_EVT_HCI_STATUS: DBG_PRINTF("CYBLE_EVT_HCI_STATUS: %x \r\n", *(uint8 *)eventParam); break; /********************************************************** * GAP Events ***********************************************************/ case CYBLE_EVT_GAP_AUTH_REQ: DBG_PRINTF("CYBLE_EVT_AUTH_REQ: security=%x, bonding=%x, ekeySize=%x, err=%x \r\n", (*(CYBLE_GAP_AUTH_INFO_T *)eventParam).security, (*(CYBLE_GAP_AUTH_INFO_T *)eventParam).bonding, (*(CYBLE_GAP_AUTH_INFO_T *)eventParam).ekeySize, (*(CYBLE_GAP_AUTH_INFO_T *)eventParam).authErr); break; case CYBLE_EVT_GAP_PASSKEY_ENTRY_REQUEST: DBG_PRINTF("CYBLE_EVT_PASSKEY_ENTRY_REQUEST press 'p' to enter passkey \r\n"); break; case CYBLE_EVT_GAP_PASSKEY_DISPLAY_REQUEST: DBG_PRINTF("CYBLE_EVT_PASSKEY_DISPLAY_REQUEST %6.6ld \r\n", *(uint32 *)eventParam); break; case CYBLE_EVT_GAP_KEYINFO_EXCHNGE_CMPLT: DBG_PRINTF("CYBLE_EVT_GAP_KEYINFO_EXCHNGE_CMPLT \r\n"); break; case CYBLE_EVT_GAP_AUTH_COMPLETE: authInfo = (CYBLE_GAP_AUTH_INFO_T *)eventParam; (void)authInfo; DBG_PRINTF("AUTH_COMPLETE: security:%x, bonding:%x, ekeySize:%x, authErr %x \r\n", authInfo->security, authInfo->bonding, authInfo->ekeySize, authInfo->authErr); break; case CYBLE_EVT_GAP_AUTH_FAILED: DBG_PRINTF("CYBLE_EVT_AUTH_FAILED: %x \r\n", *(uint8 *)eventParam); break; case CYBLE_EVT_GAPP_ADVERTISEMENT_START_STOP: DBG_PRINTF("CYBLE_EVT_ADVERTISING, state: %x \r\n", CyBle_GetState()); if(CYBLE_STATE_DISCONNECTED == CyBle_GetState()) { /* Fast and slow advertising period complete, go to low power * mode (Hibernate mode) and wait for an external * user event to wake up the device again */ DBG_PRINTF("Hibernate \r\n"); LED_BLU_Write(LED_OFF); LED_RED_Write(LED_ON); LED_GRN_Write(LED_OFF); SW2_ClearInterrupt(); Wakeup_Interrupt_ClearPending(); Wakeup_Interrupt_Start(); #if (DEBUG_UART_ENABLED == ENABLED) /* Wait until debug info is sent */ while((UART_DEB_SpiUartGetTxBufferSize() + UART_DEB_GET_TX_FIFO_SR_VALID) != 0); #endif /* (DEBUG_UART_ENABLED == ENABLED) */ CySysPmHibernate(); } break; case CYBLE_EVT_GAP_DEVICE_CONNECTED: DBG_PRINTF("CYBLE_EVT_GAP_DEVICE_CONNECTED \r\n"); LED_BLU_Write(LED_OFF); break; case CYBLE_EVT_GAP_DEVICE_DISCONNECTED: DBG_PRINTF("CYBLE_EVT_GAP_DEVICE_DISCONNECTED\r\n"); apiResult = CyBle_GappStartAdvertisement(CYBLE_ADVERTISING_FAST); if(apiResult != CYBLE_ERROR_OK) { DBG_PRINTF("StartAdvertisement API Error: %d \r\n", apiResult); } break; case CYBLE_EVT_GATTS_XCNHG_MTU_REQ: { uint16 mtu; CyBle_GattGetMtuSize(&mtu); DBG_PRINTF("CYBLE_EVT_GATTS_XCNHG_MTU_REQ, final mtu= %d \r\n", mtu); } break; case CYBLE_EVT_GATTS_WRITE_REQ: DBG_PRINTF("CYBLE_EVT_GATT_WRITE_REQ: %x = ",((CYBLE_GATTS_WRITE_REQ_PARAM_T *)eventParam)->handleValPair.attrHandle); ShowValue(&((CYBLE_GATTS_WRITE_REQ_PARAM_T *)eventParam)->handleValPair.value); (void)CyBle_GattsWriteRsp(((CYBLE_GATTS_WRITE_REQ_PARAM_T *)eventParam)->connHandle); break; case CYBLE_EVT_GAP_ENCRYPT_CHANGE: DBG_PRINTF("CYBLE_EVT_GAP_ENCRYPT_CHANGE: %x \r\n", *(uint8 *)eventParam); break; case CYBLE_EVT_GAPC_CONNECTION_UPDATE_COMPLETE: DBG_PRINTF("CYBLE_EVT_CONNECTION_UPDATE_COMPLETE: %x \r\n", *(uint8 *)eventParam); break; /********************************************************** * GATT Events ***********************************************************/ case CYBLE_EVT_GATT_CONNECT_IND: DBG_PRINTF("CYBLE_EVT_GATT_CONNECT_IND: %x, %x \r\n", cyBle_connHandle.attId, cyBle_connHandle.bdHandle); /* Register service specific callback functions */ HidsInit(); BasInit(); ScpsInit(); break; case CYBLE_EVT_GATT_DISCONNECT_IND: DBG_PRINTF("CYBLE_EVT_GATT_DISCONNECT_IND \r\n"); break; case CYBLE_EVT_GATTS_READ_CHAR_VAL_ACCESS_REQ: /* Triggered on server side when client sends read request and when * characteristic has CYBLE_GATT_DB_ATTR_CHAR_VAL_RD_EVENT property set. * This event could be ignored by application unless it need to response * by error response which needs to be set in gattErrorCode field of * event parameter. */ DBG_PRINTF("CYBLE_EVT_GATTS_READ_CHAR_VAL_ACCESS_REQ: handle: %x \r\n", ((CYBLE_GATTS_CHAR_VAL_READ_REQ_T *)eventParam)->attrHandle); break; /********************************************************** * Other Events ***********************************************************/ case CYBLE_EVT_PENDING_FLASH_WRITE: /* Inform application that flash write is pending. Stack internal data * structures are modified and require to be stored in Flash using * CyBle_StoreBondingData() */ DBG_PRINTF("CYBLE_EVT_PENDING_FLASH_WRITE\r\n"); break; default: DBG_PRINTF("OTHER event: %lx \r\n", event); break; } }