BLE: Add explicit constructor for Duration that accepts millisecond in input.

pull/8738/head
Vincent Coubard 2018-11-15 21:19:40 +00:00
parent fa4aa8f068
commit c165bd98b7
1 changed files with 6 additions and 0 deletions

View File

@ -18,6 +18,7 @@
#define BLE_COMMON_DURATION_H_
#include <stdint.h>
#include <stddef.h>
#include "platform/mbed_assert.h"
namespace ble {
@ -62,6 +63,11 @@ struct Duration {
MBED_STATIC_ASSERT(OtherTB >= TB && (OtherTB % TB) == 0, "Incompatible units");
}
template<typename OtherRep>
explicit Duration(Duration<OtherRep, 1000> other_ms, void* = NULL) :
duration(clamp(((other_ms.value() * 1000) + TB - 1) / TB))
{ }
Rep value() {
return duration;
}