diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index a79feaf..b433d33 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -12,7 +12,6 @@ target_sources(app PRIVATE eeprom.cpp half_bridge.cpp hardware.cpp - helper.cpp leds.cpp load.cpp load_driver.c diff --git a/src/helper.cpp b/src/helper.cpp deleted file mode 100644 index f778b85..0000000 --- a/src/helper.cpp +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2020 Martin Jäger / Libre Solar - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#include "helper.h" - -#include - -#include - -uint32_t uptime() -{ -#ifdef __ZEPHYR__ - return k_uptime_get() / 1000; -#else - return time(NULL); -#endif -} - -float interpolate(const float a[], const float b[], size_t size, float value_a) -{ - if (a[0] < a[size - 1]) { - for (unsigned int i = 0; i < size; i++) { - if (value_a <= a[i]) { - if (i == 0) { - return b[0]; // value_a smaller than first element - } - else { - return b[i-1] + (b[i] - b[i-1]) * (value_a - a[i-1]) / (a[i] - a[i-1]); - } - } - } - return b[size - 1]; // value_a larger than last element - } - else { - for (unsigned int i = 0; i < size; i++) { - if (value_a >= a[i]) { - if (i == 0) { - return b[0]; // value_a smaller than first element - } - else { - return b[i-1] + (b[i] - b[i-1]) * (value_a - a[i-1]) / (a[i] - a[i-1]); - } - } - } - return b[size - 1]; // value_a larger than last element - } -} diff --git a/src/helper.h b/src/helper.h index 02b0030..958afee 100644 --- a/src/helper.h +++ b/src/helper.h @@ -15,24 +15,27 @@ #include #include +#include + +#include #ifdef __cplusplus extern "C" { #endif -/** - * Interpolation in a look-up table. Values of a must be monotonically increasing/decreasing - * - * @returns interpolated value of array b at position value_a - */ -float interpolate(const float a[], const float b[], size_t size, float value_a); - /** * Framework-independent system uptime * * @returns seconds since the system booted */ -uint32_t uptime(); +static inline uint32_t uptime() +{ +#ifdef __ZEPHYR__ + return k_uptime_get() / 1000; +#else + return time(NULL); +#endif +} /** * Sets one or more flags in given field