<commit_before>/*
 * Copyright (c) 2020 Linumiz
 *
 * SPDX-License-Identifier: Apache-2.0
 */

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

static void bq274xx_show_values(const char *type, struct sensor_value value)
{
	if ((value.val2 < 0) && (value.val1 >= 0)) {
		value.val2 = -(value.val2);
		printk("%s: -%d.%06d\n", type, value.val1, value.val2);
	} else if ((value.val2 > 0) && (value.val1 < 0)) {
		printk("%s: %d.%06d\n", type, value.val1, value.val2);
	} else if ((value.val2 < 0) && (value.val1 < 0)) {
		value.val2 = -(value.val2);
		printk("%s: %d.%06d\n", type, value.val1, value.val2);
	} else {
		printk("%s: %d.%06d\n", type, value.val1, value.val2);
	}
}

static void do_main(const struct device *dev)
{
	int status = 0;
	struct sensor_value voltage, current, state_of_charge,
		full_charge_capacity, remaining_charge_capacity, avg_power,
		int_temp, current_standby, current_max_load, state_of_health;

	while (1) {
		status = sensor_sample_fetch_chan(dev,
						  SENSOR_CHAN_GAUGE_VOLTAGE);
		if (status < 0) {
			printk("Unable to fetch the voltage\n");
			return;
		}

		status = sensor_channel_get(dev, SENSOR_CHAN_GAUGE_VOLTAGE,
					    &voltage);
		if (status < 0) {
			printk("Unable to get the voltage value\n");
			return;
		}

		printk("Voltage: %d.%06dV\n", voltage.val1, voltage.val2);

		status = sensor_channel_get(dev, SENSOR_CHAN_GAUGE_AVG_CURRENT,
					    &current);
		if (status < 0) {
			printk("Unable to get the current value\n");
		}
		bq274xx_show_values("Avg Current in Amps", current);

		status = sensor_channel_get(
			dev, SENSOR_CHAN_GAUGE_STDBY_CURRENT, &current_standby);
		if (status < 0) {
			printk("Unable to get the current value\n");
		}
		bq274xx_show_values("Standby Current in Amps", current_standby);

		status = sensor_channel_get(dev,
					    SENSOR_CHAN_GAUGE_MAX_LOAD_CURRENT,
					    &current_max_load);
		if (status < 0) {
			printk("Unable to get the current value\n");
		}
		bq274xx_show_values("Max Load Current in Amps",
				    current_max_load);

		status = sensor_channel_get(dev,
					    SENSOR_CHAN_GAUGE_STATE_OF_CHARGE,
					    &state_of_charge);
		if (status < 0) {
			printk("Unable to get state of charge\n");
		}

		printk("State of charge: %d%%\n", state_of_charge.val1);

		status = sensor_channel_get(dev,
					    SENSOR_CHAN_GAUGE_STATE_OF_HEALTH,
					    &state_of_health);
		if (status < 0) {
			printk("Unable to get state of charge\n");
		}

		printk("State of health: %d%%\n", state_of_health.val1);

		status = sensor_channel_get(dev, SENSOR_CHAN_GAUGE_AVG_POWER,
					    &avg_power);
		if (status < 0) {
			printk("Unable to get avg power\n");
		}
		bq274xx_show_values("Avg Power in Watt", avg_power);

		status = sensor_channel_get(
			dev, SENSOR_CHAN_GAUGE_FULL_CHARGE_CAPACITY,
			&full_charge_capacity);
		if (status < 0) {
			printk("Unable to get full charge capacity\n");
		}

		printk("Full charge capacity: %d.%06dAh\n",
		       full_charge_capacity.val1, full_charge_capacity.val2);

		status = sensor_channel_get(
			dev, SENSOR_CHAN_GAUGE_REMAINING_CHARGE_CAPACITY,
			&remaining_charge_capacity);
		if (status < 0) {
			printk("Unable to get remaining charge capacity\n");
		}

		printk("Remaining charge capacity: %d.%06dAh\n",
		       remaining_charge_capacity.val1,
		       remaining_charge_capacity.val2);

		status = sensor_channel_get(dev, SENSOR_CHAN_GAUGE_TEMP,
					    &int_temp);
		if (status < 0) {
			printk("Unable to read internal temperature\n");
		}

		printk("Gauge Temperature: %d.%06d C\n", int_temp.val1,<commit_msg>samples: sensor: bq274xx: Read all gauge channel individually.<commit_after>/*
 * Copyright (c) 2020 Linumiz
 *
 * SPDX-License-Identifier: Apache-2.0
 */

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

static void bq274xx_show_values(const char *type, struct sensor_value value)
{
	if ((value.val2 < 0) && (value.val1 >= 0)) {
		value.val2 = -(value.val2);
		printk("%s: -%d.%06d\n", type, value.val1, value.val2);
	} else if ((value.val2 > 0) && (value.val1 < 0)) {
		printk("%s: %d.%06d\n", type, value.val1, value.val2);
	} else if ((value.val2 < 0) && (value.val1 < 0)) {
		value.val2 = -(value.val2);
		printk("%s: %d.%06d\n", type, value.val1, value.val2);
	} else {
		printk("%s: %d.%06d\n", type, value.val1, value.val2);
	}
}

static void do_main(const struct device *dev)
{
	int status = 0;
	struct sensor_value voltage, current, state_of_charge,
		full_charge_capacity, remaining_charge_capacity, avg_power,
		int_temp, current_standby, current_max_load, state_of_health;

	while (1) {
		status = sensor_sample_fetch_chan(dev,
						  SENSOR_CHAN_GAUGE_VOLTAGE);
		if (status < 0) {
			printk("Unable to fetch the voltage\n");
			return;
		}

		status = sensor_channel_get(dev, SENSOR_CHAN_GAUGE_VOLTAGE,
					    &voltage);
		if (status < 0) {
			printk("Unable to get the voltage value\n");
			return;
		}

		printk("Voltage: %d.%06dV\n", voltage.val1, voltage.val2);

		status = sensor_sample_fetch_chan(dev,
					       SENSOR_CHAN_GAUGE_AVG_CURRENT);
		if (status < 0) {
			printk("Unable to fetch the Average current\n");
			return;
		}

		status = sensor_channel_get(dev, SENSOR_CHAN_GAUGE_AVG_CURRENT,
					    &current);
		if (status < 0) {
			printk("Unable to get the current value\n");
			return;
		}

		bq274xx_show_values("Avg Current in Amps", current);

		status = sensor_sample_fetch_chan(dev,
					SENSOR_CHAN_GAUGE_STDBY_CURRENT);
		if (status < 0) {
			printk("Unable to fetch Standby Current\n");
			return;
		}

		status = sensor_channel_get(dev,
					SENSOR_CHAN_GAUGE_STDBY_CURRENT,
					&current_standby);
		if (status < 0) {
			printk("Unable to get the current value\n");
			return;
		}

		bq274xx_show_values("Standby Current in Amps", current_standby);

		status = sensor_sample_fetch_chan(dev,
					SENSOR_CHAN_GAUGE_MAX_LOAD_CURRENT);
		if (status < 0) {
			printk("Unable to fetch Max Load Current\n");
			return;
		}

		status = sensor_channel_get(dev,
					SENSOR_CHAN_GAUGE_MAX_LOAD_CURRENT,
					&current_max_load);
		if (status < 0) {
			printk("Unable to get the current value\n");
			return;
		}

		bq274xx_show_values("Max Load Current in Amps",
				    current_max_load);

		status = sensor_sample_fetch_chan(dev,
					SENSOR_CHAN_GAUGE_STATE_OF_CHARGE);
		if (status < 0) {
			printk("Unable to fetch State of Charge\n");
			return;
		}

		status = sensor_channel_get(dev,
					    SENSOR_CHAN_GAUGE_STATE_OF_CHARGE,
					    &state_of_charge);
		if (status < 0) {
			printk("Unable to get state of charge\n");
			return;
		}

		printk("State of charge: %d%%\n", state_of_charge.val1);

		status = sensor_sample_fetch_chan(dev,
					SENSOR_CHAN_GAUGE_STATE_OF_HEALTH);
		if (status < 0) {
			printk("Failed to fetch State of Health\n");
			return;
		}

		status = sensor_channel_get(dev,
					    SENSOR_CHAN_GAUGE_STATE_OF_HEALTH,
					    &state_of_health);
		if (status < 0) {
			printk("Unable to get state of charge\n");
			return;
		}

		printk("State of health: %d%%\n", state_of_health.val1);

		status = sensor_sample_fetch_chan(dev,
					SENSOR_CHAN_GAUGE_AVG_POWER);
		if (status < 0) {
			printk("Unable to fetch Avg Power\n");
			return;
		}

		status = sensor_channel_get(dev, SENSOR_CHAN_GAUGE_AVG_POWER,
					    &avg_power);
		if (status < 0) {
			printk("Unable to get avg power\n");
			return;
		}

		bq274xx_show_values("Avg Power in Watt", avg_power);

		status = sensor_sample_fetch_chan(dev,
				SENSOR_CHAN_GAUGE_FULL_CHARGE_CAPACITY);
		if (status < 0) {
			printk("Failed to fetch Full Charge Capacity\n");
			return;
		}

		status = sensor_channel_get(dev,
				SENSOR_CHAN_GAUGE_FULL_CHARGE_CAPACITY,
				&full_charge_capacity);
		if (status < 0) {
			printk("Unable to get full charge capacity\n");
			return;
		}

		printk("Full charge capacity: %d.%06dAh\n",
		       full_charge_capacity.val1, full_charge_capacity.val2);

		status = sensor_sample_fetch_chan(dev,
				SENSOR_CHAN_GAUGE_REMAINING_CHARGE_CAPACITY);
		if (status < 0) {
			printk("Unable to fetch Remaining Charge Capacity\n");
			return;
		}

		status = sensor_channel_get(dev,
				SENSOR_CHAN_GAUGE_REMAINING_CHARGE_CAPACITY,
				&remaining_charge_capacity);
		if (status < 0) {
			printk("Unable to get remaining charge capacity\n");
			return;
		}

		printk("Remaining charge capacity: %d.%06dAh\n",
		       remaining_charge_capacity.val1,
		       remaining_charge_capacity.val2);

		status = sensor_sample_fetch_chan(dev, SENSOR_CHAN_GAUGE_TEMP);
		if (status < 0) {
			printk("Failed to fetch Gauge Temp\n");
			return;
		}

		status = sensor_channel_get(dev, SENSOR_CHAN_GAUGE_TEMP,
					    &int_temp);
		if (status < 0) {
			printk("Unable to read internal temperature\n");
			return;
		}

		printk("Gauge Temperature: %d.%06d C\n", int_temp.val1,
{'fraction_non_alphanumeric': 0.12779408444344095, 'fraction_numerical': 0.020094829532625876, 'mean_word_length': 3.7526824034334765, 'pattern_counts': {'":': 0, '<': 50, '<?xml version=': 0, '>': 15, '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': '4918093', 'n_tokens_mistral': 3896, 'n_tokens_neox': 3338, 'n_words': 694}