RBControl
Library for the RB3201-RBControl board with the ESP32 by RoboticsBrno.
RBControl_util.hpp
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 
8 #include "RBControl_logger.hpp"
9 
10 namespace rb {
11 
12 template <typename T, typename... Args>
13 T clamp(T value, T min, T max, const char* tag = "",
14  const char* msg = NULL, Args... args) {
15  if (value < min) {
16  if (msg != NULL) {
17  rb::logWarning(tag, msg, std::forward<Args>(args)...);
18  }
19  return min;
20  } else if (value > max) {
21  if (msg != NULL) {
22  rb::logWarning(tag, msg, std::forward<Args>(args)...);
23  }
24  return max;
25  }
26  return value;
27 }
28 
29 inline void delayMs(int ms) {
30  vTaskDelay(ms / portTICK_PERIOD_MS);
31 }
32 
33 inline void delay(std::chrono::duration<uint32_t, std::milli> delay) {
34  vTaskDelay(delay.count() / portTICK_PERIOD_MS);
35 }
36 
37 } // namespace rb
The base namespace. Contains some logging functions, too.
Definition: half_duplex_uart.cpp:53
FormatString logWarning(const std::string &tag, const std::string &message, Args... args)
Definition: RBControl_logger.hpp:31
void delayMs(int ms)
Definition: RBControl_util.hpp:29
T clamp(T value, T min, T max, const char *tag="", const char *msg=NULL, Args... args)
Definition: RBControl_util.hpp:13
void delay(std::chrono::duration< uint32_t, std::milli > delay)
Definition: RBControl_util.hpp:33