main/task_ina219.h

Thu, 30 Mar 2023 21:55:24 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Thu, 30 Mar 2023 21:55:24 +0200
changeset 6
bad3414f7bc4
parent 5
b1f38105ca7e
permissions
-rw-r--r--

Added the getTempBaro and getVoltsCurrent functions to process the measured data. Added some main task code. Added subscribe to MQTT events.

/**
 * @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