source: ctrl/firmware/Main/SES/Core/Inc/utils.h

Last change on this file was 66, checked in by Zed, 4 months ago

FAN PWM control and TACHO signal measuring are working.

File size: 597 bytes
Line 
1#ifndef __UTILS_H
2#define __UTILS_H
3
4#include <utility>
5
6void printThreadStackInfo(const char* const TAG);
7
8// This function converts all numbers from range [x0, x1] to range [y0, y1]
9template <typename TYPE> TYPE Rescale(TYPE x, TYPE x1, TYPE x2, TYPE y1, TYPE y2, bool doNotExtrapolate = true)
10{
11        if (x1 > x2) std::swap(x1, x2);
12        if (y1 > y2) std::swap(y1, y2);
13
14        if (doNotExtrapolate)
15        {
16                if (x > x2) return y2;
17                if (x < x1) return y1;
18        }
19        //SEGGER_RTT_printf(0, "x0 = %d, x1 = %d\n", x0, x1);
20        return (((y2 - y1)*(x - x1))/(x2 - x1) + y1);
21}
22
23
24#endif /* __UTILS_H */
Note: See TracBrowser for help on using the repository browser.