ALL THE CHANGES
This commit is contained in:
parent
d4f0a3b90f
commit
b97c7818f5
6 changed files with 53 additions and 14 deletions
|
@ -1,5 +1,5 @@
|
|||
set(REQUIRES "")
|
||||
set(SRCS "src/configulator.c")
|
||||
set(SRCS src/configulator.c src/cfglr_signal_callback.c)
|
||||
|
||||
if(${ESP_PLATFORM})
|
||||
list(APPEND REQUIRES nvs_flash esp_event)
|
||||
|
|
|
@ -7,8 +7,8 @@
|
|||
|
||||
ESP_EVENT_DECLARE_BASE(CFGLR_EVENT_BASE);
|
||||
|
||||
uint8_t cfglr_signaler_idf_init(cfglr_signaler_t *signaler, cfglr_handle_t *handle);
|
||||
uint8_t cfglr_signaler_idf_dispatch(cfglr_signaler_t *signaler, cfglr_element_t *element, cfglr_signal_e sig);
|
||||
void cfglr_signaler_idf_init(cfglr_signaler_t *signaler, cfglr_handle_t *handle);
|
||||
void cfglr_signaler_idf_dispatch(cfglr_signaler_t *signaler, cfglr_element_t *element, cfglr_signal_e sig);
|
||||
|
||||
#define CFGLR_SIGNALER_IDF_EVENT() {\
|
||||
.dispatch = &cfglr_signaler_idf_dispatch,\
|
||||
|
|
|
@ -35,6 +35,7 @@ typedef struct cfglr_element cfglr_element_t;
|
|||
typedef void (*cfglr_signaler_init_t)(cfglr_signaler_t *signaler, cfglr_element_t *element, cfglr_handle_t *handle);
|
||||
typedef void (*cfglr_signaler_dispatch_t)(cfglr_signaler_t *signaler, cfglr_element_t *element, cfglr_signal_e sig);
|
||||
|
||||
// TODO determine if key is actually needed here
|
||||
struct cfglr_signaler {
|
||||
const char *key;
|
||||
cfglr_signaler_dispatch_t dispatch;
|
||||
|
@ -76,6 +77,8 @@ struct cfglr_element {
|
|||
#define CFGLR_ELEMENT_I32(KEY, DEFAULT, SIGNALERS...) CFGLR_ELEMENT(KEY, CFGLR_DATATYPE_I32, sizeof(int32_t), DEFAULT, 4, SIGNALERS)
|
||||
#define CFGLR_ELEMENT_U64(KEY, DEFAULT, SIGNALERS...) CFGLR_ELEMENT(KEY, CFGLR_DATATYPE_U64, sizeof(uint64_t), DEFAULT, 8, SIGNALERS)
|
||||
#define CFGLR_ELEMENT_I64(KEY, DEFAULT, SIGNALERS...) CFGLR_ELEMENT(KEY, CFGLR_DATATYPE_I64, sizeof(int64_t), DEFAULT, 8, SIGNALERS)
|
||||
#define CFGLR_ELEMENT_BIN(KEY, SIZE, DEFAULT, DEF_SIZE, SIGNALERS...) CFGLR_ELEMENT(KEY, CFGLR_DATATYPE_BIN, SIZE, DEFAULT, DEF_SIZE, SIGNALERS)
|
||||
#define CFGLR_ELEMENT_STR(KEY, SIZE, DEFAULT, SIGNALERS...) CFGLR_ELEMENT(KEY, CFGLR_DATATYPE_STR, SIZE, DEFAULT, strlen(DEFAULT), SIGNALERS)
|
||||
|
||||
typedef struct cfglr_backend cfglr_backend_t;
|
||||
|
||||
|
@ -114,6 +117,7 @@ struct cfglr_handle_struct {
|
|||
|
||||
uint8_t cfglr_init(cfglr_handle_t *handle);
|
||||
uint8_t cfglr_fetch_data(cfglr_backend_t *backend, cfglr_element_t *element, cfglr_handle_t *handler);
|
||||
cfglr_element_t * cfglr_get_element(cfglr_handle_t *handle, const char *name);
|
||||
|
||||
#include "cfglr_log.h"
|
||||
#include "cfglr_nvs.h"
|
||||
|
|
|
@ -12,14 +12,14 @@ const char* cfglr_signal_names[] = {
|
|||
"CFGLR_SIGNAL_DELETE",
|
||||
};
|
||||
|
||||
uint8_t cfglr_signaler_idf_init(cfglr_signaler_t *signaler, cfglr_handle_t *handle) {
|
||||
return 0;
|
||||
void cfglr_signaler_idf_init(cfglr_signaler_t *signaler, cfglr_handle_t *handle) {
|
||||
return;
|
||||
}
|
||||
|
||||
uint8_t cfglr_signaler_idf_dispatch(cfglr_signaler_t *signaler, cfglr_element_t *element, cfglr_signal_e sig) {
|
||||
void cfglr_signaler_idf_dispatch(cfglr_signaler_t *signaler, cfglr_element_t *element, cfglr_signal_e sig) {
|
||||
CFGLR_LOGI(TAG, "dispatch: %s", cfglr_signal_names[sig]);
|
||||
|
||||
esp_event_post(CFGLR_EVENT_BASE, sig, element->data, element->datatype_size, portMAX_DELAY);
|
||||
|
||||
return 0;
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
#include "configulator.h"
|
||||
#include "cfglr_log.h"
|
||||
#include "cfglr_signaler_lvgl.h"
|
||||
#include "lvgl.h"
|
||||
|
@ -24,25 +25,48 @@ void cfglr_signaler_lvgl_change_cb(lv_event_t *e) {
|
|||
}
|
||||
|
||||
uint8_t cfglr_signaler_lvgl_init(cfglr_signaler_t *signaler, cfglr_element_t *element, cfglr_handle_t *handle) {
|
||||
CFGLR_LOGI(TAG, "init");
|
||||
CFGLR_LOGI(TAG, "init: %s", element->key);
|
||||
|
||||
CFGLR_LOGI(TAG, "ui handle: %p", signaler->handle);
|
||||
// TODO add appropriate handlers based on UI element type, eg: labels dont change on their own, one way binding
|
||||
lv_obj_add_event_cb((lv_obj_t*)signaler->handle, cfglr_signaler_lvgl_change_cb, LV_EVENT_VALUE_CHANGED, element);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t cfglr_signaler_lvgl_dispatch(cfglr_signaler_t *signaler, cfglr_element_t *element, cfglr_signal_e sig) {
|
||||
CFGLR_LOGI(TAG, "dispatch: %d", *(uint8_t*)element->data);
|
||||
CFGLR_LOGI(TAG, "dispatch: %s = %d", element->key, *(uint8_t*)element->data);
|
||||
|
||||
if(strstr(element->key, "monitor") != NULL) {
|
||||
// TODO determine state/actions based on UI element type/datatype
|
||||
// XXX this application specific check needs to go..
|
||||
lv_obj_t *lv_obj = signaler->handle;
|
||||
|
||||
if(lv_obj_check_type(lv_obj, &lv_checkbox_class) || lv_obj_check_type(lv_obj, &lv_switch_class)) {
|
||||
//if(strstr(element->key, "monitor") != NULL) {
|
||||
if(*(uint8_t*)element->data == 1) {
|
||||
lv_obj_add_state((lv_obj_t*)signaler->handle, LV_STATE_CHECKED);
|
||||
lv_obj_add_state(lv_obj, LV_STATE_CHECKED);
|
||||
} else {
|
||||
lv_obj_clear_state((lv_obj_t*)signaler->handle, LV_STATE_CHECKED);
|
||||
lv_obj_clear_state(lv_obj, LV_STATE_CHECKED);
|
||||
}
|
||||
|
||||
lv_event_send((lv_obj_t*)signaler->handle, LV_EVENT_VALUE_CHANGED, NULL);
|
||||
lv_event_send(lv_obj, LV_EVENT_VALUE_CHANGED, NULL);
|
||||
|
||||
return 0;
|
||||
} else if(element->datatype == CFGLR_DATATYPE_STR && lv_obj_check_type(lv_obj, &lv_textarea_class)) {
|
||||
lv_textarea_set_text(lv_obj, element->data);
|
||||
}
|
||||
|
||||
switch(element->datatype) {
|
||||
case CFGLR_DATATYPE_U8:
|
||||
break;
|
||||
|
||||
case CFGLR_DATATYPE_BIN:
|
||||
break;
|
||||
|
||||
case CFGLR_DATATYPE_STR:
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -89,3 +89,14 @@ uint16_t cfglr_commit_data(cfglr_backend_t *backend, cfglr_element_t *element, c
|
|||
|
||||
return ret;
|
||||
}
|
||||
|
||||
cfglr_element_t * cfglr_get_element(cfglr_handle_t *handle, const char *name) {
|
||||
cfglr_element_t *element;
|
||||
|
||||
uint8_t i = 0;
|
||||
while((element = &handle->elements[i++]) != NULL) {
|
||||
if(strcmp(element->key, name) == 0) return element;
|
||||
}
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue