From ec1068f461e07440aff2166ba8060b3546d59176 Mon Sep 17 00:00:00 2001 From: Sara Date: Fri, 22 Sep 2023 12:30:43 +0200 Subject: [PATCH] added some math functions (min, max, clamp) --- main/shared.h | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/main/shared.h b/main/shared.h index 7fee108..24dbdd2 100644 --- a/main/shared.h +++ b/main/shared.h @@ -25,6 +25,15 @@ static const char* APP_TAG="CINEKID_LEDS"; printf("\n");\ } while(0) +static inline +int min(int a, int b) { return a < b ? a : b; } +static inline +int max(int a, int b) { return a > b ? a : b; } +static inline +int clamp(int x, int mi, int ma) { + return max(mi, min(ma, x)); +} + #define GLOBAL(__a) (uint8_t)(__a|0xE0) #endif // !_shared_h