1 /* 2 * Copyright (c) 2016 Intel Corporation 3 * 4 * SPDX-License-Identifier: Apache-2.0 5 */ 6 7 #include <zephyr/kernel.h> 8 #include <zephyr/sys/printk.h> 9 #include <zephyr/drivers/sensor.h> 10 11 /** 12 * @file Sample app using the MAX44009 light sensor through ARC I2C. 13 * 14 * This app will read the sensor reading via I2C interface and show 15 * the result every 4 seconds. 16 */ 17 main(void)18int main(void) 19 { 20 const struct device *const dev = DEVICE_DT_GET_ONE(maxim_max44009); 21 struct sensor_value val; 22 uint32_t lum = 0U; 23 24 printk("MAX44009 light sensor application\n"); 25 26 if (!device_is_ready(dev)) { 27 printk("Device %s is not ready\n", dev->name); 28 return 0; 29 } 30 31 while (1) { 32 if (sensor_sample_fetch_chan(dev, SENSOR_CHAN_LIGHT) != 0) { 33 printk("sensor: sample fetch fail.\n"); 34 return 0; 35 } 36 37 if (sensor_channel_get(dev, SENSOR_CHAN_LIGHT, &val) != 0) { 38 printk("sensor: channel get fail.\n"); 39 return 0; 40 } 41 42 lum = val.val1; 43 printk("sensor: lum reading: %d\n", lum); 44 45 k_sleep(K_MSEC(4000)); 46 } 47 return 0; 48 } 49