Remove unneeded helper.cpp

This commit is contained in:
Martin Jäger
2020-11-05 20:42:46 +01:00
parent b63cdaa06d
commit 62d28d9e5e
3 changed files with 11 additions and 59 deletions
-1
View File
@@ -12,7 +12,6 @@ target_sources(app PRIVATE
eeprom.cpp
half_bridge.cpp
hardware.cpp
helper.cpp
leds.cpp
load.cpp
load_driver.c
-50
View File
@@ -1,50 +0,0 @@
/*
* Copyright (c) 2020 Martin Jäger / Libre Solar
*
* SPDX-License-Identifier: Apache-2.0
*/
#include "helper.h"
#include <time.h>
#include <zephyr.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
}
}
+11 -8
View File
@@ -15,24 +15,27 @@
#include <string.h>
#include <stdint.h>
#include <time.h>
#include <zephyr.h>
#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