This commit is contained in:
v0stap
2026-04-03 16:34:46 +02:00
commit bd00d0025d
139 changed files with 132443 additions and 0 deletions

33
Test2/Core/Src/math.c Normal file
View File

@@ -0,0 +1,33 @@
/*
* math.c
*
* Created on: 2 февр. 2026г.
* Author: v0stap
*/
#include "main.h"
uint16_t map16_t(uint16_t x, uint16_t in_min, uint16_t in_max, uint16_t out_min, uint16_t out_max) {
// Input validation: avoid division by zero
if (in_max == in_min) {
fprintf(stderr, "Error: Input range cannot be zero.\n");
return out_min;
} else {
// Perform mapping
return (uint16_t)(out_min + (x - in_min) * (out_max - out_min) / (in_max - in_min));
}
}
uint16_t LPF(unsigned short lpf_c, unsigned short value, unsigned short old_value) {
// Averageing filtering
float tmp;
tmp = ((float) (value - old_value) * ((float) (lpf_c) / (float) 1000.0)); // filter
if (tmp > 0)
tmp += (float) 0.5; // roundup
else
tmp -= (float) 0.5;
return (uint16_t)((signed int) old_value + (signed int) tmp);
}