From e6d44fb85f4019479178969c071ee7794e2d49fb Mon Sep 17 00:00:00 2001 From: rusEfi Date: Mon, 26 Nov 2018 20:40:24 -0500 Subject: [PATCH] NAN handling --- firmware/controllers/electronic_throttle.cpp | 6 +++++- firmware/controllers/system/pwm_generator_logic.cpp | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/firmware/controllers/electronic_throttle.cpp b/firmware/controllers/electronic_throttle.cpp index 4db940644a..385e678720 100644 --- a/firmware/controllers/electronic_throttle.cpp +++ b/firmware/controllers/electronic_throttle.cpp @@ -180,6 +180,10 @@ static msg_t etbThread(void *arg) { */ static void setThrottleDutyCycle(float level) { scheduleMsg(&logger, "setting ETB duty=%f%%", level); + if (cisnan(level)) { + valueOverride = NAN; + return; + } float dc = PERCENT_TO_DUTY(level); valueOverride = dc; @@ -314,7 +318,7 @@ void initElectronicThrottle(void) { startETBPins(); // - addConsoleActionF("set_etb", setThrottleDutyCycle); + addConsoleActionNANF("set_etb", setThrottleDutyCycle); tuneWorkingPidSettings.pFactor = 1; diff --git a/firmware/controllers/system/pwm_generator_logic.cpp b/firmware/controllers/system/pwm_generator_logic.cpp index 6616e7babd..cef347fd01 100644 --- a/firmware/controllers/system/pwm_generator_logic.cpp +++ b/firmware/controllers/system/pwm_generator_logic.cpp @@ -52,6 +52,10 @@ void PwmConfig::init(float *st, single_wave_s *waves) { * @param dutyCycle value between 0 and 1 */ void SimplePwm::setSimplePwmDutyCycle(float dutyCycle) { + if (cisnan(dutyCycle)) { + warning(CUSTOM_ERR_6691, "spwd:dutyCycle %.2f", dutyCycle); + return; + } if (dutyCycle < 0 || dutyCycle > 1) { warning(CUSTOM_ERR_6579, "spwd:dutyCycle %.2f", dutyCycle); return;