diff --git a/samples/subsys/mgmt/hawkbit/prj.conf b/samples/subsys/mgmt/hawkbit/prj.conf index e79a4be7871..4ff8a11bd93 100644 --- a/samples/subsys/mgmt/hawkbit/prj.conf +++ b/samples/subsys/mgmt/hawkbit/prj.conf @@ -70,3 +70,6 @@ CONFIG_BUILD_OUTPUT_HEX=y #Use custom attributes for hawkBit CONFIG_HAWKBIT_CUSTOM_ATTRIBUTES=y + +# Use event callbacks for hawkBit +CONFIG_HAWKBIT_EVENT_CALLBACKS=y diff --git a/samples/subsys/mgmt/hawkbit/src/main.c b/samples/subsys/mgmt/hawkbit/src/main.c index d1e64e8185e..1fb1eb3d8d2 100644 --- a/samples/subsys/mgmt/hawkbit/src/main.c +++ b/samples/subsys/mgmt/hawkbit/src/main.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -55,6 +56,29 @@ int hawkbit_new_config_data_cb(const char *device_id, uint8_t *buffer, const siz } #endif /* CONFIG_HAWKBIT_CUSTOM_ATTRIBUTES */ +#ifdef CONFIG_HAWKBIT_EVENT_CALLBACKS +void hawkbit_event_cb(struct hawkbit_event_callback *cb, enum hawkbit_event_type event) +{ + LOG_INF("hawkBit event: %d", event); + + switch (event) { + case HAWKBIT_EVENT_START_RUN: + LOG_INF("Run of hawkBit started"); + break; + + case HAWKBIT_EVENT_END_RUN: + LOG_INF("Run of hawkBit ended"); + break; + + default: + break; + } +} + +static HAWKBIT_EVENT_CREATE_CALLBACK(hb_event_cb_start, hawkbit_event_cb, HAWKBIT_EVENT_START_RUN); +static HAWKBIT_EVENT_CREATE_CALLBACK(hb_event_cb_end, hawkbit_event_cb, HAWKBIT_EVENT_END_RUN); +#endif /* CONFIG_HAWKBIT_EVENT_CALLBACKS */ + int main(void) { int ret = -1; @@ -73,6 +97,11 @@ int main(void) } #endif /* CONFIG_HAWKBIT_CUSTOM_ATTRIBUTES */ +#ifdef CONFIG_HAWKBIT_EVENT_CALLBACKS + hawkbit_event_add_callback(&hb_event_cb_start); + hawkbit_event_add_callback(&hb_event_cb_end); +#endif /* CONFIG_HAWKBIT_EVENT_CALLBACKS */ + ret = hawkbit_init(); if (ret < 0) { LOG_ERR("Failed to init hawkBit");