Fuel Gauge

This module provides a set of functionalities for managing the Fuel Gauge system, including initialization, bar state updates, low fuel warnings, and configuration management to ensure accurate representation of fuel levels.

Configuration Parameters

All API functions have the first argument as the module ID.

Configuration

Name

Description

Range

enable

Enables Fuel Gauge functionality.

0 (disabled) or 1 (enabled)

fuel_capacity

Total fuel tank capacity (in liters).

1 to 48 liters

reserve_fuel_value

Reserve fuel level threshold (in percentage).

0 to 100%

max_bar_count

Maximum number of bars for fuel display.

1 to 7

bar_thresholds

ON/OFF thresholds for each bar in the fuel gauge.

Array of thresholds (configurable values).

APIs

The Fuel Gauge module provides the following APIs to initialize, process, and update the fuel gauge data:

API Functions

Function

Description

rs_am_fuelgauge_init

Initializes the fuel gauge system with default configuration values.

rs_am_fuelgauge_process

Processes the fuel gauge system by updating the bar states and checking for warnings.

Error Codes

Each API for the fuel gauge module returns success or failure codes. For detailed information on the error codes, please refer to the following section:

See also

:doc:/error_codes

Fuel Gauge Module Header Details

The header file for fuel gauge modules, rs_am_fuel_gauge.h, defines the required structures and APIs for initialization and processing.

Defines

RS_AM_FUEL_GAUGE_MAX_BAR_VALUE

Maximum number of bars for fuel gauge.

Typedefs

typedef struct tag_rs_fuel_bar_threshold rs_fuel_bar_threshold_t

Fuel Gauge threshold data structure.

typedef struct tag_rs_fuel_config rs_fuel_config_t

Fuel Gauge configuration data structure.

typedef struct tag_rs_fuel_runtime rs_fuel_runtime_t

Fuel Gauge runtime data structure.

typedef struct tag_rs_fuel_output rs_fuel_output_t

Fuel Gauge output data structure.

typedef struct tag_rs_am_fuelgauge rs_am_fuelgauge_t

Contains information about fuel gauge.

Functions

rs_ret_val_t rs_am_fuelgauge_init(rs_am_fuelgauge_t *ptr_fuelgauge)

Initializes the fuel gauge module.

This function Sets default values for configuration and runtime state, and registers the module with the dispatcher.

Parameters:

ptr_fuelgauge[in] Pointer to the fuel gauge structure to be initialized.

Returns:

Returns success on successful initialization.

rs_ret_val_t rs_am_fuelgauge_process(rs_am_fuelgauge_t *ptr_fuelgauge)

Periodically updates the fuel gauge state.

Updates the bar states, writes fuel level data to memory, and dispatches the updated display fuel level to consumers.

Parameters:

ptr_fuelgauge[in] Pointer to the fuel gauge structure.

Returns:

Returns success after processing the fuel state.

struct tag_rs_fuel_bar_threshold
#include <rs_am_fuel_gauge.h>

Fuel Gauge threshold data structure.

Public Members

uint32_t on_threshold

Threshold for turning the bar ON.

uint32_t off_threshold

Threshold for turning the bar OFF.

struct tag_rs_fuel_config
#include <rs_am_fuel_gauge.h>

Fuel Gauge configuration data structure.

Public Members

uint8_t enable

Enable or disable the fuel gauge functionality.

uint8_t fuel_capacity

Total fuel tank capacity (e.g., 48 liters)

uint8_t reserve_fuel_value

Reserve fuel threshold (in value)

uint8_t max_bar_count

Maximum number of bars for fuel display.

uint8_t fuel_threshold_value

Fuel gauge threshold value.

rs_fuel_bar_threshold_t fuel_bar_thresholds[RS_AM_FUEL_GAUGE_MAX_BAR_VALUE]

Thresholds for each bar’s on/off state.

struct tag_rs_fuel_runtime
#include <rs_am_fuel_gauge.h>

Fuel Gauge runtime data structure.

Public Members

uint8_t fuel_level

Current fuel level in percentage (0-100)

uint8_t raw_fuel_data

Raw fuel data read from the sensor.

uint8_t bar_state[RS_AM_FUEL_GAUGE_MAX_BAR_VALUE]

State of each fuel bar (on/off)

uint8_t fuel_low_value_threshold

Fuel gauge low threshold value.

struct tag_rs_fuel_output
#include <rs_am_fuel_gauge.h>

Fuel Gauge output data structure.

Public Members

uint8_t display_fuel_level

Fuel level to be displayed on the gauge.

uint8_t display_fuel_value

Fuel value to be displayed.

uint8_t filtered_fuel_level

Filtered value of the fuel level for smooth updates.

uint8_t fuel_state

State of the fuel system (e.g., low, normal)

struct tag_rs_am_fuelgauge
#include <rs_am_fuel_gauge.h>

Contains information about fuel gauge.

Public Members

rs_fuel_config_t config

Configuration settings for the fuel gauge.

rs_fuel_runtime_t runtime

Runtime data of the fuel gauge system.

rs_fuel_output_t output

Output data to control the display of the fuel gauge.