Skip to content
Snippets Groups Projects
Commit 0bd98191 authored by schneider's avatar schneider
Browse files

feat(config): Upgrade some calls to epics

parent 0bad3364
No related branches found
No related tags found
1 merge request!339New config api with support for dynamic keys
Pipeline #4297 passed
......@@ -143,6 +143,9 @@ typedef _Bool bool;
#define API_WS2812_WRITE 0x0120
#define API_CONFIG_GET_STRING 0x130
#define API_CONFIG_GET_INTEGER 0x131
#define API_CONFIG_GET_BOOLEAN 0x132
/* clang-format on */
typedef uint32_t api_int_id_t;
......@@ -1924,5 +1927,49 @@ API(API_USB_CDCACM, int epic_usb_cdcacm(void));
*/
API(API_WS2812_WRITE, void epic_ws2812_write(uint8_t pin, uint8_t *pixels, uint32_t n_bytes));
/**
* Configuration
* ======
*/
/**
* Read an integer from the configuration file
*
* :param char* key: Name of the option to read
* :param int* value: Place to read the value into
* :return: `0` on success or a negative value if an error occured. Possible
* errors:
*
* - ``-ENOENT``: Value can not be read
*/
API(API_CONFIG_GET_INTEGER, int epic_config_get_integer(const char *key, int *value));
/**
* Read a boolean from the configuration file
*
* :param char* key: Name of the option to read
* :param bool* value: Place to read the value into
* :return: `0` on success or a negative value if an error occured. Possible
* errors:
*
* - ``-ENOENT``: Value can not be read
*/
API(API_CONFIG_GET_BOOLEAN, int epic_config_get_boolean(const char *key, bool *value));
/**
* Read a string from the configuration file
*
* :param char* key: Name of the option to read
* :param char* buf: Place to read the string into
* :param size_t buf_len: Size of the provided buffer
* :return: `0` on success or a negative value if an error occured. Possible
* errors:
*
* - ``-ENOENT``: Value can not be read
*/
API(API_CONFIG_GET_STRING, int epic_config_get_string(const char *key, char *buf, size_t buf_len));
#endif /* _EPICARDIUM_H */
#include "modules/log.h"
#include "modules/config.h"
#include "modules/filesystem.h"
#include "epicardium.h"
#include <assert.h>
#include <stdbool.h>
......@@ -319,7 +320,7 @@ static size_t read_config_offset(size_t seek_offset, char *buf, size_t buf_len)
}
// returns error if not found or invalid
int config_get_integer(const char *key, int *value)
int epic_config_get_integer(const char *key, int *value)
{
config_slot *slot = find_config_slot(key);
if (slot && slot->value != NOT_INT_MAGIC) {
......@@ -333,7 +334,7 @@ int config_get_integer(const char *key, int *value)
int config_get_integer_with_default(const char *key, int default_value)
{
int value;
int ret = config_get_integer(key, &value);
int ret = epic_config_get_integer(key, &value);
if (ret) {
return default_value;
} else {
......@@ -342,7 +343,7 @@ int config_get_integer_with_default(const char *key, int default_value)
}
// returns error if not found
int config_get_string(const char *key, char *buf, size_t buf_len)
int epic_config_get_string(const char *key, char *buf, size_t buf_len)
{
config_slot *slot = find_config_slot(key);
if (!(slot && slot->value_offset)) {
......@@ -366,7 +367,7 @@ int config_get_string(const char *key, char *buf, size_t buf_len)
char *config_get_string_with_default(
const char *key, char *buf, size_t buf_len, char *dflt
) {
int ret = config_get_string(key, buf, buf_len);
int ret = epic_config_get_string(key, buf, buf_len);
if (ret) {
return dflt;
} else {
......@@ -375,10 +376,10 @@ char *config_get_string_with_default(
}
// returns error if not found or invalid
int config_get_boolean(const char *key, bool *value)
int epic_config_get_boolean(const char *key, bool *value)
{
int int_value;
int ret = config_get_integer(key, &int_value);
int ret = epic_config_get_integer(key, &int_value);
if (ret == 0) {
*value = !!int_value;
......@@ -386,7 +387,7 @@ int config_get_boolean(const char *key, bool *value)
}
char buf[MAX_LINE_LENGTH + 1];
config_get_string(key, buf, MAX_LINE_LENGTH);
epic_config_get_string(key, buf, MAX_LINE_LENGTH);
if (buf == NULL) {
return -ENOENT;
......@@ -407,7 +408,7 @@ int config_get_boolean(const char *key, bool *value)
bool config_get_boolean_with_default(const char *key, bool default_value)
{
bool value;
int ret = config_get_boolean(key, &value);
int ret = epic_config_get_boolean(key, &value);
if (ret) {
return default_value;
} else {
......
......@@ -7,11 +7,6 @@
//initialize configuration values and load card10.cfg
void load_config(void);
// returns error if not found
int config_get_integer(const char *key, int *value);
int config_get_boolean(const char *key, bool *value);
int config_get_string(const char *key, char *buf, size_t buf_len);
// returns default_value if not found or invalid
bool config_get_boolean_with_default(const char *key, bool default_value);
int config_get_integer_with_default(const char *key, int default_value);
......
......@@ -362,7 +362,7 @@ void vLifecycleTask(void *pvParameters)
hardware_init();
execute_elfs = config_get_boolean("execute_elf", false);
execute_elfs = config_get_boolean_with_default("execute_elf", false);
/* When triggered, reset core 1 to menu */
while (1) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment