Hello everybody,
i succeeded to get the output from BME280 and MPU6060 sensors
I need to merge them together
Kindly, I need help to Setup prj.conf file
Thanks & Regards
Test the following sample. I added a work queue, such that you can offload the sensor reading when the button is pressed
Get the sensor data from the functions get_mpu6050_data_work_fn and get_bme280_data_data_work_work_fn. (run the sensor_sample_fetch and sensor_channel_get functions inside work queue functions).
diff --git a/samples/commun/src/main.c b/samples/commun/src/main.c
index 44557eaaf..ff1bce410 100644
--- a/samples/commun/src/main.c
+++ b/samples/commun/src/main.c
@@ -21,8 +21,15 @@ static const struct gpio_dt_spec button = GPIO_DT_SPEC_GET_OR(SW0_NODE, gpios,
static struct gpio_callback button_cb_data;
static struct gpio_dt_spec led = GPIO_DT_SPEC_GET_OR(DT_ALIAS(led0), gpios,
{0});
-
-
+
+#define APP_WORK_QUEUE_SIZE 4096
+#define APP_WORK_QUEUE_PRI -1
+
+K_THREAD_STACK_DEFINE(application_stack_area, APP_WORK_QUEUE_SIZE);
+static struct k_work_q application_work_q;
+
+static struct k_work get_bme280_data_data_work;
+static struct k_work get_mpu6050_data_work;
static const char *now_str(void)
{
@@ -117,15 +124,39 @@ static void handle_mpu6050_drdy(const struct device *dev,
}
}
#endif /* CONFIG_MPU6050_TRIGGER */
+
+static void get_mpu6050_data_work_fn(struct k_work *work)
+{
+ printk("Get MPU6050 data\n");
+}
+
+static void get_bme280_data_data_work_work_fn(struct k_work *work)
+{
+ printk("Get BME280 data\n");
+}
+
void button_pressed(const struct device *dev, struct gpio_callback *cb,
uint32_t pins)
{
printk("Button pressed at %" PRIu32 "\n", k_cycle_get_32());
+ k_work_submit_to_queue(&application_work_q, &get_bme280_data_data_work);
+ k_work_submit_to_queue(&application_work_q, &get_mpu6050_data_work);
+}
+
+static void work_init(void)
+{
+ k_work_init(&get_mpu6050_data_work, get_mpu6050_data_work_fn);
+ k_work_init(&get_bme280_data_data_work, get_bme280_data_data_work_work_fn);
}
void main(void)
{
int ret;
+ k_work_queue_start(&application_work_q, application_stack_area,
+ K_THREAD_STACK_SIZEOF(application_stack_area),
+ APP_WORK_QUEUE_PRI, NULL);
+ work_init();
+
if (!device_is_ready(button.port)) {
printk("Error: button device %s is not ready\n",
button.port->name);