Move mapf out of class, and remove truncate function

This commit is contained in:
Lukas Schmid 2023-06-20 18:57:32 +02:00
parent f901077931
commit 4112283a1f

View File

@ -49,6 +49,13 @@
#define USERMOD_ABL_EXT 2500 #define USERMOD_ABL_EXT 2500
#endif #endif
// custom map function
// https://forum.arduino.cc/t/floating-point-using-map-function/348113/2
double mapf(double x, double in_min, double in_max, double out_min, double out_max)
{
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
class UsermodULCBatteryManagement : public Usermod { class UsermodULCBatteryManagement : public Usermod {
private: private:
@ -82,26 +89,6 @@ class UsermodULCBatteryManagement : public Usermod {
static const char _maxCurrentBattery[]; static const char _maxCurrentBattery[];
static const char _maxCurrentExt[]; static const char _maxCurrentExt[];
// custom map function
// https://forum.arduino.cc/t/floating-point-using-map-function/348113/2
double mapf(double x, double in_min, double in_max, double out_min, double out_max)
{
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
float truncate(float val, byte dec)
{
float x = val * pow(10, dec);
float y = round(x);
float z = x - y;
if ((int)z == 5)
{
y++;
}
x = y / pow(10, dec);
return x;
}
public: public:
void setup() { void setup() {