<commit_before>/*
 * Copyright (c) 2019, Linaro Ltd.
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include <zephyr/zephyr.h>
#include <zephyr/device.h>
#include <zephyr/drivers/sensor.h>
#include <stdio.h>
#include <zephyr/sys/printk.h>


static int32_t read_sensor(const struct device *sensor)
{
	struct sensor_value val[3];
	int32_t ret = 0;

	ret = sensor_sample_fetch(sensor);
	if (ret) {
		printk("sensor_sample_fetch failed ret %d\n", ret);
		goto end;
	}

	ret = sensor_channel_get(sensor, SENSOR_CHAN_MAGN_XYZ, val);
	if (ret < 0) {
		printf("Cannot read sensor channels\n");
		goto end;
	}

	printf("( x y z ) = ( %f  %f  %f )\n", sensor_value_to_double(&val[0]),
	       sensor_value_to_double(&val[1]),
	       sensor_value_to_double(&val[2]));

end:
	return ret;
}

void main(void)
{
	const struct device *dev;

	dev = device_get_binding(DT_LABEL(DT_INST(0, honeywell_hmc5883l)));

	if (dev == NULL) {
		printk("Could not get %s device at I2C addr 0x%02X\n",
		       DT_LABEL(DT_INST(0, honeywell_hmc5883l)),
		       DT_REG_ADDR(DT_INST(0, honeywell_hmc5883l)));
		return;
	}

	printk("device is %p, name is %s\n", dev, dev->name);

	while (1) {
		read_sensor(dev);
		k_sleep(K_MSEC(1000));
	}
}<commit_msg>samples: sensor: hmc5883l: Convert sample to use DEVICE_DT_GET_ONE<commit_after>/*
 * Copyright (c) 2019, Linaro Ltd.
 *
 * SPDX-License-Identifier: Apache-2.0
 */

#include <zephyr/zephyr.h>
#include <zephyr/device.h>
#include <zephyr/drivers/sensor.h>
#include <stdio.h>
#include <zephyr/sys/printk.h>


static int32_t read_sensor(const struct device *sensor)
{
	struct sensor_value val[3];
	int32_t ret = 0;

	ret = sensor_sample_fetch(sensor);
	if (ret) {
		printk("sensor_sample_fetch failed ret %d\n", ret);
		goto end;
	}

	ret = sensor_channel_get(sensor, SENSOR_CHAN_MAGN_XYZ, val);
	if (ret < 0) {
		printf("Cannot read sensor channels\n");
		goto end;
	}

	printf("( x y z ) = ( %f  %f  %f )\n", sensor_value_to_double(&val[0]),
	       sensor_value_to_double(&val[1]),
	       sensor_value_to_double(&val[2]));

end:
	return ret;
}

void main(void)
{
	const struct device *dev = DEVICE_DT_GET_ONE(honeywell_hmc5883l);

	if (!device_is_ready(dev)) {
		printk("Device %s is not ready\n", dev->name);
		return;
	}

	printk("device is %p, name is %s\n", dev, dev->name);

	while (1) {
		read_sensor(dev);
		k_sleep(K_MSEC(1000));
	}
}
{'fraction_non_alphanumeric': 0.15644820295983086, 'fraction_numerical': 0.029175475687103596, 'mean_word_length': 4.18859649122807, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 16, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '910081', 'n_tokens_mistral': 1041, 'n_tokens_neox': 964, 'n_words': 209}