I'm working on modifying the ble_app_uart pca10040_s132 to send strings stored in flash memory over BLE to the nRF connect app on an iphone. From what I understand the uart_event_handle is called every time an input to uart is read and sends the data under the case APP_UART_DATA_READY if a new line is read. I don't understand how the program is calling this uart_event_handle function though.
To understand the program I tried to understand the sequence of events in main. From what I understand the advertising_start() function is called (after everything is initialized) which I assume starts the advertising, and contains a ble_evt_handler function with the case BLE_GAP_EVT_CONNECTED which handles the connection from the phone and exits the advertising_start() function. Assuming at this point I've just connected on the phone app, I don't understand how main knows when uart_events happen and how to handle subsequent disconnection and connection events as the only code left in main is the for loop to handle the idle state.
How and from where is the uart_event_handle function called? I want to modify the program by adding a different event handler that would get a string from flash memory and send it over BLE, but I don't know how to replace uart_event_handle since I don't understand where it is being called from. If someone could explain how the advertising_start function handles the connection events and where the uart_event_handle is being called from or how the program knows when words have been sent to the uart port that would be greatly helpful, thanks!

