diff --git a/samples/subsys/mgmt/hawkbit/prj.conf b/samples/subsys/mgmt/hawkbit/prj.conf index 9ce8e044da2332a..602fee66b7a34c8 100644 --- a/samples/subsys/mgmt/hawkbit/prj.conf +++ b/samples/subsys/mgmt/hawkbit/prj.conf @@ -71,3 +71,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 d1e64e8185e10b9..78dbdd269ff98fa 100644 --- a/samples/subsys/mgmt/hawkbit/src/main.c +++ b/samples/subsys/mgmt/hawkbit/src/main.c @@ -55,6 +55,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 +96,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");