From cfa3e58d092da8f781a1465b55de47c9612a35ff Mon Sep 17 00:00:00 2001 From: Rune Harlyk Date: Fri, 12 Jul 2024 13:34:31 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9E=95=20Moves=20common=20math=20functions?= =?UTF-8?q?=20to=20own=20file?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- esp32/lib/ESP32-sveltekit/MathUtils.h | 12 ++++++++++++ esp32/lib/ESP32-sveltekit/MotionService.h | 3 +-- esp32/lib/ESP32-sveltekit/Peripherals.h | 3 +-- 3 files changed, 14 insertions(+), 4 deletions(-) create mode 100644 esp32/lib/ESP32-sveltekit/MathUtils.h diff --git a/esp32/lib/ESP32-sveltekit/MathUtils.h b/esp32/lib/ESP32-sveltekit/MathUtils.h new file mode 100644 index 0000000..9c89525 --- /dev/null +++ b/esp32/lib/ESP32-sveltekit/MathUtils.h @@ -0,0 +1,12 @@ +#ifndef MATHUTILS_H +#define MATHUTILS_H + +#include + +inline float lerp(float start, float end, float t) { return (1 - t) * start + t * end; } + +inline bool isEqual(float a, float b, float epsilon) { return std::fabs(a - b) < epsilon; } + +inline float round2(float value) { return (int)(value * 100 + 0.5) / 100.0; } + +#endif \ No newline at end of file diff --git a/esp32/lib/ESP32-sveltekit/MotionService.h b/esp32/lib/ESP32-sveltekit/MotionService.h index 9614b2a..ae7a4f1 100644 --- a/esp32/lib/ESP32-sveltekit/MotionService.h +++ b/esp32/lib/ESP32-sveltekit/MotionService.h @@ -4,6 +4,7 @@ #include #include #include +#include #define DEFAULT_STATE false #define LIGHT_SETTINGS_ENDPOINT_PATH "/api/input" @@ -91,8 +92,6 @@ class MotionService { _socket->emit(ANGLES_EVENT, output, originId.c_str()); } - float lerp(float start, float end, float t) { return (1 - t) * start + t * end; } - bool updateMotion() { switch (motionState) { case MOTION_STATE::IDLE: return false; break; diff --git a/esp32/lib/ESP32-sveltekit/Peripherals.h b/esp32/lib/ESP32-sveltekit/Peripherals.h index 17f5dab..95fccfc 100644 --- a/esp32/lib/ESP32-sveltekit/Peripherals.h +++ b/esp32/lib/ESP32-sveltekit/Peripherals.h @@ -6,6 +6,7 @@ #include #include #include +#include #include #include @@ -333,8 +334,6 @@ class Peripherals : public StatefulService { return temperature; } - double round2(double value) { return (int)(value * 100 + 0.5) / 100.0; } - protected: void updateImu() { doc.clear();