ASCEND Flight Software
Loading...
Searching...
No Matches
Public Member Functions | Private Attributes | List of all members
INA260Sensor Class Reference

A class to interface with the Adafruit INA260 sensor for current, voltage, and power measurements. More...

#include <INA260Sensor.h>

Inheritance diagram for INA260Sensor:
Collaboration diagram for INA260Sensor:

Public Member Functions

 INA260Sensor ()
 Default constructor for the INA260Sensor class.
 
 INA260Sensor (unsigned long minimum_period)
 Parameterized constructor for the INA260Sensor class.
 
void readDataPacket (uint8_t *&packet) override
 Reads sensor data and appends to packet byte array, data includes current(mA), voltage(mV), and power (mW).
 
String decodeToCSV (uint8_t *&packet) override
 Decodes sensor data from the packet into a CSV string.
 
bool verify () override
 Verifies the connection to the INA260 sensor.
 
String readData () override
 Reads data from the INA260 sensor and returns it in CSV format.
 
- Public Member Functions inherited from Sensor
 Sensor (String sensor_name, String csv_header, unsigned long minimum_period)
 
 Sensor (String sensor_name, String csv_header)
 
 Sensor (String sensor_name, String csv_header, int fields)
 Construct a new Sensor object with default minimum_period of 0 (depreciated)
 
 Sensor (String sensor_name, String csv_header, int fields, unsigned long minimum_period)
 Construct a new Sensor object (Depreciated)
 
unsigned long getPeriod () const
 Get the minimum minimum_period between sensor reads in ms.
 
void setPeriod (int minimum_period)
 Set the minimum minimum_period between sensor reads in ms.
 
unsigned long getLastExecution () const
 Get the system time of the last execution in ms.
 
void setLastExecution (int last_execution)
 Set the system time of the last execution in ms.
 
const String & getSensorCSVHeader () const
 Get the csv header string associated with this sensor.
 
void getDataPacket (uint32_t &sensor_id, uint8_t *&packet)
 Append the data from a sensor to the packet if the minium period is satisfied.
 
String readEmpty () const
 Returns CSV line in the same format as readData() but with "-" instead of data.
 
String getDataCSV ()
 Uses readData and readEmpty to get the data-filled or empty-celled CSV line for the sensor.
 
- Public Member Functions inherited from Device
 Device (String device_name)
 Default constructor, sets a max_attempt of 1 (device recovery won't be attempted)
 
 Device (String device_name, int max_attempts, int wait_factor)
 
const String & getDeviceName ()
 
bool getVerified ()
 Get if the Device is Verified.
 
void recoveryConfig (int max_attempts, int wait_factor)
 Set recovery config (used keep default constructor)
 
void setWaitFactor (int wait_factor)
 Set wait_factor.
 
void setMaxAttempts (int max_attempts)
 Set max_attempts.
 
bool attemptConnection ()
 If the sensor is verified, return true, if not and it has been long enough since the last attempt (decided by wait_factor and attempt_number), attempt to reverify (reinitialize) it.
 

Private Attributes

Adafruit_INA260 ina260
 

Additional Inherited Members

- Protected Attributes inherited from Sensor
int num_fields
 
- Protected Attributes inherited from Device
bool verified
 
String device_name
 

Detailed Description

A class to interface with the Adafruit INA260 sensor for current, voltage, and power measurements.

The INA260Sensor class is responsible for interacting with the Adafruit INA260 sensor to gather electrical data, including current (in mA), voltage (in mV), and power (in mW). This class inherits from the Sensor base class and overrides the verify() and readData() methods to provide specific functionality for the INA260 sensor.

Key functionalities:

Constructor & Destructor Documentation

◆ INA260Sensor() [1/2]

INA260Sensor::INA260Sensor ( )

Default constructor for the INA260Sensor class.

Initializes the sensor object with a default minimum period of 0 milliseconds by calling the parameterized constructor with 0.

◆ INA260Sensor() [2/2]

INA260Sensor::INA260Sensor ( unsigned long  minimum_period)

Parameterized constructor for the INA260Sensor class.

Initializes the sensor object with a specified minimum period and sets up the sensor name, CSV header, and number of data fields (3: current, voltage, and power).

Parameters
minimum_periodThe minimum time period between sensor readings, in milliseconds.

Member Function Documentation

◆ decodeToCSV()

String INA260Sensor::decodeToCSV ( uint8_t *&  packet)
overridevirtual

Decodes sensor data from the packet into a CSV string.

Data includes current(mA), voltage(mV), and power (mW).

Parameters
packetPointer to packet byte array that will be decoded.
Returns
String Decoded sensor data in CSV format.

Reimplemented from Sensor.

◆ readData()

String INA260Sensor::readData ( )
overridevirtual

Reads data from the INA260 sensor and returns it in CSV format.

This function reads the current (in mA), bus voltage (in mV), and power (in mW) values from the INA260 sensor and formats them into a CSV string.

Returns
String A string containing the sensor data in the format: "Current (mA), Voltage (mV), Power (mW), ".

Implements Sensor.

◆ readDataPacket()

void INA260Sensor::readDataPacket ( uint8_t *&  packet)
overridevirtual

Reads sensor data and appends to packet byte array, data includes current(mA), voltage(mV), and power (mW).

Parameters
packetPointer to the packet byte array.

Reimplemented from Sensor.

◆ verify()

bool INA260Sensor::verify ( )
overridevirtual

Verifies the connection to the INA260 sensor.

This function initializes the INA260 sensor object and checks whether the sensor is successfully detected on the I2C bus.

Returns
true If the sensor is successfully initialized.
false If the sensor fails to initialize or is not detected.

Implements Sensor.

Member Data Documentation

◆ ina260

Adafruit_INA260 INA260Sensor::ina260
private

The documentation for this class was generated from the following files: