#ifndef __CHARGER_H__
#define __CHARGER_H__

#include "smart_battery.h"

#define MAX_CHARGE_STAGES (3)
#define CHARGER_CURRENT_DEFAULTS(i) ( \
               i==0 ? 5.0 : \
               i==1 ? 3.0 : \
               i==2 ? 2.0 : \
               0.0 )
#define CHARGER_VTRIP_DEFAULT (4.20) /* volts */
#define MAX_VTRIP (4.25) /* volts */
#define CHARGER_VMIN_DEFAULT (3.25) /* volts - for balancing/discharging purposes */
#define BALANCE_VMIN (3.20) /* volts */
#define MAX_CHARGE_CURRENT (20.0) /* amps each */

typedef enum {CHARGER_IDLE, CHARGER_START, CHARGER_STAGES, CHARGER_STOP, 
	      CHARGER_POST, CHARGER_BALANCE_START, CHARGER_BALANCE,
	      CHARGER_DISCHARGE_START, CHARGER_DISCHARGE} AutoChargeState_t;

#define ChargerState(i) ( \
             i==CHARGER_IDLE ? "Idle" : \
             i==CHARGER_START ? "Start Charging" : \
             i==CHARGER_STAGES ? "Stages of Charging" : \
             i==CHARGER_STOP ? "Stopping" : \
             i==CHARGER_POST ? "Post-Charge" : \
             i==CHARGER_BALANCE_START ? "Start Balancing" : \
             i==CHARGER_BALANCE ? "Balancing" : \
             i==CHARGER_DISCHARGE_START ? "Start Discharging" : \
             i==CHARGER_DISCHARGE ? "Discharging" : \
             "Unknown" )

typedef struct {
  double vtrip; // voltage to signal next state
  double vmin; // minimum cell voltage for balancing cut-off
  double currents[MAX_CHARGE_STAGES]; // Amps of current for each stage
  int current_state; // from 0 to MAX_CHARGE_STATES
  char batts[MAX_BATTS]; // 1-charge it, 0-don't charge it
  int num_batts_to_charge; // decides how many amps to push out max
  int num_batts_on_charge; // decides how many amps to push out now
  AutoChargeState_t state;
} AutoCharger_t;

#endif /* __CHARGER_H__ */
