Why is Timer's "read_ms" method deprecated in the upcoming Mbed OS 6?

To save time, make the source code more readable and avoid frustration with typos, for larger programs one can define macros for example as follows:

#include "mbed.h"

#define timer_read_f(x)     chrono::duration<float>((x).elapsed_time()).count()
#define timer_read_s(x)     chrono::duration_cast<chrono::seconds>((x).elapsed_time()).count();
#define timer_read_ms(x)    chrono::duration_cast<chrono::milliseconds>((x).elapsed_time()).count()
#define timer_read_us(x)    (x).elapsed_time().count()

int main() {
    Timer t;
    t.start();
    ThisThread::sleep_for(1s);
    t.stop();
    auto f = timer_read_f(t);
    auto s = timer_read_s(t);
    auto ms = timer_read_ms(t);
    auto us = timer_read_us(t);
    printf ("Timer time: %f s\n", f);
    printf ("Timer time: %llu s\n", s);
    printf ("Timer time: %llu ms\n", ms);
    printf ("Timer time: %llu us\n", us);
}
3 Likes