From 8496e71e6ff4894e56bcc4f86ad53809979efea1 Mon Sep 17 00:00:00 2001 From: Drew Rife Date: Wed, 21 May 2025 07:29:07 -0400 Subject: [PATCH] Use etl::clamp for setting value in cyclic_value (#1104) * Add Zephyr build system module.yml (#1074) The Zephyr build system requires that modules have a `module.yml` file to specify where the module cmake and kconfig files are located. These can also be explicitly set as "external" meaning that they do not exist within the module tree, itself. These build file can still be specified elsewhere via cmake variables, explained more in-depth here: https://docs.zephyrproject.org/latest/develop/modules.html#modules-module-ext-root This change makes it such that ETL can be included more easily in zephyr projects running on embedded systems. A similar change can be observed in the public nanopb repository, where the repo only requires its own `zephyr/module.yml` file to be found by the zephyr build system, but the kconfig and cmake additions can exist outside of the library repository. * Add full West support for ETL (#1075) This will allow ETL to be included via west in a zephyr build without any additional wrappers or external kconfigs. Signed-off-by: Zach Van Camp Co-authored-by: Zach Van Camp * refactor: use etl::clamp for clamping the set value --------- Signed-off-by: Zach Van Camp Co-authored-by: Zach Van Camp Co-authored-by: Zach Van Camp Co-authored-by: John Wellbelove --- include/etl/cyclic_value.h | 22 ++-------------------- 1 file changed, 2 insertions(+), 20 deletions(-) diff --git a/include/etl/cyclic_value.h b/include/etl/cyclic_value.h index 392c7a14..b0491b23 100644 --- a/include/etl/cyclic_value.h +++ b/include/etl/cyclic_value.h @@ -109,16 +109,7 @@ namespace etl //************************************************************************* void set(T value_) { - if (value_ > Last) - { - value_ = Last; - } - else if (value_ < First) - { - value_ = First; - } - - value = value_; + value = clamp(value_, First, Last); } //************************************************************************* @@ -398,16 +389,7 @@ namespace etl //************************************************************************* void set(T value_) { - if (value_ > last_value) - { - value_ = last_value; - } - else if (value_ < first_value) - { - value_ = first_value; - } - - value = value_; + value = clamp(value_, first_value, last_value); } //*************************************************************************