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:
parent
fd36c626a3
commit
424192fbe7
@ -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"
|
||||
|
@ -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;
|
||||
|
||||
/**
|
||||
|
58
sys/progress_bar/Kconfig
Normal file
58
sys/progress_bar/Kconfig
Normal 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
|
@ -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) {
|
||||
|
@ -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
|
||||
|
@ -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):
|
||||
|
Loading…
Reference in New Issue
Block a user