File tree Expand file tree Collapse file tree 3 files changed +21
-16
lines changed Expand file tree Collapse file tree 3 files changed +21
-16
lines changed Original file line number Diff line number Diff line change @@ -114,9 +114,8 @@ main()
114114 modm::platform::I2cMaster1::connect<modm::platform::GpioB7::Sda, modm::platform::GpioB6::Scl>();
115115 modm::platform::I2cMaster1::initialize<Board::SystemClock, 100_kHz>();
116116
117- constexpr uint32_t rate = 1 ; // Hz
118- constexpr float interval = 1000.0 / rate; // msec
119- modm::ShortPeriodicTimer heartbeat (interval);
117+ constexpr std::chrono::milliseconds interval{1000 };
118+ modm::ShortPeriodicTimer heartbeat{interval};
120119
121120 // Main loop
122121 DeviceThread deviceThread;
Original file line number Diff line number Diff line change 1010
1111#include < modm/board.hpp>
1212#include < modm/processing.hpp>
13+ #include < chrono>
1314
1415using Led = Board::LedGreen;
1516
17+ using namespace std ::chrono_literals;
18+
1619class BlinkingLight : public modm ::pt::Protothread, private modm::NestedResumable<2 >
1720{
1821public:
@@ -31,7 +34,7 @@ class BlinkingLight : public modm::pt::Protothread, private modm::NestedResumabl
3134 PT_CALL (waitForTimer ());
3235
3336 Led::reset ();
34- PT_CALL (setTimer (200 ));
37+ PT_CALL (setTimer (200ms ));
3538
3639 PT_WAIT_UNTIL (timeout.isExpired ());
3740 }
@@ -45,7 +48,7 @@ class BlinkingLight : public modm::pt::Protothread, private modm::NestedResumabl
4548 RF_BEGIN ();
4649
4750 // nested calling is allowed
48- if (RF_CALL (setTimer (100 )))
51+ if (RF_CALL (setTimer (100ms )))
4952 {
5053 RF_WAIT_UNTIL (timeout.isExpired ());
5154 RF_RETURN (true );
@@ -55,7 +58,7 @@ class BlinkingLight : public modm::pt::Protothread, private modm::NestedResumabl
5558 }
5659
5760 modm::ResumableResult<bool >
58- setTimer (uint16_t new_timeout)
61+ setTimer (std::chrono::milliseconds new_timeout)
5962 {
6063 RF_BEGIN ();
6164
@@ -78,7 +81,7 @@ BlinkingLight light;
7881
7982int main (void )
8083{
81- while (true ) {
82- light.run ();
83- }
84+ while (true ) {
85+ light.run ();
86+ }
8487}
Original file line number Diff line number Diff line change 1212#include < modm/board.hpp>
1313#include < modm/processing/timer.hpp>
1414#include < modm/driver/rtc/ds1302.hpp>
15+ #include < chrono>
16+
17+ using namespace std ::chrono_literals;
1518
1619struct ds1302_config : public modm ::ds1302::Config
1720{
7780 // Side effect: set seconds to 0
7881 ds1302::enableOscillator ();
7982
80- uint16_t tt = 9995 ; // Milliseconds
83+ auto tt = 9995ms;
8184 modm::Timeout timeout;
82- timeout.restart (std::chrono::milliseconds (tt) );
85+ timeout.restart (tt );
8386
8487 // Periodically report progress
8588 modm::PeriodicTimer blinkTimer (250ms);
@@ -102,19 +105,19 @@ main()
102105 ds1302::readRtc (rtc_data);
103106 uint8_t seconds = rtc_data.getSeconds ();
104107
105- MODM_LOG_DEBUG.printf (" \b * %2d.%03d seconds from CPU are %2d seconds from RTC.\n " ,
106- tt / 1000 ,
107- tt % 1000 ,
108+ MODM_LOG_DEBUG.printf (" \b * %2lld.%03lld seconds from CPU are %2d seconds from RTC.\n " ,
109+ tt. count () / 1000 ,
110+ tt. count () % 1000 ,
108111 seconds);
109112
110113 // Reset seconds to 0
111114 ds1302::write (0x80 , 0x00 );
112115
113116 // Adjust timeout time by some milliseconds to match RTC time.
114117 if (seconds >= 10 ) {
115- tt -= 20 ;
118+ tt -= 20ms ;
116119 } else {
117- tt += 1 ;
120+ tt += 1ms ;
118121 }
119122
120123 timeout.restart (tt);
You can’t perform that action at this time.
0 commit comments