From 4112283a1f494a763a1d6cc844018356519a96f2 Mon Sep 17 00:00:00 2001 From: Lukas Schmid Date: Tue, 20 Jun 2023 18:57:32 +0200 Subject: [PATCH] Move mapf out of class, and remove truncate function --- .../usermod_ulc_batterymanagement.h | 27 +++++-------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/usermods/ULC_Battery_Management/usermod_ulc_batterymanagement.h b/usermods/ULC_Battery_Management/usermod_ulc_batterymanagement.h index 571da8a7..d2047d4a 100644 --- a/usermods/ULC_Battery_Management/usermod_ulc_batterymanagement.h +++ b/usermods/ULC_Battery_Management/usermod_ulc_batterymanagement.h @@ -49,6 +49,13 @@ #define USERMOD_ABL_EXT 2500 #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 { private: @@ -82,26 +89,6 @@ class UsermodULCBatteryManagement : public Usermod { static const char _maxCurrentBattery[]; 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: void setup() {