1 of 1 people found this helpful
This is fine, as long as the function you are calling does not do complex tasks (such as reading from the flash, accessing bonding data, accessing I2C, SPI interfaces etc.,)
If the function is complex, I recommend you to simply set a flag in the BLE Event Callback. In the for loop of the main function, this flag is constantly polled to see if it has been set, upon which the function to be executed is called.
This is done because, it is not recommended to call complex functions in BLE Callback.
- Madhu Sudhan
/** Event parameter type is CYBLE_GATTS_CHAR_VAL_READ_REQ_T. It is 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. */
Thus, unless you only want it to run for certain characteristic responses, you don't really need to check what handle/value is being read/sent.
void BleCallBack( uint32 event, void* eventParam )
switch( event )
rdRspParam = ( CYBLE_GATTS_READ_RSP_PARAM_T * ) eventParam;
if( rdRspParam->attrHandle == CYBLE_DIAPER_BUCKLE_STOREDDIAPERCOUNT_CHAR_HANDLE; )
//code to run upon specific characteristic being read
//code that runs upon any characteristic being read
Please note: As mady stated, if you are doing any long/involved calculations or functions that take up time, you will want to run them in main instead, and to only set the trigger/flag in the event here.
This also allows for more event-based programming too; With main loop being run continuously, and functions being called only when triggered by events or changes.
Yes, I should have thought of that. Thanks much!