Skip to content

Commit 5bcae4f

Browse files
committed
Convert time related functions to std::chrono
To get rid of deprecation warnings
1 parent f5d5b46 commit 5bcae4f

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

cores/arduino/Tone.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#include "Arduino.h"
22
#include "mbed.h"
33

4+
using namespace std::chrono_literals;
5+
using namespace std::chrono;
6+
47
class Tone {
58
mbed::DigitalOut *pin;
69
mbed::Timer timer;
@@ -21,7 +24,7 @@ class Tone {
2124
}
2225

2326
void start(void) {
24-
ticker.attach(mbed::callback(this, &Tone::toggle), 0.5f / float(frequency));
27+
ticker.attach(mbed::callback(this, &Tone::toggle), 500ms / frequency );
2528
if (duration != 0) {
2629
start_timeout();
2730
}
@@ -37,7 +40,7 @@ class Tone {
3740
}
3841

3942
void start_timeout(void) {
40-
timeout.attach(mbed::callback(this, &Tone::stop), duration/1000.0f);
43+
timeout.attach(mbed::callback(this, &Tone::stop), duration * 1ms);
4144
}
4245
};
4346

cores/arduino/wiring.cpp

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,22 @@ static mbed::LowPowerTimer t;
3232
static mbed::Timer t;
3333
#endif
3434

35+
using namespace std::chrono_literals;
36+
using namespace std::chrono;
37+
3538
unsigned long millis()
3639
{
37-
return t.read_ms();
40+
return duration_cast<milliseconds>(t.elapsed_time()).count();
3841
}
3942

4043
unsigned long micros() {
41-
return t.read_us();
44+
return t.elapsed_time().count();
4245
}
4346

4447
void delay(unsigned long ms)
4548
{
4649
#ifndef NO_RTOS
47-
rtos::ThisThread::sleep_for(ms);
50+
rtos::ThisThread::sleep_for(ms * 1ms);
4851
#else
4952
wait_us(ms * 1000);
5053
#endif

0 commit comments

Comments
 (0)