zephyr/samples/sensor/ina219/src/main.c
Gerard Marull-Paretas c7b5b3c419 samples: migrate includes to contain <zephyr/...> prefix
In order to bring consistency in-tree, migrate all samples to the use
the new prefix <zephyr/...>. Note that the conversion has been scripted:

```python
from pathlib import Path
import re

EXTENSIONS = ("c", "h", "cpp", "rst")

for p in Path(".").glob("samples/**/*"):
    if not p.is_file() or p.suffix and p.suffix[1:] not in EXTENSIONS:
        continue

    content = ""
    with open(p) as f:
        for line in f:
            m = re.match(r"^(.*)#include <(.*)>(.*)$", line)
            if (m and
                not m.group(2).startswith("zephyr/") and
                (Path(".") / "include" / "zephyr" / m.group(2)).exists()):
                content += (
                    m.group(1) +
                    "#include <zephyr/" + m.group(2) +">" +
                    m.group(3) + "\n"
                )
            else:
                content += line

    with open(p, "w") as f:
        f.write(content)
```

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
2022-05-06 11:29:59 +02:00

43 lines
915 B
C

/*
* Copyright (c) 2021 Leonard Pollak
*
* SPDX-License-Identifier: Apache-2.0
*/
#include <zephyr/zephyr.h>
#include <stdio.h>
#include <zephyr/drivers/sensor.h>
void main(void)
{
const struct device *ina = DEVICE_DT_GET_ONE(ti_ina219);
struct sensor_value v_bus, power, current;
int rc;
if (!device_is_ready(ina)) {
printf("Device %s is not ready.\n", ina->name);
return;
}
while (true) {
rc = sensor_sample_fetch(ina);
if (rc) {
printf("Could not fetch sensor data.\n");
return;
}
sensor_channel_get(ina, SENSOR_CHAN_VOLTAGE, &v_bus);
sensor_channel_get(ina, SENSOR_CHAN_POWER, &power);
sensor_channel_get(ina, SENSOR_CHAN_CURRENT, &current);
printf("Bus: %f [V] -- "
"Power: %f [W] -- "
"Current: %f [A]\n",
sensor_value_to_double(&v_bus),
sensor_value_to_double(&power),
sensor_value_to_double(&current));
k_sleep(K_MSEC(2000));
}
}