Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
François Revol
firmware
Commits
0bd98191
Commit
0bd98191
authored
Nov 10, 2019
by
schneider
Browse files
feat(config): Upgrade some calls to epics
parent
0bad3364
Changes
4
Hide whitespace changes
Inline
Side-by-side
epicardium/epicardium.h
View file @
0bd98191
...
...
@@ -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 */
epicardium/modules/config.c
View file @
0bd98191
#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
{
...
...
epicardium/modules/config.h
View file @
0bd98191
...
...
@@ -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
);
...
...
epicardium/modules/lifecycle.c
View file @
0bd98191
...
...
@@ -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
)
{
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment