diff --git a/sys/Kconfig b/sys/Kconfig index 02a636d7c1..3c768062d6 100644 --- a/sys/Kconfig +++ b/sys/Kconfig @@ -42,6 +42,7 @@ rsource "posix/Kconfig" rsource "oneway-malloc/Kconfig" rsource "phydat/Kconfig" rsource "pm_layered/Kconfig" +rsource "progress_bar/Kconfig" rsource "ps/Kconfig" rsource "random/Kconfig" rsource "saul_reg/Kconfig" diff --git a/sys/include/progress_bar.h b/sys/include/progress_bar.h index d1f3855654..5c7f9b0ea3 100644 --- a/sys/include/progress_bar.h +++ b/sys/include/progress_bar.h @@ -29,50 +29,50 @@ extern "C" { /** * @brief Progress bar maximum characters length */ -#ifndef PROGRESS_BAR_LENGTH -#define PROGRESS_BAR_LENGTH (25U) +#ifndef CONFIG_PROGRESS_BAR_LENGTH +#define CONFIG_PROGRESS_BAR_LENGTH (25U) #endif /** * @brief Progress bar character */ -#ifndef PROGRESS_BAR_FULL_CHARACTER -#define PROGRESS_BAR_FULL_CHARACTER "█" +#ifndef CONFIG_PROGRESS_BAR_FULL_CHARACTER +#define CONFIG_PROGRESS_BAR_FULL_CHARACTER "█" #endif /** * @brief Progress bar empty character */ -#ifndef PROGRESS_BAR_EMPTY_CHARACTER -#define PROGRESS_BAR_EMPTY_CHARACTER " " +#ifndef CONFIG_PROGRESS_BAR_EMPTY_CHARACTER +#define CONFIG_PROGRESS_BAR_EMPTY_CHARACTER " " #endif /** * @brief Character displayed on the left of the progress bar */ -#ifndef PROGRESS_BAR_PREFIX_CHARACTER -#define PROGRESS_BAR_PREFIX_CHARACTER "|" +#ifndef CONFIG_PROGRESS_BAR_PREFIX_CHARACTER +#define CONFIG_PROGRESS_BAR_PREFIX_CHARACTER "|" #endif /** * @brief Character displayed on the left of the progress bar */ -#ifndef PROGRESS_BAR_SUFFIX_CHARACTER -#define PROGRESS_BAR_SUFFIX_CHARACTER "|" +#ifndef CONFIG_PROGRESS_BAR_SUFFIX_CHARACTER +#define CONFIG_PROGRESS_BAR_SUFFIX_CHARACTER "|" #endif /** * @brief Progress bar prefix max length */ -#ifndef PROGRESS_BAR_PREFIX_MAX_LENGTH -#define PROGRESS_BAR_PREFIX_MAX_LENGTH (32U) +#ifndef CONFIG_PROGRESS_BAR_PREFIX_MAX_LENGTH +#define CONFIG_PROGRESS_BAR_PREFIX_MAX_LENGTH (32U) #endif /** * @brief Progress bar suffix max length */ -#ifndef PROGRESS_BAR_SUFFIX_MAX_LENGTH -#define PROGRESS_BAR_SUFFIX_MAX_LENGTH (32U) +#ifndef CONFIG_PROGRESS_BAR_SUFFIX_MAX_LENGTH +#define CONFIG_PROGRESS_BAR_SUFFIX_MAX_LENGTH (32U) #endif /** @@ -82,9 +82,9 @@ typedef struct { /** Current value of the progress bar. Must be between 0 and 100 (included) */ uint8_t value; /** Prefix displayed on the left of the progress bar */ - char prefix[PROGRESS_BAR_PREFIX_MAX_LENGTH]; + char prefix[CONFIG_PROGRESS_BAR_PREFIX_MAX_LENGTH]; /** Suffix displayed on the right of the progress bar */ - char suffix[PROGRESS_BAR_SUFFIX_MAX_LENGTH]; + char suffix[CONFIG_PROGRESS_BAR_SUFFIX_MAX_LENGTH]; } progress_bar_t; /** diff --git a/sys/progress_bar/Kconfig b/sys/progress_bar/Kconfig new file mode 100644 index 0000000000..afae742786 --- /dev/null +++ b/sys/progress_bar/Kconfig @@ -0,0 +1,58 @@ +# Copyright (c) 2021 Inria +# +# This file is subject to the terms and conditions of the GNU Lesser +# General Public License v2.1. See the file LICENSE in the top level +# directory for more details. +# + +config MODULE_PROGRESS_BAR + bool "A simple CLI progress bar" + depends on TEST_KCONFIG + +menuconfig KCONFIG_USEMODULE_PROGRESS_BAR + bool "Configure progress bar module" + depends on USEMODULE_PROGRESS_BAR + help + Configure the progress bar module using Kconfig. + +if KCONFIG_USEMODULE_PROGRESS_BAR + +config PROGRESS_BAR_LENGTH + int "Progress bar length" + default 25 + help + Progress bar maximum characters length + +config PROGRESS_BAR_FULL_CHARACTER + string "Progress bar character" + default "█" + help + The character that will be printed when the progress bar fills up. + +config PROGRESS_BAR_EMPTY_CHARACTER + string "Progress bar empty character" + default " " + help + The character that will be printed when the progress bar empties. + +config PROGRESS_BAR_PREFIX_CHARACTER + string "Progress bar prefix" + default "|" + help + Character displayed on the left of the progress bar + +config PROGRESS_BAR_SUFFIX_CHARACTER + string "Progress bar suffix" + default "|" + help + Character displayed on the left of the progress bar + +config PROGRESS_BAR_PREFIX_MAX_LENGTH + int "Progress bar prefix max length" + default 32 + +config PROGRESS_BAR_SUFFIX_MAX_LENGTH + int "Progress bar suffix max length" + default 32 + +endif # KCONFIG_USEMODULE_PROGRESS_BAR diff --git a/sys/progress_bar/progress_bar.c b/sys/progress_bar/progress_bar.c index cdde2d00a9..932e7536b2 100644 --- a/sys/progress_bar/progress_bar.c +++ b/sys/progress_bar/progress_bar.c @@ -44,19 +44,19 @@ void progress_bar_print(char *prefix, char *suffix, uint8_t value) printf("%s", prefix); } - printf(PROGRESS_BAR_PREFIX_CHARACTER); + printf(CONFIG_PROGRESS_BAR_PREFIX_CHARACTER); /* Fully reprint the progress bar */ - for (unsigned i = 0; i < PROGRESS_BAR_LENGTH; ++i) { - if (100 * i < (uint16_t)(value * PROGRESS_BAR_LENGTH)) { - printf(PROGRESS_BAR_FULL_CHARACTER); + for (unsigned i = 0; i < CONFIG_PROGRESS_BAR_LENGTH; ++i) { + if (100 * i < (uint16_t)(value * CONFIG_PROGRESS_BAR_LENGTH)) { + printf(CONFIG_PROGRESS_BAR_FULL_CHARACTER); } else { - printf(PROGRESS_BAR_EMPTY_CHARACTER); + printf(CONFIG_PROGRESS_BAR_EMPTY_CHARACTER); } } - printf(PROGRESS_BAR_SUFFIX_CHARACTER); + printf(CONFIG_PROGRESS_BAR_SUFFIX_CHARACTER); /* Display progress bar suffix if any */ if (suffix) { diff --git a/tests/progress_bar/Makefile b/tests/progress_bar/Makefile index 38204f7906..a57c7a488f 100644 --- a/tests/progress_bar/Makefile +++ b/tests/progress_bar/Makefile @@ -3,24 +3,24 @@ include ../Makefile.tests_common USEMODULE += xtimer USEMODULE += progress_bar -PROGRESS_BAR_LENGTH ?= 50 -PROGRESS_BAR_FULL_CHARACTER ?= "█" -PROGRESS_BAR_EMPTY_CHARACTER ?= " " +CONFIG_PROGRESS_BAR_LENGTH ?= 50 +CONFIG_PROGRESS_BAR_FULL_CHARACTER ?= "█" +CONFIG_PROGRESS_BAR_EMPTY_CHARACTER ?= " " # Other nice progress bar characters: -#PROGRESS_BAR_FULL_CHARACTER ?= "◉" -#PROGRESS_BAR_EMPTY_CHARACTER ?= "◯" -#PROGRESS_BAR_FULL_CHARACTER ?= "▣" -#PROGRESS_BAR_EMPTY_CHARACTER ?= "▢" +#CONFIG_PROGRESS_BAR_FULL_CHARACTER ?= "◉" +#CONFIG_PROGRESS_BAR_EMPTY_CHARACTER ?= "◯" +#CONFIG_PROGRESS_BAR_FULL_CHARACTER ?= "▣" +#CONFIG_PROGRESS_BAR_EMPTY_CHARACTER ?= "▢" -CFLAGS += -DPROGRESS_BAR_FULL_CHARACTER=\"$(PROGRESS_BAR_FULL_CHARACTER)\" -CFLAGS += -DPROGRESS_BAR_EMPTY_CHARACTER=\"$(PROGRESS_BAR_EMPTY_CHARACTER)\" -CFLAGS += -DPROGRESS_BAR_LENGTH=$(PROGRESS_BAR_LENGTH) +CFLAGS += -DCONFIG_PROGRESS_BAR_FULL_CHARACTER=\"$(CONFIG_PROGRESS_BAR_FULL_CHARACTER)\" +CFLAGS += -DCONFIG_PROGRESS_BAR_EMPTY_CHARACTER=\"$(CONFIG_PROGRESS_BAR_EMPTY_CHARACTER)\" +CFLAGS += -DCONFIG_PROGRESS_BAR_LENGTH=$(CONFIG_PROGRESS_BAR_LENGTH) include $(RIOTBASE)/Makefile.include # Make custom progress bar characters available in Python test script via # environment variables -export PROGRESS_BAR_FULL_CHARACTER -export PROGRESS_BAR_EMPTY_CHARACTER -export PROGRESS_BAR_LENGTH +export CONFIG_PROGRESS_BAR_FULL_CHARACTER +export CONFIG_PROGRESS_BAR_EMPTY_CHARACTER +export CONFIG_PROGRESS_BAR_LENGTH diff --git a/tests/progress_bar/tests/01-run.py b/tests/progress_bar/tests/01-run.py index 572fd61ac5..29ebe6d41b 100755 --- a/tests/progress_bar/tests/01-run.py +++ b/tests/progress_bar/tests/01-run.py @@ -12,9 +12,9 @@ from testrunner import run TIMEOUT = 60 -LENGTH = int(os.getenv('PROGRESS_BAR_LENGTH')) -FULL_CHARACTER = os.getenv('PROGRESS_BAR_FULL_CHARACTER')[1:-1] -EMPTY_CHARACTER = os.getenv('PROGRESS_BAR_EMPTY_CHARACTER')[1:-1] +LENGTH = int(os.getenv('CONFIG_PROGRESS_BAR_LENGTH')) +FULL_CHARACTER = os.getenv('CONFIG_PROGRESS_BAR_FULL_CHARACTER')[1:-1] +EMPTY_CHARACTER = os.getenv('CONFIG_PROGRESS_BAR_EMPTY_CHARACTER')[1:-1] def testfunc(child):