zephyr/samples/sensor/max44009/src/main.c
Patrik Flykt 079f55d519 samples: Add 'U' to unsigned variable assignments
Add 'U' to a value when assigning it to an unsigned variable.
MISRA-C rule 7.2

Signed-off-by: Patrik Flykt <patrik.flykt@intel.com>
2018-12-04 22:51:56 -05:00

49 lines
916 B
C

/*
* Copyright (c) 2016 Intel Corporation
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr.h>
#include <misc/printk.h>
#include <sensor.h>
/**
* @file Sample app using the MAX44009 light sensor through ARC I2C.
*
* This app will read the sensor reading via I2C interface and show
* the result every 4 seconds.
*/
void main(void)
{
struct device *dev;
struct sensor_value val;
u32_t lum = 0U;
printk("MAX44009 light sensor application\n");
dev = device_get_binding("MAX44009");
if (!dev) {
printk("sensor: device not found.\n");
return;
}
while (1) {
if (sensor_sample_fetch_chan(dev, SENSOR_CHAN_LIGHT) != 0) {
printk("sensor: sample fetch fail.\n");
return;
}
if (sensor_channel_get(dev, SENSOR_CHAN_LIGHT, &val) != 0) {
printk("sensor: channel get fail.\n");
return;
}
lum = val.val1;
printk("sensor: lum reading: %d\n", lum);
k_sleep(4000);
}
}