1 /*
2 * Copyright (c) 2022 Rodrigo Peixoto <rodrigopex@gmail.com>
3 * SPDX-License-Identifier: Apache-2.0
4 */
5 #include "messages.h"
6
7 #include <zephyr/logging/log.h>
8 #include <zephyr/zbus/zbus.h>
9 LOG_MODULE_DECLARE(zbus, CONFIG_ZBUS_LOG_LEVEL);
10
11 static bool sensor_from_bridge;
12 ZBUS_CHAN_DEFINE(sensor_data_chan, /* Name */
13 struct sensor_data_msg, /* Message type */
14
15 NULL, /* Validator */
16 &sensor_from_bridge, /* Validator */
17 ZBUS_OBSERVERS(proxy_lis), /* observers */
18 ZBUS_MSG_INIT(0) /* Initial value {0} */
19 );
20
21 ZBUS_SUBSCRIBER_DEFINE(peripheral_sub, 8);
22
peripheral_thread(void)23 static void peripheral_thread(void)
24 {
25 const struct zbus_channel *chan;
26 struct sensor_data_msg sd = {0};
27
28 while (!zbus_sub_wait(&peripheral_sub, &chan, K_FOREVER)) {
29 sd.value += 1;
30
31 LOG_DBG("sending sensor data err = %d",
32 zbus_chan_pub(&sensor_data_chan, &sd, K_MSEC(250)));
33 }
34 }
35
36 K_THREAD_DEFINE(peripheral_thread_id, 1024, peripheral_thread, NULL, NULL, NULL, 5, 0, 0);
37