diff --git a/.pio/libdeps/esp32dev/18650CL-master/LICENSE b/.pio/libdeps/esp32dev/18650CL-master/LICENSE new file mode 100644 index 0000000..6bc87c7 --- /dev/null +++ b/.pio/libdeps/esp32dev/18650CL-master/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 Pangodream + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/.pio/libdeps/esp32dev/18650CL-master/README.md b/.pio/libdeps/esp32dev/18650CL-master/README.md new file mode 100644 index 0000000..c33da68 --- /dev/null +++ b/.pio/libdeps/esp32dev/18650CL-master/README.md @@ -0,0 +1,2 @@ +# 18650CL +Library to calculate 18650 charge in Arduino environment diff --git a/.pio/libdeps/esp32dev/18650CL-master/examples/GetChargeLevel/GetChargeLevel.ino b/.pio/libdeps/esp32dev/18650CL-master/examples/GetChargeLevel/GetChargeLevel.ino new file mode 100644 index 0000000..7ba0fd4 --- /dev/null +++ b/.pio/libdeps/esp32dev/18650CL-master/examples/GetChargeLevel/GetChargeLevel.ino @@ -0,0 +1,28 @@ +#include + +//#define ADC_PIN 34 +//#define CONV_FACTOR 1.7 +//#define READS 20 + +Pangodream_18650_CL BL; +/** + * If you need to change default values you can use it as + * Pangodream_18650_CL BL(ADC_PIN, CONV_FACTOR, READS); + */ + +void setup() { + Serial.begin(115200); +} + +void loop() { + Serial.print("Value from pin: "); + Serial.println(analogRead(34)); + Serial.print("Average value from pin: "); + Serial.println(BL.pinRead()); + Serial.print("Volts: "); + Serial.println(BL.getBatteryVolts()); + Serial.print("Charge level: "); + Serial.println(BL.getBatteryChargeLevel()); + Serial.println(""); + delay(1000); +} diff --git a/.pio/libdeps/esp32dev/18650CL-master/keywords.txt b/.pio/libdeps/esp32dev/18650CL-master/keywords.txt new file mode 100644 index 0000000..70cc330 --- /dev/null +++ b/.pio/libdeps/esp32dev/18650CL-master/keywords.txt @@ -0,0 +1,18 @@ +####################################### +# Syntax Coloring Map BH1750FVI +####################################### + +####################################### +# Datatypes (KEYWORD1) +####################################### + +Pangodream_18650_CL KEYWORD1 + +####################################### +# Methods and Functions (KEYWORD2) +####################################### +getBatteryChargeLevel KEYWORD2 +getBatteryVolts KEYWORD2 +getAnalogPin KEYWORD2 +pinRead KEYWORD2 +getConvFactor KEYWORD2 diff --git a/.pio/libdeps/esp32dev/18650CL-master/library.properties b/.pio/libdeps/esp32dev/18650CL-master/library.properties new file mode 100644 index 0000000..a0d14b7 --- /dev/null +++ b/.pio/libdeps/esp32dev/18650CL-master/library.properties @@ -0,0 +1,9 @@ +name=Pangodream_18650_CL +version=1.0.1 +author=Pangodream +maintainer=Pangodream +sentence=Pangodream Library to calculate 18650 charge +paragraph=Pangodream Library to calculate 18650 Ion-Li battery charge +category=Uncategorized +url=https://github.com/pangodream/18650CL +architectures=esp32 diff --git a/.pio/libdeps/esp32dev/18650CL-master/src/Pangodream_18650_CL.cpp b/.pio/libdeps/esp32dev/18650CL-master/src/Pangodream_18650_CL.cpp new file mode 100644 index 0000000..7e19bfb --- /dev/null +++ b/.pio/libdeps/esp32dev/18650CL-master/src/Pangodream_18650_CL.cpp @@ -0,0 +1,154 @@ +/* + MIT License + + Copyright (c) 2019 Pangodream + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ +#include "Arduino.h" +#include "Pangodream_18650_CL.h" + +Pangodream_18650_CL::Pangodream_18650_CL(int addressPin, double convFactor, int reads) +{ + _reads = reads; + _convFactor = convFactor; + _addressPin = addressPin; + _initVoltsArray(); +} + +Pangodream_18650_CL::Pangodream_18650_CL(int addressPin, double convFactor) +{ + _reads = DEF_READS; + _convFactor = convFactor; + _addressPin = addressPin; + _initVoltsArray(); +} + +Pangodream_18650_CL::Pangodream_18650_CL(int addressPin) +{ + _reads = DEF_READS; + _convFactor = DEF_CONV_FACTOR; + _addressPin = addressPin; + _initVoltsArray(); +} + +Pangodream_18650_CL::Pangodream_18650_CL() +{ + _reads = DEF_READS; + _convFactor = DEF_CONV_FACTOR; + _addressPin = DEF_PIN; + _initVoltsArray(); +} + +int Pangodream_18650_CL::getAnalogPin() +{ + return _addressPin; +} +double Pangodream_18650_CL::getConvFactor() +{ + return _convFactor; +} + +/** + * Loads each voltage value in its matching charge element (index) + */ +void Pangodream_18650_CL::_initVoltsArray(){ + _vs[0] = 7.800; + _vs[1] = 7.848; _vs[2] = 7.896; _vs[3] = 7.944; _vs[4] = 7.992; _vs[5] = 8.040; + _vs[6] = 8.088; _vs[7] = 8.136; _vs[8] = 8.184; _vs[9] = 8.232; _vs[10] = 8.280; + _vs[11] = 8.328; _vs[12] = 8.376; _vs[13] = 8.424; _vs[14] = 8.472; _vs[15] = 8.520; + _vs[16] = 8.568; _vs[17] = 8.616; _vs[18] = 8.664; _vs[19] = 8.712; _vs[20] = 8.760; + _vs[21] = 8.808; _vs[22] = 8.856; _vs[23] = 8.904; _vs[24] = 8.952; _vs[25] = 9.000; + _vs[26] = 9.048; _vs[27] = 9.096; _vs[28] = 9.144; _vs[29] = 9.192; _vs[30] = 9.240; + _vs[31] = 9.288; _vs[32] = 9.336; _vs[33] = 9.384; _vs[34] = 9.432; _vs[35] = 9.480; + _vs[36] = 9.528; _vs[37] = 9.576; _vs[38] = 9.624; _vs[39] = 9.672; _vs[40] = 9.720; + _vs[41] = 9.768; _vs[42] = 9.816; _vs[43] = 9.864; _vs[44] = 9.912; _vs[45] = 9.960; + _vs[46] = 10.008; _vs[47] = 10.056; _vs[48] = 10.104; _vs[49] = 10.152; _vs[50] = 10.200; + _vs[51] = 10.248; _vs[52] = 310.296; _vs[53] = 10.344; _vs[54] = 10.392; _vs[55] = 10.440; + _vs[56] = 10.488; _vs[57] = 10.536; _vs[58] = 10.584; _vs[59] = 10.632; _vs[60] = 10.680; + _vs[61] = 10.728; _vs[62] = 10.776; _vs[63] = 10.824; _vs[64] = 10.872; _vs[65] = 10.920; + _vs[66] = 10.968; _vs[67] = 11.016; _vs[68] = 11.064; _vs[69] = 11.112; _vs[70] = 11.160; + _vs[71] = 11.208; _vs[72] = 11.256; _vs[73] = 11.304; _vs[74] = 11.352; _vs[75] = 11.400; + _vs[76] = 11.448; _vs[77] = 11.496; _vs[78] = 11.544; _vs[79] = 11.592; _vs[80] = 11.640; + _vs[81] = 11.688; _vs[82] = 11.736; _vs[83] = 11.784; _vs[84] = 11.832; _vs[85] = 11.880; + _vs[86] = 11.928; _vs[87] = 11.976; _vs[88] = 12.024; _vs[89] = 12.072; _vs[90] = 12.120; + _vs[91] = 12.168; _vs[92] = 12.216; _vs[93] = 12.264; _vs[94] = 12.312; _vs[95] = 12.360; + _vs[96] = 12.408; _vs[97] = 12.456; _vs[98] = 12.504; _vs[99] = 12.552; _vs[100] = 12.600; +} + +int Pangodream_18650_CL::getBatteryChargeLevel() +{ + int readValue = _analogRead(_addressPin); + double volts = _analogReadToVolts(readValue); + int chargeLevel = _getChargeLevel(volts); + return chargeLevel; +} + +int Pangodream_18650_CL::pinRead(){ + return _analogRead(_addressPin); +} + +int Pangodream_18650_CL::_analogRead(int pinNumber){ + int totalValue = 0; + int averageValue = 0; + for(int i = 0; i < _reads; i++){ + totalValue += analogRead(pinNumber); + } + averageValue = totalValue / _reads; + return averageValue; +} +/** + * Performs a binary search to find the index corresponding to a voltage. + * The index of the array is the charge % +*/ +int Pangodream_18650_CL::_getChargeLevel(double volts){ + int idx = 50; + int prev = 0; + int half = 0; + if (volts >= 12.6){ + return 100; + } + if (volts <= 7.8){ + return 0; + } + while(true){ + half = abs(idx - prev) / 2; + prev = idx; + if(volts >= _vs[idx]){ + idx = idx + half; + }else{ + idx = idx - half; + } + if (prev == idx){ + break; + } + } + return idx; +} + +double Pangodream_18650_CL::_analogReadToVolts(int readValue){ + double volts; + volts = readValue * _convFactor / 1000; + return volts; +} + +double Pangodream_18650_CL::getBatteryVolts(){ + int readValue = analogRead(_addressPin); + return _analogReadToVolts(readValue); +} diff --git a/.pio/libdeps/esp32dev/18650CL-master/src/Pangodream_18650_CL.h b/.pio/libdeps/esp32dev/18650CL-master/src/Pangodream_18650_CL.h new file mode 100644 index 0000000..d38b0ed --- /dev/null +++ b/.pio/libdeps/esp32dev/18650CL-master/src/Pangodream_18650_CL.h @@ -0,0 +1,94 @@ +/* + MIT License + + Copyright (c) 2019 Pangodream + + Permission is hereby granted, free of charge, to any person obtaining a copy + of this software and associated documentation files (the "Software"), to deal + in the Software without restriction, including without limitation the rights + to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + copies of the Software, and to permit persons to whom the Software is + furnished to do so, subject to the following conditions: + + The above copyright notice and this permission notice shall be included in all + copies or substantial portions of the Software. + + THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + SOFTWARE. +*/ + +/* + * 18650 Ion-Li battery charge + */ + +#ifndef Pangodream_18650_CL_h +#define Pangodream_18650_CL_h + +#include "Arduino.h" + +#define DEF_PIN 34 +#define DEF_CONV_FACTOR 1.7 +#define DEF_READS 20 + +/* + * 18650 Ion-Li battery charge + * Calculates charge level of an 18650 Ion-Li battery + */ +class Pangodream_18650_CL { + public: + + /* + * Constructor + * @param addressPin, ADC pin number where the voltage divider is connected to + */ + Pangodream_18650_CL(int addressPin); + + /* + * Constructor + * @param addressPin, ADC pin number where the voltage divider is connected to + * @param convFactor, Convertion factor for analog read units to volts + */ + Pangodream_18650_CL(int addressPin, double convFactor); + + /* + * Constructor + * @param addressPin, ADC pin number where the voltage divider is connected to + * @param convFactor, Convertion factor for analog read units to volts + * @param reads, Number of reads of analog pin to calculate an average value + */ + Pangodream_18650_CL(int addressPin, double convFactor, int reads); + /* + * Constructor + */ + Pangodream_18650_CL(); + + /* + * Get the battery charge level (0-100) + * @return The calculated battery charge level + */ + int getBatteryChargeLevel(); + double getBatteryVolts(); + int getAnalogPin(); + int pinRead(); + double getConvFactor(); + + private: + + int _addressPin; //!< ADC pin used, default is GPIO34 - ADC1_6 + int _reads; //Number of reads of ADC pin to calculate an average value + double _convFactor; //!< Convertion factor to translate analog units to volts + double _vs[101]; //Array with voltage - charge definitions + + void _initVoltsArray(); + int _getChargeLevel(double volts); + int _analogRead(int pinNumber); + double _analogReadToVolts(int readValue); + +}; + +#endif \ No newline at end of file