Krolyxon
Commit 3120783

Branches

Tags

Refs →

orion-rf.piolibdepsesp32-s3-n16r8RF24utilitypigpiocompatibility.cpp

45 lines · 1.0 KB · C++

1#include <time.h>
2#include <chrono>
3#include "compatibility.h"
4
5long long mtime, seconds, useconds;
6//static struct timeval start, end;
7//struct timespec start, end;
8
9void __msleep(int millisec)
10{
11 struct timespec req; // = {0};
12 req.tv_sec = (time_t)millisec / 1000;
13 req.tv_nsec = (millisec % 1000) * 1000000L;
14 //nanosleep(&req, (struct timespec *)NULL);
15 clock_nanosleep(CLOCK_REALTIME, 0, &req, NULL);
16}
17
18void __usleep(int microsec)
19{
20 struct timespec req; // = {0};
21 req.tv_sec = (time_t)microsec / 1000000;
22 req.tv_nsec = (microsec % 1000000) * 1000;
23 //nanosleep(&req, (struct timespec *)NULL);
24 clock_nanosleep(CLOCK_REALTIME, 0, &req, NULL);
25}
26
27/**
28 * This function is added in order to simulate arduino millis() function
29 */
30
31bool timerStarted = false;
32
33void __start_timer()
34{
35}
36
37auto start = std::chrono::steady_clock::now();
38
39uint32_t __millis()
40{
41
42 auto end = std::chrono::steady_clock::now();
43
44 return std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count();
45}