Skip to content
Snippets Groups Projects
Commit fa1cf343 authored by Bilal Hassan's avatar Bilal Hassan
Browse files

Merge branch 'sensor_readout' into HEAD

parents 01aa1fe8 00d9d833
No related branches found
No related tags found
5 merge requests!39Merge Develop into Main,!19development into master,!17Inital Host, initial Client,!10merge serial comm and sd write into espnow,!8merge sensor_readout into develop
Showing
with 906 additions and 0 deletions
.pio
.vscode/.browse.c_cpp.db*
.vscode/c_cpp_properties.json
.vscode/launch.json
.vscode/ipch
{
// See http://go.microsoft.com/fwlink/?LinkId=827846
// for the documentation about the extensions.json format
"recommendations": [
"platformio.platformio-ide"
],
"unwantedRecommendations": [
"ms-vscode.cpptools-extension-pack"
]
}
{
"files.associations": {
"array": "cpp",
"atomic": "cpp",
"*.tcc": "cpp",
"cctype": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"deque": "cpp",
"unordered_map": "cpp",
"unordered_set": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"functional": "cpp",
"iterator": "cpp",
"map": "cpp",
"memory": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"optional": "cpp",
"random": "cpp",
"string": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"tuple": "cpp",
"type_traits": "cpp",
"utility": "cpp",
"fstream": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"istream": "cpp",
"limits": "cpp",
"new": "cpp",
"ostream": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"cinttypes": "cpp",
"typeinfo": "cpp"
}
}
\ No newline at end of file
/**************************************************************************/
/*!
@file Adafruit_ADS1X15.cpp
@author K.Townsend (Adafruit Industries)
@mainpage Adafruit ADS1X15 ADC Breakout Driver
@section intro_sec Introduction
This is a library for the Adafruit ADS1X15 ADC breakout boards.
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
@section author Author
Written by Kevin "KTOWN" Townsend for Adafruit Industries.
@section HISTORY
v1.0 - First release
v1.1 - Added ADS1115 support - W. Earl
v2.0 - Refactor - C. Nelson
@section license License
BSD license, all text here must be included in any redistribution
*/
/**************************************************************************/
#include "Adafruit_ADS1X15_Forte.h"
/**************************************************************************/
/*!
@brief Instantiates a new ADS1015 class w/appropriate properties
*/
/**************************************************************************/
Adafruit_ADS1015::Adafruit_ADS1015() {
m_bitShift = 4;
m_gain = GAIN_TWOTHIRDS; /* +/- 6.144V range (limited to VDD +0.3V max!) */
m_dataRate = RATE_ADS1015_1600SPS;
}
/**************************************************************************/
/*!
@brief Instantiates a new ADS1115 class w/appropriate properties
*/
/**************************************************************************/
Adafruit_ADS1115::Adafruit_ADS1115() {
m_bitShift = 0;
m_gain = GAIN_TWOTHIRDS; /* +/- 6.144V range (limited to VDD +0.3V max!) */
m_dataRate = RATE_ADS1115_128SPS;
}
/**************************************************************************/
/*!
@brief Sets up the HW (reads coefficients values, etc.)
@param i2c_addr I2C address of device
@param wire I2C bus
@return true if successful, otherwise false
*/
/**************************************************************************/
bool Adafruit_ADS1X15::begin(uint8_t i2c_addr, TwoWire *wire) {
m_i2c_dev = new Adafruit_I2CDevice(i2c_addr, wire);
return m_i2c_dev->begin();
}
/**************************************************************************/
/*!
@brief Sets the gain and input voltage range
@param gain gain setting to use
*/
/**************************************************************************/
void Adafruit_ADS1X15::setGain(adsGain_t gain) { m_gain = gain; }
/**************************************************************************/
/*!
@brief Gets a gain and input voltage range
@return the gain setting
*/
/**************************************************************************/
adsGain_t Adafruit_ADS1X15::getGain() { return m_gain; }
/**************************************************************************/
/*!
@brief Sets the data rate
@param rate the data rate to use
*/
/**************************************************************************/
void Adafruit_ADS1X15::setDataRate(uint16_t rate) { m_dataRate = rate; }
/**************************************************************************/
/*!
@brief Gets the current data rate
@return the data rate
*/
/**************************************************************************/
uint16_t Adafruit_ADS1X15::getDataRate() { return m_dataRate; }
/**************************************************************************/
/*!
@brief Gets a single-ended ADC reading from the specified channel
@param channel ADC channel to read
@return the ADC reading
*/
/**************************************************************************/
int16_t Adafruit_ADS1X15::readADC_SingleEnded(uint8_t channel) {
if (channel > 3) {
return 0;
}
startADCReading(MUX_BY_CHANNEL[channel], /*continuous=*/false);
// Wait for the conversion to complete
while (!conversionComplete())
;
// Read the conversion results
return getLastConversionResults();
}
/**************************************************************************/
/*!
@brief Reads the conversion results, measuring the voltage
difference between the P (AIN0) and N (AIN1) input. Generates
a signed value since the difference can be either
positive or negative.
@return the ADC reading
*/
/**************************************************************************/
int16_t Adafruit_ADS1X15::readADC_Differential_0_1() {
startADCReading(ADS1X15_REG_CONFIG_MUX_DIFF_0_1, /*continuous=*/false);
// Wait for the conversion to complete
while (!conversionComplete())
;
// Read the conversion results
return getLastConversionResults();
}
/**************************************************************************/
/*!
@brief Reads the conversion results, measuring the voltage
difference between the P (AIN0) and N (AIN3) input. Generates
a signed value since the difference can be either
positive or negative.
@return the ADC reading
*/
/**************************************************************************/
int16_t Adafruit_ADS1X15::readADC_Differential_0_3() {
startADCReading(ADS1X15_REG_CONFIG_MUX_DIFF_0_3, /*continuous=*/false);
// Wait for the conversion to complete
while (!conversionComplete())
;
// Read the conversion results
return getLastConversionResults();
}
/**************************************************************************/
/*!
@brief Reads the conversion results, measuring the voltage
difference between the P (AIN1) and N (AIN3) input. Generates
a signed value since the difference can be either
positive or negative.
@return the ADC reading
*/
/**************************************************************************/
int16_t Adafruit_ADS1X15::readADC_Differential_1_3() {
startADCReading(ADS1X15_REG_CONFIG_MUX_DIFF_1_3, /*continuous=*/false);
// Wait for the conversion to complete
while (!conversionComplete())
;
// Read the conversion results
return getLastConversionResults();
}
/**************************************************************************/
/*!
@brief Reads the conversion results, measuring the voltage
difference between the P (AIN2) and N (AIN3) input. Generates
a signed value since the difference can be either
positive or negative.
@return the ADC reading
*/
/**************************************************************************/
int16_t Adafruit_ADS1X15::readADC_Differential_2_3() {
startADCReading(ADS1X15_REG_CONFIG_MUX_DIFF_2_3, /*continuous=*/false);
// Wait for the conversion to complete
while (!conversionComplete())
;
// Read the conversion results
return getLastConversionResults();
}
/**************************************************************************/
/*!
@brief Sets up the comparator to operate in basic mode, causing the
ALERT/RDY pin to assert (go from high to low) when the ADC
value exceeds the specified threshold.
This will also set the ADC in continuous conversion mode.
@param channel ADC channel to use
@param threshold comparator threshold
*/
/**************************************************************************/
void Adafruit_ADS1X15::startComparator_SingleEnded(uint8_t channel,
int16_t threshold) {
// Start with default values
uint16_t config =
ADS1X15_REG_CONFIG_CQUE_1CONV | // Comparator enabled and asserts on 1
// match
ADS1X15_REG_CONFIG_CLAT_LATCH | // Latching mode
ADS1X15_REG_CONFIG_CPOL_ACTVLOW | // Alert/Rdy active low (default val)
ADS1X15_REG_CONFIG_CMODE_TRAD | // Traditional comparator (default val)
ADS1X15_REG_CONFIG_MODE_CONTIN | // Continuous conversion mode
ADS1X15_REG_CONFIG_MODE_CONTIN; // Continuous conversion mode
// Set PGA/voltage range
config |= m_gain;
// Set data rate
config |= m_dataRate;
config |= MUX_BY_CHANNEL[channel];
// Set the high threshold register
// Shift 12-bit results left 4 bits for the ADS1015
writeRegister(ADS1X15_REG_POINTER_HITHRESH, threshold << m_bitShift);
// Write config register to the ADC
writeRegister(ADS1X15_REG_POINTER_CONFIG, config);
}
/**************************************************************************/
/*!
@brief In order to clear the comparator, we need to read the
conversion results. This function reads the last conversion
results without changing the config value.
@return the last ADC reading
*/
/**************************************************************************/
int16_t Adafruit_ADS1X15::getLastConversionResults() {
// Read the conversion results
uint16_t res = readRegister(ADS1X15_REG_POINTER_CONVERT) >> m_bitShift;
if (m_bitShift == 0) {
return (int16_t)res;
} else {
// Shift 12-bit results right 4 bits for the ADS1015,
// making sure we keep the sign bit intact
if (res > 0x07FF) {
// negative number - extend the sign to 16th bit
res |= 0xF000;
}
return (int16_t)res;
}
}
/**************************************************************************/
/*!
@brief Returns true if conversion is complete, false otherwise.
@param counts the ADC reading in raw counts
@return the ADC reading in volts
*/
/**************************************************************************/
float Adafruit_ADS1X15::computeVolts(int16_t counts) {
// see data sheet Table 3
float fsRange;
switch (m_gain) {
case GAIN_TWOTHIRDS:
fsRange = 6.144f;
break;
case GAIN_ONE:
fsRange = 4.096f;
break;
case GAIN_TWO:
fsRange = 2.048f;
break;
case GAIN_FOUR:
fsRange = 1.024f;
break;
case GAIN_EIGHT:
fsRange = 0.512f;
break;
case GAIN_SIXTEEN:
fsRange = 0.256f;
break;
default:
fsRange = 0.0f;
}
return counts * (fsRange / (32768 >> m_bitShift));
}
/**************************************************************************/
/*!
@brief Non-blocking start conversion function
Call getLastConversionResults() once conversionComplete() returns true.
In continuous mode, getLastConversionResults() will always return the
latest result.
ALERT/RDY pin is set to RDY mode, and a 8us pulse is generated every
time new data is ready.
@param mux mux field value
@param continuous continuous if set, otherwise single shot
*/
/**************************************************************************/
void Adafruit_ADS1X15::startADCReading(uint16_t mux, bool continuous) {
// Start with default values
uint16_t config =
ADS1X15_REG_CONFIG_CQUE_1CONV | // Set CQUE to any value other than
// None so we can use it in RDY mode
ADS1X15_REG_CONFIG_CLAT_NONLAT | // Non-latching (default val)
ADS1X15_REG_CONFIG_CPOL_ACTVLOW | // Alert/Rdy active low (default val)
ADS1X15_REG_CONFIG_CMODE_TRAD; // Traditional comparator (default val)
if (continuous) {
config |= ADS1X15_REG_CONFIG_MODE_CONTIN;
} else {
config |= ADS1X15_REG_CONFIG_MODE_SINGLE;
}
// Set PGA/voltage range
config |= m_gain;
// Set data rate
config |= m_dataRate;
// Set channels
config |= mux;
// Set 'start single-conversion' bit
config |= ADS1X15_REG_CONFIG_OS_SINGLE;
// Write config register to the ADC
writeRegister(ADS1X15_REG_POINTER_CONFIG, config);
// Set ALERT/RDY to RDY mode.
writeRegister(ADS1X15_REG_POINTER_HITHRESH, 0x8000);
writeRegister(ADS1X15_REG_POINTER_LOWTHRESH, 0x0000);
}
/**************************************************************************/
/*!
@brief Returns true if conversion is complete, false otherwise.
@return True if conversion is complete, false otherwise.
*/
/**************************************************************************/
bool Adafruit_ADS1X15::conversionComplete() {
return (readRegister(ADS1X15_REG_POINTER_CONFIG) & 0x8000) != 0;
}
/**************************************************************************/
/*!
@brief Writes 16-bits to the specified destination register
@param reg register address to write to
@param value value to write to register
*/
/**************************************************************************/
void Adafruit_ADS1X15::writeRegister(uint8_t reg, uint16_t value) {
buffer[0] = reg;
buffer[1] = value >> 8;
buffer[2] = value & 0xFF;
m_i2c_dev->write(buffer, 3);
}
/**************************************************************************/
/*!
@brief Read 16-bits from the specified destination register
@param reg register address to read from
@return 16 bit register value read
*/
/**************************************************************************/
uint16_t Adafruit_ADS1X15::readRegister(uint8_t reg) {
buffer[0] = reg;
m_i2c_dev->write(buffer, 1);
m_i2c_dev->read(buffer, 2);
return ((buffer[0] << 8) | buffer[1]);
}
/**************************************************************************/
/*!
@file Adafruit_ADS1X15.h
This is a library for the Adafruit ADS1X15 ADC breakout boards.
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Kevin "KTOWN" Townsend for Adafruit Industries.
BSD license, all text here must be included in any redistribution
*/
/**************************************************************************/
#ifndef __ADS1X15_Forte_H__
#define __ADS1X15_Forte_H__
#include <Adafruit_I2CDevice.h>
#include <Arduino.h>
#include <Wire.h>
/*=========================================================================
I2C ADDRESS/BITS
-----------------------------------------------------------------------*/
#define ADS1X15_ADDRESS (0x48) ///< 1001 000 (ADDR = GND)
/*=========================================================================*/
/*=========================================================================
POINTER REGISTER
-----------------------------------------------------------------------*/
#define ADS1X15_REG_POINTER_MASK (0x03) ///< Point mask
#define ADS1X15_REG_POINTER_CONVERT (0x00) ///< Conversion
#define ADS1X15_REG_POINTER_CONFIG (0x01) ///< Configuration
#define ADS1X15_REG_POINTER_LOWTHRESH (0x02) ///< Low threshold
#define ADS1X15_REG_POINTER_HITHRESH (0x03) ///< High threshold
/*=========================================================================*/
/*=========================================================================
CONFIG REGISTER
-----------------------------------------------------------------------*/
#define ADS1X15_REG_CONFIG_OS_MASK (0x8000) ///< OS Mask
#define ADS1X15_REG_CONFIG_OS_SINGLE \
(0x8000) ///< Write: Set to start a single-conversion
#define ADS1X15_REG_CONFIG_OS_BUSY \
(0x0000) ///< Read: Bit = 0 when conversion is in progress
#define ADS1X15_REG_CONFIG_OS_NOTBUSY \
(0x8000) ///< Read: Bit = 1 when device is not performing a conversion
#define ADS1X15_REG_CONFIG_MUX_MASK (0x7000) ///< Mux Mask
#define ADS1X15_REG_CONFIG_MUX_DIFF_0_1 \
(0x0000) ///< Differential P = AIN0, N = AIN1 (default)
#define ADS1X15_REG_CONFIG_MUX_DIFF_0_3 \
(0x1000) ///< Differential P = AIN0, N = AIN3
#define ADS1X15_REG_CONFIG_MUX_DIFF_1_3 \
(0x2000) ///< Differential P = AIN1, N = AIN3
#define ADS1X15_REG_CONFIG_MUX_DIFF_2_3 \
(0x3000) ///< Differential P = AIN2, N = AIN3
#define ADS1X15_REG_CONFIG_MUX_SINGLE_0 (0x4000) ///< Single-ended AIN0
#define ADS1X15_REG_CONFIG_MUX_SINGLE_1 (0x5000) ///< Single-ended AIN1
#define ADS1X15_REG_CONFIG_MUX_SINGLE_2 (0x6000) ///< Single-ended AIN2
#define ADS1X15_REG_CONFIG_MUX_SINGLE_3 (0x7000) ///< Single-ended AIN3
constexpr uint16_t MUX_BY_CHANNEL[] = {
ADS1X15_REG_CONFIG_MUX_SINGLE_0, ///< Single-ended AIN0
ADS1X15_REG_CONFIG_MUX_SINGLE_1, ///< Single-ended AIN1
ADS1X15_REG_CONFIG_MUX_SINGLE_2, ///< Single-ended AIN2
ADS1X15_REG_CONFIG_MUX_SINGLE_3 ///< Single-ended AIN3
}; ///< MUX config by channel
#define ADS1X15_REG_CONFIG_PGA_MASK (0x0E00) ///< PGA Mask
#define ADS1X15_REG_CONFIG_PGA_6_144V (0x0000) ///< +/-6.144V range = Gain 2/3
#define ADS1X15_REG_CONFIG_PGA_4_096V (0x0200) ///< +/-4.096V range = Gain 1
#define ADS1X15_REG_CONFIG_PGA_2_048V \
(0x0400) ///< +/-2.048V range = Gain 2 (default)
#define ADS1X15_REG_CONFIG_PGA_1_024V (0x0600) ///< +/-1.024V range = Gain 4
#define ADS1X15_REG_CONFIG_PGA_0_512V (0x0800) ///< +/-0.512V range = Gain 8
#define ADS1X15_REG_CONFIG_PGA_0_256V (0x0A00) ///< +/-0.256V range = Gain 16
#define ADS1X15_REG_CONFIG_MODE_MASK (0x0100) ///< Mode Mask
#define ADS1X15_REG_CONFIG_MODE_CONTIN (0x0000) ///< Continuous conversion mode
#define ADS1X15_REG_CONFIG_MODE_SINGLE \
(0x0100) ///< Power-down single-shot mode (default)
#define ADS1X15_REG_CONFIG_RATE_MASK (0x00E0) ///< Data Rate Mask
#define ADS1X15_REG_CONFIG_CMODE_MASK (0x0010) ///< CMode Mask
#define ADS1X15_REG_CONFIG_CMODE_TRAD \
(0x0000) ///< Traditional comparator with hysteresis (default)
#define ADS1X15_REG_CONFIG_CMODE_WINDOW (0x0010) ///< Window comparator
#define ADS1X15_REG_CONFIG_CPOL_MASK (0x0008) ///< CPol Mask
#define ADS1X15_REG_CONFIG_CPOL_ACTVLOW \
(0x0000) ///< ALERT/RDY pin is low when active (default)
#define ADS1X15_REG_CONFIG_CPOL_ACTVHI \
(0x0008) ///< ALERT/RDY pin is high when active
#define ADS1X15_REG_CONFIG_CLAT_MASK \
(0x0004) ///< Determines if ALERT/RDY pin latches once asserted
#define ADS1X15_REG_CONFIG_CLAT_NONLAT \
(0x0000) ///< Non-latching comparator (default)
#define ADS1X15_REG_CONFIG_CLAT_LATCH (0x0004) ///< Latching comparator
#define ADS1X15_REG_CONFIG_CQUE_MASK (0x0003) ///< CQue Mask
#define ADS1X15_REG_CONFIG_CQUE_1CONV \
(0x0000) ///< Assert ALERT/RDY after one conversions
#define ADS1X15_REG_CONFIG_CQUE_2CONV \
(0x0001) ///< Assert ALERT/RDY after two conversions
#define ADS1X15_REG_CONFIG_CQUE_4CONV \
(0x0002) ///< Assert ALERT/RDY after four conversions
#define ADS1X15_REG_CONFIG_CQUE_NONE \
(0x0003) ///< Disable the comparator and put ALERT/RDY in high state (default)
/*=========================================================================*/
/** Gain settings */
typedef enum {
GAIN_TWOTHIRDS = ADS1X15_REG_CONFIG_PGA_6_144V,
GAIN_ONE = ADS1X15_REG_CONFIG_PGA_4_096V,
GAIN_TWO = ADS1X15_REG_CONFIG_PGA_2_048V,
GAIN_FOUR = ADS1X15_REG_CONFIG_PGA_1_024V,
GAIN_EIGHT = ADS1X15_REG_CONFIG_PGA_0_512V,
GAIN_SIXTEEN = ADS1X15_REG_CONFIG_PGA_0_256V
} adsGain_t;
/** Data rates */
#define RATE_ADS1015_128SPS (0x0000) ///< 128 samples per second
#define RATE_ADS1015_250SPS (0x0020) ///< 250 samples per second
#define RATE_ADS1015_490SPS (0x0040) ///< 490 samples per second
#define RATE_ADS1015_920SPS (0x0060) ///< 920 samples per second
#define RATE_ADS1015_1600SPS (0x0080) ///< 1600 samples per second (default)
#define RATE_ADS1015_2400SPS (0x00A0) ///< 2400 samples per second
#define RATE_ADS1015_3300SPS (0x00C0) ///< 3300 samples per second
#define RATE_ADS1115_8SPS (0x0000) ///< 8 samples per second
#define RATE_ADS1115_16SPS (0x0020) ///< 16 samples per second
#define RATE_ADS1115_32SPS (0x0040) ///< 32 samples per second
#define RATE_ADS1115_64SPS (0x0060) ///< 64 samples per second
#define RATE_ADS1115_128SPS (0x0080) ///< 128 samples per second (default)
#define RATE_ADS1115_250SPS (0x00A0) ///< 250 samples per second
#define RATE_ADS1115_475SPS (0x00C0) ///< 475 samples per second
#define RATE_ADS1115_860SPS (0x00E0) ///< 860 samples per second
/**************************************************************************/
/*!
@brief Sensor driver for the Adafruit ADS1X15 ADC breakouts.
*/
/**************************************************************************/
class Adafruit_ADS1X15 {
protected:
// Instance-specific properties
Adafruit_I2CDevice *m_i2c_dev; ///< I2C bus device
uint8_t m_bitShift; ///< bit shift amount
adsGain_t m_gain; ///< ADC gain
uint16_t m_dataRate; ///< Data rate
public:
bool begin(uint8_t i2c_addr = ADS1X15_ADDRESS, TwoWire *wire = &Wire);
int16_t readADC_SingleEnded(uint8_t channel);
int16_t readADC_Differential_0_1();
int16_t readADC_Differential_0_3();
int16_t readADC_Differential_1_3();
int16_t readADC_Differential_2_3();
void startComparator_SingleEnded(uint8_t channel, int16_t threshold);
int16_t getLastConversionResults();
float computeVolts(int16_t counts);
void setGain(adsGain_t gain);
adsGain_t getGain();
void setDataRate(uint16_t rate);
uint16_t getDataRate();
void startADCReading(uint16_t mux, bool continuous);
bool conversionComplete();
private:
void writeRegister(uint8_t reg, uint16_t value);
uint16_t readRegister(uint8_t reg);
uint8_t buffer[3];
};
/**************************************************************************/
/*!
@brief Sensor driver for the Adafruit ADS1015 ADC breakout.
*/
/**************************************************************************/
class Adafruit_ADS1015 : public Adafruit_ADS1X15 {
public:
Adafruit_ADS1015();
};
/**************************************************************************/
/*!
@brief Sensor driver for the Adafruit ADS1115 ADC breakout.
*/
/**************************************************************************/
class Adafruit_ADS1115 : public Adafruit_ADS1X15 {
public:
Adafruit_ADS1115();
};
#endif
#pragma once
#include <exception>
#include <iostream>
struct NoDataAvailableException : public std::exception {
const char *what() const throw() { return "Sensor could not read data"; }
};
\ No newline at end of file
This directory is intended for project header files.
A header file is a file containing C declarations and macro definitions
to be shared between several project source files. You request the use of a
header file in your project source file (C, C++, etc) located in `src` folder
by including it, with the C preprocessing directive `#include'.
```src/main.c
#include "header.h"
int main (void)
{
...
}
```
Including a header file produces the same results as copying the header file
into each source file that needs it. Such copying would be time-consuming
and error-prone. With a header file, the related declarations appear
in only one place. If they need to be changed, they can be changed in one
place, and programs that include the header file will automatically use the
new version when next recompiled. The header file eliminates the labor of
finding and changing all the copies as well as the risk that a failure to
find one copy will result in inconsistencies within a program.
In C, the usual convention is to give header files names that end with `.h'.
It is most portable to use only letters, digits, dashes, and underscores in
header file names, and at most one dot.
Read more about using header files in official GCC documentation:
* Include Syntax
* Include Operation
* Once-Only Headers
* Computed Includes
https://gcc.gnu.org/onlinedocs/cpp/Header-Files.html
#ifndef _FORTE_SENSOR
#define _FORTE_SENSOR
// #include "Message.hpp"
template <class T>
class Forte_Sensor {
public:
virtual T read_data() = 0;
virtual void setup() = 0;
//virtual Message build_message() = 0;
private:
};
#endif
\ No newline at end of file
#ifndef _FORTE_PINOUT
#define _FORTE_PINOUT
// Pins for I2C
#define I2C_SDA 6
#define I2C_SCL 7
#endif
\ No newline at end of file
; PlatformIO Project Configuration File
;
; Build options: build flags, source filter
; Upload options: custom upload port, speed and extra flags
; Library options: dependencies, extra library storages
; Advanced options: extra scripting
;
; Please visit documentation for the other options and examples
; https://docs.platformio.org/page/projectconf.html
[env:esp32-c3-devkitm-1]
platform = espressif32
board = esp32-c3-devkitm-1
framework = arduino
monitor_speed = 9600
build_flags =
-I include
lib_deps =
sparkfun/SparkFun SCD30 Arduino Library@^1.0.18
Wire
adafruit/Adafruit BusIO@^1.13.2
Adafruit_I2CDevice
SPI
envirodiy/SDI-12@^2.1.4
fbiego/ESP32Time@^2.0.0
Wifi
adafruit/Adafruit INA219@^1.2.0
#include <Arduino.h>
#include <Wire.h>
#include <dr26.hpp>
#include <ina219.hpp>
#include "esp_debug_helpers.h"
Adafruit_ADS1115 adss;
Forte_DR26 dr26;
Forte_INA219 ina219;
void setup()
{
Serial.begin(9600);
Wire.begin(6, 7);
adss.setGain(GAIN_ONE);
adss.begin() ? Serial.println("ADS initialized") : Serial.println("failed to initialize ADS");
delay(100);
dr26.setup();
ina219.setup();
}
int x =0;
void loop()
{
Serial.println("******************************DR26-Analog********************Tree-Size**********************************");
float data_drs26=-1;
try
{
data_drs26=dr26.read_data();
Serial.print("dr26: ");
Serial.println(data_drs26);
}
catch(NoDataAvailableException& e){
Serial.println("No Sensor aviable");
}
out_data_ina219 data_ina219;
Serial.println("******************************INA219********************Power--Consumption**********************************");
try{
data_ina219=ina219.read_data();
Serial.print("Shunt Voltage [mV]: "); Serial.println(data_ina219.shuntVoltage_mV);
Serial.print("Bus Voltage [V]: "); Serial.println(data_ina219.busVoltage_V);
Serial.print("Load Voltage [V]: "); Serial.println(data_ina219.loadVoltage_V);
Serial.print("Current[mA]: "); Serial.println(data_ina219.current_mA);
Serial.print("Bus Power [mW]: "); Serial.println(data_ina219.power_mW);
data_ina219.ina219_overflow== false ? Serial.println("Values OK - no overflow") : Serial.println("Overflow! Choose higher PGAIN");
Serial.println();
}
catch(NoDataAvailableException& e){
Serial.println("No Sensor aviable");
}
// Serial.println("Free Heap:"); Keep trach of the free stack -> momery leak can cause stack overflow
// Serial.println(esp_get_free_heap_size());
delay(4000);
}
This directory is intended for PlatformIO Test Runner and project tests.
Unit Testing is a software testing method by which individual units of
source code, sets of one or more MCU program modules together with associated
control data, usage procedures, and operating procedures, are tested to
determine whether they are fit for use. Unit testing finds problems early
in the development cycle.
More information about PlatformIO Unit Testing:
- https://docs.platformio.org/en/latest/advanced/unit-testing/index.html
#include "TestESPNow.hpp"
void test_on_data_recv_valid_config()
{
uint8_t mac_addr[6] = {0x00, 0x00, 0x00, 0x00, 0x00, 0x00};
int len = 0;
config conf = {host : {0xAA, 0xAA, 0xAA, 0xAA, 0xAA, 0xAA}, time_millis : 0};
// preferences / hostinfo would need to be global for this to work
TEST_FAIL();
}
#pragma once
#include <Arduino.h>
#include <ESPNow.hpp>
#include <unity.h>
void test_on_data_recv_valid_config();
\ No newline at end of file
#include "TestMessage.hpp"
void test_on_data_recv()
{
Message message = Message{};
TEST_ASSERT_EQUAL(0, message.getData().amountData);
}
void test_new_message_filled()
{
Message message = Message{};
message.add_data(1.1, 0);
message.add_data(1.2, 1);
message.add_data(1.3, 2);
float expectedValuesArray[] = {1.1, 1.2, 1.3};
int expectedIdentifiersArray[] = {0, 1, 2};
TEST_ASSERT_EQUAL(3, message.getData().amountData);
TEST_ASSERT_EQUAL_FLOAT_ARRAY(expectedValuesArray, message.getData().values, 3);
TEST_ASSERT_EQUAL_INT_ARRAY(expectedIdentifiersArray, message.getData().identifiers, 3);
}
\ No newline at end of file
#pragma once
#include <Arduino.h>
#include <ESPNow.hpp>
#include <unity.h>
void test_on_data_recv();
void test_new_message_filled();
\ No newline at end of file
#include "TestESPNow.hpp"
#include "TestMessage.hpp"
#include <Arduino.h>
#include <unity.h>
void setup()
{
delay(2000); // service delay
UNITY_BEGIN();
RUN_TEST(test_on_data_recv_valid_config);
RUN_TEST(test_on_data_recv);
RUN_TEST(test_new_message_filled);
UNITY_END();
}
void loop() {}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment