Skip to content

Commit 97cdd97

Browse files
maass-hamburgkartben
authored andcommitted
mgmt: hawkbit: samples: add event callbacks
add event callbacks to sample. Signed-off-by: Fin Maaß <[email protected]>
1 parent 49f5bc9 commit 97cdd97

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

samples/subsys/mgmt/hawkbit/prj.conf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,6 @@ CONFIG_BUILD_OUTPUT_HEX=y
7070

7171
#Use custom attributes for hawkBit
7272
CONFIG_HAWKBIT_CUSTOM_ATTRIBUTES=y
73+
74+
# Use event callbacks for hawkBit
75+
CONFIG_HAWKBIT_EVENT_CALLBACKS=y

samples/subsys/mgmt/hawkbit/src/main.c

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
#include <zephyr/mgmt/hawkbit/hawkbit.h>
99
#include <zephyr/mgmt/hawkbit/config.h>
1010
#include <zephyr/mgmt/hawkbit/autohandler.h>
11+
#include <zephyr/mgmt/hawkbit/event.h>
1112
#include <zephyr/dfu/mcuboot.h>
1213
#include <zephyr/sys/printk.h>
1314
#include <zephyr/sys/reboot.h>
@@ -55,6 +56,29 @@ int hawkbit_new_config_data_cb(const char *device_id, uint8_t *buffer, const siz
5556
}
5657
#endif /* CONFIG_HAWKBIT_CUSTOM_ATTRIBUTES */
5758

59+
#ifdef CONFIG_HAWKBIT_EVENT_CALLBACKS
60+
void hawkbit_event_cb(struct hawkbit_event_callback *cb, enum hawkbit_event_type event)
61+
{
62+
LOG_INF("hawkBit event: %d", event);
63+
64+
switch (event) {
65+
case HAWKBIT_EVENT_START_RUN:
66+
LOG_INF("Run of hawkBit started");
67+
break;
68+
69+
case HAWKBIT_EVENT_END_RUN:
70+
LOG_INF("Run of hawkBit ended");
71+
break;
72+
73+
default:
74+
break;
75+
}
76+
}
77+
78+
static HAWKBIT_EVENT_CREATE_CALLBACK(hb_event_cb_start, hawkbit_event_cb, HAWKBIT_EVENT_START_RUN);
79+
static HAWKBIT_EVENT_CREATE_CALLBACK(hb_event_cb_end, hawkbit_event_cb, HAWKBIT_EVENT_END_RUN);
80+
#endif /* CONFIG_HAWKBIT_EVENT_CALLBACKS */
81+
5882
int main(void)
5983
{
6084
int ret = -1;
@@ -73,6 +97,11 @@ int main(void)
7397
}
7498
#endif /* CONFIG_HAWKBIT_CUSTOM_ATTRIBUTES */
7599

100+
#ifdef CONFIG_HAWKBIT_EVENT_CALLBACKS
101+
hawkbit_event_add_callback(&hb_event_cb_start);
102+
hawkbit_event_add_callback(&hb_event_cb_end);
103+
#endif /* CONFIG_HAWKBIT_EVENT_CALLBACKS */
104+
76105
ret = hawkbit_init();
77106
if (ret < 0) {
78107
LOG_ERR("Failed to init hawkBit");

0 commit comments

Comments
 (0)