time(NULL) replaced with uptime() in helper files

Reason: Zephyr does not support time(NULL). This way it is portable.
This commit is contained in:
Martin Jaeger
2020-01-16 20:04:37 +01:00
parent 632eb5a4f7
commit a76b92c27b
12 changed files with 137 additions and 37 deletions
+54
View File
@@ -0,0 +1,54 @@
/*
* Copyright (c) 2020 Martin Jäger / Libre Solar
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "helper.h"
#ifdef __MBED__
#include "mbed.h"
#elif defined(__ZEPHYR__)
#include <zephyr.h>
#endif
#include <time.h>
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
}
}