1
0
mirror of https://github.com/RIOT-OS/RIOT.git synced 2024-12-29 04:50:03 +01:00

sys/progress_bar: add Konfig configuration

This commit is contained in:
Francisco Molina 2021-03-22 11:48:11 +01:00
parent fd36c626a3
commit 424192fbe7
No known key found for this signature in database
GPG Key ID: 3E94EAC3DBDEEDA8
6 changed files with 97 additions and 38 deletions

View File

@ -42,6 +42,7 @@ rsource "posix/Kconfig"
rsource "oneway-malloc/Kconfig" rsource "oneway-malloc/Kconfig"
rsource "phydat/Kconfig" rsource "phydat/Kconfig"
rsource "pm_layered/Kconfig" rsource "pm_layered/Kconfig"
rsource "progress_bar/Kconfig"
rsource "ps/Kconfig" rsource "ps/Kconfig"
rsource "random/Kconfig" rsource "random/Kconfig"
rsource "saul_reg/Kconfig" rsource "saul_reg/Kconfig"

View File

@ -29,50 +29,50 @@ extern "C" {
/** /**
* @brief Progress bar maximum characters length * @brief Progress bar maximum characters length
*/ */
#ifndef PROGRESS_BAR_LENGTH #ifndef CONFIG_PROGRESS_BAR_LENGTH
#define PROGRESS_BAR_LENGTH (25U) #define CONFIG_PROGRESS_BAR_LENGTH (25U)
#endif #endif
/** /**
* @brief Progress bar character * @brief Progress bar character
*/ */
#ifndef PROGRESS_BAR_FULL_CHARACTER #ifndef CONFIG_PROGRESS_BAR_FULL_CHARACTER
#define PROGRESS_BAR_FULL_CHARACTER "█" #define CONFIG_PROGRESS_BAR_FULL_CHARACTER "█"
#endif #endif
/** /**
* @brief Progress bar empty character * @brief Progress bar empty character
*/ */
#ifndef PROGRESS_BAR_EMPTY_CHARACTER #ifndef CONFIG_PROGRESS_BAR_EMPTY_CHARACTER
#define PROGRESS_BAR_EMPTY_CHARACTER " " #define CONFIG_PROGRESS_BAR_EMPTY_CHARACTER " "
#endif #endif
/** /**
* @brief Character displayed on the left of the progress bar * @brief Character displayed on the left of the progress bar
*/ */
#ifndef PROGRESS_BAR_PREFIX_CHARACTER #ifndef CONFIG_PROGRESS_BAR_PREFIX_CHARACTER
#define PROGRESS_BAR_PREFIX_CHARACTER "|" #define CONFIG_PROGRESS_BAR_PREFIX_CHARACTER "|"
#endif #endif
/** /**
* @brief Character displayed on the left of the progress bar * @brief Character displayed on the left of the progress bar
*/ */
#ifndef PROGRESS_BAR_SUFFIX_CHARACTER #ifndef CONFIG_PROGRESS_BAR_SUFFIX_CHARACTER
#define PROGRESS_BAR_SUFFIX_CHARACTER "|" #define CONFIG_PROGRESS_BAR_SUFFIX_CHARACTER "|"
#endif #endif
/** /**
* @brief Progress bar prefix max length * @brief Progress bar prefix max length
*/ */
#ifndef PROGRESS_BAR_PREFIX_MAX_LENGTH #ifndef CONFIG_PROGRESS_BAR_PREFIX_MAX_LENGTH
#define PROGRESS_BAR_PREFIX_MAX_LENGTH (32U) #define CONFIG_PROGRESS_BAR_PREFIX_MAX_LENGTH (32U)
#endif #endif
/** /**
* @brief Progress bar suffix max length * @brief Progress bar suffix max length
*/ */
#ifndef PROGRESS_BAR_SUFFIX_MAX_LENGTH #ifndef CONFIG_PROGRESS_BAR_SUFFIX_MAX_LENGTH
#define PROGRESS_BAR_SUFFIX_MAX_LENGTH (32U) #define CONFIG_PROGRESS_BAR_SUFFIX_MAX_LENGTH (32U)
#endif #endif
/** /**
@ -82,9 +82,9 @@ typedef struct {
/** Current value of the progress bar. Must be between 0 and 100 (included) */ /** Current value of the progress bar. Must be between 0 and 100 (included) */
uint8_t value; uint8_t value;
/** Prefix displayed on the left of the progress bar */ /** 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 */ /** 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; } progress_bar_t;
/** /**

58
sys/progress_bar/Kconfig Normal file
View File

@ -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

View File

@ -44,19 +44,19 @@ void progress_bar_print(char *prefix, char *suffix, uint8_t value)
printf("%s", prefix); printf("%s", prefix);
} }
printf(PROGRESS_BAR_PREFIX_CHARACTER); printf(CONFIG_PROGRESS_BAR_PREFIX_CHARACTER);
/* Fully reprint the progress bar */ /* Fully reprint the progress bar */
for (unsigned i = 0; i < PROGRESS_BAR_LENGTH; ++i) { for (unsigned i = 0; i < CONFIG_PROGRESS_BAR_LENGTH; ++i) {
if (100 * i < (uint16_t)(value * PROGRESS_BAR_LENGTH)) { if (100 * i < (uint16_t)(value * CONFIG_PROGRESS_BAR_LENGTH)) {
printf(PROGRESS_BAR_FULL_CHARACTER); printf(CONFIG_PROGRESS_BAR_FULL_CHARACTER);
} }
else { 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 */ /* Display progress bar suffix if any */
if (suffix) { if (suffix) {

View File

@ -3,24 +3,24 @@ include ../Makefile.tests_common
USEMODULE += xtimer USEMODULE += xtimer
USEMODULE += progress_bar USEMODULE += progress_bar
PROGRESS_BAR_LENGTH ?= 50 CONFIG_PROGRESS_BAR_LENGTH ?= 50
PROGRESS_BAR_FULL_CHARACTER ?= "█" CONFIG_PROGRESS_BAR_FULL_CHARACTER ?= "█"
PROGRESS_BAR_EMPTY_CHARACTER ?= " " CONFIG_PROGRESS_BAR_EMPTY_CHARACTER ?= " "
# Other nice progress bar characters: # Other nice progress bar characters:
#PROGRESS_BAR_FULL_CHARACTER ?= "◉" #CONFIG_PROGRESS_BAR_FULL_CHARACTER ?= "◉"
#PROGRESS_BAR_EMPTY_CHARACTER ?= "◯" #CONFIG_PROGRESS_BAR_EMPTY_CHARACTER ?= "◯"
#PROGRESS_BAR_FULL_CHARACTER ?= "▣" #CONFIG_PROGRESS_BAR_FULL_CHARACTER ?= "▣"
#PROGRESS_BAR_EMPTY_CHARACTER ?= "▢" #CONFIG_PROGRESS_BAR_EMPTY_CHARACTER ?= "▢"
CFLAGS += -DPROGRESS_BAR_FULL_CHARACTER=\"$(PROGRESS_BAR_FULL_CHARACTER)\" CFLAGS += -DCONFIG_PROGRESS_BAR_FULL_CHARACTER=\"$(CONFIG_PROGRESS_BAR_FULL_CHARACTER)\"
CFLAGS += -DPROGRESS_BAR_EMPTY_CHARACTER=\"$(PROGRESS_BAR_EMPTY_CHARACTER)\" CFLAGS += -DCONFIG_PROGRESS_BAR_EMPTY_CHARACTER=\"$(CONFIG_PROGRESS_BAR_EMPTY_CHARACTER)\"
CFLAGS += -DPROGRESS_BAR_LENGTH=$(PROGRESS_BAR_LENGTH) CFLAGS += -DCONFIG_PROGRESS_BAR_LENGTH=$(CONFIG_PROGRESS_BAR_LENGTH)
include $(RIOTBASE)/Makefile.include include $(RIOTBASE)/Makefile.include
# Make custom progress bar characters available in Python test script via # Make custom progress bar characters available in Python test script via
# environment variables # environment variables
export PROGRESS_BAR_FULL_CHARACTER export CONFIG_PROGRESS_BAR_FULL_CHARACTER
export PROGRESS_BAR_EMPTY_CHARACTER export CONFIG_PROGRESS_BAR_EMPTY_CHARACTER
export PROGRESS_BAR_LENGTH export CONFIG_PROGRESS_BAR_LENGTH

View File

@ -12,9 +12,9 @@ from testrunner import run
TIMEOUT = 60 TIMEOUT = 60
LENGTH = int(os.getenv('PROGRESS_BAR_LENGTH')) LENGTH = int(os.getenv('CONFIG_PROGRESS_BAR_LENGTH'))
FULL_CHARACTER = os.getenv('PROGRESS_BAR_FULL_CHARACTER')[1:-1] FULL_CHARACTER = os.getenv('CONFIG_PROGRESS_BAR_FULL_CHARACTER')[1:-1]
EMPTY_CHARACTER = os.getenv('PROGRESS_BAR_EMPTY_CHARACTER')[1:-1] EMPTY_CHARACTER = os.getenv('CONFIG_PROGRESS_BAR_EMPTY_CHARACTER')[1:-1]
def testfunc(child): def testfunc(child):