Merge pull request #73 from romoloman/master
[openXsensor.git] / openXsensor / oXs_voltage.h
blob6482d34ab24461e4282c1a28781ca85b98e44894
1 #ifndef OXS_VOLTAGE_h
2 #define OXS_VOLTAGE_h
4 #include "Arduino.h"
5 #include "oXs_config_basic.h"
6 #include "oXs_config_advanced.h"
7 #include "oXs_config_macros.h"
9 struct VOLTAGEDATA {
10 // bool available; // to remove afterward
11 uint16_t vrefMilliVolts; // in mV the internal measured voltage Reference ; to remove afterward
13 struct ONE_MEASUREMENT mVolt[6] ; // in mV
14 // int32_t mVolt[6] ; // in mV
15 // bool mVoltAvailable[6] ;
17 byte mVoltPin[6] ; // Arduino pin number to use to read each voltage (See hardware setting in oXs_config.h)
18 int offset[6] ; // offset to apply while converting ADC to millivolt (See setting in oXs_config.h)
19 float mVoltPerStep[6] ; // rate to apply while converting ADC to millivolt (See setting in oXs_config.h)
21 bool atLeastOneVolt ; // true if there is at least one voltage to measure (added because otherwise a while in cpp never end)
23 int32_t sumVoltage[6] ; // used to calculate average voltage
25 uint8_t maxNumberOfCells ; // used to fill in the max number of cells
26 uint32_t mVoltCell[6] ;
27 bool mVoltCell_Available [6];
28 uint32_t mVoltCellMin ;
29 bool mVoltCellMin_Available ;
30 uint32_t mVoltCellTot ;
31 bool mVoltCellTot_Available ;
33 #if defined(PROTOCOL) && ( (PROTOCOL == FRSKY_SPORT) || ( PROTOCOL == FRSKY_HUB ) || (PROTOCOL == FRSKY_SPORT_HUB ) ) //if Frsky protocol is used
34 struct ONE_MEASUREMENT mVoltCell_1_2 ;
35 struct ONE_MEASUREMENT mVoltCell_3_4 ;
36 struct ONE_MEASUREMENT mVoltCell_5_6 ;
37 #endif
41 class OXS_VOLTAGE {
42 public:
43 #ifdef DEBUG
44 OXS_VOLTAGE(HardwareSerial &print);
45 #else
46 OXS_VOLTAGE( uint8_t x );
47 #endif
48 VOLTAGEDATA voltageData ;
49 void setupVoltage( void );
50 void readSensor();
51 void resetValues();
52 void convertNtcVoltToTemp (int32_t &voltage ) ;
54 private:
55 #ifdef DEBUG
56 HardwareSerial* printer;
57 #endif
58 int readVoltage( int value) ; // read the voltage from the sensor specify by value
59 void voltageNrIncrease() ;
60 uint32_t calculateCell(int32_t V0 , int32_t V1 , int32_t V2 , uint8_t cellId , uint8_t maxNumberOfCells) ;
63 extern bool lowVoltage ;
65 #endif