tortuga DataLogging Library: battery, speed, time, average...

Dependents:   TORTUGA_BLE

Fork of DataLogging by aapje monkey

Committer:
ptuytsch
Date:
Fri Jul 15 12:48:06 2016 +0000
Revision:
4:f91f45d52f9b
working datalogging on prototype itself

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ptuytsch 4:f91f45d52f9b 1 #include "mbed.h"
ptuytsch 4:f91f45d52f9b 2 #include "BatteryState.h"
ptuytsch 4:f91f45d52f9b 3 #define batVoltage_Factor_48V 0.001510643 //Voltage increase when readValue increases with 1.
ptuytsch 4:f91f45d52f9b 4 // calculated for max 60V
ptuytsch 4:f91f45d52f9b 5
ptuytsch 4:f91f45d52f9b 6
ptuytsch 4:f91f45d52f9b 7
ptuytsch 4:f91f45d52f9b 8 BatteryState::BatteryState(PinName pin, batteryType batType):
ptuytsch 4:f91f45d52f9b 9 batteryPin(pin),
ptuytsch 4:f91f45d52f9b 10 type(batType){
ptuytsch 4:f91f45d52f9b 11 }
ptuytsch 4:f91f45d52f9b 12
ptuytsch 4:f91f45d52f9b 13 uint8_t BatteryState::getBatteryPercentage(){
ptuytsch 4:f91f45d52f9b 14 uint16_t readValue = /*34500;*/batteryPin.read_u16();//reading the adc value
ptuytsch 4:f91f45d52f9b 15
ptuytsch 4:f91f45d52f9b 16 if (type == Battery48V){
ptuytsch 4:f91f45d52f9b 17 double BatVoltage = (readValue * batVoltage_Factor_48V); // convert it to battery voltage
ptuytsch 4:f91f45d52f9b 18
ptuytsch 4:f91f45d52f9b 19 if(BatVoltage > 54) return 100;
ptuytsch 4:f91f45d52f9b 20 else if (BatVoltage > 53.22) return 95;
ptuytsch 4:f91f45d52f9b 21 else if (BatVoltage > 52.86) return 90;
ptuytsch 4:f91f45d52f9b 22 else if (BatVoltage > 52.69) return 80;
ptuytsch 4:f91f45d52f9b 23 else if (BatVoltage > 52.53) return 70;
ptuytsch 4:f91f45d52f9b 24 else if (BatVoltage > 52.35) return 60;
ptuytsch 4:f91f45d52f9b 25 else if (BatVoltage > 52.18) return 50;
ptuytsch 4:f91f45d52f9b 26 else if (BatVoltage > 51.82) return 40;
ptuytsch 4:f91f45d52f9b 27 else if (BatVoltage > 51.47) return 30;
ptuytsch 4:f91f45d52f9b 28 else if (BatVoltage > 51.14) return 20;
ptuytsch 4:f91f45d52f9b 29 else if (BatVoltage > 50.61) return 10;
ptuytsch 4:f91f45d52f9b 30 else return 0;
ptuytsch 4:f91f45d52f9b 31 }
ptuytsch 4:f91f45d52f9b 32 else if (type == Battery12V){
ptuytsch 4:f91f45d52f9b 33 return 37; //TODO
ptuytsch 4:f91f45d52f9b 34 }
ptuytsch 4:f91f45d52f9b 35 return 0;
ptuytsch 4:f91f45d52f9b 36 }
ptuytsch 4:f91f45d52f9b 37