From d4f0a3b90f63282139f3071ad06c10766c4d8d63 Mon Sep 17 00:00:00 2001 From: "Morgan 'ARR\\!' Allen" Date: Fri, 29 Nov 2024 21:15:19 -0800 Subject: [PATCH] add generic callback signaler --- include/cfglr_signaler_callback.h | 14 ++++++++++++++ include/configulator.h | 2 ++ src/cfglr_signal_callback.c | 16 ++++++++++++++++ 3 files changed, 32 insertions(+) create mode 100644 include/cfglr_signaler_callback.h create mode 100644 src/cfglr_signal_callback.c diff --git a/include/cfglr_signaler_callback.h b/include/cfglr_signaler_callback.h new file mode 100644 index 0000000..8f9a705 --- /dev/null +++ b/include/cfglr_signaler_callback.h @@ -0,0 +1,14 @@ +typedef void (*cfglr_callback_t)(cfglr_signaler_t *signaler, cfglr_element_t *element, cfglr_signal_e sig); + +typedef struct { + cfglr_callback_t callback; +} cfglr_callback_handle_t; + +void cfglr_signaler_callback_init(cfglr_signaler_t *signaler, cfglr_element_t *element, cfglr_handle_t *handle); +void cfglr_signaler_callback_dispatch(cfglr_signaler_t *signaler, cfglr_element_t *element, cfglr_signal_e sig); + +#define CFGLR_SIGNALER_CALLBACK(FN_CALLBACK) (cfglr_signaler_t){\ + .init = &cfglr_signaler_callback_init,\ + .dispatch = &cfglr_signaler_callback_dispatch,\ + .handle = (void*)FN_CALLBACK\ +} diff --git a/include/configulator.h b/include/configulator.h index fe5638c..a666045 100644 --- a/include/configulator.h +++ b/include/configulator.h @@ -115,7 +115,9 @@ 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); +#include "cfglr_log.h" #include "cfglr_nvs.h" +#include "cfglr_signaler_callback.h" #include "cfglr_signaler_idf_event.h" #include "cfglr_signaler_lvgl.h" diff --git a/src/cfglr_signal_callback.c b/src/cfglr_signal_callback.c new file mode 100644 index 0000000..b5e74c0 --- /dev/null +++ b/src/cfglr_signal_callback.c @@ -0,0 +1,16 @@ +#include "configulator.h" + +#define TAG "CFGLR_SIG_CB" + +void cfglr_signaler_callback_init(cfglr_signaler_t *signaler, cfglr_element_t *element, cfglr_handle_t *handle) { + CFGLR_LOGI(TAG, "init"); +} + +void cfglr_signaler_callback_dispatch(cfglr_signaler_t *signaler, cfglr_element_t *element, cfglr_signal_e sig) { + CFGLR_LOGI(TAG, "dispatch"); + + if(signaler->handle != NULL) { + cfglr_callback_t callback = signaler->handle; + callback(signaler, element, sig); + } +}