acid-drop

- Hacking the planet from a LilyGo T-Deck using custom firmware
git clone git://git.acid.vegas/acid-drop.git
Log | Files | Refs | Archive | README | LICENSE

Pangodream_18650_CL.h (3065B)

      1 /*
      2   MIT License
      3   
      4   Copyright (c) 2019 Pangodream
      5   
      6   Permission is hereby granted, free of charge, to any person obtaining a copy
      7   of this software and associated documentation files (the "Software"), to deal
      8   in the Software without restriction, including without limitation the rights
      9   to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
     10   copies of the Software, and to permit persons to whom the Software is
     11   furnished to do so, subject to the following conditions:
     12   
     13   The above copyright notice and this permission notice shall be included in all
     14   copies or substantial portions of the Software.
     15   
     16   THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
     17   IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
     18   FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
     19   AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
     20   LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
     21   OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
     22   SOFTWARE.
     23 */
     24 
     25 /* 
     26  *  18650 Ion-Li battery charge
     27  */
     28   
     29 #ifndef Pangodream_18650_CL_h
     30 #define Pangodream_18650_CL_h
     31 
     32 #include "Arduino.h"
     33 
     34 #define DEF_PIN 34
     35 #define DEF_CONV_FACTOR 1.7
     36 #define DEF_READS 20
     37 
     38 /*
     39  * 18650 Ion-Li battery charge
     40  * Calculates charge level of an 18650 Ion-Li battery
     41  */
     42 class Pangodream_18650_CL {    
     43   public:  
     44     
     45     /*
     46     * Constructor
     47     * @param addressPin, ADC pin number where the voltage divider is connected to
     48     */
     49     Pangodream_18650_CL(int addressPin);
     50     
     51     /*
     52     * Constructor
     53     * @param addressPin, ADC pin number where the voltage divider is connected to
     54     * @param convFactor, Convertion factor for analog read units to volts
     55     */
     56     Pangodream_18650_CL(int addressPin, double convFactor);
     57     
     58     /*
     59     * Constructor
     60     * @param addressPin, ADC pin number where the voltage divider is connected to
     61     * @param convFactor, Convertion factor for analog read units to volts
     62     * @param reads, Number of reads of analog pin to calculate an average value
     63     */
     64     Pangodream_18650_CL(int addressPin, double convFactor, int reads);
     65     /*
     66     * Constructor
     67     */
     68     Pangodream_18650_CL();    
     69 
     70     /*
     71      * Get the battery charge level (0-100)
     72      * @return The calculated battery charge level
     73      */
     74     int getBatteryChargeLevel();
     75     double getBatteryVolts();
     76     int getAnalogPin();
     77     int pinRead();
     78     double getConvFactor();
     79        
     80   private:
     81 
     82     int    _addressPin;               //!< ADC pin used, default is GPIO34 - ADC1_6
     83     int    _reads;                    //Number of reads of ADC pin to calculate an average value
     84     double _convFactor;               //!< Convertion factor to translate analog units to volts
     85     double _vs[101];                 //Array with voltage - charge definitions
     86     
     87     void   _initVoltsArray();
     88     int    _getChargeLevel(double volts);
     89     int    _analogRead(int pinNumber);
     90     double _analogReadToVolts(int readValue);
     91     
     92 };
     93 
     94 #endif