board.cpp 755 B

12345678910111213141516171819202122232425262728293031323334
  1. #include "board.h"
  2. #include <chrono>
  3. #include <cstdio>
  4. #include <thread>
  5. using namespace std::chrono;
  6. using Clock = steady_clock;
  7. using TimeUnit = microseconds;
  8. void Board::init_start() {}
  9. void Board::enable_timer() {}
  10. rl::TimePoint Board::get_now() {
  11. return duration_cast<TimeUnit>(Clock::now().time_since_epoch()).count();
  12. }
  13. void Board::toggle_led() {
  14. auto now = Clock::now();
  15. auto now_ms = duration_cast<TimeUnit>(now.time_since_epoch()).count();
  16. printf("%ld led toggle\n", now_ms);
  17. }
  18. void Board::delay() {
  19. printf("delay\n");
  20. using namespace std::chrono_literals;
  21. std::this_thread::sleep_for(1s);
  22. }
  23. void Board::sleep(const rl::TimePoint &until) {
  24. auto delta = until - get_now();
  25. std::this_thread::sleep_for(TimeUnit(delta));
  26. }