Skip to content
Snippets Groups Projects
DR26.hpp 2.24 KiB
Newer Older
#ifndef _DR26
#define _DR26

#include "../espnow/Message.hpp"
#include "ForteSensor.hpp"
#include "esp_log.h"
#include <ADS1115_WE.h>
#include <Wire.h>


    // TODO: Should ADS be a singleton?

    /**
     * @brief Set the voltage range of the ADS1115
     * @param newVoltageRange
     * @details The following functions change the ADC input range: be careful
        * to never to exceed VDD +0.3V max, or to exceed the upper and
        * lower limits if you adjust the input range.
        * SETTING THE GAIN VALUE INCORRECTLY MAY DESTROY THE ADC!
        * The maximum output of the dendrometer is 2.5V, and so a gain of
        * one (max 4.096V) or two (max 2.048V) is optimal. Changing the gain
        * changes the accuracy of the sensor: higher gain gives a higher
        * precision but a smaller range.
        *
        *  GAIN_TWOTHIRDS  // 2/3x gain +/- 6.144V  1 bit = 0.1875mV (default)
        *  GAIN_ONE* // 1x gain   +/- 4.096V  1 bit = 0.125mV
        *  GAIN_TWO* // 2x gain   +/- 2.048V  1 bit = 0.0625mV
        *  GAIN_FOUR       // 4x gain   +/- 1.024V  1 bit = 0.03125mV
        *  GAIN_EIGHT      // 8x gain   +/- 0.512V  1 bit = 0.015625mV
        *  GAIN_SIXTEEN    // 16x gain  +/- 0.256V  1 bit = 0.0078125mV
     */
    void setVoltageRange(ADS1115_RANGE newVoltageRange);

    /**
     * @brief Set the channel of the ADS1115
     * @param newChannel
     */
    void setChannel(ADS1115_MUX newChannel);
    [[nodiscard]] SensorInformation getSensorInformation() const override;

    /**
     * @brief Constructor for the DR26 class.
     * @param channel
     * @param voltageRange
     */
    explicit DR26(ADS1115_MUX channel, ADS1115_RANGE voltageRange);
    explicit DR26(ADS1115_MUX channel, ADS1115_RANGE voltageRange, uint8_t address);

    float readChannel(ADS1115_MUX compareChannel);
    const SensorInformation sensorInformation{HardwareName::DRS26, SensorProtocol::Analog};
    ADS1115_MUX channel;
    ADS1115_RANGE voltageRange = ADS1115_RANGE::ADS1115_RANGE_4096;