util.h
1 /*
2  * EEZ PSU Firmware
3  * Copyright (C) 2015-present, Envox d.o.o.
4  *
5  * This program is free software: you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or
8  * (at your option) any later version.
9 
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14 
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 
19 #pragma once
20 
21 #define clear_bit(reg, bitmask) *reg &= ~bitmask
22 #define set_bit(reg, bitmask) *reg |= bitmask
23 
24 #define util_swap(type, i, j) {type t = i; i = j; j = t;}
25 
26 #define MIN(a,b) ((a)<(b)?(a):(b))
27 #define MAX(a,b) ((a)>(b)?(a):(b))
28 
29 #include "gui_data.h"
30 
31 namespace eez {
32 namespace psu {
33 
35 namespace util {
36 
37 float remap(float x, float x1, float y1, float x2, float y2);
38 float clamp(float x, float min, float max);
39 
40 void strcatInt(char *str, int value);
41 void strcatUInt32(char *str, uint32_t value);
42 void strcatFloat(char *str, float value, int numSignificantDecimalDigits = FLOAT_TO_STR_NUM_DECIMAL_DIGITS);
43 void strcatVoltage(char *str, float value, int numSignificantDecimalDigits = FLOAT_TO_STR_NUM_DECIMAL_DIGITS);
44 void strcatCurrent(char *str, float value, int numSignificantDecimalDigits = FLOAT_TO_STR_NUM_DECIMAL_DIGITS);
45 void strcatDuration(char *str, float value);
46 void strcatLoad(char *str, float value);
47 
48 uint32_t crc32(const uint8_t *message, size_t size);
49 
50 uint8_t toBCD(uint8_t bin);
51 uint8_t fromBCD(uint8_t bcd);
52 
53 float floorPrec(float a, float prec);
54 float ceilPrec(float a, float prec);
55 float roundPrec(float a, float prec);
56 
57 bool greater(float a, float b, float prec);
58 bool greaterOrEqual(float a, float b, float prec);
59 bool less(float a, float b, float prec);
60 bool lessOrEqual(float a, float b, float prec);
61 bool equal(float a, float b, float prec);
62 
63 bool between(float x, float a, float b, float prec);
64 
65 float multiply(float a, float b, float prec);
66 
67 bool isNaN(float x);
68 
69 bool isDigit(char ch);
70 bool isUperCaseLetter(char ch);
71 
72 void removeTrailingZerosFromFloat(char *str);
73 
74 bool pointInsideRect(int xPoint, int yPoint, int xRect, int yRect, int wRect, int hRect);
75 
76 void getParentDir(const char *path, char *parentDirPath);
77 
78 }
79 }
80 } // namespace eez::psu::util
Namespace for the everything from the EEZ.
Definition: actions.cpp:41
#define FLOAT_TO_STR_NUM_DECIMAL_DIGITS
Number of digits after decimal point in float to string conversion.
Definition: conf_advanced.h:97