RBCX
Library for the RB3204-RBCX board with the ESP32 by RoboticsBrno.
Loading...
Searching...
No Matches
RBCXUtil.h
Go to the documentation of this file.
1#pragma once
2
3#include <chrono>
4#include <freertos/FreeRTOS.h>
5#include <freertos/task.h>
6#include <ratio>
7
8namespace rb {
9
10template <typename T> T clamp(T value, T min, T max) {
11 if (value < min) {
12 return min;
13 } else if (value > max) {
14 return max;
15 }
16 return value;
17}
18
23inline void delayMs(int ms) { vTaskDelay(ms / portTICK_PERIOD_MS); }
24
29inline void delay(std::chrono::duration<uint32_t, std::milli> delay) {
30 vTaskDelay(delay.count() / portTICK_PERIOD_MS);
31}
32
33#define RBCX_ENUM_IMPL_MASK_OPERATORS(T) \
34 inline T operator|(T a, T b) { \
35 return static_cast<T>(static_cast<int>(a) | static_cast<int>(b)); \
36 } \
37 \
38 inline T operator&(T a, T b) { \
39 return static_cast<T>(static_cast<int>(a) & static_cast<int>(b)); \
40 } \
41 \
42 inline T operator^(T a, T b) { \
43 return static_cast<T>(static_cast<int>(a) ^ static_cast<int>(b)); \
44 } \
45 \
46 inline T operator|=(T& a, T b) { \
47 return static_cast<T>( \
48 reinterpret_cast<int&>(a) |= static_cast<int>(b)); \
49 } \
50 \
51 inline T operator&=(T& a, T b) { \
52 return static_cast<T>( \
53 reinterpret_cast<int&>(a) &= static_cast<int>(b)); \
54 } \
55 \
56 inline T operator^=(T& a, T b) { \
57 return static_cast<T>( \
58 reinterpret_cast<int&>(a) ^= static_cast<int>(b)); \
59 } \
60 \
61 inline T operator~(T a) { return static_cast<T>(~static_cast<int>(a)); } \
62 \
63 inline T operator<<=(T& a, int b) { \
64 return static_cast<T>( \
65 reinterpret_cast<int&>(a) <<= static_cast<int>(b)); \
66 } \
67 \
68 inline T operator>>=(T& a, int b) { \
69 return static_cast<T>( \
70 reinterpret_cast<int&>(a) >>= static_cast<int>(b)); \
71 } \
72 \
73 inline T operator<<(T a, int b) { \
74 return static_cast<T>(static_cast<int>(a) << static_cast<int>(b)); \
75 } \
76 \
77 inline T operator>>(T a, int b) { \
78 return static_cast<T>(static_cast<int>(a) >> static_cast<int>(b)); \
79 } \
80 \
81 T operator+=(T& a, T b) = delete; \
82 T operator-=(T& a, T b) = delete; \
83 T operator++(T a) = delete; \
84 T operator--(T a) = delete;
85
86} // namespace rb
Definition: RBCXAngle.cpp:3
T clamp(T value, T min, T max)
Definition: RBCXUtil.h:10
void delayMs(int ms)
Delay for given number of milliseconds. Like Arduino's delay()
Definition: RBCXUtil.h:23
void delay(std::chrono::duration< uint32_t, std::milli > delay)
Delay for given number of microseconds. Like Arduino's delayMicroseconds()
Definition: RBCXUtil.h:29