Skip to content

Commit e726492

Browse files
remove the sadly deprecated read_ms function
1 parent 62308e8 commit e726492

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

BLE_GAP/source/main.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,8 @@ static const ble::scan_duration_t scan_duration(ble::millisecond_t(10000));
8181

8282
events::EventQueue event_queue;
8383

84+
using namespace std::chrono;
85+
using std::milli;
8486
using namespace std::literals::chrono_literals;
8587

8688
/* Delay between steps */
@@ -261,6 +263,12 @@ class GapDemo : private mbed::NonCopyable<GapDemo>, public ble::Gap::EventHandle
261263
_demo_duration.start();
262264
}
263265

266+
/* helper function to hide the casts */
267+
int read_demo_duration_in_ms()
268+
{
269+
return duration_cast<duration<int, milli>>(_demo_duration.elapsed_time()).count();
270+
}
271+
264272
private:
265273
/* Gap::EventHandler */
266274

@@ -359,7 +367,7 @@ class GapDemo : private mbed::NonCopyable<GapDemo>, public ble::Gap::EventHandle
359367
return;
360368
}
361369

362-
printf("Connected in %dms\r\n", _demo_duration.read_ms());
370+
printf("Connected in %dms\r\n", read_demo_duration_in_ms());
363371

364372
/* cancel the connect timeout since we connected */
365373
_event_queue.cancel(_cancel_handle);
@@ -503,7 +511,7 @@ class GapDemo : private mbed::NonCopyable<GapDemo>, public ble::Gap::EventHandle
503511
void print_scanning_performance()
504512
{
505513
/* measure time from mode start, may have been stopped by timeout */
506-
uint16_t duration_ms = _demo_duration.read_ms();
514+
uint16_t duration_ms = read_demo_duration_in_ms();
507515

508516
/* convert ms into timeslots for accurate calculation as internally
509517
* all durations are in timeslots (0.625ms) */
@@ -528,7 +536,7 @@ class GapDemo : private mbed::NonCopyable<GapDemo>, public ble::Gap::EventHandle
528536
void print_advertising_performance()
529537
{
530538
/* measure time from mode start, may have been stopped by timeout */
531-
uint16_t duration_ms = _demo_duration.read_ms();
539+
uint16_t duration_ms = read_demo_duration_in_ms();
532540

533541
/* convert ms into timeslots for accurate calculation as internally
534542
* all durations are in timeslots (0.625ms) */

0 commit comments

Comments
 (0)