Logic_library
Library for Logic board by RoboticsBrno.
Loading...
Searching...
No Matches
ArduinoLikeUtils.hpp
Go to the documentation of this file.
1#pragma once
2
3#include <freertos/FreeRTOS.h>
4#include <freertos/task.h>
5#include <esp_random.h>
6#include <stdint.h>
7#include <string>
8
14inline void delay(uint32_t ms) {
15 vTaskDelay(pdMS_TO_TICKS(ms));
16}
17
23inline void waitSeconds(float seconds) {
24 delay(uint32_t(seconds * 1000.f));
25}
26
32inline void cekejVteriny(float vteriny) {
34}
35
41inline uint32_t millis() {
42 return pdTICKS_TO_MS(xTaskGetTickCount());
43}
44
50inline float seconds() {
51 return float(millis()) / 1000.f;
52}
53
59inline float vteriny() {
60 return seconds();
61}
62
69inline long random(long max) {
70 uint32_t x = esp_random();
71 uint64_t m = uint64_t(x) * uint64_t(max);
72 uint32_t l = uint32_t(m);
73 if (l < max) {
74 uint32_t t = -max;
75 if (t >= max) {
76 t -= max;
77 if (t >= max)
78 t %= max;
79 }
80 while (l < t) {
81 x = esp_random();
82 m = uint64_t(x) * uint64_t(max);
83 l = uint32_t(m);
84 }
85 }
86 return m >> 32;
87}
88
96inline long random(long min, long max) {
97 if (min >= max) {
98 return min;
99 }
100 long diff = max - min;
101 return random(diff) + min;
102}
103
110inline long nahodne(long maximum) {
111 return random(maximum);
112}
113
121inline long nahodne(long minimum, long maximum) {
122 return random(minimum, maximum);
123}
124
131void saveInt(const std::string& name, int value);
132
140int loadInt(const std::string& name, int defaultVal = 0);
long random(long max)
Get random number from 0 to max.
Definition: ArduinoLikeUtils.hpp:69
void saveInt(const std::string &name, int value)
Saves an integer into the persisent NVS storage.
Definition: ArduinoLikeUtils.cpp:4
void delay(uint32_t ms)
Wait for specified amount of milliseconds.
Definition: ArduinoLikeUtils.hpp:14
long nahodne(long maximum)
Vrátí náhodné číslo od 0 do maximum.
Definition: ArduinoLikeUtils.hpp:110
float vteriny()
Vrátí počet vteřin od začátku programu.
Definition: ArduinoLikeUtils.hpp:59
float seconds()
Returns time since boot in seconds.
Definition: ArduinoLikeUtils.hpp:50
uint32_t millis()
Returns time since boot in milliseconds.
Definition: ArduinoLikeUtils.hpp:41
void cekejVteriny(float vteriny)
Čeká po specifikovaný počet vteřin.
Definition: ArduinoLikeUtils.hpp:32
void waitSeconds(float seconds)
Wait for specified amount of seconds.
Definition: ArduinoLikeUtils.hpp:23
int loadInt(const std::string &name, int defaultVal=0)
Loads an integer from the persistent NVS storage.
Definition: ArduinoLikeUtils.cpp:9