In my code, I have some 'print'-style functions that write data to a buffer, and that buffer then goes to the Nordic UART implementation. This is user code, and I don't know when it's 'done' printing. Let's say something like this happens:
output_char('{');
for (int i=0;i<10;i++) {
output_str(foo);
output_char(':');
output_str(bar);
output_char(',');
}
output_char('}');
And:
void output_char(char ch) {
if (!is_ble_busy) nus_string_send(as_string(ch));
else add_to_buffer(ch);
}
void nus_string_is_sent(char ch) {
if (!buffer_empty) nus_string_send(buffer_as_string());
}
So my problem is that on the first output_char
I call ble_nus_string_send
immediately with just one character, and then everything else goes into a buffer while I wait for an acknowledgement that the data has been received.
Ideally I would put everything into a buffer and then issue a ble_nus_string_send
only after I'd filled the buffer or a timeout had passed.
Now obviously I could add a timer, but is there an interrupt I could use that fires just before the timeslot where BLE notification data could be written? For instance could I use ble_radio_notification_init
or something similar?
Something like:
void output_char(char ch) {
add_to_buffer(ch);
}
void ble_radio_notification() {
if (!buffer_empty) nus_string_send(buffer_as_string());
}