/* Battery Holder library
 
 Copyright 2020 Christine Whybrow

 
 Unless required by applicable law or agreed to in writing,
 software distributed under the License is distributed on an "AS IS" BASIS, 
 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 See the License for the specific language governing permissions and
 limitations under the License.
 
 This library takes care of all the code to charge an individual battery, either AAA, AA.
 This is an example of constructors for NiMH AA Battery in each slot. 
 You can of course change this, & in that eventuality, you should vary the following 
 
    BatterySlot:      1       BatterySlot:      2       BatterySlot:      3       BatterySlot:      4
    PWN pin:          4       PWN pin:          6       PWN pin:          8       PWN pin:          10
    Relay pin:        5       Relay pin:        7       Relay pin:        9       Relay pin:        11
    Highside pin:     A0      Highside pin:     A3      Highside pin:     A6      Highside pin:     A9
    Lowside pin:      A1      Lowside pin:      A4      Lowside pin:      A7      Lowside pin:      A10
    Temperature pin;  A2      Temperature pin;  A5      Temperature pin;  A8      Temperature pin;  A11
    BatteryType:      2       BatteryType:      2       BatteryType:      2       BatteryType:      2
    Capacity:         2500    Capacity:         2500    Capacity:         2500    Capacity:         2500
    ChargeRate:       6       ChargeRate:       6       ChargeRate:       6       ChargeRate:       6
    INA219Adress:     0x40    INA219Adress:     0x41    INA219Adress:     0x42    INA219Adress:     0x43
           
 Please take care to assign the correct pins when constructing the individual battery circuit.

 I have used 3.3v from the Arduino Mega, to supply the TMP36 temperature sensor, as this gives better
 readings & stability!
 */

#ifndef BatteryHolder_h
#define BatteryHolder_h

#include "Arduino.h"
#include "Adafruit_INA219.h"

class BatteryHolder
{
  public:
    BatteryHolder (int slot, int PWM, int relay, uint8_t highside, uint8_t lowside, 
                  uint8_t temperature, int batteryType, float capacity, float chargeDivider, 
                  uint8_t address);
    bool    batteryUpdate();                        //main class function to charge battery
    bool    doesExist();                            //check if class created
    bool    setCapacity(float capacity);            //update capacity post constructor
    bool    setBatteryType(int batteryType);        //update battery type "
    bool    setChargeDivider(float chargerDivider); //change di/dt
            ~BatteryHolder();                       //class destructor
  
  private:
    int       _slot;            //slot, from left '0' to right '3'
    int       _PWM;             //digital pin to output PWM to MSFET
    int       _relay;           //pin to turn on or off charging
    uint8_t   _highside;        //checking voltaage at '+' side of battery
    uint8_t   _lowside;         //same, except at '-' terminal
    uint8_t   _temperature;     //set temp to STOP charging
    int       _batteryType;     //either AAA or AA NiMh or Lithium 18650
    float     _capacity;        //cpacity of battery in mAh
    float     _chargeDivider;   //current to charge as divisor of mAh
    uint8_t   _address;         //address of ina219 current sensor

};

#endif
