#include <stdio.h>
#define VOLTAGE_DISCONNECT 1 // Threshold for detecting disconnected battery
int main()
{
double pack_voltage;
double cell_voltage;
double jack_voltage;
if(pack_voltage<0.0 || jack_voltage<0.0){
fprintf(stderr,"ERROR: can't read voltages\n");
return -1;
}
if(pack_voltage<VOLTAGE_DISCONNECT){
pack_voltage = 0;
}
if(jack_voltage<VOLTAGE_DISCONNECT){
jack_voltage = 0;
}
cell_voltage = pack_voltage/2;
printf("\rPack: %0.2lfV Cell: %0.2lfV DC Jack: %0.2lfV ", \
pack_voltage, cell_voltage, jack_voltage);
fflush(stdout);
}
return 0;
}