1 /* 2 * Copyright (c) 2023, Vitrolife A/S 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #include <zephyr/kernel.h> 8 #include <zephyr/drivers/sensor.h> 9 #include <zephyr/logging/log.h> 10 11 LOG_MODULE_REGISTER(MAIN); 12 main(void)13int main(void) 14 { 15 struct sensor_value value; 16 const struct device *const dev = DEVICE_DT_GET(DT_ALIAS(co2)); 17 18 if (!device_is_ready(dev)) { 19 LOG_ERR("%s is not ready", dev->name); 20 return 0; 21 } 22 23 while (1) { 24 if (sensor_sample_fetch(dev) == 0 && 25 sensor_channel_get(dev, SENSOR_CHAN_CO2, &value) == 0) { 26 LOG_INF("CO2 %d ppm", value.val1); 27 } 28 29 k_msleep(1000); 30 } 31 32 return 0; 33 } 34