Added getLegacyBatteryVoltage

This commit is contained in:
fgiudice98 2018-12-27 12:16:26 +01:00
parent 9d5fb85474
commit 979e56e14d
9 changed files with 14 additions and 8 deletions

View File

@ -523,7 +523,7 @@ static bool mspCommonProcessOutCommand(uint8_t cmdMSP, sbuf_t *dst, mspPostProce
break;
case MSP_ANALOG:
sbufWriteU8(dst, (uint8_t)constrain((getBatteryVoltage() + 5) / 10, 0, 255));
sbufWriteU8(dst, (uint8_t)constrain(getLegacyBatteryVoltage(), 0, 255));
sbufWriteU16(dst, (uint16_t)constrain(getMAhDrawn(), 0, 0xFFFF)); // milliamp hours drawn from battery
sbufWriteU16(dst, getRssi());
sbufWriteU16(dst, (int16_t)constrain(getAmperage(), -0x8000, 0x7FFF)); // send current in 0.01 A steps, range is -320A to 320A
@ -560,7 +560,7 @@ static bool mspCommonProcessOutCommand(uint8_t cmdMSP, sbuf_t *dst, mspPostProce
sbufWriteU16(dst, batteryConfig()->batteryCapacity); // in mAh
// battery state
sbufWriteU8(dst, (uint8_t)constrain((getBatteryVoltage() + 5) / 10, 0, 255)); // in 0.1V steps
sbufWriteU8(dst, (uint8_t)constrain(getLegacyBatteryVoltage(), 0, 255)); // in 0.1V steps
sbufWriteU16(dst, (uint16_t)constrain(getMAhDrawn(), 0, 0xFFFF)); // milliamp hours drawn from battery
sbufWriteU16(dst, (int16_t)constrain(getAmperage(), -0x8000, 0x7FFF)); // send current in 0.01 A steps, range is -320A to 320A

View File

@ -198,7 +198,7 @@ static void buildTelemetryFrame(uint8_t *packet)
if (rxFrSkySpiConfig()->useExternalAdc) {
a1Value = (uint8_t)((adcGetChannel(ADC_EXTERNAL1) & 0xfe0) >> 5);
} else {
a1Value = ((getBatteryVoltage() + 5) / 10) & 0x7f;
a1Value = getLegacyBatteryVoltage() & 0x7f;
}
frame[4] = a1Value;
}

View File

@ -480,6 +480,11 @@ uint16_t getBatteryVoltage(void)
return voltageMeter.filtered;
}
uint16_t getLegacyBatteryVoltage(void)
{
return (voltageMeter.filtered + 5) / 10;
}
uint16_t getBatteryVoltageLatest(void)
{
return voltageMeter.unfiltered;

View File

@ -86,6 +86,7 @@ float calculateVbatPidCompensation(void);
uint8_t calculateBatteryPercentageRemaining(void);
bool isBatteryVoltageConfigured(void);
uint16_t getBatteryVoltage(void);
uint16_t getLegacyBatteryVoltage(void);
uint16_t getBatteryVoltageLatest(void);
uint8_t getBatteryCellCount(void);
uint16_t getBatteryAverageCellVoltage(void);

View File

@ -146,7 +146,7 @@ STATIC_UNIT_TESTED uint16_t voltageAdcToVoltage(const uint16_t src, const voltag
{
// calculate battery voltage based on ADC reading
// result is Vbatt in 0.01V steps. 3.3V = ADC Vref, 0xFFF = 12bit adc, 110 = 10:1 voltage divider (10k:1k) * 100 for 0.01V
return ((((uint32_t)src * config->vbatscale * getVrefMv() / 10 + (0xFFF * 5)) / (0xFFF * config->vbatresdivval)) / config->vbatresdivmultiplier);
return ((((uint32_t)src * config->vbatscale * getVrefMv() / 10 + (0xFFF * 5)) / (0xFFF * config->vbatresdivval)) / config->vbatresdivmultiplier);
}
void voltageMeterADCRefresh(void)

View File

@ -203,7 +203,7 @@ void crsfFrameBatterySensor(sbuf_t *dst)
if (telemetryConfig()->report_cell_voltage) {
sbufWriteU16BigEndian(dst, (getBatteryAverageCellVoltage() + 5) / 10); // vbat is in units of 0.01V
} else {
sbufWriteU16BigEndian(dst, (getBatteryVoltage() + 5) / 10);
sbufWriteU16BigEndian(dst, getLegacyBatteryVoltage());
}
sbufWriteU16BigEndian(dst, getAmperage() / 10);
const uint32_t mAhDrawn = getMAhDrawn();

View File

@ -389,7 +389,7 @@ static void sendVoltageCells(void)
*/
static void sendVoltageAmp(void)
{
uint16_t voltage = (getBatteryVoltage() + 5) / 10;
uint16_t voltage = getLegacyBatteryVoltage();
const uint8_t cellCount = getBatteryCellCount();
if (telemetryConfig()->frsky_vfas_precision == FRSKY_VFAS_PRECISION_HIGH) {

View File

@ -279,7 +279,7 @@ static inline void updateAlarmBatteryStatus(HOTT_EAM_MSG_t *hottEAMMessage)
static inline void hottEAMUpdateBattery(HOTT_EAM_MSG_t *hottEAMMessage)
{
const uint16_t volt = (getBatteryVoltage() + 5) / 10;
const uint16_t volt = getLegacyBatteryVoltage();
hottEAMMessage->main_voltage_L = volt & 0xFF;
hottEAMMessage->main_voltage_H = volt >> 8;
hottEAMMessage->batt1_voltage_L = volt & 0xFF;

View File

@ -306,7 +306,7 @@ int32_t getSensorValue(uint8_t sensor)
{
switch (sensor) {
case EX_VOLTAGE:
return ((getBatteryVoltage() + 5) / 10);
return getLegacyBatteryVoltage();
break;
case EX_CURRENT: