diff --git a/src/tests/BoardConfig.cpp b/src/tests/BoardConfig.cpp deleted file mode 100644 index 2c137d8..0000000 --- a/src/tests/BoardConfig.cpp +++ /dev/null @@ -1,18 +0,0 @@ -#include "BoardConfig.h" - -BoardConfig::BoardConfig( const Pin LDOEnable, - const Pin NRFCe, - const Pin NRFCs, - const Pin I2CSDA, - const Pin I2CSCL, - const Pin LDRVSensEnable, - const Pin BATVSensEnable, - const Pin MOSI, - const Pin MISO, - const Pin SCK, - const Pin BATAnalogVSens, - const Pin LDRAnalogVSens -):LDOEnable(LDOEnable), NRFCe(NRFCe), NRFCs(NRFCs), I2CSDA(I2CSDA), I2CSCL(I2CSCL), LDRVSensEnable(LDRVSensEnable), BATVSensEnable(BATVSensEnable), MOSI(MOSI), MISO(MISO), SCK(SCK), BATAnalogVSens(BATAnalogVSens), LDRAnalogVSens(LDRAnalogVSens) -{ - -} diff --git a/src/tests/BoardConfig.h b/src/tests/BoardConfig.h deleted file mode 100644 index 3cebdd0..0000000 --- a/src/tests/BoardConfig.h +++ /dev/null @@ -1,46 +0,0 @@ -/** - * Author : Anatole SCHRAMM-HENRY - * Created the : 30/05/2021 - * This class encapsulates the various configuration values for the board like the Pin Mapping for instance. - */ -#ifndef BOARDCONFIG_H -#define BOARDCONFIG_H - -#include "definition.h" - -class BoardConfig -{ - public: - BoardConfig( - const Pin LDOEnable = D2_LDO_EN, - const Pin NRFCe = D3_NRF_CE, - const Pin NRFCs = D10_NRF_CS, - const Pin I2CSDA = A4_SDA, - const Pin I2CSCL = A5_SCL, - const Pin LDRVSensEnable = D4_LDR_V_SENS_EN, - const Pin BATVSensEnable = D5_BAT_V_SENS_EN, - const Pin MOSI = D11_MOSI, - const Pin MISO = D12_MISO, - const Pin SCK = D13_SCK, - const Pin BATAnalogVSens = A0_BAT_V_SENS, - const Pin LDRAnalogVSens = A1_LDR_V_SENS - ); - - const Pin LDOEnable; - const Pin NRFCe; - const Pin NRFCs; - const Pin I2CSDA; - const Pin I2CSCL; - const Pin LDRVSensEnable; - const Pin BATVSensEnable; - const Pin MOSI; - const Pin MISO; - const Pin SCK; - const Pin BATAnalogVSens; - const Pin LDRAnalogVSens; - - protected: - private: -}; - -#endif //BOARDCONFIG_H diff --git a/src/tests/WSPeripherals.cpp b/src/tests/WSPeripherals.cpp deleted file mode 100644 index 068ab2f..0000000 --- a/src/tests/WSPeripherals.cpp +++ /dev/null @@ -1,121 +0,0 @@ -#include "WSPeripherals.h" - -WSPeripherals::WSPeripherals(const BoardConfig &boardConfig): _boardConfig(boardConfig), _HTU21(HTU21D_RES_RH12_TEMP14), _NRF(boardConfig.NRFCe, boardConfig.NRFCs) -{} - -uint8_t WSPeripherals::init() -{ - uint8_t toReturn(0); - //We initialize used pins : - pinMode(_boardConfig.LDOEnable, OUTPUT); - _3V3PowerRail(OFF); - pinMode(_boardConfig.LDRVSensEnable, OUTPUT); - digitalWrite(_boardConfig.LDRVSensEnable, HIGH); //High means that it is disabled and low is active /!\/ - pinMode(_boardConfig.BATVSensEnable, OUTPUT); - digitalWrite(_boardConfig.BATVSensEnable, LOW); - - //Unused pins are set as inputs with internal pullup inable to reduce power consumption during sleep - pinMode(0,INPUT_PULLUP); - //pinMode(1,INPUT_PULLUP); TX pin for serial - pinMode(6,INPUT_PULLUP); - pinMode(7,INPUT_PULLUP); - pinMode(8,INPUT_PULLUP); - pinMode(9,INPUT_PULLUP); - pinMode(10,INPUT_PULLUP); - pinMode(11,INPUT_PULLUP); - pinMode(12,INPUT_PULLUP); - pinMode(A2,INPUT_PULLUP); - pinMode(A3,INPUT_PULLUP); - pinMode(A6,INPUT_PULLUP); - pinMode(A7,INPUT_PULLUP); - - //We check that every external devices are responding - _3V3PowerRail(ON); - toReturn |= _BMP280.begin(0x76); - toReturn |= _HTU21.begin() << 1; - toReturn |= _NRF.begin() << 2; - _3V3PowerRail(OFF); - return toReturn; -} - -uint8_t WSPeripherals::initExternalPeripherals() -{ - uint8_t toReturn(0); - - toReturn |= _BMP280.begin(0x76); - toReturn |= _HTU21.begin() << 1; - toReturn |= _NRF.begin() << 2; - - //We disable the I2C internal pullups : - digitalWrite(SDA, LOW); - digitalWrite(SCL, LOW); - - return toReturn; -} - -float WSPeripherals::batteryVoltage() -{ - //We close the voltage divider bridge and we do the measurement - digitalWrite(_boardConfig.BATVSensEnable, HIGH); - int rawBatteryValue = analogRead(_boardConfig.BATAnalogVSens); - digitalWrite(_boardConfig.BATVSensEnable, LOW); - - return float(rawBatteryValue) * ADC_QUANTUM * VOLTAGE_DIV_COEFF; -} - -int WSPeripherals::sunlightMeasurement() -{ - //We enable the voltage divider bridge and we do the measurement - digitalWrite(_boardConfig.LDRVSensEnable, LOW); - int rawSunlightMeasurement = analogRead(_boardConfig.LDRAnalogVSens); - digitalWrite(_boardConfig.LDRVSensEnable, HIGH); - - return rawSunlightMeasurement; -} - -void WSPeripherals::temperatureAndATMPressureFromBMP280(float *temperature, float *ATMPressure) -{ - if(!temperature && !ATMPressure)return; - - _BMP280.setSampling( Adafruit_BMP280::MODE_FORCED, - Adafruit_BMP280::SAMPLING_X16, - Adafruit_BMP280::SAMPLING_X16, - Adafruit_BMP280::FILTER_X16, - Adafruit_BMP280::STANDBY_MS_4000); - if(temperature) - *temperature = _BMP280.readTemperature(); - - if(ATMPressure) - *ATMPressure = _BMP280.readPressure(); -} - -float WSPeripherals::temperatureFromHTU21() -{ - return _HTU21.readTemperature(); -} - -float WSPeripherals::humidity() -{ - return _HTU21.readHumidity(); -} - -float WSPeripherals::compensatedHumidity() -{ - return _HTU21.readCompensatedHumidity(); -} - -void WSPeripherals::_3V3PowerRail(State state) -{ - digitalWrite(_boardConfig.LDOEnable, state); - if(state) //We let some time for the voltage to stabilize on the rail. - delay(10); -} - -const RF24 &WSPeripherals::getRadio(){return _NRF;} - -void WSPeripherals::applyRadioConfig(uint8_t channel, uint8_t paLevel, rf24_datarate_e datarate) -{ - _NRF.setChannel(channel); - _NRF.setPALevel(paLevel); - _NRF.setDataRate(datarate); -} diff --git a/src/tests/WSPeripherals.h b/src/tests/WSPeripherals.h deleted file mode 100644 index 212dd28..0000000 --- a/src/tests/WSPeripherals.h +++ /dev/null @@ -1,60 +0,0 @@ -/** - * Author : Anatole SCHRAMM-HENRY - * Created the : 30/05/2021 - * This classe exposes all the methods necessary to init the WSPeripherals (Weather Station Peripherals) and - * to retrieve various data and measurements like battery voltage, Temperatures etc... - */ -#ifndef WSPERIPHERALS_H -#define WSPERIPHERALS_H - -#include -#include -#include -#include - -#include "BoardConfig.h" - -class WSPeripherals -{ - public: - enum State {OFF, ON}; - - WSPeripherals(const BoardConfig &boardConfig); - /* - * Returns 7 if all the external devices are working properly, or an other value if it is not the case. - */ - uint8_t init(); - /* - * After calling this methode , you need to execute initExternalPeripherals() to init the peripherals. - */ - void externalPeripherals(State state){_3V3PowerRail(state);} - - /* - * Used to init devices after each LDO powerup, external devices need to be turned one externalPeripherals(ON) before calling this function. - */ - uint8_t initExternalPeripherals(); - - float batteryVoltage(); - int sunlightMeasurement(); - void temperatureAndATMPressureFromBMP280(float *temperature = NULL, float *ATMPressure = NULL); - float temperatureFromHTU21(); - float humidity(); - float compensatedHumidity(); - - /* - * Before calling this method, externalPeripherals(ON) and initExternalPeripherals() must be called respectively - */ - void applyRadioConfig(uint8_t channel = RADIO_CHANNEL, uint8_t paLevel = RADIO_PA_LEVEL, rf24_datarate_e datarate = RADIO_DATARATE); - const RF24 &getRadio(); - - protected: - private: - void _3V3PowerRail(State state); - const BoardConfig &_boardConfig; - const Adafruit_BMP280 _BMP280; - const HTU21D _HTU21; - const RF24 _NRF; - -}; - -#endif //WSPERIPHERALS_H diff --git a/src/tests/definition.h b/src/tests/definition.h deleted file mode 100644 index c2e5f54..0000000 --- a/src/tests/definition.h +++ /dev/null @@ -1,61 +0,0 @@ -/** - * Author : Anatole SCHRAMM-HENRY - * Created the : 29/05/2021 - * This file contains all the config used by the other classes and sources files. - */ -#ifndef DEFINITION_H -#define DEFINITION_H - -#include -#include -#include "packet_format.h" - -//Serial debug config part -#define SERIAL_DEBUG_ENABLED 0 -#define SERIAL_BAUD_RATE 115200 - -//Battery config part -#define ADC_QUANTUM 0.00323632812 //ADC_VREF / ADC_RESOLUTION -> 3.314 and 10 bits (1024) in my case -#define VOLTAGE_DIV_COEFF 1.3125 //(R1 + R2)/R2 - -//NRF Radio config part -#define RADIO_CHANNEL 108 -#define RADIO_NODE_ADDRESS "WEST1" //Weather Station 1 -#define RADIO_PA_LEVEL RF24_PA_LOW //RF24_PA_MIN,RF24_PA_LOW,RF24_PA_HIGH,RF24_PA_MAX -#define RADIO_DATARATE RF24_250KBPS - -//Sleep config part : in 4 second increments ie : 1 corresponds to 4s of sleep, and 15 correponds to 60 seconds of sleep. -#define SLEEP_4_SEC_INTERVAL 15 - -//Pin config part -typedef enum -{ - D2_LDO_EN = 2, - D3_NRF_CE = 3, - A4_SDA = A4, - A5_SCL = A5, - D4_LDR_V_SENS_EN = 4, - D5_BAT_V_SENS_EN = 5, - D10_NRF_CS = 10, - D11_MOSI = 11, - D12_MISO = 12, - D13_SCK = 13, - A0_BAT_V_SENS = A0, - A1_LDR_V_SENS = A1, -} Pin; - -//Payload structure -typedef struct -{ - uint16_t id; - HEADER_e header : 6; - unsigned int ldr : 10; - float battery; - float bmpTemp; - float bmpPress; - float humidity; - float compensatedHumidity; - float htuTemp; -} DataPacket __attribute__((__packed__)); - -#endif //DEFINITION_H diff --git a/src/tests/packet_format.h b/src/tests/packet_format.h deleted file mode 100644 index 5b35254..0000000 --- a/src/tests/packet_format.h +++ /dev/null @@ -1,6 +0,0 @@ -#ifndef PACKET_FORMAT_H -#define PACKET_FORMAT_H - -enum HEADER_e {WEATHER_STATION = 0}; - -#endif //PACKET_FORMAT_H