Skip to content

Commit

Permalink
[examples] Fix outdated use of duration types
Browse files Browse the repository at this point in the history
  • Loading branch information
chris-durand committed Mar 29, 2022
1 parent 4d93b1c commit 9c34fb1
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
5 changes: 2 additions & 3 deletions examples/generic/i2c_multiplex/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,8 @@ main()
modm::platform::I2cMaster1::connect<modm::platform::GpioB7::Sda, modm::platform::GpioB6::Scl>();
modm::platform::I2cMaster1::initialize<Board::SystemClock, 100_kHz>();

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;
Expand Down
11 changes: 7 additions & 4 deletions examples/generic/resumable/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@

#include <modm/board.hpp>
#include <modm/processing.hpp>
#include <chrono>

using Led = Board::LedGreen;

using namespace std::chrono_literals;

class BlinkingLight : public modm::pt::Protothread, private modm::NestedResumable<2>
{
public:
Expand All @@ -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());
}
Expand All @@ -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);
Expand All @@ -55,7 +58,7 @@ class BlinkingLight : public modm::pt::Protothread, private modm::NestedResumabl
}

modm::ResumableResult<bool>
setTimer(uint16_t new_timeout)
setTimer(std::chrono::milliseconds new_timeout)
{
RF_BEGIN();

Expand All @@ -79,6 +82,6 @@ BlinkingLight light;
int main(void)
{
while (true) {
light.run();
light.run();
}
}
17 changes: 10 additions & 7 deletions examples/generic/rtc_ds1302/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
#include <modm/board.hpp>
#include <modm/processing/timer.hpp>
#include <modm/driver/rtc/ds1302.hpp>
#include <chrono>

using namespace std::chrono_literals;

struct ds1302_config : public modm::ds1302::Config
{
Expand Down Expand Up @@ -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);
Expand All @@ -102,19 +105,19 @@ 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
ds1302::write(0x80, 0x00);

// 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);
Expand Down

0 comments on commit 9c34fb1

Please sign in to comment.