Skip to content

Commit

Permalink
mgmt: hawkbit: samples: add event callbacks
Browse files Browse the repository at this point in the history
add event callbacks to sample.

Signed-off-by: Fin Maaß <[email protected]>
  • Loading branch information
maass-hamburg committed Jun 5, 2024
1 parent 4199637 commit 5faedd0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 0 deletions.
3 changes: 3 additions & 0 deletions samples/subsys/mgmt/hawkbit/prj.conf
Original file line number Diff line number Diff line change
Expand Up @@ -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
28 changes: 28 additions & 0 deletions samples/subsys/mgmt/hawkbit/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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");
Expand Down

0 comments on commit 5faedd0

Please sign in to comment.