diff --git a/examples/generic/i2c_multiplex/main.cpp b/examples/generic/i2c_multiplex/main.cpp index 1c4de04ca2..742007da9c 100644 --- a/examples/generic/i2c_multiplex/main.cpp +++ b/examples/generic/i2c_multiplex/main.cpp @@ -114,9 +114,8 @@ main() modm::platform::I2cMaster1::connect(); modm::platform::I2cMaster1::initialize(); - constexpr uint32_t rate = 1; // Hz - constexpr float interval = 1000.0 / rate; // msec - modm::ShortPeriodicTimer heartbeat(interval); + constexpr std::chrono::milliseconds interval{1000}; + modm::ShortPeriodicTimer heartbeat{interval}; // Main loop DeviceThread deviceThread; diff --git a/examples/generic/resumable/main.cpp b/examples/generic/resumable/main.cpp index d8a4d61635..a8cfec5291 100644 --- a/examples/generic/resumable/main.cpp +++ b/examples/generic/resumable/main.cpp @@ -10,9 +10,12 @@ #include #include +#include using Led = Board::LedGreen; +using namespace std::chrono_literals; + class BlinkingLight : public modm::pt::Protothread, private modm::NestedResumable<2> { public: @@ -31,7 +34,7 @@ class BlinkingLight : public modm::pt::Protothread, private modm::NestedResumabl PT_CALL(waitForTimer()); Led::reset(); - PT_CALL(setTimer(200)); + PT_CALL(setTimer(200ms)); PT_WAIT_UNTIL(timeout.isExpired()); } @@ -45,7 +48,7 @@ class BlinkingLight : public modm::pt::Protothread, private modm::NestedResumabl RF_BEGIN(); // nested calling is allowed - if (RF_CALL(setTimer(100))) + if (RF_CALL(setTimer(100ms))) { RF_WAIT_UNTIL(timeout.isExpired()); RF_RETURN(true); @@ -55,7 +58,7 @@ class BlinkingLight : public modm::pt::Protothread, private modm::NestedResumabl } modm::ResumableResult - setTimer(uint16_t new_timeout) + setTimer(std::chrono::milliseconds new_timeout) { RF_BEGIN(); @@ -78,7 +81,7 @@ BlinkingLight light; int main(void) { - while (true) { - light.run(); - } + while (true) { + light.run(); + } } diff --git a/examples/generic/rtc_ds1302/main.cpp b/examples/generic/rtc_ds1302/main.cpp index 2fdc1ea193..fff50bc2ea 100644 --- a/examples/generic/rtc_ds1302/main.cpp +++ b/examples/generic/rtc_ds1302/main.cpp @@ -12,6 +12,9 @@ #include #include #include +#include + +using namespace std::chrono_literals; struct ds1302_config : public modm::ds1302::Config { @@ -77,9 +80,9 @@ main() // Side effect: set seconds to 0 ds1302::enableOscillator(); - uint16_t tt = 9995; // Milliseconds + auto tt = 9995ms; modm::Timeout timeout; - timeout.restart(std::chrono::milliseconds(tt)); + timeout.restart(tt); // Periodically report progress modm::PeriodicTimer blinkTimer(250ms); @@ -102,9 +105,9 @@ main() ds1302::readRtc(rtc_data); uint8_t seconds = rtc_data.getSeconds(); - MODM_LOG_DEBUG.printf("\b* %2d.%03d seconds from CPU are %2d seconds from RTC.\n", - tt / 1000, - tt % 1000, + MODM_LOG_DEBUG.printf("\b* %2lld.%03lld seconds from CPU are %2d seconds from RTC.\n", + tt.count() / 1000, + tt.count() % 1000, seconds); // Reset seconds to 0 @@ -112,9 +115,9 @@ main() // Adjust timeout time by some milliseconds to match RTC time. if (seconds >= 10) { - tt -= 20; + tt -= 20ms; } else { - tt += 1; + tt += 1ms; } timeout.restart(tt);