main/task_ina219.h

Sat, 15 Apr 2023 13:29:40 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Sat, 15 Apr 2023 13:29:40 +0200
changeset 29
551a53b31373
parent 6
bad3414f7bc4
permissions
-rw-r--r--

Final release and installed for production.

/**
 * @file task_ina219.h
 * @brief The FreeRTOS task to query the INA219 sensors connected to
 *        the I2C bus.
 *        The task will update the sensor state structures.
 */

#ifndef	_TASK_INA219_H
#define	_TASK_INA219_H

/*
 * Error codes in this task
 */
#define	INA219_ERR_NONE			0	///< No errors
#define INA219_ERR_READ			1

#define	I_MAX_LOOPS			32
#define	I_MAX_CURRENT			5	///< Max 5 Ampere
#define	I_SHUNT_RESISTOR_MILLI_OHM	100	///< Shunt value


typedef struct {
    bool		valid;			///< Valid measurement
    bool		fake;			///< Fake measurement
    uint8_t		address;		///< Device i2c address
    float		shunt;			///< Shunt voltage
    float		volts;			///< Bus voltage
    float		current;		///< Current mA
    int			error;			///< Error result
} INA219_tt;


/**
 * @brief Structure containing the variables for the INA219 task.
 */
typedef struct {
    bool		valid;			///< Valid measurement
    bool		fake;			///< Fake measurement
    INA219_tt		Battery;		///< Battery measurement
    INA219_tt		Solar;			///< Solar measurement
    int			error;			///< Error result
} INA219_State;



/**
 * @brief Request a new measurement from selected sensors.
 */
void request_ina219(void);


/**
 * @brief Check if results are ready
 * @return true of results are ready, else false.
 */
bool ready_ina219(void);


/**
 * @brief The FreeRTOS task to update the INA219 on request.
 * @param pvParameters Parameters for the task.
 */
void task_ina219(void *pvParameters);


#endif

mercurial