From 8484854576493fd8300f15c2510aee34e6d51ef4 Mon Sep 17 00:00:00 2001 From: Oleg Kalachev Date: Sat, 1 Nov 2025 23:55:55 +0300 Subject: [PATCH] Keep only one floating point version of map function Two variants are redundant --- flix/motors.ino | 4 ++-- flix/util.h | 6 +----- 2 files changed, 3 insertions(+), 7 deletions(-) diff --git a/flix/motors.ino b/flix/motors.ino index 8574551..6b2af65 100644 --- a/flix/motors.ino +++ b/flix/motors.ino @@ -38,9 +38,9 @@ void setupMotors() { int getDutyCycle(float value) { value = constrain(value, 0, 1); - float pwm = mapff(value, 0, 1, PWM_MIN, PWM_MAX); + float pwm = mapf(value, 0, 1, PWM_MIN, PWM_MAX); if (value == 0) pwm = PWM_STOP; - float duty = mapff(pwm, 0, 1000000 / PWM_FREQUENCY, 0, (1 << PWM_RESOLUTION) - 1); + float duty = mapf(pwm, 0, 1000000 / PWM_FREQUENCY, 0, (1 << PWM_RESOLUTION) - 1); return round(duty); } diff --git a/flix/util.h b/flix/util.h index ee69a43..bba411f 100644 --- a/flix/util.h +++ b/flix/util.h @@ -12,11 +12,7 @@ const float ONE_G = 9.80665; extern float t; -float mapf(long x, long in_min, long in_max, float out_min, float out_max) { - return (float)(x - in_min) * (out_max - out_min) / (float)(in_max - in_min) + out_min; -} - -float mapff(float x, float in_min, float in_max, float out_min, float out_max) { +float mapf(float x, float in_min, float in_max, float out_min, float out_max) { return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min; }